Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
import { assert, it } from "@effect/vitest";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import * as SqlClient from "effect/unstable/sql/SqlClient";
import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
import * as RepositoryIdentityResolver from "../../project/RepositoryIdentityResolver.ts";
import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
import * as ThreadBackgroundLiveness from "../ThreadBackgroundLiveness.ts";
import * as ThreadPlanProgress from "../ThreadPlanProgress.ts";
import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
it.effect(
"ProjectionSnapshotQuery dedupes repository identity resolution by workspace root and skips deleted projects for shell snapshots",
() => {
const resolveCalls: string[] = [];
const layer = OrchestrationProjectionSnapshotQueryLive.pipe(
Layer.provide(ThreadBackgroundLiveness.layer),
Layer.provide(ThreadPlanProgress.layer),
Layer.provideMerge(
Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, {
resolve: (cwd: string) =>
Effect.sync(() => {
resolveCalls.push(cwd);
return {
canonicalKey: `github.com/acme${cwd}`,
locator: {
source: "git-remote" as const,
remoteName: "origin",
remoteUrl: `https://github.com/acme${cwd}.git`,
},
rootPath: cwd,
};
}),
}),
),
Layer.provideMerge(SqlitePersistenceMemory),
);
return Effect.gen(function* () {
const snapshotQuery = yield* ProjectionSnapshotQuery;
const sql = yield* SqlClient.SqlClient;
yield* sql`DELETE FROM projection_projects`;
yield* sql`DELETE FROM projection_threads`;
yield* sql`DELETE FROM projection_turns`;
yield* sql`DELETE FROM projection_state`;
yield* sql`
INSERT INTO projection_projects (
project_id,
title,
workspace_root,
default_model_selection_json,
scripts_json,
created_at,
updated_at,
deleted_at
)
VALUES
(
'project-1',
'Shared Project 1',
'/tmp/shared-root',
'{"provider":"codex","model":"gpt-5-codex"}',
'[]',
'2026-04-04T00:00:00.000Z',
'2026-04-04T00:00:01.000Z',
NULL
),
(
'project-2',
'Shared Project 2',
'/tmp/shared-root',
'{"provider":"codex","model":"gpt-5-codex"}',
'[]',
'2026-04-04T00:00:02.000Z',
'2026-04-04T00:00:03.000Z',
NULL
),
(
'project-3',
'Deleted Project',
'/tmp/deleted-root',
'{"provider":"codex","model":"gpt-5-codex"}',
'[]',
'2026-04-04T00:00:04.000Z',
'2026-04-04T00:00:05.000Z',
'2026-04-04T00:00:06.000Z'
)
`;
const shellSnapshot = yield* snapshotQuery.getShellSnapshot();
assert.deepStrictEqual(resolveCalls.toSorted(), ["/tmp/shared-root"]);
assert.equal(shellSnapshot.projects.length, 2);
assert.equal(shellSnapshot.projects[0]?.repositoryIdentity?.rootPath, "/tmp/shared-root");
assert.equal(shellSnapshot.projects[1]?.repositoryIdentity?.rootPath, "/tmp/shared-root");
resolveCalls.length = 0;
const fullSnapshot = yield* snapshotQuery.getSnapshot();
assert.deepStrictEqual(resolveCalls.toSorted(), ["/tmp/deleted-root", "/tmp/shared-root"]);
assert.equal(fullSnapshot.projects.length, 3);
assert.equal(fullSnapshot.projects[2]?.repositoryIdentity?.rootPath, "/tmp/deleted-root");
}).pipe(Effect.provide(layer));
},
);