Files
AgentCompany/tests/integration/autonomous-chain/wakeup-queue.spec.ts
T
ZacharyZhang-NY 118e3d8795 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.
2026-04-20 13:31:39 -04:00

56 lines
2.3 KiB
TypeScript

/**
* Step 3: Deferred wake queue lifecycle.
* 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 3: Wakeup request lifecycle (database)", () => {
it("enqueue and list wakeup requests with coalescing", () => {
const agentId = createAgent({ name: "TestAgent" });
// Enqueue two wakes for the same busy agent. Coalesced into one row
// with trigger_detail JSON array containing both triggers.
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.wakeup.listWakeupRequests(shared.companyId, { agentId, status: "queued" });
expect(wakes).toHaveLength(1);
expect(wakes[0].companyId).toBe(shared.companyId);
expect(wakes[0].coalescedCount).toBe(1);
const triggers = JSON.parse(wakes[0].triggerDetail!);
expect(triggers).toHaveLength(2);
expect(triggers[0].trigger).toBe("subtask_completed");
expect(triggers[1].trigger).toBe("comment");
});
it("returns empty array when no wakeup requests exist", () => {
const agentId = createAgent({ name: "TestAgent" });
const wakes = shared.db.wakeup.listWakeupRequests(shared.companyId, { agentId, status: "queued" });
expect(wakes).toHaveLength(0);
});
it("does not return wakes for other agents", () => {
const agent1 = createAgent({ name: "Agent1" });
const agent2 = createAgent({ name: "Agent2" });
shared.db.wakeup.enqueueWakeupRequest(shared.companyId, agent1, "comment", "comment");
shared.db.wakeup.enqueueWakeupRequest(shared.companyId, agent2, "subtask_completed", "subtask_completed");
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.wakeup.listWakeupRequests(shared.companyId, { agentId: agent2, status: "queued" });
expect(wakes2).toHaveLength(1);
expect(wakes2[0].source).toBe("subtask_completed");
});
});