Files
AgentCompany/tests/integration/autonomous-chain/approval-decisions.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

77 lines
2.6 KiB
TypeScript

/**
* Step 4: Hire approval + decideApproval side effects.
* 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 4: Hire approval + decideApproval", () => {
it("decideApproval sets hired agent to idle when approved", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const hireId = createAgent({ name: "CTO", role: "CTO", reportsTo: ceoId, status: "pending_approval" as "idle" });
const approvalId = shared.db.requestApproval({
companyId: shared.companyId,
requestedByAgentId: ceoId,
type: "hire_agent",
payloadSummary: "Hire CTO",
impactSummary: "Test impact",
payloadJson: JSON.stringify({ agentId: hireId }),
});
shared.db.decideApproval({
approvalId,
state: "approved",
decisionNote: "Approved by board",
});
const updatedAgent = shared.db.entityCrud.getAgent(hireId);
expect(updatedAgent.status).toBe("idle");
});
it("decideApproval sets hired agent to terminated when rejected", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const hireId = createAgent({ name: "CTO", role: "CTO", reportsTo: ceoId, status: "pending_approval" as "idle" });
const approvalId = shared.db.requestApproval({
companyId: shared.companyId,
requestedByAgentId: ceoId,
type: "hire_agent",
payloadSummary: "Hire CTO",
impactSummary: "Test impact",
payloadJson: JSON.stringify({ agentId: hireId }),
});
shared.db.decideApproval({
approvalId,
state: "rejected",
decisionNote: "Not needed",
});
const updatedAgent = shared.db.entityCrud.getAgent(hireId);
expect(updatedAgent.status).toBe("terminated");
});
it("getApprovalRecord includes payloadJson", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const hireId = createAgent({ name: "CTO", role: "CTO", reportsTo: ceoId, status: "pending_approval" as "idle" });
const approvalId = shared.db.requestApproval({
companyId: shared.companyId,
requestedByAgentId: ceoId,
type: "hire_agent",
payloadSummary: "Hire CTO",
impactSummary: "Test",
payloadJson: JSON.stringify({ agentId: hireId, config: { connector: "openai-codex" } }),
});
const approval = shared.db.getApprovalRecord(approvalId);
expect(approval.payloadJson).toBeTruthy();
const payload = JSON.parse(approval.payloadJson!);
expect(payload.agentId).toBe(hireId);
});
});