77 type OrchestrationProjectShell ,
88 type OrchestrationV2AppThread ,
99 type OrchestrationV2DomainEvent ,
10- type OrchestrationV2ThreadShell ,
1110 type OrchestrationV2ServerCommand ,
1211} from "@t3tools/contracts" ;
1312import { describe , expect , it } from "@effect/vitest" ;
@@ -51,7 +50,7 @@ describe("ThreadPullRequestServiceV2 project guard", () => {
5150
5251describe ( "ThreadPullRequestServiceV2 reads" , ( ) => {
5352 const NOW = DateTime . makeUnsafe ( "2026-09-20T00:00:00.000Z" ) ;
54- const threadShell = ( id : string ) : OrchestrationV2ThreadShell => {
53+ const appThread = ( id : string ) : OrchestrationV2AppThread => {
5554 const threadId = ThreadId . make ( id ) ;
5655 return {
5756 id : threadId ,
@@ -68,15 +67,6 @@ describe("ThreadPullRequestServiceV2 reads", () => {
6867 forkedFrom : null ,
6968 createdBy : "user" ,
7069 creationSource : "web" ,
71- activeRunId : null ,
72- latestRunId : null ,
73- status : "idle" ,
74- pendingRuntimeRequest : null ,
75- latestVisibleMessage : null ,
76- latestUserMessageAt : null ,
77- hasActionableProposedPlan : false ,
78- itemCount : 0 ,
79- visibleItemCount : 0 ,
8070 createdAt : NOW ,
8171 updatedAt : NOW ,
8272 archivedAt : null ,
@@ -91,7 +81,7 @@ describe("ThreadPullRequestServiceV2 reads", () => {
9181 Effect . scoped (
9282 Effect . gen ( function * ( ) {
9383 // Polling active branches without a connected client wastes GitHub requests.
94- const thread = { ...threadShell ( "idle-branch-thread" ) , branch : "feature/idle" } ;
84+ const thread = { ...appThread ( "idle-branch-thread" ) , branch : "feature/idle" } ;
9585 const project : OrchestrationProjectShell = {
9686 id : thread . projectId ,
9787 title : "Project" ,
@@ -108,15 +98,10 @@ describe("ThreadPullRequestServiceV2 reads", () => {
10898 const dependencies = Layer . mergeAll (
10999 Layer . mock ( Orchestrator . OrchestratorV2 ) ( {
110100 streamDomainEvents : Stream . fromQueue ( domainEvents ) ,
111- getShellSnapshot : ( ) =>
112- Effect . succeed ( {
113- schemaVersion : 2 ,
114- snapshotSequence : 1 ,
115- threads : [ thread ] ,
116- archivedThreads : [ ] ,
117- } ) ,
118- getThreadEventSequence : ( ) => Effect . succeed ( 1 ) ,
119- getThreadShell : ( ) => Effect . succeed ( thread ) ,
101+ } ) ,
102+ Layer . mock ( ProjectionStore . ProjectionStoreV2 ) ( {
103+ getPullRequestDiscoverySnapshot : ( ) =>
104+ Effect . succeed ( { snapshotSequence : 1 , threads : [ thread ] } ) ,
120105 } ) ,
121106 Layer . mock ( ProjectStore . ProjectStoreV2 ) ( {
122107 listShells : ( ) => Effect . succeed ( [ project ] ) ,
@@ -202,7 +187,7 @@ describe("ThreadPullRequestServiceV2 reads", () => {
202187 url : "https://github.com/acme/project/pull/42" ,
203188 } ;
204189 const thread = {
205- ...threadShell ( "branch-pr-thread" ) ,
190+ ...appThread ( "branch-pr-thread" ) ,
206191 branch : "main" ,
207192 branchPullRequest : savedReference ,
208193 linkedPullRequest : savedReference ,
@@ -222,21 +207,18 @@ describe("ThreadPullRequestServiceV2 reads", () => {
222207 const dependencies = Layer . mergeAll (
223208 Layer . mock ( Orchestrator . OrchestratorV2 ) ( {
224209 streamDomainEvents : Stream . never ,
225- getShellSnapshot : ( ) =>
226- Deferred . succeed ( sweepStarted , undefined ) . pipe (
227- Effect . as ( {
228- schemaVersion : 2 ,
229- snapshotSequence : 1 ,
230- threads : [ thread ] ,
231- archivedThreads : [ ] ,
232- } ) ,
233- ) ,
234210 dispatch : ( command ) =>
235211 Effect . sync ( ( ) => {
236212 commands . push ( command ) ;
237213 return { sequence : 2 , storedEvents : [ ] } ;
238214 } ) ,
239215 } ) ,
216+ Layer . mock ( ProjectionStore . ProjectionStoreV2 ) ( {
217+ getPullRequestDiscoverySnapshot : ( ) =>
218+ Deferred . succeed ( sweepStarted , undefined ) . pipe (
219+ Effect . as ( { snapshotSequence : 1 , threads : [ thread ] } ) ,
220+ ) ,
221+ } ) ,
240222 Layer . mock ( ProjectStore . ProjectStoreV2 ) ( {
241223 listShells : ( ) => Effect . succeed ( [ project ] ) ,
242224 getShell : ( ) => Effect . succeedSome ( project ) ,
@@ -307,30 +289,7 @@ describe("ThreadPullRequestServiceV2 reads", () => {
307289 it . effect ( "discovers a branch pull request without reading thread history" , ( ) =>
308290 Effect . scoped (
309291 Effect . gen ( function * ( ) {
310- const shell = threadShell ( "history-free-thread" ) ;
311- const thread : OrchestrationV2AppThread = {
312- createdBy : shell . createdBy ,
313- creationSource : shell . creationSource ,
314- id : shell . id ,
315- projectId : shell . projectId ,
316- title : shell . title ,
317- providerInstanceId : shell . providerInstanceId ,
318- modelSelection : shell . modelSelection ,
319- runtimeMode : shell . runtimeMode ,
320- interactionMode : shell . interactionMode ,
321- branch : "feature/discovered" ,
322- worktreePath : null ,
323- activeProviderThreadId : null ,
324- lineage : shell . lineage ,
325- forkedFrom : null ,
326- createdAt : NOW ,
327- updatedAt : NOW ,
328- archivedAt : null ,
329- settledOverride : null ,
330- settledAt : null ,
331- lastVisitedAt : null ,
332- deletedAt : null ,
333- } ;
292+ const thread = { ...appThread ( "history-free-thread" ) , branch : "feature/discovered" } ;
334293 const project : OrchestrationProjectShell = {
335294 id : thread . projectId ,
336295 title : "Project" ,
@@ -353,22 +312,26 @@ describe("ThreadPullRequestServiceV2 reads", () => {
353312 const activation = yield * Deferred . make < void > ( ) ;
354313 const sweepStarted = yield * Deferred . make < void > ( ) ;
355314 const commands : Array < OrchestrationV2ServerCommand > = [ ] ;
356- const shellRead = < A , E > (
357- read : ( store : ProjectionStore . ProjectionStoreV2 [ "Service" ] ) => Effect . Effect < A , E > ,
358- ) =>
315+ const projectionStore = Layer . effect (
316+ ProjectionStore . ProjectionStoreV2 ,
359317 Effect . gen ( function * ( ) {
360- return yield * read ( yield * ProjectionStore . ProjectionStoreV2 ) ;
361- } ) . pipe ( Effect . orDie ) ;
318+ const store = yield * ProjectionStore . ProjectionStoreV2 ;
319+ return {
320+ ...store ,
321+ getPullRequestDiscoverySnapshot : ( options ) =>
322+ Deferred . succeed ( sweepStarted , undefined ) . pipe (
323+ Effect . andThen ( store . getPullRequestDiscoverySnapshot ( options ) ) ,
324+ ) ,
325+ } ;
326+ } ) ,
327+ ) . pipe (
328+ Layer . provide ( ProjectionStore . layer ) ,
329+ Layer . provideMerge ( SqlitePersistence . layerMemory ) ,
330+ ) ;
362331 const dependencies = Layer . mergeAll (
363- ProjectionStore . layer . pipe ( Layer . provideMerge ( SqlitePersistence . layerMemory ) ) ,
332+ projectionStore ,
364333 Layer . mock ( Orchestrator . OrchestratorV2 ) ( {
365334 streamDomainEvents : Stream . never ,
366- getShellSnapshot : ( options ) =>
367- Deferred . succeed ( sweepStarted , undefined ) . pipe (
368- Effect . andThen ( shellRead ( ( store ) => store . getShellSnapshot ( options ) ) ) ,
369- ) ,
370- getThreadEventSequence : ( ) => Effect . succeed ( 0 ) ,
371- getThreadShell : ( threadId ) => shellRead ( ( store ) => store . getThreadShell ( threadId ) ) ,
372335 dispatch : ( command ) =>
373336 Effect . sync ( ( ) => {
374337 commands . push ( command ) ;
@@ -417,8 +380,18 @@ describe("ThreadPullRequestServiceV2 reads", () => {
417380 occurredAt : NOW ,
418381 payload : thread ,
419382 } ) ;
420- // Any read of run, item, message or provider history now fails.
421383 const sql = yield * SqlClient . SqlClient ;
384+ yield * sql `
385+ INSERT INTO orchestration_events (
386+ sequence, event_id, aggregate_kind, stream_id, stream_version, event_type,
387+ occurred_at, actor_kind, payload_json, metadata_json, application_event_version
388+ )
389+ VALUES (
390+ 42, ${ `event:${ thread . id } ` } , 'thread', ${ thread . id } , 1, 'thread.created',
391+ ${ DateTime . formatIso ( NOW ) } , 'server', '{}', '{}', 2
392+ )
393+ ` ;
394+ // Any read of run, item, message or provider history now fails.
422395 const historyTables = yield * sql < { readonly name : string } > `
423396 SELECT name FROM sqlite_master
424397 WHERE type = 'table'
@@ -438,6 +411,7 @@ describe("ThreadPullRequestServiceV2 reads", () => {
438411 expect ( commands [ 0 ] ) . toMatchObject ( {
439412 type : "thread.pull-request.sync" ,
440413 threadId : thread . id ,
414+ snapshotSequence : 42 ,
441415 branchPullRequest : {
442416 projectId : project . id ,
443417 repository : "acme/project" ,
0 commit comments