@@ -10,6 +10,7 @@ import * as Fiber from "effect/Fiber";
1010import * as Layer from "effect/Layer" ;
1111import * as Metric from "effect/Metric" ;
1212import * as Option from "effect/Option" ;
13+ import * as PubSub from "effect/PubSub" ;
1314import * as Ref from "effect/Ref" ;
1415import { TestClock } from "effect/testing" ;
1516import * as SqlClient from "effect/sql/SqlClient" ;
@@ -107,6 +108,88 @@ const layerTestFor = (
107108
108109const layerTest = layerTestFor ( layerMetadata ) ;
109110
111+ it . effect ( "resolves only the requested active project page in creation order" , ( ) =>
112+ Effect . gen ( function * ( ) {
113+ const inspected = yield * Ref . make < ReadonlySet < string > > ( new Set ( ) ) ;
114+ const note = ( workspaceRoot : string ) =>
115+ Ref . update ( inspected , ( roots ) => new Set ( [ ...roots , workspaceRoot ] ) ) ;
116+ const metadata = Layer . merge (
117+ Layer . succeed ( RepositoryIdentityResolver . RepositoryIdentityResolver , {
118+ resolve : ( workspaceRoot ) =>
119+ note ( workspaceRoot ) . pipe (
120+ Effect . as ( {
121+ canonicalKey : `example.test${ workspaceRoot } ` ,
122+ locator : {
123+ source : "git-remote" as const ,
124+ remoteName : "origin" ,
125+ remoteUrl : `https://example.test${ workspaceRoot } .git` ,
126+ } ,
127+ rootPath : workspaceRoot ,
128+ } ) ,
129+ ) ,
130+ } ) ,
131+ Layer . succeed ( ProjectFaviconResolver . ProjectFaviconResolver , {
132+ invalidate : ( ) => Effect . void ,
133+ resolvePath : ( workspaceRoot ) => note ( workspaceRoot ) . pipe ( Effect . as ( null ) ) ,
134+ } ) ,
135+ ) ;
136+ yield * Effect . gen ( function * ( ) {
137+ const sql = yield * SqlClient . SqlClient ;
138+ const service = yield * ProjectService . ProjectService ;
139+ const enrichment = yield * ProjectEnrichmentService . ProjectEnrichmentService ;
140+ const changes = yield * enrichment . subscribeChanges ;
141+ const rows = Array . from ( { length : 6 } , ( _ , index ) => ( {
142+ project_id : `page:${ index } ` ,
143+ title : `Project ${ index } ` ,
144+ workspace_root : `/work/page-${ index } ` ,
145+ scripts_json : "[]" ,
146+ created_at : "2026-10-01T00:00:00.000Z" ,
147+ updated_at : "2026-10-01T00:00:00.000Z" ,
148+ deleted_at : index === 1 ? "2026-10-02T00:00:00.000Z" : null ,
149+ auto_pull : 0 ,
150+ } ) ) ;
151+ yield * sql `INSERT INTO projection_projects ${ sql . insert ( rows ) } ` ;
152+ const first = yield * service . listPage ( { cursor : 0 , limit : 2 } ) ;
153+ assert . deepEqual (
154+ first . projects . map ( ( project ) => project . id ) ,
155+ [ "page:0" , "page:2" ] ,
156+ ) ;
157+ assert . equal ( first . nextCursor , 2 ) ;
158+ assert . deepEqual (
159+ first . projects . map ( ( project ) => project . repositoryIdentity ?. canonicalKey ) ,
160+ [ "example.test/work/page-0" , "example.test/work/page-2" ] ,
161+ ) ;
162+ // A sentinel queued after the page lets the enrichment workers finish
163+ // earlier requests before checking which workspaces were inspected.
164+ yield * enrichment . request ( "/work/page-sentinel" ) ;
165+ for ( ; ; ) {
166+ if ( ( yield * PubSub . take ( changes ) ) . workspaceRoot === "/work/page-sentinel" ) break ;
167+ }
168+ assert . deepEqual (
169+ new Set ( yield * Ref . get ( inspected ) ) ,
170+ new Set ( [ "/work/page-0" , "/work/page-2" , "/work/page-sentinel" ] ) ,
171+ ) ;
172+ const second = yield * service . listPage ( { cursor : first . nextCursor ! , limit : 2 } ) ;
173+ assert . deepEqual (
174+ second . projects . map ( ( project ) => project . id ) ,
175+ [ "page:3" , "page:4" ] ,
176+ ) ;
177+ assert . equal ( second . nextCursor , 4 ) ;
178+ const last = yield * service . listPage ( { cursor : second . nextCursor ! , limit : 2 } ) ;
179+ assert . deepEqual (
180+ last . projects . map ( ( project ) => project . id ) ,
181+ [ "page:5" ] ,
182+ ) ;
183+ assert . isNull ( last . nextCursor ) ;
184+ assert . isFalse ( ( yield * Ref . get ( inspected ) ) . has ( "/work/page-1" ) ) ;
185+ assert . deepEqual ( yield * service . listPage ( { cursor : 99 , limit : 2 } ) , {
186+ projects : [ ] ,
187+ nextCursor : null ,
188+ } ) ;
189+ } ) . pipe ( Effect . scoped , Effect . provide ( layerTestFor ( metadata ) ) ) ;
190+ } ) ,
191+ ) ;
192+
110193const layerProjectServiceDependencies = Layer . mergeAll (
111194 RuntimeLayer . layerEventSink ,
112195 ProjectStore . layer ,
0 commit comments