@@ -7,12 +7,18 @@ import {
77 logFailureOnce ,
88 markFailureKind ,
99 markFailureLogged ,
10- wasFailureLogged ,
1110} from '@/lib/core/errors/failure-log'
1211import { RetryableSetupError } from '@/lib/core/errors/retryable-infrastructure'
1312import { UserFailure } from '@/lib/core/errors/user-failure'
1413import { HostedKeyRateLimitedError , HostedKeyUnavailableError } from '@/tools/errors'
1514
15+ const logger = createLogger ( 'FailureLogTest' )
16+
17+ /** What an outer boundary does with the failure: the kind it logs at, or undefined when it skips. */
18+ function outerBoundary ( error : unknown , executionId ?: string ) {
19+ return logFailureOnce ( logger , 'probe' , error , { executionId } )
20+ }
21+
1622describe ( 'classifyFailure' , ( ) => {
1723 it ( 'keeps a database failure internal even beneath a user mark' , ( ) => {
1824 const queryError = new DrizzleQueryError ( 'select 1' , [ ] , new Error ( 'connection reset' ) )
@@ -52,8 +58,7 @@ describe('classifyFailure', () => {
5258 const first = new Error ( 'first' )
5359 const second = new Error ( 'second' , { cause : first } )
5460 Object . assign ( first , { cause : second } )
55- expect ( classifyFailure ( first ) ) . toBe ( 'internal' )
56- expect ( wasFailureLogged ( first ) ) . toBe ( false )
61+ expect ( outerBoundary ( first ) ) . toBe ( 'internal' )
5762 } )
5863} )
5964
@@ -62,37 +67,35 @@ describe('inheritFailureMarks', () => {
6267 const logged = new Error ( 'child failed' )
6368 markFailureLogged ( logged )
6469 const boundary = inheritFailureMarks ( new Error ( 'Custom block execution failed' ) , logged )
65- expect ( wasFailureLogged ( boundary ) ) . toBe ( true )
70+ expect ( outerBoundary ( boundary ) ) . toBeUndefined ( )
6671 expect ( classifyFailure ( boundary ) ) . toBe ( 'internal' )
6772
6873 const authored = inheritFailureMarks ( new Error ( 'wrapped' ) , new UserFailure ( 'missing input' ) )
69- expect ( wasFailureLogged ( authored ) ) . toBe ( false )
70- expect ( classifyFailure ( authored ) ) . toBe ( 'user' )
74+ expect ( outerBoundary ( authored ) ) . toBe ( 'user' )
7175 } )
7276} )
7377
74- describe ( 'wasFailureLogged ' , ( ) => {
78+ describe ( 'logFailureOnce ' , ( ) => {
7579 it ( 'marks a frozen error, which a property write would throw on' , ( ) => {
7680 const frozen = Object . freeze ( new Error ( 'frozen' ) )
7781 markFailureLogged ( frozen )
7882 markFailureKind ( frozen , 'user' )
79- expect ( wasFailureLogged ( frozen ) ) . toBe ( true )
83+ expect ( outerBoundary ( frozen ) ) . toBeUndefined ( )
8084 expect ( classifyFailure ( frozen ) ) . toBe ( 'user' )
8185 } )
8286
8387 it ( 'does not treat an unrelated error as logged' , ( ) => {
8488 markFailureLogged ( new Error ( 'logged elsewhere' ) )
85- expect ( wasFailureLogged ( new Error ( 'fresh' ) ) ) . toBe ( false )
89+ expect ( outerBoundary ( new Error ( 'fresh' ) ) ) . toBe ( 'internal' )
8690 } )
8791
8892 it ( 'scopes a raw value logged at an execution boundary to that execution only' , ( ) => {
8993 const persistentFault = new Error ( 'module failed to load' )
90- logFailureOnce ( createLogger ( 'FailureLogTest' ) , 'Execution failed' , persistentFault , {
91- executionId : 'exec-1' ,
92- } )
94+ expect ( outerBoundary ( persistentFault , 'exec-1' ) ) . toBe ( 'internal' )
9395
94- expect ( wasFailureLogged ( persistentFault , 'exec-1' ) ) . toBe ( true )
95- expect ( wasFailureLogged ( persistentFault , 'exec-2' ) ) . toBe ( false )
96- expect ( wasFailureLogged ( persistentFault ) ) . toBe ( false )
96+ expect ( outerBoundary ( persistentFault , 'exec-1' ) ) . toBeUndefined ( )
97+ expect ( outerBoundary ( persistentFault , 'exec-2' ) ) . toBe ( 'internal' )
98+ expect ( outerBoundary ( persistentFault ) ) . toBe ( 'internal' )
99+ expect ( outerBoundary ( persistentFault , '' ) ) . toBe ( 'internal' )
97100 } )
98101} )
0 commit comments