11// Subagent delivery-context tests protect route metadata inheritance for child
22// agent sessions and outbound delivery through channel plugins.
3+ import { randomUUID } from "node:crypto" ;
34import { describe , expect , test } from "vitest" ;
45import type { ChannelPlugin } from "../channels/plugins/types.public.js" ;
56import { loadSessionEntry } from "../config/sessions/session-accessor.js" ;
@@ -12,7 +13,13 @@ import { projectSessionDeliveryFields } from "../utils/delivery-context.shared.j
1213import { setRegistry } from "./server.agent.gateway-server-agent.mocks.js" ;
1314import { createRegistry } from "./server.e2e-registry-helpers.js" ;
1415import { installConnectedSessionStoreGatewaySuite } from "./test-helpers.connected-session-store.js" ;
15- import { installGatewayTestHooks , rpcReq , testState , writeSessionStore } from "./test-helpers.js" ;
16+ import {
17+ installGatewayTestHooks ,
18+ onceMessage ,
19+ prepareGatewayReplyRuntimeForTest ,
20+ testState ,
21+ writeSessionStore ,
22+ } from "./test-helpers.js" ;
1623
1724installGatewayTestHooks ( { scope : "suite" } ) ;
1825
@@ -74,11 +81,20 @@ async function readStoredSessionEntry(key: string): Promise<StoredEntry> {
7481}
7582
7683async function sendAgentRequest ( params : Record < string , unknown > ) : Promise < void > {
77- const res = await rpcReq ( gatewaySuite . ws , "agent" , {
78- deliver : false ,
79- ...params ,
80- } ) ;
84+ await prepareGatewayReplyRuntimeForTest ( ) ;
85+ const id = randomUUID ( ) ;
86+ // Acceptance precedes execution; the next fixture must not delete a session with an active run.
87+ const finalResponse = onceMessage (
88+ gatewaySuite . ws ,
89+ ( message ) =>
90+ message . type === "res" && message . id === id && message . payload ?. status !== "accepted" ,
91+ ) ;
92+ gatewaySuite . ws . send (
93+ JSON . stringify ( { type : "req" , id, method : "agent" , params : { deliver : false , ...params } } ) ,
94+ ) ;
95+ const res = await finalResponse ;
8196 expect ( res . ok ) . toBe ( true ) ;
97+ expect ( res . payload ?. status ) . toBe ( "ok" ) ;
8298}
8399
84100function expectDeliveryContextFields ( entry : StoredEntry , expected : Record < string , unknown > ) : void {
0 commit comments