@@ -59,71 +59,63 @@ const createThread = Effect.fn(function* (
5959 return id ;
6060} ) ;
6161
62- const cases = [
63- [ "sql" , sqlLayer ] ,
64- [ "memory" , ProjectionStore . layerMemory ] ,
65- ] as const ;
66- it . effect . each ( cases ) (
67- "%s: discovery preserves legacy links and explicit unlinking" ,
68- ( [ _name , layer ] ) =>
69- Effect . gen ( function * ( ) {
70- const store = yield * ProjectionStore . ProjectionStoreV2 ;
71- const linkedPullRequest = {
72- projectId : ProjectId . make ( "project" ) ,
73- repository : "example/repo" ,
74- number : 1 ,
75- url : "https://github.com/example/repo/pull/1" ,
76- } ;
77- yield * createThread ( "legacy" , { linkedPullRequest } ) ;
78- yield * createThread ( "unlinked" , { linkedPullRequest, pullRequests : [ ] } ) ;
79- const snapshot = yield * store . getPullRequestDiscoverySnapshot ( { unsettledOnly : false } ) ;
80- assert . equal ( snapshot . threads [ 0 ] ?. pullRequests ?. [ 0 ] ?. number , 1 ) ;
81- assert . deepEqual ( snapshot . threads [ 1 ] ?. pullRequests , [ ] ) ;
82- } ) . pipe ( Effect . provide ( layer ) ) ,
62+ it . effect ( "SQL discovery preserves legacy links and explicit unlinking" , ( ) =>
63+ Effect . gen ( function * ( ) {
64+ const store = yield * ProjectionStore . ProjectionStoreV2 ;
65+ const linkedPullRequest = {
66+ projectId : ProjectId . make ( "project" ) ,
67+ repository : "example/repo" ,
68+ number : 1 ,
69+ url : "https://github.com/example/repo/pull/1" ,
70+ } ;
71+ yield * createThread ( "legacy" , { linkedPullRequest } ) ;
72+ yield * createThread ( "unlinked" , { linkedPullRequest, pullRequests : [ ] } ) ;
73+ const snapshot = yield * store . getPullRequestDiscoverySnapshot ( { unsettledOnly : false } ) ;
74+ assert . equal ( snapshot . threads [ 0 ] ?. pullRequests ?. [ 0 ] ?. number , 1 ) ;
75+ assert . deepEqual ( snapshot . threads [ 1 ] ?. pullRequests , [ ] ) ;
76+ } ) . pipe ( Effect . provide ( sqlLayer ) ) ,
8377) ;
84- it . effect . each ( cases ) (
85- "%s: discovery keeps active and backfill metadata without archive or deleted rows" ,
86- ( [ _name , layer ] ) =>
87- Effect . gen ( function * ( ) {
88- const store = yield * ProjectionStore . ProjectionStoreV2 ;
89- const active = yield * createThread ( "active" , { branch : null } ) ;
90- const settled = yield * createThread ( "settled" , { settledAt : now } ) ;
91- yield * createThread ( "override" , { settledOverride : "settled" } ) ;
92- const archived = yield * createThread ( "archived" , { archivedAt : now } ) ;
93- yield * createThread ( "deleted" , { deletedAt : now } ) ;
94- const all = yield * store . getPullRequestDiscoverySnapshot ( { unsettledOnly : false } ) ;
95- assert . deepEqual (
96- all . threads . map ( ( thread ) => thread . id ) ,
97- [ active , ThreadId . make ( "override" ) , settled ] ,
98- ) ;
99- assert . equal ( all . threads [ 0 ] ?. branch , null ) ;
100- assert . deepEqual ( all . threads [ 0 ] ?. pullRequests , [ ] ) ;
101- const pending = yield * store . getPullRequestDiscoverySnapshot ( { unsettledOnly : true } ) ;
102- assert . deepEqual (
103- pending . threads . map ( ( thread ) => thread . id ) ,
104- [ active ] ,
105- ) ;
106- const single = yield * store . getPullRequestDiscoverySnapshot ( {
107- threadId : settled ,
78+ it . effect ( "SQL discovery keeps active and backfill metadata without archive or deleted rows" , ( ) =>
79+ Effect . gen ( function * ( ) {
80+ const store = yield * ProjectionStore . ProjectionStoreV2 ;
81+ const active = yield * createThread ( "active" , { branch : null } ) ;
82+ const settled = yield * createThread ( "settled" , { settledAt : now } ) ;
83+ yield * createThread ( "override" , { settledOverride : "settled" } ) ;
84+ const archived = yield * createThread ( "archived" , { archivedAt : now } ) ;
85+ yield * createThread ( "deleted" , { deletedAt : now } ) ;
86+ const all = yield * store . getPullRequestDiscoverySnapshot ( { unsettledOnly : false } ) ;
87+ assert . deepEqual (
88+ all . threads . map ( ( thread ) => thread . id ) ,
89+ [ active , ThreadId . make ( "override" ) , settled ] ,
90+ ) ;
91+ assert . equal ( all . threads [ 0 ] ?. branch , null ) ;
92+ assert . deepEqual ( all . threads [ 0 ] ?. pullRequests , [ ] ) ;
93+ const pending = yield * store . getPullRequestDiscoverySnapshot ( { unsettledOnly : true } ) ;
94+ assert . deepEqual (
95+ pending . threads . map ( ( thread ) => thread . id ) ,
96+ [ active ] ,
97+ ) ;
98+ const single = yield * store . getPullRequestDiscoverySnapshot ( {
99+ threadId : settled ,
100+ unsettledOnly : false ,
101+ } ) ;
102+ assert . deepEqual (
103+ single . threads . map ( ( thread ) => thread . id ) ,
104+ [ settled ] ,
105+ ) ;
106+ assert . isEmpty (
107+ ( yield * store . getPullRequestDiscoverySnapshot ( {
108+ threadId : archived ,
108109 unsettledOnly : false ,
109- } ) ;
110- assert . deepEqual (
111- single . threads . map ( ( thread ) => thread . id ) ,
112- [ settled ] ,
113- ) ;
114- assert . isEmpty (
115- ( yield * store . getPullRequestDiscoverySnapshot ( {
116- threadId : archived ,
117- unsettledOnly : false ,
118- } ) ) . threads ,
119- ) ;
120- assert . isEmpty (
121- ( yield * store . getPullRequestDiscoverySnapshot ( {
122- threadId : ThreadId . make ( "unknown" ) ,
123- unsettledOnly : false ,
124- } ) ) . threads ,
125- ) ;
126- } ) . pipe ( Effect . provide ( layer ) ) ,
110+ } ) ) . threads ,
111+ ) ;
112+ assert . isEmpty (
113+ ( yield * store . getPullRequestDiscoverySnapshot ( {
114+ threadId : ThreadId . make ( "unknown" ) ,
115+ unsettledOnly : false ,
116+ } ) ) . threads ,
117+ ) ;
118+ } ) . pipe ( Effect . provide ( sqlLayer ) ) ,
127119) ;
128120
129121it . effect ( "SQL discovery reads no run, message, item or fork history" , ( ) =>
@@ -157,42 +149,3 @@ it.effect("SQL discovery reads no run, message, item or fork history", () =>
157149 assert . isTrue ( statements . some ( ( query ) => query . includes ( "MAX(sequence)" ) ) ) ;
158150 } ) . pipe ( Effect . provide ( sqlLayer ) ) ,
159151) ;
160-
161- it . effect ( "SQL discovery identifies the thread whose metadata cannot decode" , ( ) =>
162- Effect . gen ( function * ( ) {
163- const store = yield * ProjectionStore . ProjectionStoreV2 ;
164- const sql = yield * SqlClient . SqlClient ;
165- const id = yield * createThread ( "malformed-metadata" ) ;
166- yield * sql `UPDATE orchestration_v2_projection_threads SET payload_json = '{}' WHERE thread_id = ${ id } ` ;
167- const error = yield * Effect . flip (
168- store . getPullRequestDiscoverySnapshot ( { unsettledOnly : false } ) ,
169- ) ;
170- assert . equal ( error . _tag , "ProjectionStoreReadError" ) ;
171- if ( error . _tag === "ProjectionStoreReadError" ) {
172- assert . equal ( error . threadId , id ) ;
173- assert . isDefined ( error . cause ) ;
174- }
175- } ) . pipe ( Effect . provide ( sqlLayer ) ) ,
176- ) ;
177-
178- it . effect ( "SQL discovery reports read failures with single-thread or sweep context" , ( ) =>
179- Effect . gen ( function * ( ) {
180- const store = yield * ProjectionStore . ProjectionStoreV2 ;
181- const sql = yield * SqlClient . SqlClient ;
182- const id = yield * createThread ( "read-failure" ) ;
183- yield * sql `DROP TABLE orchestration_v2_projection_threads` ;
184- for ( const threadId of [ undefined , id ] ) {
185- const error = yield * Effect . flip (
186- store . getPullRequestDiscoverySnapshot ( {
187- ...( threadId === undefined ? { } : { threadId } ) ,
188- unsettledOnly : false ,
189- } ) ,
190- ) ;
191- assert . equal ( error . _tag , "ProjectionStoreReadError" ) ;
192- if ( error . _tag === "ProjectionStoreReadError" ) {
193- assert . equal ( error . threadId , threadId ?? ThreadId . make ( "thread:pull-request-discovery" ) ) ;
194- assert . isDefined ( error . cause ) ;
195- }
196- }
197- } ) . pipe ( Effect . provide ( sqlLayer ) ) ,
198- ) ;
0 commit comments