The original tests/integration/autonomous-chain.spec.ts was ~1400 lines and 50 KB, covering 19 describe blocks across 10 orthogonal scenarios. Physically extract each describe (or closely related group) into its own file inside tests/integration/autonomous-chain/ so each file stays under the project's 500-line ceiling and failures point at the scenario that regressed. Shared beforeEach / afterEach / createAgent / buildCtx helpers move to autonomous-chain/shared-setup.ts, which exposes installSharedSetup() as a factory that each spec calls at module load. The tests themselves are moved byte-for-byte; only module-level references (`db`, `companyId`, `workspaceId`, `tempDirs`) are rewritten to go through the shared handle. No assertions, it() calls, or behavior are changed. Split layout: role-detection.spec.ts — Step 1: CEO role detection ceo-phased-prompts.spec.ts — Step 2: phased prompts + approvals wakeup-queue.spec.ts — Step 3: deferred wake queue approval-decisions.spec.ts — Step 4: hire approval decisions task-propagation.spec.ts — Step 5: task/comment wake propagation run-failure.spec.ts — Step 6: run failure escalation crash-recovery.spec.ts — Step 7: worker crash recovery wake-reason.spec.ts — Step 8: wake reason injection e2e-flows.spec.ts — full-chain + review-fix regressions automation-messages.spec.ts — automation/messages/assignment/workflows Test count stays at 363 passing; typecheck stays at 156 errors.
77 lines
2.6 KiB
TypeScript
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.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.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: "codex_local" } }),
|
|
});
|
|
|
|
const approval = shared.db.getApprovalRecord(approvalId);
|
|
expect(approval.payloadJson).toBeTruthy();
|
|
const payload = JSON.parse(approval.payloadJson!);
|
|
expect(payload.agentId).toBe(hireId);
|
|
});
|
|
});
|