Remove final AppDatabase pass-through methods with ESLint guard (C1 part 3/3)

Migrate all remaining pass-through call sites (social, skills, budget,
entityCrud, documents, knowledge, automation, wakeup, backup, threads,
settings, snapshot, connectors, workspaces, activity) to their owning
domain modules. `AppDatabase` now carries only three methods:

  - createHireRequest (multi-module composite: agents + approvalsMod)
  - rollbackConfigRevision (multi-module composite: documents + entityCrud)
  - queryAll (raw-SQL escape hatch, @internal)

The vault/env-binding infrastructure previously passed argument-by-
argument into `entityCrud.saveSecret`/`resolveSecretEnv` now binds at
module construction, letting callers invoke `db.entityCrud.saveSecret({...})`
without carrying vault plumbing.

Structural types that narrowed AppDatabase to a bag of flat methods
(`ConnectorModelPolicyDeps` callers, `CapabilityMatchDb`, test mocks in
budget-enforcement / budget-incidents / task-quality-gates /
failure-escalation / task-quality-gates-sweep) are reshaped to the new
namespace. `connectorPolicyDepsFromDb` replaces the old pattern of
handing the whole AppDatabase to `validateConnectorModelSelection`.

A new ESLint rule in eslint.config.mjs blocks new top-level methods on
AppDatabase so the pass-through layer cannot silently grow back.
`AppDatabase.ts` dropped from 193 lines to 58; `AppDatabaseBase` lost
the 270-line trailing pass-through block.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-20 13:31:39 -04:00
1 parent a69fbb053b
commit 118e3d8795
120 files changed
+838 -933

No files matched your search

@@ -11,7 +11,7 @@ const { createAgent } = shared;
describe("Automation Rules CRUD", () => {
it("creates, reads, toggles, and deletes an automation rule", () => {
const ruleId = shared.db.saveAutomationRule({
const ruleId = shared.db.automationMod.saveAutomationRule({
companyId: shared.companyId,
name: "Auto-escalate blocked tasks",
description: "When a task is blocked, notify the manager",
@@ -28,7 +28,7 @@ describe("Automation Rules CRUD", () => {
expect(ruleId).toBeTruthy();
// Rule appears in snapshot
const snapshot = shared.db.listSnapshot();
const snapshot = shared.db.snap.listSnapshot();
const rule = snapshot.automationRules.find(r => r.id === ruleId);
expect(rule).toBeTruthy();
expect(rule!.name).toBe("Auto-escalate blocked tasks");
@@ -39,36 +39,36 @@ describe("Automation Rules CRUD", () => {
expect(rule!.executionCount).toBe(0);
// Toggle to paused
shared.db.toggleAutomationRule(ruleId, shared.companyId, "paused");
const updated = shared.db.listSnapshot().automationRules.find(r => r.id === ruleId);
shared.db.automationMod.toggleAutomationRule(ruleId, shared.companyId, "paused");
const updated = shared.db.snap.listSnapshot().automationRules.find(r => r.id === ruleId);
expect(updated!.status).toBe("paused");
// Record execution
shared.db.recordAutomationExecution(ruleId, shared.companyId, "Auto-escalate blocked tasks", "task_blocked", "escalate_to_manager", "Escalated task-123");
const afterExec = shared.db.listSnapshot().automationRules.find(r => r.id === ruleId);
shared.db.automationMod.recordAutomationExecution(ruleId, shared.companyId, "Auto-escalate blocked tasks", "task_blocked", "escalate_to_manager", "Escalated task-123");
const afterExec = shared.db.snap.listSnapshot().automationRules.find(r => r.id === ruleId);
expect(afterExec!.executionCount).toBe(1);
expect(afterExec!.lastExecutedAt).toBeTruthy();
// Automation log
const log = shared.db.getAutomationLog(shared.companyId);
const log = shared.db.automationMod.getAutomationLog(shared.companyId);
expect(log).toHaveLength(1);
expect(log[0].ruleName).toBe("Auto-escalate blocked tasks");
// Delete
shared.db.deleteAutomationRule(ruleId, shared.companyId);
const afterDelete = shared.db.listSnapshot().automationRules.find(r => r.id === ruleId);
shared.db.automationMod.deleteAutomationRule(ruleId, shared.companyId);
const afterDelete = shared.db.snap.listSnapshot().automationRules.find(r => r.id === ruleId);
expect(afterDelete).toBeUndefined();
});
it("updates an existing rule", () => {
const ruleId = shared.db.saveAutomationRule({
const ruleId = shared.db.automationMod.saveAutomationRule({
companyId: shared.companyId,
name: "Original name",
trigger: "task_created",
action: "assign_task",
});
shared.db.saveAutomationRule({
shared.db.automationMod.saveAutomationRule({
id: ruleId,
companyId: shared.companyId,
name: "Updated name",
@@ -77,7 +77,7 @@ describe("Automation Rules CRUD", () => {
priority: 90,
});
const rule = shared.db.listSnapshot().automationRules.find(r => r.id === ruleId);
const rule = shared.db.snap.listSnapshot().automationRules.find(r => r.id === ruleId);
expect(rule!.name).toBe("Updated name");
expect(rule!.action).toBe("notify_agent");
expect(rule!.priority).toBe(90);
@@ -171,7 +171,7 @@ describe("Agent Messages", () => {
const engineeringLeadId = createAgent({ name: "Engineering Lead", role: "Lead", department: "engineering" });
const productLeadId = createAgent({ name: "Product Lead", role: "Lead", department: "product" });
const projectId = shared.db.saveProject({
const projectId = shared.db.entityCrud.saveProject({
companyId: shared.companyId,
name: "Cross-team Project",
description: "Scope",
@@ -229,7 +229,7 @@ describe("Agent Messages", () => {
it("appears in snapshot", () => {
shared.db.messages.sendAgentMessage({ companyId: shared.companyId, fromAgentId: agentAId, channel: "company", subject: "Snapshot test", body: "Hi" });
const snapshot = shared.db.listSnapshot();
const snapshot = shared.db.snap.listSnapshot();
expect(snapshot.agentMessages.length).toBeGreaterThanOrEqual(1);
expect(snapshot.agentMessages[0].subject).toBe("Snapshot test");
});
@@ -316,7 +316,7 @@ describe("Auto Task Assignment", () => {
describe("Workflow Pipelines", () => {
it("creates, activates, and deletes a workflow", () => {
const wfId = shared.db.saveWorkflow({
const wfId = shared.db.automationMod.saveWorkflow({
companyId: shared.companyId,
name: "Code Review Pipeline",
description: "Auto-review flow for PRs",
@@ -330,14 +330,14 @@ describe("Workflow Pipelines", () => {
});
expect(wfId).toBeTruthy();
const snapshot = shared.db.listSnapshot();
const snapshot = shared.db.snap.listSnapshot();
const wf = snapshot.workflows.find(w => w.id === wfId);
expect(wf!.name).toBe("Code Review Pipeline");
expect(wf!.status).toBe("draft");
expect(wf!.runCount).toBe(0);
// Delete
shared.db.deleteWorkflow(wfId, shared.companyId);
expect(shared.db.listSnapshot().workflows.find(w => w.id === wfId)).toBeUndefined();
shared.db.automationMod.deleteWorkflow(wfId, shared.companyId);
expect(shared.db.snap.listSnapshot().workflows.find(w => w.id === wfId)).toBeUndefined();
});
});
@@ -34,7 +34,7 @@ describe("Step 7: Worker crash recovery (database layer)", () => {
shared.db.runs.markRunStatus(run.id, "running", "Started");
// Verify it's running
let snapshot = shared.db.listSnapshot();
let snapshot = shared.db.snap.listSnapshot();
expect(snapshot.runs.find((r) => r.id === run.id)?.status).toBe("running");
// Simulate app restart — close and re-init
@@ -44,7 +44,7 @@ describe("Step 7: Worker crash recovery (database layer)", () => {
shared.db = new AppDatabase(profileDir);
shared.db.init(); // This calls interruptStaleRuns()
snapshot = shared.db.listSnapshot();
snapshot = shared.db.snap.listSnapshot();
const recoveredRun = snapshot.runs.find((r) => r.id === run.id);
expect(recoveredRun?.status).toBe("interrupted");
});
@@ -83,7 +83,7 @@ describe("Step 7: Worker crash recovery (database layer)", () => {
unattributedCost: true,
});
const snapshot = shared.db.listSnapshot();
const snapshot = shared.db.snap.listSnapshot();
const recovered = snapshot.runs.find((r) => r.id === run.id);
expect(recovered?.status).toBe("interrupted");
expect(recovered?.errorMessage).toBe("Worker process exited unexpectedly.");
@@ -111,7 +111,7 @@ describe("E2E: Full autonomous CEO cold start flow", () => {
expect(ctoChain[0].id).toBe(ceoId);
// 8. Create task tree
const projectId = shared.db.saveProject({
const projectId = shared.db.entityCrud.saveProject({
companyId: shared.companyId,
name: "Launch MVP",
description: "Build and launch MVP",
@@ -150,8 +150,8 @@ describe("E2E: Full autonomous CEO cold start flow", () => {
expect(subtask.parentId).toBe(parentTaskId);
// 9. Wakeup request test: enqueue wake while IC is busy
shared.db.enqueueWakeupRequest(shared.companyId, icId, "comment", "comment");
const queuedWakes = shared.db.listWakeupRequests(shared.companyId, { agentId: icId, status: "queued" });
shared.db.wakeup.enqueueWakeupRequest(shared.companyId, icId, "comment", "comment");
const queuedWakes = shared.db.wakeup.listWakeupRequests(shared.companyId, { agentId: icId, status: "queued" });
expect(queuedWakes).toHaveLength(1);
expect(queuedWakes[0].source).toBe("comment");
@@ -175,12 +175,12 @@ describe("E2E: Wakeup request lifecycle with run lifecycle", () => {
// Simulate: agent is running, wakes come in. All triggers are coalesced
// into a single wakeup request with JSON array of trigger details.
shared.db.enqueueWakeupRequest(shared.companyId, agentId, "subtask_completed", "subtask_completed");
shared.db.enqueueWakeupRequest(shared.companyId, agentId, "comment", "comment");
shared.db.enqueueWakeupRequest(shared.companyId, agentId, "report_blocked", "report_blocked");
shared.db.wakeup.enqueueWakeupRequest(shared.companyId, agentId, "subtask_completed", "subtask_completed");
shared.db.wakeup.enqueueWakeupRequest(shared.companyId, agentId, "comment", "comment");
shared.db.wakeup.enqueueWakeupRequest(shared.companyId, agentId, "report_blocked", "report_blocked");
// Verify coalesced into single row with all triggers
const wakes = shared.db.listWakeupRequests(shared.companyId, { agentId, status: "queued" });
const wakes = shared.db.wakeup.listWakeupRequests(shared.companyId, { agentId, status: "queued" });
expect(wakes).toHaveLength(1);
expect(wakes[0].coalescedCount).toBe(2);
@@ -191,7 +191,7 @@ describe("E2E: Wakeup request lifecycle with run lifecycle", () => {
expect(triggers[2].trigger).toBe("report_blocked");
// Wakes remain queued until consumed by the run lifecycle
expect(shared.db.listWakeupRequests(shared.companyId, { agentId, status: "queued" })).toHaveLength(1);
expect(shared.db.wakeup.listWakeupRequests(shared.companyId, { agentId, status: "queued" })).toHaveLength(1);
});
});
@@ -45,7 +45,7 @@ describe("Step 6: Run failure escalation (database layer)", () => {
expect(outcome.budgetHardStopped).toBe(false);
const snapshot = shared.db.listSnapshot();
const snapshot = shared.db.snap.listSnapshot();
const finishedRun = snapshot.runs.find((r) => r.id === run.id);
expect(finishedRun?.status).toBe("failed");
expect(finishedRun?.errorMessage).toBe("Process crashed");
@@ -60,7 +60,7 @@ export function installSharedSetup(): SharedHandle {
status: "active",
});
state.workspaceId = state.db.saveWorkspace({
state.workspaceId = state.db.workspacesMod.saveWorkspace({
companyId: state.companyId,
name: "Primary",
localPath: profileDir,
@@ -15,11 +15,11 @@ describe("Step 3: Wakeup request lifecycle (database)", () => {
// Enqueue two wakes for the same busy agent. Coalesced into one row
// with trigger_detail JSON array containing both triggers.
shared.db.enqueueWakeupRequest(shared.companyId, agentId, "subtask_completed", "subtask_completed");
shared.db.enqueueWakeupRequest(shared.companyId, agentId, "comment", "comment");
shared.db.wakeup.enqueueWakeupRequest(shared.companyId, agentId, "subtask_completed", "subtask_completed");
shared.db.wakeup.enqueueWakeupRequest(shared.companyId, agentId, "comment", "comment");
// List returns the coalesced wake
const wakes = shared.db.listWakeupRequests(shared.companyId, { agentId, status: "queued" });
const wakes = shared.db.wakeup.listWakeupRequests(shared.companyId, { agentId, status: "queued" });
expect(wakes).toHaveLength(1);
expect(wakes[0].companyId).toBe(shared.companyId);
expect(wakes[0].coalescedCount).toBe(1);
@@ -32,7 +32,7 @@ describe("Step 3: Wakeup request lifecycle (database)", () => {
it("returns empty array when no wakeup requests exist", () => {
const agentId = createAgent({ name: "TestAgent" });
const wakes = shared.db.listWakeupRequests(shared.companyId, { agentId, status: "queued" });
const wakes = shared.db.wakeup.listWakeupRequests(shared.companyId, { agentId, status: "queued" });
expect(wakes).toHaveLength(0);
});
@@ -40,15 +40,15 @@ describe("Step 3: Wakeup request lifecycle (database)", () => {
const agent1 = createAgent({ name: "Agent1" });
const agent2 = createAgent({ name: "Agent2" });
shared.db.enqueueWakeupRequest(shared.companyId, agent1, "comment", "comment");
shared.db.enqueueWakeupRequest(shared.companyId, agent2, "subtask_completed", "subtask_completed");
shared.db.wakeup.enqueueWakeupRequest(shared.companyId, agent1, "comment", "comment");
shared.db.wakeup.enqueueWakeupRequest(shared.companyId, agent2, "subtask_completed", "subtask_completed");
const wakes1 = shared.db.listWakeupRequests(shared.companyId, { agentId: agent1, status: "queued" });
const wakes1 = shared.db.wakeup.listWakeupRequests(shared.companyId, { agentId: agent1, status: "queued" });
expect(wakes1).toHaveLength(1);
expect(wakes1[0].source).toBe("comment");
// Agent2's wake should still be there
const wakes2 = shared.db.listWakeupRequests(shared.companyId, { agentId: agent2, status: "queued" });
const wakes2 = shared.db.wakeup.listWakeupRequests(shared.companyId, { agentId: agent2, status: "queued" });
expect(wakes2).toHaveLength(1);
expect(wakes2[0].source).toBe("subtask_completed");
});