11import { beforeEach , describe , expect , it , vi } from "vitest" ;
2+ import { createSubagentAnnounceDeliveryRuntimeMock } from "./subagent-announce.test-support.js" ;
23
34type AgentCallRequest = { method ?: string ; params ?: Record < string , unknown > } ;
45
@@ -15,7 +16,7 @@ const readLatestAssistantReplyMock = vi.fn(async (_params?: unknown) => "raw sub
1516const isEmbeddedPiRunActiveMock = vi . fn ( ( _sessionId : string ) => false ) ;
1617const queueEmbeddedPiMessageMock = vi . fn ( ( _sessionId : string , _text : string ) => false ) ;
1718const waitForEmbeddedPiRunEndMock = vi . fn ( async ( _sessionId : string , _timeoutMs ?: number ) => true ) ;
18- let mockConfig : Record < string , unknown > = {
19+ let mockConfig : ReturnType < ( typeof import ( "../config/config.js" ) ) [ "loadConfig" ] > = {
1920 session : {
2021 mainKey : "main" ,
2122 scope : "per-sender" ,
@@ -35,16 +36,6 @@ const { subagentRegistryRuntimeMock } = vi.hoisted(() => ({
3536 } ,
3637} ) ) ;
3738
38- vi . mock ( "../plugins/hook-runner-global.js" , ( ) => ( {
39- getGlobalHookRunner : ( ) => ( { hasHooks : ( ) => false } ) ,
40- } ) ) ;
41- vi . mock ( "../config/sessions.js" , ( ) => ( {
42- loadSessionStore : ( storePath : string ) => loadSessionStoreMock ( storePath ) ,
43- resolveAgentIdFromSessionKey : ( sessionKey : string ) =>
44- resolveAgentIdFromSessionKeyMock ( sessionKey ) ,
45- resolveMainSessionKey : ( cfg : unknown ) => resolveMainSessionKeyMock ( cfg ) ,
46- resolveStorePath : ( store : unknown , options : unknown ) => resolveStorePathMock ( store , options ) ,
47- } ) ) ;
4839vi . mock ( "./subagent-announce.runtime.js" , ( ) => ( {
4940 callGateway : ( request : unknown ) => callGatewayMock ( request ) ,
5041 isEmbeddedPiRunActive : ( sessionId : string ) => isEmbeddedPiRunActiveMock ( sessionId ) ,
@@ -64,44 +55,22 @@ vi.mock("./tools/agent-step.js", () => ({
6455 readLatestAssistantReply : ( params ?: unknown ) => readLatestAssistantReplyMock ( params ) ,
6556} ) ) ;
6657
67- vi . mock ( "./subagent-announce-delivery.runtime.js" , ( ) => ( {
68- createBoundDeliveryRouter : ( ) => ( {
69- resolveDestination : ( ) => ( { mode : "none" } ) ,
70- } ) ,
71- resolveConversationIdFromTargets : ( ) => "" ,
72- resolveExternalBestEffortDeliveryTarget : ( params : {
73- channel ?: string ;
74- to ?: string ;
75- accountId ?: string ;
76- threadId ?: string ;
77- } ) => ( {
78- deliver : Boolean ( params . channel && params . to ) ,
79- channel : params . channel ,
80- to : params . to ,
81- accountId : params . accountId ,
82- threadId : params . threadId ,
58+ vi . mock ( "./subagent-announce-delivery.runtime.js" , ( ) =>
59+ createSubagentAnnounceDeliveryRuntimeMock ( {
60+ callGateway : ( request : unknown ) => callGatewayMock ( request ) ,
61+ loadConfig : ( ) => mockConfig ,
62+ loadSessionStore : ( storePath : string ) => loadSessionStoreMock ( storePath ) ,
63+ resolveAgentIdFromSessionKey : ( sessionKey : string ) =>
64+ resolveAgentIdFromSessionKeyMock ( sessionKey ) ,
65+ resolveMainSessionKey : ( cfg : unknown ) => resolveMainSessionKeyMock ( cfg ) ,
66+ resolveStorePath : ( store : unknown , options : unknown ) => resolveStorePathMock ( store , options ) ,
67+ isEmbeddedPiRunActive : ( sessionId : string ) => isEmbeddedPiRunActiveMock ( sessionId ) ,
68+ queueEmbeddedPiMessage : ( sessionId : string , text : string ) =>
69+ queueEmbeddedPiMessageMock ( sessionId , text ) ,
8370 } ) ,
84- resolveQueueSettings : ( params : {
85- cfg ?: {
86- messages ?: {
87- queue ?: {
88- byChannel ?: Record < string , string > ;
89- } ;
90- } ;
91- } ;
92- channel ?: string ;
93- } ) => ( {
94- mode : ( params . channel && params . cfg ?. messages ?. queue ?. byChannel ?. [ params . channel ] ) ?? "none" ,
95- } ) ,
96- } ) ) ;
97- vi . mock ( "./pi-embedded.js" , ( ) => ( {
98- isEmbeddedPiRunActive : ( sessionId : string ) => isEmbeddedPiRunActiveMock ( sessionId ) ,
99- queueEmbeddedPiMessage : ( sessionId : string , text : string ) =>
100- queueEmbeddedPiMessageMock ( sessionId , text ) ,
101- } ) ) ;
71+ ) ;
10272
10373vi . mock ( "./subagent-announce.registry.runtime.js" , ( ) => subagentRegistryRuntimeMock ) ;
104- import { __testing as subagentAnnounceDeliveryTesting } from "./subagent-announce-delivery.js" ;
10574import { runSubagentAnnounceFlow } from "./subagent-announce.js" ;
10675
10776describe ( "subagent announce seam flow" , ( ) => {
@@ -142,11 +111,6 @@ describe("subagent announce seam flow", () => {
142111 scope : "per-sender" ,
143112 } ,
144113 } ;
145- subagentAnnounceDeliveryTesting . setDepsForTest ( {
146- callGateway : ( async < T = Record < string , unknown > > ( request : unknown ) =>
147- ( await callGatewayMock ( request ) ) as T ) as typeof import ( "../gateway/call.js" ) . callGateway ,
148- loadConfig : ( ) => mockConfig ,
149- } ) ;
150114 subagentRegistryRuntimeMock . shouldIgnorePostCompletionAnnounceForSession . mockReset ( ) ;
151115 subagentRegistryRuntimeMock . shouldIgnorePostCompletionAnnounceForSession . mockReturnValue ( false ) ;
152116 subagentRegistryRuntimeMock . isSubagentSessionRunActive . mockReset ( ) ;
0 commit comments