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.
This commit is contained in:
1 parent
6e4fd078d9
commit
0f1b7c0b33
12 files changed
+1517
-1409
No files matched your search
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* Shared setup for the autonomous-chain integration test suite.
|
||||
*
|
||||
* The original 50KB autonomous-chain.spec.ts shared a module-level `db`,
|
||||
* `companyId`, and `workspaceId` across every describe block via top-level
|
||||
* `beforeEach`/`afterEach` hooks. This module exports `installSharedSetup`,
|
||||
* which each split spec file calls to wire equivalent hooks into its own
|
||||
* vitest context and hand back a live handle.
|
||||
*
|
||||
* The helpers preserve the exact behavior of the original file — tests are
|
||||
* physically moved, not rewritten.
|
||||
*/
|
||||
|
||||
import { mkdtemp, rm } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
import { afterEach, beforeEach } from "vitest";
|
||||
import { AppDatabase } from "../../../src/main/database";
|
||||
import { buildSystemPrompt } from "../../../src/main/prompt-builder";
|
||||
import type { AgentRecord, ApprovalRecord, TaskRecord } from "../../../src/shared/types";
|
||||
|
||||
export interface SharedContext {
|
||||
db: AppDatabase;
|
||||
companyId: string;
|
||||
workspaceId: string;
|
||||
}
|
||||
|
||||
export interface SharedHandle {
|
||||
get db(): AppDatabase;
|
||||
set db(value: AppDatabase);
|
||||
get companyId(): string;
|
||||
get workspaceId(): string;
|
||||
createAgent(overrides?: Partial<Parameters<AppDatabase["saveAgent"]>[0]>): string;
|
||||
buildCtx(overrides?: Record<string, unknown>): Parameters<typeof buildSystemPrompt>[0];
|
||||
tempDirs: string[];
|
||||
}
|
||||
|
||||
export function installSharedSetup(): SharedHandle {
|
||||
const state = {
|
||||
db: null as AppDatabase | null,
|
||||
companyId: "",
|
||||
workspaceId: "",
|
||||
};
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
async function createTempDir(prefix: string) {
|
||||
const dir = await mkdtemp(join(tmpdir(), prefix));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
const profileDir = await createTempDir("agentcompany-chain-test-");
|
||||
state.db = new AppDatabase(profileDir);
|
||||
state.db.init();
|
||||
|
||||
state.companyId = state.db.saveCompany({
|
||||
name: "Autonomous Test Corp",
|
||||
description: "Test company for autonomous chain",
|
||||
status: "active",
|
||||
});
|
||||
|
||||
state.workspaceId = state.db.saveWorkspace({
|
||||
companyId: state.companyId,
|
||||
name: "Primary",
|
||||
localPath: profileDir,
|
||||
repoUrl: "https://example.com/repo.git",
|
||||
repoRef: "main",
|
||||
isPrimary: true,
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
state.db?.close();
|
||||
await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
|
||||
});
|
||||
|
||||
function currentDb(): AppDatabase {
|
||||
if (!state.db) throw new Error("shared-setup: db accessed outside test hook");
|
||||
return state.db;
|
||||
}
|
||||
|
||||
function createAgent(overrides: Partial<Parameters<AppDatabase["saveAgent"]>[0]> = {}): string {
|
||||
return currentDb().saveAgent({
|
||||
companyId: state.companyId,
|
||||
name: "TestAgent",
|
||||
role: "CEO",
|
||||
title: "Test",
|
||||
status: "idle",
|
||||
reportsTo: null,
|
||||
connectorId: "codex_local",
|
||||
workspaceId: state.workspaceId,
|
||||
model: null,
|
||||
capabilities: "Test capabilities",
|
||||
budgetMonthlyUsd: 200,
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
function buildCtx(overrides: Record<string, unknown> = {}): Parameters<typeof buildSystemPrompt>[0] {
|
||||
const agent = currentDb().getAgent(overrides.agentId as string ?? createAgent());
|
||||
return {
|
||||
agent,
|
||||
apiUrl: "http://127.0.0.1:3000",
|
||||
apiKey: "test-key",
|
||||
runId: "test-run-id",
|
||||
task: null,
|
||||
companyName: "Autonomous Test Corp",
|
||||
goals: [],
|
||||
projects: [],
|
||||
directReports: overrides.directReports as AgentRecord[] ?? [],
|
||||
chainOfCommand: overrides.chainOfCommand as AgentRecord[] ?? [],
|
||||
assignedTasks: [],
|
||||
allAgents: [],
|
||||
pendingApprovals: overrides.pendingApprovals as ApprovalRecord[] ?? [],
|
||||
tasksAwaitingReview: overrides.tasksAwaitingReview as TaskRecord[] ?? [],
|
||||
wakeReason: overrides.wakeReason as string | null ?? null,
|
||||
allTasks: [],
|
||||
recentComments: [],
|
||||
companyDescription: "",
|
||||
socialAccounts: [],
|
||||
...overrides,
|
||||
} as Parameters<typeof buildSystemPrompt>[0];
|
||||
}
|
||||
|
||||
return {
|
||||
get db() { return currentDb(); },
|
||||
set db(value: AppDatabase) { state.db = value; },
|
||||
get companyId() { return state.companyId; },
|
||||
get workspaceId() { return state.workspaceId; },
|
||||
createAgent,
|
||||
buildCtx,
|
||||
tempDirs,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user