Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import * as SqlClient from "effect/unstable/sql/SqlClient";
6
7import { ServerConfig } from "../../config.ts";
8import { SqlitePersistenceMemory } from "../../persistence/Layers/Sqlite.ts";
9import * as ProjectEnrichment from "../../project/ProjectEnrichmentService.ts";
10import * as ProjectFaviconResolver from "../../project/ProjectFaviconResolver.ts";
11import * as RepositoryIdentityResolver from "../../project/RepositoryIdentityResolver.ts";
12import { ProjectionSnapshotQuery } from "../Services/ProjectionSnapshotQuery.ts";
13import * as ThreadBackgroundLiveness from "../ThreadBackgroundLiveness.ts";
14import * as ThreadPlanProgress from "../ThreadPlanProgress.ts";
15import { OrchestrationProjectionSnapshotQueryLive } from "./ProjectionSnapshotQuery.ts";
16
17const metadataLayer = Layer.merge(
18 Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, {
19 resolve: () => Effect.succeed(null),
20 }),
21 Layer.succeed(ProjectFaviconResolver.ProjectFaviconResolver, {
22 resolvePath: () => Effect.succeed(null),
23 }),
24);
25
26const TestLayer = OrchestrationProjectionSnapshotQueryLive.pipe(
27 Layer.provideMerge(ThreadBackgroundLiveness.layer),
28 Layer.provideMerge(ThreadPlanProgress.layer),
29 Layer.provideMerge(ProjectEnrichment.layer),
30 Layer.provideMerge(metadataLayer),
31 Layer.provideMerge(SqlitePersistenceMemory),
32 Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "projection-search-test-" })),
33 Layer.provide(NodeServices.layer),
34);
35
36it.effect("search uses v2 visibility while legacy transcripts are still lazy", () =>
37 Effect.gen(function* () {
38 const sql = yield* SqlClient.SqlClient;
39 const query = yield* ProjectionSnapshotQuery;
40 const now = "2026-08-29T00:00:00.000Z";
41 yield* sql`
42 INSERT INTO projection_projects (
43 project_id, title, workspace_root, default_model_selection_json,
44 scripts_json, created_at, updated_at, deleted_at
45 ) VALUES (
46 'project:search', 'Search', '/tmp/search', NULL,
47 '[]', ${now}, ${now}, NULL
48 )
49 `;
50 yield* sql`
51 INSERT INTO projection_threads (
52 thread_id, project_id, title, model_selection_json, runtime_mode,
53 interaction_mode, branch, worktree_path, latest_turn_id, created_at,
54 updated_at, archived_at, settled_override, settled_at, deleted_at
55 ) VALUES
56 ('thread:active', 'project:search', 'Active', '{"instanceId":"codex","model":"gpt-5.4"}', 'full-access', 'default', NULL, NULL, NULL, ${now}, ${now}, NULL, NULL, NULL, NULL),
57 ('thread:archived', 'project:search', 'Archived', '{"instanceId":"codex","model":"gpt-5.4"}', 'full-access', 'default', NULL, NULL, NULL, ${now}, ${now}, NULL, NULL, NULL, NULL),
58 ('thread:deleted', 'project:search', 'Deleted', '{"instanceId":"codex","model":"gpt-5.4"}', 'full-access', 'default', NULL, NULL, NULL, ${now}, ${now}, NULL, NULL, NULL, NULL),
59 ('thread:assistant', 'project:search', 'Assistant', '{"instanceId":"codex","model":"gpt-5.4"}', 'full-access', 'default', NULL, NULL, 'turn:assistant', ${now}, ${now}, NULL, NULL, NULL, NULL)
60 `;
61 yield* sql`
62 INSERT INTO projection_thread_messages (
63 message_id, thread_id, turn_id, role, text, attachments_json,
64 is_streaming, created_at, updated_at
65 ) VALUES
66 ('message:active', 'thread:active', NULL, 'user', 'migration needle active', '[]', 0, ${now}, ${now}),
67 ('message:archived', 'thread:archived', NULL, 'user', 'migration needle archived', '[]', 0, ${now}, ${now}),
68 ('message:deleted', 'thread:deleted', NULL, 'user', 'migration needle deleted', '[]', 0, ${now}, ${now}),
69 ('message:orphan-assistant', 'thread:assistant', NULL, 'assistant', 'migration needle orphan', '[]', 0, ${now}, ${now}),
70 ('message:assistant', 'thread:assistant', 'turn:assistant', 'assistant', 'migration needle answer', '[]', 0, ${now}, ${now})
71 `;
72 yield* sql`
73 INSERT INTO projection_turns (
74 turn_id, thread_id, state, requested_at, started_at, completed_at,
75 assistant_message_id, checkpoint_files_json,
76 source_proposed_plan_thread_id, source_proposed_plan_id
77 ) VALUES (
78 'turn:assistant', 'thread:assistant', 'completed', ${now}, ${now}, ${now},
79 'message:assistant', '[]', NULL, NULL
80 )
81 `;
82 yield* sql`
83 INSERT INTO orchestration_v2_projection_threads (
84 thread_id, project_id, title, default_provider, provider_instance_id,
85 runtime_mode, interaction_mode, active_provider_thread_id, created_at,
86 updated_at, archived_at, deleted_at, payload_json
87 ) VALUES
88 ('thread:active', 'project:search', 'Active', 'codex', 'codex', 'full-access', 'default', NULL, ${now}, ${now}, NULL, NULL, '{}'),
89 ('thread:archived', 'project:search', 'Archived', 'codex', 'codex', 'full-access', 'default', NULL, ${now}, ${now}, ${now}, NULL, '{}'),
90 ('thread:deleted', 'project:search', 'Deleted', 'codex', 'codex', 'full-access', 'default', NULL, ${now}, ${now}, NULL, ${now}, '{}')
91 `;
92
93 const result = yield* query.searchThreads({ query: "migration needle", limit: 20 });
94 assert.deepEqual(
95 result.matches.map((match) => [match.threadId, match.source, match.snippet]),
96 [
97 ["thread:active", "user", "migration needle active"],
98 ["thread:assistant", "assistant", "migration needle answer"],
99 ],
100 );
101 }).pipe(Effect.provide(TestLayer)),
102);