From d522dc637e9afefb9b7914bbb169e44d5c3d47c2 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 10 Apr 2026 18:32:45 +0100 Subject: [PATCH] test: trim embedded agents slow paths --- ....spawn-workspace.context-injection.test.ts | 56 +++++++++---------- ...bagent-registry.persistence.resume.test.ts | 14 ++++- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-injection.test.ts b/src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-injection.test.ts index 1e8bfd0760c..1444cf8d7b8 100644 --- a/src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-injection.test.ts +++ b/src/agents/pi-embedded-runner/run/attempt.spawn-workspace.context-injection.test.ts @@ -1,22 +1,15 @@ import type { AgentMessage } from "@mariozechner/pi-agent-core"; -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { beforeEach, describe, expect, it, vi } from "vitest"; import { filterHeartbeatPairs } from "../../../auto-reply/heartbeat-filter.js"; import { HEARTBEAT_PROMPT } from "../../../auto-reply/heartbeat.js"; import { limitHistoryTurns } from "../history.js"; +import { buildEmbeddedMessageActionDiscoveryInput } from "../message-action-discovery-input.js"; import { assembleAttemptContextEngine, type AttemptContextEngine, resolveAttemptBootstrapContext, } from "./attempt.context-engine-helpers.js"; -import { - cleanupTempPaths, - createContextEngineAttemptRunner, - getHoisted, - resetEmbeddedAttemptHarness, -} from "./attempt.spawn-workspace.test-support.js"; - -const hoisted = getHoisted(); -const tempPaths: string[] = []; +import { resetEmbeddedAttemptHarness } from "./attempt.spawn-workspace.test-support.js"; async function resolveBootstrapContext(params: { contextInjectionMode?: "always" | "continuation-skip"; @@ -50,10 +43,6 @@ describe("embedded attempt context injection", () => { resetEmbeddedAttemptHarness(); }); - afterEach(async () => { - await cleanupTempPaths(tempPaths); - }); - it("skips bootstrap reinjection on safe continuation turns when configured", async () => { const { result, hasCompletedBootstrapTurn, resolveBootstrapContextForRun } = await resolveBootstrapContext({ @@ -87,25 +76,32 @@ describe("embedded attempt context injection", () => { }); it("forwards senderIsOwner into embedded message-action discovery", async () => { - await createContextEngineAttemptRunner({ - contextEngine: { - assemble: async ({ messages }) => ({ messages, estimatedTokens: 1 }), - }, - attemptOverrides: { - messageChannel: "matrix", - messageProvider: "matrix", - senderIsOwner: false, - }, + const input = buildEmbeddedMessageActionDiscoveryInput({ + cfg: {}, + channel: "matrix", + currentChannelId: "room", + currentThreadTs: "thread", + currentMessageId: 123, + accountId: "work", sessionKey: "agent:main", - tempPaths, + sessionId: "session", + agentId: "main", + senderId: "@alice:example.org", + senderIsOwner: false, }); - expect(hoisted.buildEmbeddedMessageActionDiscoveryInputMock).toHaveBeenCalledWith( - expect.objectContaining({ - channel: "matrix", - senderIsOwner: false, - }), - ); + expect(input).toMatchObject({ + channel: "matrix", + currentChannelId: "room", + currentThreadTs: "thread", + currentMessageId: 123, + accountId: "work", + sessionKey: "agent:main", + sessionId: "session", + agentId: "main", + requesterSenderId: "@alice:example.org", + senderIsOwner: false, + }); }); it("never skips heartbeat bootstrap filtering", async () => { diff --git a/src/agents/subagent-registry.persistence.resume.test.ts b/src/agents/subagent-registry.persistence.resume.test.ts index 2cd402fcfee..34c85510b32 100644 --- a/src/agents/subagent-registry.persistence.resume.test.ts +++ b/src/agents/subagent-registry.persistence.resume.test.ts @@ -115,7 +115,19 @@ describe("subagent registry persistence resume", () => { beforeEach(async () => { announceSpy.mockClear(); - mod.__testing.setDepsForTest(); + mod.__testing.setDepsForTest({ + cleanupBrowserSessionsForLifecycleEnd: vi.fn(async () => {}), + ensureContextEnginesInitialized: vi.fn(), + ensureRuntimePluginsLoaded: vi.fn(), + loadConfig: vi.fn(() => ({})), + resolveAgentTimeoutMs: vi.fn(() => 100), + resolveContextEngine: vi.fn(async () => ({ + info: { id: "test", name: "Test", version: "0.0.1" }, + ingest: vi.fn(async () => ({ ingested: false })), + assemble: vi.fn(async ({ messages }) => ({ messages, estimatedTokens: 0 })), + compact: vi.fn(async () => ({ ok: false, compacted: false })), + })), + }); mod.resetSubagentRegistryForTests({ persist: false }); vi.mocked(callGatewayModule.callGateway).mockReset(); vi.mocked(callGatewayModule.callGateway).mockResolvedValue({