@@ -144,16 +144,22 @@ function getPreviousIds(): PreviousIdsResult {
144144 return { kind : 'ok' , map }
145145}
146146
147- function checkSubblockIdStability ( ) : string [ ] {
147+ type CheckResult =
148+ | { kind : 'pass' ; message : string }
149+ | { kind : 'skip' ; message : string }
150+ | { kind : 'fail' ; errors : string [ ] }
151+
152+ function checkSubblockIdStability ( ) : CheckResult {
148153 const previous = getPreviousIds ( )
149154
150155 if ( previous . kind === 'skip' ) {
151- console . log ( `⚠ ${ previous . reason } — skipping subblock ID stability check` )
152- return [ ]
156+ return { kind : 'skip' , message : `${ previous . reason } — skipping subblock ID stability check` }
153157 }
154158 if ( previous . kind === 'noop' ) {
155- console . log ( '✓ No block definition changes detected — skipping subblock ID stability check' )
156- return [ ]
159+ return {
160+ kind : 'skip' ,
161+ message : 'No block definition changes detected — skipping subblock ID stability check' ,
162+ }
157163 }
158164
159165 const current = getCurrentIds ( )
@@ -177,10 +183,13 @@ function checkSubblockIdStability(): string[] {
177183 }
178184 }
179185
180- return errors
186+ if ( errors . length === 0 ) {
187+ return { kind : 'pass' , message : 'Subblock ID stability check passed' }
188+ }
189+ return { kind : 'fail' , errors }
181190}
182191
183- function checkCanonicalIdContract ( ) : string [ ] {
192+ function checkCanonicalIdContract ( ) : CheckResult {
184193 const errors : string [ ] = [ ]
185194
186195 for ( const block of getAllBlocks ( ) ) {
@@ -215,36 +224,42 @@ function checkCanonicalIdContract(): string[] {
215224 }
216225 }
217226
218- return errors
219- }
220-
221- const stabilityErrors = checkSubblockIdStability ( )
222- const canonicalErrors = checkCanonicalIdContract ( )
223-
224- if ( stabilityErrors . length > 0 ) {
225- console . error ( '\n✗ Subblock ID stability check FAILED\n' )
226- console . error (
227- 'Removing subblock IDs breaks deployed workflows.\n' +
228- 'Either revert the rename or add a migration entry.\n'
229- )
230- for ( const err of stabilityErrors ) {
231- console . error ( ` ${ err } \n` )
227+ if ( errors . length === 0 ) {
228+ return { kind : 'pass' , message : 'Canonical-id contract check passed' }
232229 }
233- } else {
234- console . log ( '✓ Subblock ID stability check passed' )
230+ return { kind : 'fail' , errors }
235231}
236232
237- if ( canonicalErrors . length > 0 ) {
238- console . error ( '\n✗ Canonical-id contract check FAILED\n' )
239- for ( const err of canonicalErrors ) {
233+ function reportResult ( label : string , failureHeader : string , result : CheckResult ) : boolean {
234+ if ( result . kind === 'pass' ) {
235+ console . log ( `✓ ${ result . message } ` )
236+ return true
237+ }
238+ if ( result . kind === 'skip' ) {
239+ console . log ( `⚠ ${ result . message } ` )
240+ return true
241+ }
242+ console . error ( `\n✗ ${ label } FAILED\n` )
243+ if ( failureHeader ) console . error ( `${ failureHeader } \n` )
244+ for ( const err of result . errors ) {
240245 console . error ( ` ${ err } \n` )
241246 }
242- } else {
243- console . log ( '✓ Canonical-id contract check passed' )
247+ return false
244248}
245249
246- if ( stabilityErrors . length > 0 || canonicalErrors . length > 0 ) {
247- process . exit ( 1 )
248- }
250+ const stabilityResult = checkSubblockIdStability ( )
251+ const canonicalResult = checkCanonicalIdContract ( )
252+
253+ const stabilityOk = reportResult (
254+ 'Subblock ID stability check' ,
255+ 'Removing subblock IDs breaks deployed workflows.\nEither revert the rename or add a migration entry.' ,
256+ stabilityResult
257+ )
258+
259+ const canonicalOk = reportResult (
260+ 'Canonical-id contract check' ,
261+ "Misaligned ids cause the serializer's pre-execution validator to false-flag fields as missing at submit time." ,
262+ canonicalResult
263+ )
249264
250- process . exit ( 0 )
265+ process . exit ( stabilityOk && canonicalOk ? 0 : 1 )
0 commit comments