@@ -3503,6 +3503,77 @@ it.effect("omits foreign-host PRs from legacy snapshots while preserving native
35033503 } ) . pipe ( Effect . provide ( layer ) ) ;
35043504} ) ;
35053505
3506+ it . effect (
3507+ "lists linked threads like the shell snapshot, in one query and without identities" ,
3508+ ( ) => {
3509+ const resolved : string [ ] = [ ] ;
3510+ const layer = OrchestrationProjectionSnapshotQueryLive . pipe (
3511+ Layer . provide ( ThreadBackgroundLiveness . layer ) ,
3512+ Layer . provide ( ThreadPlanProgress . layer ) ,
3513+ Layer . provide (
3514+ Layer . succeed ( RepositoryIdentityResolver . RepositoryIdentityResolver , {
3515+ resolve : ( root ) =>
3516+ Effect . sync ( ( ) => {
3517+ resolved . push ( root ) ;
3518+ return null ;
3519+ } ) ,
3520+ } ) ,
3521+ ) ,
3522+ Layer . provideMerge ( SqlitePersistenceMemory ) ,
3523+ ) ;
3524+ return Effect . gen ( function * ( ) {
3525+ const sql = yield * SqlClient . SqlClient ;
3526+ const query = yield * ProjectionSnapshotQuery ;
3527+ yield * sql `INSERT INTO projection_projects (project_id, title, workspace_root, scripts_json, created_at, updated_at)
3528+ VALUES ('p1', 'One', '/one', '[]', '2026-09-01T00:00:00Z', '2026-09-01T00:00:00Z'),
3529+ ('p2', 'Two', '/two', '[]', '2026-09-01T00:00:00Z', '2026-09-01T00:00:00Z')` ;
3530+ yield * sql `INSERT INTO projection_threads (thread_id, project_id, title, model_selection_json, runtime_mode, interaction_mode, created_at, updated_at, archived_at, deleted_at, settled_override, settled_at)
3531+ VALUES
3532+ ('t-late', 'p1', 'Late', '{"provider":"codex","model":"gpt-5"}', 'full-access', 'default', '2026-09-03T00:00:00Z', '2026-09-03T00:00:00Z', NULL, NULL, 'settled', '2026-09-04T00:00:00Z'),
3533+ ('t-early', 'p2', 'Early', '{"provider":"codex","model":"gpt-5"}', 'full-access', 'default', '2026-09-01T00:00:00Z', '2026-09-01T00:00:00Z', NULL, NULL, NULL, NULL),
3534+ ('t-first', 'p1', 'First', '{"provider":"codex","model":"gpt-5"}', 'full-access', 'default', '2026-09-02T00:00:00Z', '2026-09-02T00:00:00Z', NULL, NULL, NULL, NULL),
3535+ ('t-plain', 'p1', 'Plain', '{"provider":"codex","model":"gpt-5"}', 'full-access', 'default', '2026-09-02T00:00:00Z', '2026-09-02T00:00:00Z', NULL, NULL, NULL, NULL),
3536+ ('t-archived', 'p1', 'Archived', '{"provider":"codex","model":"gpt-5"}', 'full-access', 'default', '2026-09-02T00:00:00Z', '2026-09-02T00:00:00Z', '2026-09-05T00:00:00Z', NULL, NULL, NULL),
3537+ ('t-deleted', 'p1', 'Deleted', '{"provider":"codex","model":"gpt-5"}', 'full-access', 'default', '2026-09-02T00:00:00Z', '2026-09-02T00:00:00Z', NULL, '2026-09-05T00:00:00Z', NULL, NULL)` ;
3538+ yield * sql `INSERT INTO projection_thread_pull_requests (thread_id, host, repository, number, url, source, linked_at, snapshot_json)
3539+ VALUES
3540+ ('t-late', 'github.com', 'acme/web', 3, 'https://github.com/acme/web/pull/3', 'manual', '2026-09-03T00:00:00Z', NULL),
3541+ ('t-early', 'github.com', 'acme/api', 4, 'https://github.com/acme/api/pull/4', 'agent', '2026-09-01T00:00:00Z', NULL),
3542+ ('t-first', 'github.com', 'acme/web', 2, 'https://github.com/acme/web/pull/2', 'stack-dismissed', '2026-09-02T00:00:00Z', NULL),
3543+ ('t-first', 'github.com', 'acme/web', 1, 'https://github.com/acme/web/pull/1', 'created', '2026-09-02T00:00:00Z',
3544+ '{"state":"open","title":"One","headBranch":"one","baseBranch":"main","isDraft":false,"updatedAt":null,"syncedAt":"2026-09-02T00:00:00Z"}'),
3545+ ('t-archived', 'github.com', 'acme/web', 5, 'https://github.com/acme/web/pull/5', 'manual', '2026-09-02T00:00:00Z', NULL),
3546+ ('t-deleted', 'github.com', 'acme/web', 6, 'https://github.com/acme/web/pull/6', 'manual', '2026-09-02T00:00:00Z', NULL)` ;
3547+ const expected = ( yield * query . getShellSnapshot ( ) ) . threads
3548+ . filter ( ( thread ) => thread . pullRequests . length > 0 )
3549+ . map ( ( { id, projectId, settledOverride, settledAt, pullRequests } ) => ( {
3550+ id,
3551+ projectId,
3552+ settledOverride,
3553+ settledAt,
3554+ pullRequests,
3555+ } ) ) ;
3556+ resolved . length = 0 ;
3557+
3558+ const counter = makeSqlStatementCounter ( ) ;
3559+ const threads = yield * query
3560+ . listThreadsWithPullRequests ( )
3561+ . pipe ( Effect . withTracer ( counter . tracer ) ) ;
3562+ assert . deepStrictEqual (
3563+ threads . map ( ( thread ) => [ thread . id , thread . pullRequests . map ( ( link ) => link . number ) ] ) ,
3564+ [
3565+ [ "t-first" , [ 1 , 2 ] ] ,
3566+ [ "t-late" , [ 3 ] ] ,
3567+ [ "t-early" , [ 4 ] ] ,
3568+ ] ,
3569+ ) ;
3570+ assert . deepStrictEqual ( threads , expected ) ;
3571+ assert . strictEqual ( counter . count ( ) , 1 ) ;
3572+ assert . deepStrictEqual ( resolved , [ ] ) ;
3573+ } ) . pipe ( Effect . provide ( layer ) ) ;
3574+ } ,
3575+ ) ;
3576+
35063577projectionSnapshotLayer ( "ProjectionSnapshotQuery activities by kind" , ( it ) => {
35073578 it . effect ( "lists one kind across active threads only, without hydrating the threads" , ( ) =>
35083579 Effect . gen ( function * ( ) {
0 commit comments