mirror of https://github.com/openclaw/openclaw.git
test: fix ci regressions
This commit is contained in:
parent
d8d13f2bde
commit
2cb15255a7
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue