+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
196 lines
7.5 KiB
TypeScript
196 lines
7.5 KiB
TypeScript
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
import { assert, it } from "@effect/vitest";
|
|
import { ProjectId } from "@t3tools/contracts";
|
|
import * as Effect from "effect/Effect";
|
|
import * as FileSystem from "effect/FileSystem";
|
|
import * as Layer from "effect/Layer";
|
|
import * as Path from "effect/Path";
|
|
import * as Schema from "effect/Schema";
|
|
import * as Stream from "effect/Stream";
|
|
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
|
|
import * as CheckpointStore from "../checkpointing/CheckpointStore.ts";
|
|
import * as ServerConfig from "../config.ts";
|
|
import * as GitWorkflow from "../git/GitWorkflowService.ts";
|
|
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
|
|
|
|
import * as McpSessionRegistryTestkit from "../mcp/McpSessionRegistry.testkit.ts";
|
|
import { makeSqlitePersistenceLive } from "../persistence/Layers/Sqlite.ts";
|
|
import { runMigrations } from "../persistence/Migrations.ts";
|
|
import * as ProjectEnrichmentService from "../project/ProjectEnrichmentService.ts";
|
|
import * as ProjectService from "../project/ProjectService.ts";
|
|
import * as ProviderInstanceRegistry from "../provider/Services/ProviderInstanceRegistry.ts";
|
|
import * as ServerSettings from "../serverSettings.ts";
|
|
import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
|
|
import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
|
|
import * as VcsProcess from "../vcs/VcsProcess.ts";
|
|
import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
|
|
import * as LegacyV1ThreadImporter from "./legacy/LegacyV1ThreadImporter.ts";
|
|
import { OrchestrationV2LayerLive, ProjectServiceLayerLive } from "./runtimeLayer.ts";
|
|
|
|
const projectId = ProjectId.make("project:upgrade");
|
|
const icon = { kind: "emoji", emoji: "🦊" } as const;
|
|
const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
|
|
|
|
const expectedSettings = {
|
|
default_thread_env_mode: "worktree",
|
|
auto_pull: 1,
|
|
favicon_path: "brand/icon.svg",
|
|
project_icon_json: encodeJson(icon),
|
|
};
|
|
|
|
const readSettings = Effect.gen(function* () {
|
|
const sql = yield* SqlClient.SqlClient;
|
|
const rows = yield* sql<typeof expectedSettings>`
|
|
SELECT default_thread_env_mode, auto_pull, favicon_path, project_icon_json
|
|
FROM projection_projects
|
|
WHERE project_id = ${projectId}
|
|
`;
|
|
return rows[0];
|
|
});
|
|
|
|
/** A released V1 database at migration 54 whose project carries all four settings. */
|
|
const seedV1Database = Effect.gen(function* () {
|
|
const sql = yield* SqlClient.SqlClient;
|
|
yield* runMigrations({ toMigrationInclusive: 54 });
|
|
const events = [
|
|
{
|
|
type: "project.created",
|
|
payload: {
|
|
projectId,
|
|
title: "Upgrade",
|
|
workspaceRoot: "/work/upgrade",
|
|
defaultModelSelection: null,
|
|
faviconPath: null,
|
|
projectIcon: null,
|
|
scripts: [],
|
|
createdAt: "2026-01-01T00:00:00.000Z",
|
|
updatedAt: "2026-01-01T00:00:00.000Z",
|
|
},
|
|
},
|
|
{
|
|
type: "project.meta-updated",
|
|
payload: {
|
|
projectId,
|
|
defaultThreadEnvMode: "worktree",
|
|
autoPull: true,
|
|
faviconPath: "brand/icon.svg",
|
|
projectIcon: icon,
|
|
updatedAt: "2026-01-02T00:00:00.000Z",
|
|
},
|
|
},
|
|
] as const;
|
|
for (const [version, event] of events.entries()) {
|
|
yield* sql`
|
|
INSERT INTO orchestration_events (
|
|
event_id, aggregate_kind, stream_id, stream_version, event_type, occurred_at,
|
|
command_id, causation_event_id, correlation_id, actor_kind, payload_json, metadata_json
|
|
) VALUES (
|
|
${`v1:${event.type}`}, 'project', ${projectId}, ${version}, ${event.type},
|
|
${event.payload.updatedAt}, ${`command:${event.type}`}, NULL, ${`command:${event.type}`},
|
|
'client', ${encodeJson(event.payload)}, '{}'
|
|
)
|
|
`;
|
|
}
|
|
// The V1 projector had applied both events before the upgrade.
|
|
yield* sql`
|
|
INSERT INTO projection_projects (
|
|
project_id, title, workspace_root, default_model_selection_json, default_thread_env_mode,
|
|
auto_pull, favicon_path, project_icon_json, scripts_json, created_at, updated_at, deleted_at
|
|
) VALUES (
|
|
${projectId}, 'Upgrade', '/work/upgrade', NULL, ${expectedSettings.default_thread_env_mode},
|
|
1, ${expectedSettings.favicon_path}, ${expectedSettings.project_icon_json}, '[]',
|
|
'2026-01-01T00:00:00.000Z', '2026-01-02T00:00:00.000Z', NULL
|
|
)
|
|
`;
|
|
yield* sql`
|
|
INSERT INTO projection_state (projector, last_applied_sequence, updated_at)
|
|
VALUES ('projection.projects', 2, '2026-01-02T00:00:00.000Z')
|
|
`;
|
|
});
|
|
|
|
const unusedEnrichment = {
|
|
repositoryIdentity: null,
|
|
faviconPath: null,
|
|
repositoryIdentityResolved: false,
|
|
};
|
|
|
|
/** The production V2 runtime and project service against one file-backed database. */
|
|
const makeRuntimeLayer = (dbPath: string) => {
|
|
const platform = Layer.merge(
|
|
NodeServices.layer,
|
|
Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({
|
|
resolveLink: () => Effect.die("unused"),
|
|
}),
|
|
);
|
|
const serverConfig = ServerConfig.layerTest(process.cwd(), {
|
|
prefix: "t3-project-upgrade-",
|
|
});
|
|
const checkpointStore = CheckpointStore.layer.pipe(
|
|
Layer.provide(
|
|
VcsDriverRegistry.layer.pipe(
|
|
Layer.provide(VcsProcess.layer),
|
|
Layer.provide(serverConfig),
|
|
Layer.provide(platform),
|
|
),
|
|
),
|
|
);
|
|
return Layer.mergeAll(
|
|
OrchestrationV2LayerLive.pipe(Layer.provide(ProjectServiceLayerLive)),
|
|
ProjectServiceLayerLive,
|
|
).pipe(
|
|
Layer.provide(
|
|
Layer.mock(ProjectEnrichmentService.ProjectEnrichmentService)({
|
|
peek: () => Effect.succeed(unusedEnrichment),
|
|
getAvailable: () => Effect.succeed(unusedEnrichment),
|
|
invalidate: () => Effect.void,
|
|
}),
|
|
),
|
|
Layer.provide(
|
|
Layer.mock(WorkspacePaths.WorkspacePaths)({
|
|
normalizeWorkspaceRoot: (workspaceRoot) => Effect.succeed(workspaceRoot),
|
|
}),
|
|
),
|
|
Layer.provide(McpSessionRegistryTestkit.layer),
|
|
Layer.provideMerge(makeSqlitePersistenceLive(dbPath)),
|
|
Layer.provide(checkpointStore),
|
|
Layer.provide(serverConfig),
|
|
Layer.provide(ServerSettings.layerTest()),
|
|
Layer.provide(
|
|
Layer.succeed(ProviderInstanceRegistry.ProviderInstanceRegistry, {
|
|
getInstance: () => Effect.succeed(undefined),
|
|
listInstances: Effect.succeed([]),
|
|
listUnavailable: Effect.succeed([]),
|
|
streamChanges: Stream.empty,
|
|
subscribeChanges: Effect.never,
|
|
}),
|
|
),
|
|
Layer.provide(
|
|
Layer.mock(GitWorkflow.GitWorkflowService)({
|
|
pruneWorktrees: () => Effect.void,
|
|
}),
|
|
),
|
|
Layer.provide(platform),
|
|
);
|
|
};
|
|
|
|
it.live("keeps project settings through the V2 migrations and the first V2 boot", () =>
|
|
Effect.scoped(
|
|
Effect.gen(function* () {
|
|
const fs = yield* FileSystem.FileSystem;
|
|
const path = yield* Path.Path;
|
|
const stateDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-project-upgrade-" });
|
|
const dbPath = path.join(stateDir, "statev2.sqlite");
|
|
|
|
// Seed the released V1 schema, then boot the V2 runtime, which runs 055+, on the same file.
|
|
yield* seedV1Database.pipe(Effect.provide(NodeSqliteClient.layer({ filename: dbPath })));
|
|
yield* Effect.gen(function* () {
|
|
yield* (yield* LegacyV1ThreadImporter.LegacyV1ThreadImporter).reconcileShells;
|
|
assert.deepEqual(yield* readSettings, expectedSettings);
|
|
const project = yield* (yield* ProjectService.ProjectService).getById(projectId);
|
|
assert.equal(project._tag, "Some");
|
|
}).pipe(Effect.provide(makeRuntimeLayer(dbPath)));
|
|
}),
|
|
).pipe(Effect.provide(NodeServices.layer)),
|
|
);
|