@@ -19,20 +19,28 @@ import fs from "fs"
1919const manifestPath = path . resolve ( import . meta. dir , "manifest.json" )
2020const manifest = JSON . parse ( fs . readFileSync ( manifestPath , "utf-8" ) )
2121
22+ // Basic manifest validation
23+ if ( ! manifest . features || typeof manifest . features !== "object" ) {
24+ throw new Error ( "manifest.json missing 'features' object" )
25+ }
26+ if ( ! manifest . upstream ?. remote || ! manifest . upstream ?. branch ) {
27+ throw new Error ( "manifest.json missing 'upstream.remote' or 'upstream.branch'" )
28+ }
29+
2230// Project root is one level up from .fork-features/
2331const PROJECT_ROOT = path . resolve ( import . meta. dir , ".." )
2432
2533// Collect absorption warnings across all features for final summary
26- const absorptionWarnings : string [ ] = [ ]
34+ const absorptionWarnings : { feature : string ; signal : string ; file : string } [ ] = [ ]
2735
2836// Filter to active features only
29- const activeFeatures = Object . entries ( manifest . features ) . filter ( ( [ , feat ] : [ string , any ] ) => feat . status === "active" )
37+ const activeFeatures = Object . entries ( manifest . features as Record < string , any > ) . filter (
38+ ( [ , feat ] ) => feat . status === "active" ,
39+ )
3040
3141// ---------- Per-feature test suites ----------
3242
33- for ( const [ featureName , feature ] of activeFeatures ) {
34- const feat = feature as any
35-
43+ for ( const [ featureName , feat ] of activeFeatures ) {
3644 describe ( `Feature: ${ featureName } ` , ( ) => {
3745 // --- New files must exist ---
3846 if ( feat . newFiles ?. length ) {
@@ -96,7 +104,8 @@ for (const [featureName, feature] of activeFeatures) {
96104 if ( feat . upstreamTracking ?. absorptionSignals ?. length ) {
97105 test ( `absorption scan (warnings only)` , ( ) => {
98106 // Get files changed upstream since our divergence point
99- const result = Bun . spawnSync ( [ "git" , "diff" , "--name-only" , "HEAD...anomalyco/dev" ] , {
107+ const upstreamRef = `${ manifest . upstream . remote } /${ manifest . upstream . branch } `
108+ const result = Bun . spawnSync ( [ "git" , "diff" , "--name-only" , `HEAD...${ upstreamRef } ` ] , {
100109 cwd : PROJECT_ROOT ,
101110 stdout : "pipe" ,
102111 stderr : "pipe" ,
@@ -146,17 +155,16 @@ for (const [featureName, feature] of activeFeatures) {
146155 }
147156
148157 if ( matched ) {
149- const warning = `⚠️ [${ featureName } ] signal "${ signal } " found in upstream file: ${ file } `
150- absorptionWarnings . push ( warning )
158+ absorptionWarnings . push ( { feature : featureName , signal, file } )
151159 }
152160 }
153161 }
154162
155- // Log per- feature warnings immediately
156- if ( absorptionWarnings . filter ( ( w ) => w . includes ( `[ ${ featureName } ]` ) ) . length > 0 ) {
163+ const featureWarnings = absorptionWarnings . filter ( ( w ) => w . feature === featureName )
164+ if ( featureWarnings . length > 0 ) {
157165 console . log ( `\n${ "=" . repeat ( 60 ) } \n⚠️ ABSORPTION DETECTED for ${ featureName } \n${ "=" . repeat ( 60 ) } ` )
158- for ( const w of absorptionWarnings . filter ( ( w ) => w . includes ( `[ ${ featureName } ]` ) ) ) {
159- console . log ( ` ${ w } ` )
166+ for ( const w of featureWarnings ) {
167+ console . log ( ` ⚠️ signal " ${ w . signal } " found in upstream file: ${ w . file } ` )
160168 }
161169 console . log ( "=" . repeat ( 60 ) )
162170 }
@@ -177,15 +185,13 @@ describe("Absorption Summary", () => {
177185 console . log ( `# ⚠️ ABSORPTION WARNINGS: ${ absorptionWarnings . length } signal(s) detected` )
178186 console . log ( `${ "#" . repeat ( 60 ) } ` )
179187 for ( const w of absorptionWarnings ) {
180- console . log ( ` ${ w } ` )
188+ console . log ( ` ⚠️ [ ${ w . feature } ] " ${ w . signal } " in ${ w . file } ` )
181189 }
182190 console . log ( `${ "#" . repeat ( 60 ) } ` )
183191 console . log ( `\nRun /sync-upstream to review upstream changes before merging.\n` )
184192 } else {
185193 console . log ( "\n✅ No absorption signals detected. Fork features are safe.\n" )
186194 }
187-
188- // Summary always passes — it's informational
189195 expect ( true ) . toBe ( true )
190196 } )
191197} )
0 commit comments