From 2cb15255a7f0b467bfd355d76cb792394bf947b4 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 31 Mar 2026 02:41:53 +0100 Subject: [PATCH] test: fix ci regressions --- src/tasks/task-registry.test.ts | 203 +++++++++++-------- test/fixtures/test-memory-hotspots.unit.json | 2 +- test/scripts/test-planner.test.ts | 8 +- 3 files changed, 118 insertions(+), 95 deletions(-) diff --git a/src/tasks/task-registry.test.ts b/src/tasks/task-registry.test.ts index e6990f9cad3..ba97cbfbb92 100644 --- a/src/tasks/task-registry.test.ts +++ b/src/tasks/task-registry.test.ts @@ -10,7 +10,6 @@ import { withTempDir } from "../test-helpers/temp-dir.js"; import { installInMemoryTaskAndFlowRegistryRuntime } from "../test-utils/task-flow-registry-runtime.js"; import { createFlowRecord, getFlowById, resetFlowRegistryForTests } from "./flow-registry.js"; import { - cancelTaskById, createTaskRecord, findLatestTaskForSessionKey, findTaskByRunId, @@ -63,6 +62,22 @@ vi.mock("../agents/subagent-control.js", () => ({ killSubagentRunAdmin: (params: unknown) => hoisted.killSubagentRunAdminMock(params), })); +async function loadFreshTaskRegistryModulesForControlTest() { + vi.resetModules(); + vi.doMock("./task-registry-delivery-runtime.js", () => ({ + sendMessage: hoisted.sendMessageMock, + })); + vi.doMock("../acp/control-plane/manager.js", () => ({ + getAcpSessionManager: () => ({ + cancelSession: hoisted.cancelSessionMock, + }), + })); + vi.doMock("../agents/subagent-control.js", () => ({ + killSubagentRunAdmin: (params: unknown) => hoisted.killSubagentRunAdminMock(params), + })); + return await import("./task-registry.js"); +} + async function waitForAssertion(assertion: () => void, timeoutMs = 2_000, stepMs = 5) { const startedAt = Date.now(); for (;;) { @@ -1484,109 +1499,119 @@ describe("task-registry", () => { it("cancels ACP-backed tasks through the ACP session manager", async () => { await withTempDir({ prefix: "openclaw-task-registry-" }, async (root) => { + const registry = await loadFreshTaskRegistryModulesForControlTest(); process.env.OPENCLAW_STATE_DIR = root; - resetTaskRegistryForTests(); - hoisted.cancelSessionMock.mockResolvedValue(undefined); + registry.resetTaskRegistryForTests(); + try { + hoisted.cancelSessionMock.mockResolvedValue(undefined); - const task = createTaskRecord({ - runtime: "acp", - requesterSessionKey: "agent:main:main", - requesterOrigin: { - channel: "telegram", - to: "telegram:123", - }, - childSessionKey: "agent:codex:acp:child", - runId: "run-cancel-acp", - task: "Investigate issue", - status: "running", - deliveryStatus: "pending", - }); - - const result = await cancelTaskById({ - cfg: {} as never, - taskId: task.taskId, - }); - - expect(hoisted.cancelSessionMock).toHaveBeenCalledWith( - expect.objectContaining({ - cfg: {}, - sessionKey: "agent:codex:acp:child", - reason: "task-cancel", - }), - ); - expect(result).toMatchObject({ - found: true, - cancelled: true, - task: expect.objectContaining({ - taskId: task.taskId, - status: "cancelled", - error: "Cancelled by operator.", - }), - }); - await waitForAssertion(() => - expect(hoisted.sendMessageMock).toHaveBeenCalledWith( - expect.objectContaining({ + const task = registry.createTaskRecord({ + runtime: "acp", + requesterSessionKey: "agent:main:main", + requesterOrigin: { channel: "telegram", to: "telegram:123", - content: "Background task cancelled: ACP background task (run run-canc).", + }, + childSessionKey: "agent:codex:acp:child", + runId: "run-cancel-acp", + task: "Investigate issue", + status: "running", + deliveryStatus: "pending", + }); + + const result = await registry.cancelTaskById({ + cfg: {} as never, + taskId: task.taskId, + }); + + expect(hoisted.cancelSessionMock).toHaveBeenCalledWith( + expect.objectContaining({ + cfg: {}, + sessionKey: "agent:codex:acp:child", + reason: "task-cancel", }), - ), - ); + ); + expect(result).toMatchObject({ + found: true, + cancelled: true, + task: expect.objectContaining({ + taskId: task.taskId, + status: "cancelled", + error: "Cancelled by operator.", + }), + }); + await waitForAssertion(() => + expect(hoisted.sendMessageMock).toHaveBeenCalledWith( + expect.objectContaining({ + channel: "telegram", + to: "telegram:123", + content: "Background task cancelled: ACP background task (run run-canc).", + }), + ), + ); + } finally { + registry.resetTaskRegistryForTests(); + } }); }); it("cancels subagent-backed tasks through subagent control", async () => { await withTempDir({ prefix: "openclaw-task-registry-" }, async (root) => { + const registry = await loadFreshTaskRegistryModulesForControlTest(); process.env.OPENCLAW_STATE_DIR = root; - resetTaskRegistryForTests(); - hoisted.killSubagentRunAdminMock.mockResolvedValue({ - found: true, - killed: true, - }); + registry.resetTaskRegistryForTests(); + try { + hoisted.killSubagentRunAdminMock.mockResolvedValue({ + found: true, + killed: true, + }); - const task = createTaskRecord({ - runtime: "subagent", - requesterSessionKey: "agent:main:main", - requesterOrigin: { - channel: "telegram", - to: "telegram:123", - }, - childSessionKey: "agent:worker:subagent:child", - runId: "run-cancel-subagent", - task: "Investigate issue", - status: "running", - deliveryStatus: "pending", - }); - - const result = await cancelTaskById({ - cfg: {} as never, - taskId: task.taskId, - }); - - expect(hoisted.killSubagentRunAdminMock).toHaveBeenCalledWith( - expect.objectContaining({ - cfg: {}, - sessionKey: "agent:worker:subagent:child", - }), - ); - expect(result).toMatchObject({ - found: true, - cancelled: true, - task: expect.objectContaining({ - taskId: task.taskId, - status: "cancelled", - error: "Cancelled by operator.", - }), - }); - await waitForAssertion(() => - expect(hoisted.sendMessageMock).toHaveBeenCalledWith( - expect.objectContaining({ + const task = registry.createTaskRecord({ + runtime: "subagent", + requesterSessionKey: "agent:main:main", + requesterOrigin: { channel: "telegram", to: "telegram:123", - content: "Background task cancelled: Subagent task (run run-canc).", + }, + childSessionKey: "agent:worker:subagent:child", + runId: "run-cancel-subagent", + task: "Investigate issue", + status: "running", + deliveryStatus: "pending", + }); + + const result = await registry.cancelTaskById({ + cfg: {} as never, + taskId: task.taskId, + }); + + expect(hoisted.killSubagentRunAdminMock).toHaveBeenCalledWith( + expect.objectContaining({ + cfg: {}, + sessionKey: "agent:worker:subagent:child", }), - ), - ); + ); + expect(result).toMatchObject({ + found: true, + cancelled: true, + task: expect.objectContaining({ + taskId: task.taskId, + status: "cancelled", + error: "Cancelled by operator.", + }), + }); + await waitForAssertion(() => + expect(hoisted.sendMessageMock).toHaveBeenCalledWith( + expect.objectContaining({ + channel: "telegram", + to: "telegram:123", + content: "Background task cancelled: Subagent task (run run-canc).", + }), + ), + ); + } finally { + registry.resetTaskRegistryForTests(); + } }); }); }); diff --git a/test/fixtures/test-memory-hotspots.unit.json b/test/fixtures/test-memory-hotspots.unit.json index 25ce45ca80a..3c316fa4567 100644 --- a/test/fixtures/test-memory-hotspots.unit.json +++ b/test/fixtures/test-memory-hotspots.unit.json @@ -4,7 +4,7 @@ "defaultMinDeltaKb": 262144, "lane": "unit-fast, unit-*", "files": { - "src/infra/outbound/targets.channel-resolution.test.ts": { + "src/infra/outbound/channel-resolution.test.ts": { "deltaKb": 1111491, "sources": ["openclaw-test-memory-trace:unit-heavy-2"] }, diff --git a/test/scripts/test-planner.test.ts b/test/scripts/test-planner.test.ts index 772cd328221..1640f22421c 100644 --- a/test/scripts/test-planner.test.ts +++ b/test/scripts/test-planner.test.ts @@ -341,7 +341,7 @@ describe("test planner", () => { const explanation = explainExecutionTarget( { mode: "local", - fileFilters: ["src/infra/outbound/targets.channel-resolution.test.ts"], + fileFilters: ["src/infra/outbound/channel-resolution.test.ts"], }, { env: { @@ -358,7 +358,7 @@ describe("test planner", () => { const relativeExplanation = explainExecutionTarget( { mode: "local", - fileFilters: ["src/infra/outbound/targets.channel-resolution.test.ts"], + fileFilters: ["src/infra/outbound/channel-resolution.test.ts"], }, { env: { @@ -369,9 +369,7 @@ describe("test planner", () => { const absoluteExplanation = explainExecutionTarget( { mode: "local", - fileFilters: [ - path.join(process.cwd(), "src/infra/outbound/targets.channel-resolution.test.ts"), - ], + fileFilters: [path.join(process.cwd(), "src/infra/outbound/channel-resolution.test.ts")], }, { env: {