@@ -3,7 +3,9 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
33import { describe , expect , it } from "vite-plus/test" ;
44import * as Effect from "effect/Effect" ;
55import * as FileSystem from "effect/FileSystem" ;
6+ import * as Layer from "effect/Layer" ;
67import * as Path from "effect/Path" ;
8+ import * as PlatformError from "effect/PlatformError" ;
79import type * as Scope from "effect/Scope" ;
810import { symlinksSupported } from "@t3tools/shared/testing/symlinks" ;
911
@@ -173,6 +175,84 @@ describe("Cursor skills", () => {
173175 } ) ,
174176 ) ) ;
175177
178+ it ( "finds sibling skills when one skill ships more files than the scan budget" , async ( ) =>
179+ await runNode (
180+ Effect . gen ( function * ( ) {
181+ const fileSystem = yield * FileSystem . FileSystem ;
182+ const path = yield * Path . Path ;
183+ const tempDirectory = ( prefix : string ) =>
184+ fileSystem
185+ . makeTempDirectoryScoped ( { directory : NodeOS . tmpdir ( ) , prefix } )
186+ . pipe ( Effect . flatMap ( ( directory ) => fileSystem . realPath ( directory ) ) ) ;
187+ const userHome = yield * tempDirectory ( "cursor-skills-home-" ) ;
188+ const workspace = yield * tempDirectory ( "cursor-skills-workspace-" ) ;
189+ const root = path . join ( workspace , ".cursor" , "skills" ) ;
190+ const artifacts = path . join ( root , "a-large" , "artifacts" ) ;
191+ yield * fileSystem . makeDirectory ( artifacts , { recursive : true } ) ;
192+ yield * fileSystem . writeFileString ( path . join ( root , "a-large" , "SKILL.md" ) , "---\n---\n" ) ;
193+ yield * fileSystem . makeDirectory ( path . join ( root , "b-small" ) , { recursive : true } ) ;
194+ yield * fileSystem . writeFileString ( path . join ( root , "b-small" , "SKILL.md" ) , "---\n---\n" ) ;
195+ // More ordinary files than the whole-scan entry budget of 10,000.
196+ yield * Effect . forEach (
197+ Array . from ( { length : 11_000 } , ( _ , index ) => path . join ( artifacts , `file-${ index } .txt` ) ) ,
198+ ( file ) => fileSystem . writeFileString ( file , "" ) ,
199+ { concurrency : 64 , discard : true } ,
200+ ) ;
201+
202+ const expected = [
203+ {
204+ name : "a-large" ,
205+ path : path . join ( root , "a-large" , "SKILL.md" ) ,
206+ scope : "project" ,
207+ enabled : true ,
208+ } ,
209+ {
210+ name : "b-small" ,
211+ path : path . join ( root , "b-small" , "SKILL.md" ) ,
212+ scope : "project" ,
213+ enabled : true ,
214+ } ,
215+ ] ;
216+ expect ( yield * discoverCursorSkills ( workspace , { HOME : userHome } ) ) . toEqual ( expected ) ;
217+ expect ( yield * probeCursorSkills ( workspace , { HOME : userHome } ) ) . toEqual ( expected ) ;
218+ } ) ,
219+ ) ) ;
220+
221+ it ( "stops a scan of a huge file tree instead of statting every file" , async ( ) => {
222+ const root = "/workspace/.cursor/skills" ;
223+ let stats = 0 ;
224+ const fileSystem = FileSystem . layerNoop ( {
225+ realPath : ( path ) => Effect . succeed ( path ) ,
226+ readDirectory : ( path ) =>
227+ path === root
228+ ? Effect . succeed ( Array . from ( { length : 200_000 } , ( _ , index ) => `file-${ index } ` ) )
229+ : Effect . succeed ( [ ] ) ,
230+ stat : ( path ) => {
231+ stats += 1 ;
232+ if ( path === root ) return Effect . succeed ( { type : "Directory" } as FileSystem . File . Info ) ;
233+ if ( path . startsWith ( `${ root } /file-` ) ) {
234+ return Effect . succeed ( { type : "File" } as FileSystem . File . Info ) ;
235+ }
236+ return Effect . fail (
237+ PlatformError . systemError ( { _tag : "NotFound" , module : "FileSystem" , method : "stat" } ) ,
238+ ) ;
239+ } ,
240+ } ) ;
241+
242+ const result = await probeCursorSkills ( "/workspace" , { HOME : "/home" } ) . pipe (
243+ Effect . result ,
244+ Effect . provide ( Layer . mergeAll ( fileSystem , Path . layer ) ) ,
245+ Effect . runPromise ,
246+ ) ;
247+
248+ expect ( result ) . toMatchObject ( {
249+ _tag : "Failure" ,
250+ failure : { reason : "scan-budget-exhausted" } ,
251+ } ) ;
252+ expect ( stats ) . toBeGreaterThanOrEqual ( 100_000 ) ;
253+ expect ( stats ) . toBeLessThanOrEqual ( 100_000 ) ;
254+ } ) ;
255+
176256 it . skipIf ( ! symlinksSupported ) (
177257 "treats a symlinked skill outside the root as a package boundary" ,
178258 async ( ) =>
0 commit comments