mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
1ced7441eb
* refactor(agents): move announce family into subagents/announce/ * refactor(agents): move completion and main-session recovery families * refactor(agents): move registry family into subagents/registry * refactor(agents): update registry state type imports * style(agents): format moved subagent imports * test(agents): preserve isolated registry test routing * fix(scripts): recognize relocated subagent announce seams
176 lines
6.5 KiB
TypeScript
176 lines
6.5 KiB
TypeScript
// Audit Seams tests cover audit seams script behavior.
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
HELP_TEXT,
|
|
describeSeamKinds,
|
|
determineSeamTestStatus,
|
|
} from "../../scripts/audit-seams.mts";
|
|
|
|
describe("audit-seams cron seam classification", () => {
|
|
it("detects cron agent handoff and outbound delivery boundaries", () => {
|
|
const source = `
|
|
import { runCliAgent } from "../../agents/cli-runner.js";
|
|
import { runWithModelFallback } from "../../agents/model-fallback-runner.js";
|
|
import { registerAgentRunContext } from "../../infra/agent-run-registry.js";
|
|
import { deliverOutboundPayloads } from "../../infra/outbound/deliver.js";
|
|
import { buildOutboundSessionContext } from "../../infra/outbound/session-context.js";
|
|
|
|
export async function runCronIsolatedAgentTurn() {
|
|
registerAgentRunContext({});
|
|
await runWithModelFallback(() => runCliAgent({}));
|
|
await deliverOutboundPayloads({ payloads: [{ text: "done" }] });
|
|
return buildOutboundSessionContext({});
|
|
}
|
|
`;
|
|
|
|
expect(describeSeamKinds("src/cron/isolated-agent/run.ts", source)).toEqual([
|
|
"cron-agent-handoff",
|
|
"cron-outbound-delivery",
|
|
]);
|
|
});
|
|
|
|
it("detects scheduler-state seams in cron service orchestration", () => {
|
|
const source = `
|
|
import { recomputeNextRuns, computeJobNextRunAtMs } from "./jobs-scheduling.js";
|
|
import { ensureLoaded, persist } from "./store.js";
|
|
import { armTimer, runMissedJobs } from "./timer.js";
|
|
|
|
export async function start(state) {
|
|
await ensureLoaded(state);
|
|
recomputeNextRuns(state);
|
|
await persist(state);
|
|
armTimer(state);
|
|
await runMissedJobs(state);
|
|
return computeJobNextRunAtMs(state.store.jobs[0], Date.now());
|
|
}
|
|
`;
|
|
|
|
expect(describeSeamKinds("src/cron/service/ops-lifecycle.ts", source)).toContain(
|
|
"cron-scheduler-state",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("audit-seams subagent seam classification", () => {
|
|
it("detects relocated native spawn executor seams", () => {
|
|
const source = `
|
|
import { callGateway } from "../../../gateway/call.js";
|
|
import { registerSubagentRun } from "../../subagent-registry.js";
|
|
import { emitSessionLifecycleEvent } from "./subagent-spawn.runtime.js";
|
|
|
|
export async function spawnSubagentDirect() {
|
|
const response = await callGateway({ method: "agent.run", params: { task: "do it" } });
|
|
registerSubagentRun({ childSessionKey: "agent:main:subagent:child" });
|
|
await callGateway({ method: "sessions.delete", params: { key: "agent:main:subagent:child" } });
|
|
emitSessionLifecycleEvent({ sessionKey: "agent:main:subagent:child", type: "spawned" });
|
|
return response;
|
|
}
|
|
`;
|
|
|
|
expect(describeSeamKinds("src/agents/subagents/spawn/subagent-spawn.ts", source)).toEqual([
|
|
"subagent-lifecycle-registry",
|
|
"subagent-session-cleanup",
|
|
"subagent-session-spawn",
|
|
]);
|
|
});
|
|
|
|
it("detects subagent lifecycle registry and announce delivery seams", () => {
|
|
const source = `
|
|
import { resolveContextEngine } from "../context-engine/registry.js";
|
|
import { captureSubagentCompletionReply, runSubagentAnnounceFlow } from "../announce/subagent-announce.js";
|
|
import { emitSubagentEndedHookOnce } from "./subagent-registry-completion.js";
|
|
import { persistSubagentRunsToDisk } from "./subagent-registry-state.js";
|
|
|
|
export async function completeRun(entry) {
|
|
await resolveContextEngine({});
|
|
await captureSubagentCompletionReply(entry.childSessionKey);
|
|
await emitSubagentEndedHookOnce({ runId: entry.runId });
|
|
persistSubagentRunsToDisk(new Map());
|
|
return runSubagentAnnounceFlow({ childSessionKey: entry.childSessionKey });
|
|
}
|
|
`;
|
|
|
|
expect(describeSeamKinds("src/agents/subagents/registry/subagent-registry.ts", source)).toEqual(
|
|
["subagent-announce-delivery", "subagent-lifecycle-registry"],
|
|
);
|
|
});
|
|
|
|
it("detects the shared delivery-context announce seam", () => {
|
|
const source = `
|
|
import { normalizeDeliveryContext } from "../utils/delivery-context.shared.js";
|
|
|
|
export function createBoundDeliveryRouter(context) {
|
|
return normalizeDeliveryContext(context);
|
|
}
|
|
`;
|
|
|
|
expect(
|
|
describeSeamKinds("src/agents/subagents/announce/subagent-announce-origin.ts", source),
|
|
).toEqual(["subagent-announce-delivery"]);
|
|
});
|
|
|
|
it("detects parent-stream seams for ACP spawn relays", () => {
|
|
const source = `
|
|
import { onAgentEvent } from "../../../infra/agent-events.js";
|
|
import { requestHeartbeat } from "../../../infra/heartbeat-wake.js";
|
|
import { enqueueSystemEvent } from "../../../infra/system-events.js";
|
|
|
|
export function startAcpSpawnParentStreamRelay() {
|
|
onAgentEvent("agent-output", () => {});
|
|
requestHeartbeat({
|
|
source: "acp-spawn",
|
|
intent: "event",
|
|
reason: "acp:spawn:stream",
|
|
sessionKey: "agent:main",
|
|
});
|
|
enqueueSystemEvent("progress", { sessionKey: "agent:main", contextKey: "stream" });
|
|
return { streamTo: "parent" };
|
|
}
|
|
`;
|
|
|
|
expect(
|
|
describeSeamKinds("src/agents/subagents/spawn/acp-spawn-parent-stream.ts", source),
|
|
).toEqual(["subagent-parent-stream"]);
|
|
});
|
|
});
|
|
|
|
describe("audit-seams status/help", () => {
|
|
it("keeps cron seam statuses conservative when nearby tests exist", () => {
|
|
expect(
|
|
determineSeamTestStatus(
|
|
["cron-agent-handoff"],
|
|
[{ file: "src/cron/service.issue-regressions.test.ts", matchQuality: "path-nearby" }],
|
|
),
|
|
).toEqual({
|
|
status: "partial",
|
|
reason:
|
|
"Nearby tests exist (best match: path-nearby), but this inventory does not prove cross-layer seam coverage end to end.",
|
|
});
|
|
});
|
|
|
|
it("keeps subagent seam statuses conservative when nearby tests exist", () => {
|
|
expect(
|
|
determineSeamTestStatus(
|
|
["subagent-session-spawn"],
|
|
[
|
|
{
|
|
file: "src/agents/subagents/spawn/subagent-spawn.workspace.test.ts",
|
|
matchQuality: "direct-import",
|
|
},
|
|
],
|
|
),
|
|
).toEqual({
|
|
status: "partial",
|
|
reason:
|
|
"Nearby tests exist (best match: direct-import), but this inventory does not prove cross-layer seam coverage end to end.",
|
|
});
|
|
});
|
|
|
|
it("documents cron and subagent seam coverage in help text", () => {
|
|
expect(HELP_TEXT).toContain("cron orchestration seams");
|
|
expect(HELP_TEXT).toContain("subagent seams");
|
|
expect(HELP_TEXT).toContain("announce delivery");
|
|
expect(HELP_TEXT).toContain("parent streaming");
|
|
});
|
|
});
|