@@ -24,6 +24,10 @@ function describeError(error: unknown): string {
2424 return error instanceof Error ? error . message : String ( error ) ;
2525}
2626
27+ function hasErrorCode ( error : unknown , code : string ) : boolean {
28+ return Boolean ( error && typeof error === "object" && "code" in error && error . code === code ) ;
29+ }
30+
2731async function writeSnapshotFiles ( root : string , files : PromptSnapshotFile [ ] ) {
2832 await Promise . all (
2933 files . map ( async ( file ) => {
@@ -71,6 +75,7 @@ async function writeSnapshots() {
7175
7276async function checkSnapshots ( ) {
7377 const files = await createFormattedPromptSnapshotFiles ( ) ;
78+ const expectedPaths = new Set ( files . map ( ( file ) => file . path ) ) ;
7479 const mismatches : string [ ] = [ ] ;
7580 for ( const file of files ) {
7681 const filePath = path . resolve ( repoRoot , file . path ) ;
@@ -85,6 +90,24 @@ async function checkSnapshots() {
8590 mismatches . push ( `${ file . path } : differs from generated output` ) ;
8691 }
8792 }
93+ let committedEntries : string [ ] ;
94+ try {
95+ committedEntries = await fs . readdir ( path . resolve ( repoRoot , HAPPY_PATH_PROMPT_SNAPSHOT_DIR ) ) ;
96+ } catch ( error ) {
97+ if ( ! hasErrorCode ( error , "ENOENT" ) ) {
98+ throw error ;
99+ }
100+ committedEntries = [ ] ;
101+ }
102+ for ( const entry of committedEntries ) {
103+ if ( ! entry . endsWith ( ".md" ) && ! entry . endsWith ( ".json" ) ) {
104+ continue ;
105+ }
106+ const snapshotPath = path . join ( HAPPY_PATH_PROMPT_SNAPSHOT_DIR , entry ) ;
107+ if ( ! expectedPaths . has ( snapshotPath ) ) {
108+ mismatches . push ( `${ snapshotPath } : stale file (not generated)` ) ;
109+ }
110+ }
88111 if ( mismatches . length > 0 ) {
89112 console . error ( "Prompt snapshot drift detected. Run `pnpm prompt:snapshots:gen`." ) ;
90113 for ( const mismatch of mismatches ) {
0 commit comments