-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Prepare datamodel for multi-environment #1765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
58 commits
Select commit
Hold shift + click to select a range
8e5c244
Refactor web store into atomic slices
justsomelegs 0737ff4
Fix project recreation keys and update web tests
justsomelegs 5e009d6
Merge upstream/main into web/atomic-store-refactor
justsomelegs a5bd205
Merge remote-tracking branch 'upstream/main' into HEAD
justsomelegs 6ff8f71
fix(web): stabilize browser test store selectors
justsomelegs f108f22
Merge branch 'main' into web/atomic-store-refactor
justsomelegs d20a403
Merge branch 'main' into web/atomic-store-refactor
justsomelegs 53b572f
Merge branch 'main' into web/atomic-store-refactor
justsomelegs 8ccfe3e
Surface environment and repository identity metadata
juliusmarminge d1437f1
Include client-runtime in release smoke checks
juliusmarminge deb215e
Treat explicit null environments distinctly
juliusmarminge a16ee82
Support nested repo remotes and late URL resolution
juliusmarminge 40ab9d9
Require environment IDs in web state sync
juliusmarminge 97ba9f9
Preserve remote scoped state across snapshot syncs
juliusmarminge 74250e9
non empty
juliusmarminge 240438d
fine
juliusmarminge 938f3d6
Cache repository identity lookups by TTL
juliusmarminge fc2de81
move
juliusmarminge 403ac96
kewl
juliusmarminge 70d3731
Handle ports in remote URL normalization
juliusmarminge babe73c
Handle empty server URLs and stale sidebar threads
juliusmarminge 54f905c
Adapt multi-environment store to atomic refactor base
juliusmarminge 010f452
Scope thread state by environment
juliusmarminge 24ac444
Add draft routes for logical projects
juliusmarminge 46c3251
Scope web native API and git queries by environment
juliusmarminge 5e27490
Rename native API wrappers to local and environment APIs
juliusmarminge 29b6385
Split local and environment API helpers
juliusmarminge 580fe19
Canonicalize promoted drafts to server thread routes
juliusmarminge aab603f
Fix server environment test config generation
juliusmarminge 74abf72
Scope bootstrap state to environment keys
juliusmarminge 583f97c
Handle promoted drafts across scoped thread refs
juliusmarminge 3e7db1d
Fix lint suppression comment syntax
juliusmarminge 29f0cbb
Refactor draft routing to use stable draft IDs
juliusmarminge ee72797
render optimization 1
juliusmarminge 8f76546
render optimization 2
juliusmarminge bb095b8
render optimization 3
juliusmarminge 8fc0a84
render optimization 4
juliusmarminge 339b035
redner optimization 5
juliusmarminge 5770c74
render optimization 6
juliusmarminge 2fb8b75
cleanup
juliusmarminge 216a587
Type sidebar thread status props
juliusmarminge 3696cb2
fix: replace redundant serverThread.id check with direct targetThread…
cursoragent 3d2973a
Guard composer traits UI without a thread target
juliusmarminge 5294bfd
fix: replace redundant serverThread.id check with direct targetThread…
cursor[bot] 1c843f4
fix: memoize scopeThreadRef in BranchToolbar to stabilize useMemo dep…
cursoragent 652aa66
fix: memoize scopeThreadRef in BranchToolbar to stabilize useMemo dep…
cursor[bot] bc35b85
Guard composer draft unload flush in non-DOM environments
juliusmarminge f18b15a
fix: remove self-provided RepositoryIdentityResolverLive from snapsho…
cursoragent b49a8a4
fix: remove self-provided RepositoryIdentityResolverLive from snapsho…
cursor[bot] 77dc225
Reduce sidebar shortcut recomputation
juliusmarminge 40b804c
fix: move repository identity resolution outside DB transaction in ge…
cursoragent e718b0d
Stabilize Git actions toast tests
juliusmarminge c1e7216
fix: move repository identity resolution outside DB transaction in ge…
cursor[bot] 18b9087
fix: fall back to threadRef when draftId is absent in BranchToolbar
cursoragent 6a24126
Merge remote-tracking branch 'origin/main' into ship-1765
juliusmarminge 3481ed8
Fix pending user input option selection
juliusmarminge 78aadd2
Stabilize pending input auto-advance callback
juliusmarminge aa92532
Use effect events for pending input option selection
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
apps/server/src/environment/Layers/ServerEnvironment.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import * as nodePath from "node:path"; | ||
| import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| import { expect, it } from "@effect/vitest"; | ||
| import { Effect, Exit, FileSystem, Layer, PlatformError } from "effect"; | ||
|
|
||
| import { deriveServerPaths, ServerConfig, type ServerConfigShape } from "../../config.ts"; | ||
| import { ServerEnvironment } from "../Services/ServerEnvironment.ts"; | ||
| import { ServerEnvironmentLive } from "./ServerEnvironment.ts"; | ||
|
|
||
| const makeServerEnvironmentLayer = (baseDir: string) => | ||
| ServerEnvironmentLive.pipe(Layer.provide(ServerConfig.layerTest(process.cwd(), baseDir))); | ||
|
|
||
| const makeServerConfig = Effect.fn(function* (baseDir: string) { | ||
| const derivedPaths = yield* deriveServerPaths(baseDir, undefined); | ||
|
|
||
| return { | ||
| ...derivedPaths, | ||
| logLevel: "Error", | ||
| traceMinLevel: "Info", | ||
| traceTimingEnabled: true, | ||
| traceBatchWindowMs: 200, | ||
| traceMaxBytes: 10 * 1024 * 1024, | ||
| traceMaxFiles: 10, | ||
| otlpTracesUrl: undefined, | ||
| otlpMetricsUrl: undefined, | ||
| otlpExportIntervalMs: 10_000, | ||
| otlpServiceName: "t3-server", | ||
| cwd: process.cwd(), | ||
| baseDir, | ||
| mode: "web", | ||
| autoBootstrapProjectFromCwd: false, | ||
| logWebSocketEvents: false, | ||
| port: 0, | ||
| host: undefined, | ||
| authToken: undefined, | ||
| staticDir: undefined, | ||
| devUrl: undefined, | ||
| noBrowser: false, | ||
| } satisfies ServerConfigShape; | ||
| }); | ||
|
|
||
| it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => { | ||
| it.effect("persists the environment id across service restarts", () => | ||
| Effect.gen(function* () { | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const baseDir = yield* fileSystem.makeTempDirectoryScoped({ | ||
| prefix: "t3-server-environment-test-", | ||
| }); | ||
|
|
||
| const first = yield* Effect.gen(function* () { | ||
| const serverEnvironment = yield* ServerEnvironment; | ||
| return yield* serverEnvironment.getDescriptor; | ||
| }).pipe(Effect.provide(makeServerEnvironmentLayer(baseDir))); | ||
| const second = yield* Effect.gen(function* () { | ||
| const serverEnvironment = yield* ServerEnvironment; | ||
| return yield* serverEnvironment.getDescriptor; | ||
| }).pipe(Effect.provide(makeServerEnvironmentLayer(baseDir))); | ||
|
|
||
| expect(first.environmentId).toBe(second.environmentId); | ||
| expect(second.capabilities.repositoryIdentity).toBe(true); | ||
| }), | ||
| ); | ||
|
|
||
| it.effect("fails instead of overwriting a persisted id when reading the file errors", () => | ||
| Effect.gen(function* () { | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const baseDir = yield* fileSystem.makeTempDirectoryScoped({ | ||
| prefix: "t3-server-environment-read-error-test-", | ||
| }); | ||
| const serverConfig = yield* makeServerConfig(baseDir); | ||
| const environmentIdPath = serverConfig.environmentIdPath; | ||
| yield* fileSystem.makeDirectory(nodePath.dirname(environmentIdPath), { recursive: true }); | ||
| yield* fileSystem.writeFileString(environmentIdPath, "persisted-environment-id\n"); | ||
| const writeAttempts: string[] = []; | ||
| const failingFileSystemLayer = FileSystem.layerNoop({ | ||
| exists: (path) => Effect.succeed(path === environmentIdPath), | ||
| readFileString: (path) => | ||
| path === environmentIdPath | ||
| ? Effect.fail( | ||
| PlatformError.systemError({ | ||
| _tag: "PermissionDenied", | ||
| module: "FileSystem", | ||
| method: "readFileString", | ||
| description: "permission denied", | ||
| pathOrDescriptor: path, | ||
| }), | ||
| ) | ||
| : Effect.fail( | ||
| PlatformError.systemError({ | ||
| _tag: "NotFound", | ||
| module: "FileSystem", | ||
| method: "readFileString", | ||
| description: "not found", | ||
| pathOrDescriptor: path, | ||
| }), | ||
| ), | ||
| writeFileString: (path) => { | ||
| writeAttempts.push(path); | ||
| return Effect.void; | ||
| }, | ||
| }); | ||
|
|
||
| const exit = yield* Effect.gen(function* () { | ||
| const serverEnvironment = yield* ServerEnvironment; | ||
| return yield* serverEnvironment.getDescriptor; | ||
| }).pipe( | ||
| Effect.provide( | ||
| ServerEnvironmentLive.pipe( | ||
| Layer.provide( | ||
| Layer.merge(Layer.succeed(ServerConfig, serverConfig), failingFileSystemLayer), | ||
| ), | ||
| ), | ||
| ), | ||
| Effect.exit, | ||
| ); | ||
|
|
||
| expect(Exit.isFailure(exit)).toBe(true); | ||
| expect(writeAttempts).toEqual([]); | ||
| expect(yield* fileSystem.readFileString(environmentIdPath)).toBe( | ||
| "persisted-environment-id\n", | ||
| ); | ||
| }), | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { EnvironmentId, type ExecutionEnvironmentDescriptor } from "@t3tools/contracts"; | ||
| import { Effect, FileSystem, Layer, Path, Random } from "effect"; | ||
|
|
||
| import { ServerConfig } from "../../config.ts"; | ||
| import { ServerEnvironment, type ServerEnvironmentShape } from "../Services/ServerEnvironment.ts"; | ||
| import { version } from "../../../package.json" with { type: "json" }; | ||
|
|
||
| function platformOs(): ExecutionEnvironmentDescriptor["platform"]["os"] { | ||
| switch (process.platform) { | ||
| case "darwin": | ||
| return "darwin"; | ||
| case "linux": | ||
| return "linux"; | ||
| case "win32": | ||
| return "windows"; | ||
| default: | ||
| return "unknown"; | ||
| } | ||
| } | ||
|
|
||
| function platformArch(): ExecutionEnvironmentDescriptor["platform"]["arch"] { | ||
| switch (process.arch) { | ||
| case "arm64": | ||
| return "arm64"; | ||
| case "x64": | ||
| return "x64"; | ||
| default: | ||
| return "other"; | ||
| } | ||
| } | ||
|
|
||
| export const makeServerEnvironment = Effect.fn("makeServerEnvironment")(function* () { | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const path = yield* Path.Path; | ||
| const serverConfig = yield* ServerConfig; | ||
|
|
||
| const readPersistedEnvironmentId = Effect.gen(function* () { | ||
| const exists = yield* fileSystem | ||
| .exists(serverConfig.environmentIdPath) | ||
| .pipe(Effect.orElseSucceed(() => false)); | ||
| if (!exists) { | ||
| return null; | ||
| } | ||
|
|
||
| const raw = yield* fileSystem | ||
| .readFileString(serverConfig.environmentIdPath) | ||
| .pipe(Effect.map((value) => value.trim())); | ||
|
|
||
| return raw.length > 0 ? raw : null; | ||
| }); | ||
macroscopeapp[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const persistEnvironmentId = (value: string) => | ||
| fileSystem.writeFileString(serverConfig.environmentIdPath, `${value}\n`); | ||
|
|
||
| const environmentIdRaw = yield* Effect.gen(function* () { | ||
| const persisted = yield* readPersistedEnvironmentId; | ||
| if (persisted) { | ||
| return persisted; | ||
| } | ||
|
|
||
| const generated = yield* Random.nextUUIDv4; | ||
| yield* persistEnvironmentId(generated); | ||
| return generated; | ||
| }); | ||
|
|
||
| const environmentId = EnvironmentId.makeUnsafe(environmentIdRaw); | ||
| const cwdBaseName = path.basename(serverConfig.cwd).trim(); | ||
| const label = | ||
| serverConfig.mode === "desktop" | ||
| ? "Local environment" | ||
| : cwdBaseName.length > 0 | ||
| ? cwdBaseName | ||
| : "T3 environment"; | ||
|
|
||
| const descriptor: ExecutionEnvironmentDescriptor = { | ||
| environmentId, | ||
| label, | ||
| platform: { | ||
| os: platformOs(), | ||
| arch: platformArch(), | ||
| }, | ||
| serverVersion: version, | ||
| capabilities: { | ||
| repositoryIdentity: true, | ||
| }, | ||
| }; | ||
|
|
||
| return { | ||
| getEnvironmentId: Effect.succeed(environmentId), | ||
| getDescriptor: Effect.succeed(descriptor), | ||
| } satisfies ServerEnvironmentShape; | ||
| }); | ||
|
|
||
| export const ServerEnvironmentLive = Layer.effect(ServerEnvironment, makeServerEnvironment()); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import type { EnvironmentId, ExecutionEnvironmentDescriptor } from "@t3tools/contracts"; | ||
| import { ServiceMap } from "effect"; | ||
| import type { Effect } from "effect"; | ||
|
|
||
| export interface ServerEnvironmentShape { | ||
| readonly getEnvironmentId: Effect.Effect<EnvironmentId>; | ||
| readonly getDescriptor: Effect.Effect<ExecutionEnvironmentDescriptor>; | ||
| } | ||
|
|
||
| export class ServerEnvironment extends ServiceMap.Service< | ||
| ServerEnvironment, | ||
| ServerEnvironmentShape | ||
| >()("t3/environment/Services/ServerEnvironment") {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.