


















@@ -13,6 +13,7 @@ describe("sessions_spawn context modes", () => {
1313const callGatewayMock = vi.fn();
1414const updateSessionStoreMock = vi.fn();
1515const forkSessionFromParentMock = vi.fn();
16+const ensureContextEnginesInitializedMock = vi.fn();
1617const resolveContextEngineMock = vi.fn();
1718let spawnSubagentDirect: Awaited<
1819ReturnType<typeof loadSubagentSpawnModuleForTest>
@@ -23,6 +24,7 @@ describe("sessions_spawn context modes", () => {
2324 callGatewayMock,
2425 updateSessionStoreMock,
2526 forkSessionFromParentMock,
27+ ensureContextEnginesInitializedMock,
2628 resolveContextEngineMock,
2729sessionStorePath: storePath,
2830}));
@@ -32,6 +34,7 @@ describe("sessions_spawn context modes", () => {
3234callGatewayMock.mockReset();
3335updateSessionStoreMock.mockReset();
3436forkSessionFromParentMock.mockReset();
37+ensureContextEnginesInitializedMock.mockReset();
3538resolveContextEngineMock.mockReset();
3639setupAcceptedSubagentGatewayMock(callGatewayMock);
3740resolveContextEngineMock.mockResolvedValue({});
@@ -112,6 +115,29 @@ describe("sessions_spawn context modes", () => {
112115);
113116});
114117118+it("initializes built-in context engines before resolving spawn preparation", async () => {
119+let initialized = false;
120+ensureContextEnginesInitializedMock.mockImplementation(() => {
121+initialized = true;
122+});
123+const prepareSubagentSpawn = vi.fn(async () => undefined);
124+resolveContextEngineMock.mockImplementation(async () => {
125+if (!initialized) {
126+throw new Error('Context engine "legacy" is not registered. Available engines: (none)');
127+}
128+return { prepareSubagentSpawn };
129+});
130+131+const result = await spawnSubagentDirect({ task: "clean worker" }, { agentSessionKey: "main" });
132+133+expect(result.status).toBe("accepted");
134+expect(ensureContextEnginesInitializedMock).toHaveBeenCalledTimes(1);
135+expect(resolveContextEngineMock).toHaveBeenCalledTimes(1);
136+expect(ensureContextEnginesInitializedMock.mock.invocationCallOrder[0]).toBeLessThan(
137+resolveContextEngineMock.mock.invocationCallOrder[0],
138+);
139+});
140+115141it("rolls back context-engine preparation when agent start fails", async () => {
116142const store: SessionStore = {
117143main: { sessionId: "parent-session-id", updatedAt: 1 },
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。