@@ -159,7 +159,13 @@ describe("native hook relay CLI", () => {
159159 ) ;
160160
161161 expect ( exitCode ) . toBe ( 0 ) ;
162- expect ( stdout . text ( ) ) . toBe ( "" ) ;
162+ expect ( JSON . parse ( stdout . text ( ) ) ) . toEqual ( {
163+ hookSpecificOutput : {
164+ hookEventName : "PreToolUse" ,
165+ permissionDecision : "deny" ,
166+ permissionDecisionReason : "Native hook relay unavailable" ,
167+ } ,
168+ } ) ;
163169 expect ( stderr . text ( ) ) . toContain ( "native hook relay unavailable" ) ;
164170 expect ( stderr . text ( ) ) . toContain ( "generation must be non-empty string" ) ;
165171 expect ( callGateway ) . toHaveBeenCalledWith (
@@ -173,7 +179,13 @@ describe("native hook relay CLI", () => {
173179 it . each ( [
174180 {
175181 event : "pre_tool_use" ,
176- stdout : null ,
182+ stdout : {
183+ hookSpecificOutput : {
184+ hookEventName : "PreToolUse" ,
185+ permissionDecision : "deny" ,
186+ permissionDecisionReason : "Native hook relay unavailable" ,
187+ } ,
188+ } ,
177189 } ,
178190 {
179191 event : "permission_request" ,
@@ -265,7 +277,7 @@ describe("native hook relay CLI", () => {
265277 expect ( callGateway ) . not . toHaveBeenCalled ( ) ;
266278 } ) ;
267279
268- it ( "keeps PreToolUse unavailable handling observational when there is no before-tool policy " , async ( ) => {
280+ it ( "fails closed for PreToolUse when the gateway relay is unavailable " , async ( ) => {
269281 const callGateway = vi . fn ( async ( ) => {
270282 throw new Error ( "gateway closed" ) ;
271283 } ) ;
@@ -282,6 +294,40 @@ describe("native hook relay CLI", () => {
282294 } ,
283295 ) ;
284296
297+ expect ( exitCode ) . toBe ( 0 ) ;
298+ expect ( JSON . parse ( stdout . text ( ) ) ) . toEqual ( {
299+ hookSpecificOutput : {
300+ hookEventName : "PreToolUse" ,
301+ permissionDecision : "deny" ,
302+ permissionDecisionReason : "Native hook relay unavailable" ,
303+ } ,
304+ } ) ;
305+ expect ( stderr . text ( ) ) . toContain ( "native hook relay unavailable" ) ;
306+ } ) ;
307+
308+ it ( "keeps PreToolUse unavailable handling observational only with an explicit no-policy marker" , async ( ) => {
309+ const callGateway = vi . fn ( async ( ) => {
310+ throw new Error ( "gateway closed" ) ;
311+ } ) ;
312+ const stdout = createWritableTextBuffer ( ) ;
313+ const stderr = createWritableTextBuffer ( ) ;
314+
315+ const exitCode = await runNativeHookRelayCli (
316+ {
317+ provider : "codex" ,
318+ relayId : "relay-1" ,
319+ generation : "generation-1" ,
320+ event : "pre_tool_use" ,
321+ preToolUseUnavailable : "noop" ,
322+ } ,
323+ {
324+ stdin : createReadableTextStream ( "{}" ) ,
325+ stdout,
326+ stderr,
327+ callGateway : callGateway as never ,
328+ } ,
329+ ) ;
330+
285331 expect ( exitCode ) . toBe ( 0 ) ;
286332 expect ( stdout . text ( ) ) . toBe ( "" ) ;
287333 expect ( stderr . text ( ) ) . toContain ( "native hook relay unavailable" ) ;
0 commit comments