Files
AgentCompany/tests/integration/autonomous-chain/ceo-phased-prompts.spec.ts
T
ZacharyZhang-NY 0f1b7c0b33 test(integration): split autonomous-chain.spec.ts into per-scenario files
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.
2026-04-16 23:34:54 -04:00

167 lines
5.7 KiB
TypeScript

/**
* Step 2: CEO phased prompts + pending approvals + credential escalation.
* Physically extracted from autonomous-chain.spec.ts without behavior changes.
*/
import { describe, expect, it } from "vitest";
import { buildSystemPrompt } from "../../../src/main/prompt-builder";
import type { ApprovalRecord } from "../../../src/shared/types";
import { installSharedSetup } from "./shared-setup";
const shared = installSharedSetup();
const { createAgent, buildCtx } = shared;
describe("Step 2: CEO phased prompts", () => {
it("Phase 0: shows team building instructions when no reports at all", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const ctx = buildCtx({
agentId: ceoId,
directReports: [], // truly no reports
chainOfCommand: [],
pendingApprovals: [],
});
const prompt = buildSystemPrompt(ctx);
expect(prompt).toContain("Team Building Phase");
expect(prompt).toContain("Design the Organization Structure");
expect(prompt).toContain("Submit Org Strategy for Approval");
expect(prompt).not.toContain("Awaiting Org Approval");
expect(prompt).not.toContain("Goal Decomposition");
});
it("Phase 0.5: shows awaiting hire approvals when pending_approval hires exist but no org approval", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const hireId = createAgent({ name: "CTO", role: "CTO", reportsTo: ceoId, status: "pending_approval" as "idle" });
const hire = shared.db.getAgent(hireId);
const ctx = buildCtx({
agentId: ceoId,
directReports: [hire],
chainOfCommand: [],
pendingApprovals: [],
});
const prompt = buildSystemPrompt(ctx);
expect(prompt).toContain("Awaiting Hire Approvals");
expect(prompt).not.toContain("Team Building Phase");
expect(prompt).not.toContain("Goal Decomposition");
});
it("Phase 1: shows awaiting org approval when pending approve_ceo_strategy exists", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const ctx = buildCtx({
agentId: ceoId,
directReports: [],
chainOfCommand: [],
pendingApprovals: [
{
id: "approval-1",
companyId: shared.companyId,
type: "approve_ceo_strategy",
state: "pending",
payloadSummary: "Org structure: CEO + CTO + CMO",
impactSummary: "Team of 3",
requestedByAgentId: ceoId,
relatedTaskId: null,
decisionNote: "",
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
} as ApprovalRecord,
],
});
const prompt = buildSystemPrompt(ctx);
expect(prompt).toContain("Awaiting Org Approval");
expect(prompt).not.toContain("Team Building Phase");
expect(prompt).not.toContain("Goal Decomposition");
});
it("Phase 2: shows normal executive instructions when active reports and no pending org approval", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const ctoId = createAgent({ name: "CTO", role: "CTO", reportsTo: ceoId, status: "idle" });
const cto = shared.db.getAgent(ctoId);
const ctx = buildCtx({
agentId: ceoId,
directReports: [cto],
chainOfCommand: [],
pendingApprovals: [],
});
const prompt = buildSystemPrompt(ctx);
expect(prompt).toContain("Executive / CEO");
expect(prompt).toContain("Goal Decomposition");
expect(prompt).toContain("Delegation");
expect(prompt).toContain("Unblock & Coordinate");
expect(prompt).not.toContain("Team Building Phase");
expect(prompt).not.toContain("Awaiting Org Approval");
});
it("includes pending approvals section in prompt", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const ctoId = createAgent({ name: "CTO", role: "CTO", reportsTo: ceoId, status: "idle" });
const cto = shared.db.getAgent(ctoId);
const ctx = buildCtx({
agentId: ceoId,
directReports: [cto],
chainOfCommand: [],
pendingApprovals: [
{
id: "approval-x",
companyId: shared.companyId,
type: "secret_access",
state: "pending",
payloadSummary: "Need Twitter API keys",
impactSummary: "",
requestedByAgentId: ceoId,
relatedTaskId: null,
decisionNote: "",
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
} as ApprovalRecord,
],
});
const prompt = buildSystemPrompt(ctx);
expect(prompt).toContain("Pending Approvals");
expect(prompt).toContain("Need Twitter API keys");
});
it("Manager prompt includes credential escalation guidance", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const ceo = shared.db.getAgent(ceoId);
const managerId = createAgent({ name: "CTO", role: "CTO", reportsTo: ceoId });
const icId = createAgent({ name: "Dev", role: "Engineer", reportsTo: managerId });
const ic = shared.db.getAgent(icId);
const ctx = buildCtx({
agentId: managerId,
directReports: [ic],
chainOfCommand: [ceo],
});
const prompt = buildSystemPrompt(ctx);
expect(prompt).toContain("Break down work and delegate it");
});
it("IC prompt includes credential escalation guidance", () => {
const ceoId = createAgent({ name: "CEO", role: "CEO" });
const ceo = shared.db.getAgent(ceoId);
const icId = createAgent({ name: "Dev", role: "Engineer", reportsTo: ceoId });
const ctx = buildCtx({
agentId: icId,
directReports: [],
chainOfCommand: [ceo],
});
const prompt = buildSystemPrompt(ctx);
expect(prompt).toContain("Your manager is auto-notified and will help");
expect(prompt).toContain("explain what API key/account you need");
});
});