Files
AgentCompany/tests/integration/autonomous-chain/run-failure.spec.ts
T
ZacharyZhang-NY 5e9b7acbc6 Codemod db pass-through calls to domain modules: tasks + agents (C1 part 1/3)
Rewrite ~525 call sites from `db.<method>()` to `db.<module>.<method>()`
for tasks and agents domains (including `getAgent`/`findAgent`/`getTask`
which live on the `entityCrud` field). Delete the corresponding
pass-through methods on AppDatabaseBase. Structural types that narrowed
`db` to a bag of flat methods (CapabilityMatchDb, EscalationDeps,
SweepStaleReviewsDeps) are reshaped to match the new namespace. Internal
callback references inside database.ts/database-base.ts now invoke the
owning module directly (e.g. `this.agents.saveAgent`) rather than the
deleted pass-through.

The codemod lives at scripts/codemod/remove-appdatabase-passthrough.mjs
and filters by owning module + optional explicit method list. It is
idempotent and does not re-rewrite already-namespaced calls.
2026-04-20 13:17:01 -04:00

65 lines
2.0 KiB
TypeScript

/**
* Step 6: Run failure escalation (database layer).
* Physically extracted from autonomous-chain.spec.ts without behavior changes.
*/
import { describe, expect, it } from "vitest";
import { installSharedSetup } from "./shared-setup";
const shared = installSharedSetup();
const { createAgent } = shared;
describe("Step 6: Run failure escalation (database layer)", () => {
it("finishRun marks run as failed and returns outcome", () => {
const agentId = createAgent({ name: "IC", role: "Engineer" });
const taskId = shared.db.tasks.saveTask({
companyId: shared.companyId,
title: "Failing task",
description: "Will fail",
assigneeAgentId: agentId,
workspaceId: shared.workspaceId,
priority: "medium",
status: "in_progress",
});
const run = shared.db.createRun({
companyId: shared.companyId,
taskId,
agentId,
workspaceId: shared.workspaceId,
connectorId: "openai-codex",
});
shared.db.markRunStatus(run.id, "running", "Started");
const outcome = shared.db.finishRun({
runId: run.id,
status: "failed",
summary: null,
errorMessage: "Process crashed",
exitCode: 1,
signal: null,
model: "gpt-5-codex",
unattributedCost: false,
});
expect(outcome.budgetHardStopped).toBe(false);
const snapshot = shared.db.listSnapshot();
const finishedRun = snapshot.runs.find((r) => r.id === run.id);
expect(finishedRun?.status).toBe("failed");
expect(finishedRun?.errorMessage).toBe("Process crashed");
});
it("getChainOfCommand returns manager for failure escalation", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const ctoId = createAgent({ name: "CTO", role: "CTO", reportsTo: ceoId });
const icId = createAgent({ name: "Dev", role: "Engineer", reportsTo: ctoId });
const chain = shared.db.agents.getChainOfCommand(icId);
// First in chain is the immediate manager (CTO)
expect(chain.length).toBeGreaterThan(0);
expect(chain[0].name).toBe("CTO");
});
});