@@ -14,7 +14,11 @@ import { resolveDeviceClaimPath } from './device-claim-paths.ts';
1414import { writeDeviceClaim } from './device-claim-store.ts' ;
1515import { settleVerifiedOrphanedClaim } from './device-claim-settlement.ts' ;
1616
17- function fixture ( reconcile : OwnerScopedClaimRecovery [ 'reconcile' ] , failureCount : 1 | 2 ) {
17+ function fixture (
18+ reconcile : OwnerScopedClaimRecovery [ 'reconcile' ] ,
19+ failureCount : 1 | 2 ,
20+ failureDetails : Record < string , unknown > = { } ,
21+ ) {
1822 const stateDir = mkdtempForTestSync ( 'claim-recovery-dispose-' ) ;
1923 const claim : DeviceClaim = {
2024 schemaVersion : 3 ,
@@ -39,6 +43,7 @@ function fixture(reconcile: OwnerScopedClaimRecovery['reconcile'], failureCount:
3943 hint : 'Inspect Android owner diagnostics.' ,
4044 diagnosticId : 'android-owner-diagnostic' ,
4145 logPath : '/tmp/android-owner.log' ,
46+ ...failureDetails ,
4247 } ) ,
4348 } ;
4449 const second = {
@@ -198,3 +203,44 @@ test.each([1, 2] as const)(
198203 expect ( f . dispose ) . toHaveBeenCalledOnce ( ) ;
199204 } ,
200205) ;
206+
207+ test . each ( [ 'primary-error' , 'retained' ] as const ) (
208+ 'bigint disposal details preserve the %s outcome and claim' ,
209+ async ( outcome ) => {
210+ const primary = new AppError ( 'DEVICE_IN_USE' , 'reconciliation refused' , {
211+ reason : 'primary-refusal' ,
212+ } ) ;
213+ const retained = { status : 'retained' , reason : 'screen-recording-owner-mismatch' } as const ;
214+ const f = fixture (
215+ async ( ) => {
216+ if ( outcome === 'primary-error' ) throw primary ;
217+ return retained ;
218+ } ,
219+ 1 ,
220+ { observedAtNs : 9_007_199_254_740_993n , samples : { elapsedNs : [ 1n , 42n ] } } ,
221+ ) ;
222+
223+ const recovery = settleVerifiedOrphanedClaim ( f . claim , f . recovery , f . env ) ;
224+ if ( outcome === 'primary-error' ) await expect ( recovery ) . rejects . toBe ( primary ) ;
225+ else await expect ( recovery ) . resolves . toBe ( retained ) ;
226+
227+ expect ( f . emit ) . toHaveBeenCalledOnce ( ) ;
228+ const event = f . emit . mock . calls [ 0 ] ?. [ 0 ] ;
229+ expect ( event . phase ) . toBe ( 'device_claim_recovery_dispose_failed' ) ;
230+ expect ( event . data . error . details . failures [ 0 ] . error ) . toMatchObject ( {
231+ code : 'COMMAND_FAILED' ,
232+ hint : 'Inspect Android owner diagnostics.' ,
233+ diagnosticId : 'android-owner-diagnostic' ,
234+ logPath : '/tmp/android-owner.log' ,
235+ details : {
236+ reason : 'android-cleanup-refused' ,
237+ observedAtNs : '9007199254740993' ,
238+ samples : { elapsedNs : [ '1' , '42' ] } ,
239+ } ,
240+ } ) ;
241+ if ( outcome === 'retained' ) expect ( event . data . retainedReason ) . toBe ( retained . reason ) ;
242+ expect ( fs . readFileSync ( f . claimPath , 'utf8' ) ) . toBe ( f . claimBytes ) ;
243+ expect ( f . reconcileOnce ) . toHaveBeenCalledOnce ( ) ;
244+ expect ( f . dispose ) . toHaveBeenCalledOnce ( ) ;
245+ } ,
246+ ) ;
0 commit comments