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:
1 parent
a69fbb053b
commit
118e3d8795
120 files changed
+838
-933
No files matched your search
@@ -84,10 +84,7 @@ function createMockDb() {
|
||||
createdAt: string;
|
||||
}> = [];
|
||||
|
||||
return {
|
||||
policies,
|
||||
costEntries,
|
||||
|
||||
const budget = {
|
||||
saveBudgetPolicy(input: Partial<BudgetPolicyRecord> & { companyId: string; scopeType: string; scopeId: string; amount: number }) {
|
||||
const id = input.id ?? crypto.randomUUID();
|
||||
const existing = policies.findIndex((p) => p.id === id);
|
||||
@@ -150,6 +147,7 @@ function createMockDb() {
|
||||
return computeSpentCents(filtered);
|
||||
},
|
||||
};
|
||||
return { policies, costEntries, budget };
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
@@ -164,7 +162,7 @@ describe("Budget Policy CRUD", () => {
|
||||
});
|
||||
|
||||
it("saveBudgetPolicy creates new policy and returns its ID", () => {
|
||||
const id = db.saveBudgetPolicy({
|
||||
const id = db.budget.saveBudgetPolicy({
|
||||
companyId: "c1",
|
||||
scopeType: "company",
|
||||
scopeId: "c1",
|
||||
@@ -177,13 +175,13 @@ describe("Budget Policy CRUD", () => {
|
||||
});
|
||||
|
||||
it("saveBudgetPolicy updates existing policy when ID provided", () => {
|
||||
const id = db.saveBudgetPolicy({
|
||||
const id = db.budget.saveBudgetPolicy({
|
||||
companyId: "c1",
|
||||
scopeType: "company",
|
||||
scopeId: "c1",
|
||||
amount: 10000,
|
||||
});
|
||||
db.saveBudgetPolicy({
|
||||
db.budget.saveBudgetPolicy({
|
||||
id,
|
||||
companyId: "c1",
|
||||
scopeType: "company",
|
||||
@@ -195,14 +193,14 @@ describe("Budget Policy CRUD", () => {
|
||||
});
|
||||
|
||||
it("deleteBudgetPolicy removes policy by ID", () => {
|
||||
const id = db.saveBudgetPolicy({
|
||||
const id = db.budget.saveBudgetPolicy({
|
||||
companyId: "c1",
|
||||
scopeType: "company",
|
||||
scopeId: "c1",
|
||||
amount: 10000,
|
||||
});
|
||||
expect(db.policies).toHaveLength(1);
|
||||
db.deleteBudgetPolicy("c1", id);
|
||||
db.budget.deleteBudgetPolicy("c1", id);
|
||||
expect(db.policies).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
@@ -215,27 +213,27 @@ describe("getActivePoliciesForRun", () => {
|
||||
});
|
||||
|
||||
it("returns all active policies matching company+agent+project scopes", () => {
|
||||
db.saveBudgetPolicy({ companyId: "c1", scopeType: "company", scopeId: "c1", amount: 50000 });
|
||||
db.saveBudgetPolicy({ companyId: "c1", scopeType: "agent", scopeId: "a1", amount: 10000 });
|
||||
db.saveBudgetPolicy({ companyId: "c1", scopeType: "project", scopeId: "p1", amount: 20000 });
|
||||
db.budget.saveBudgetPolicy({ companyId: "c1", scopeType: "company", scopeId: "c1", amount: 50000 });
|
||||
db.budget.saveBudgetPolicy({ companyId: "c1", scopeType: "agent", scopeId: "a1", amount: 10000 });
|
||||
db.budget.saveBudgetPolicy({ companyId: "c1", scopeType: "project", scopeId: "p1", amount: 20000 });
|
||||
// Different company — should not match
|
||||
db.saveBudgetPolicy({ companyId: "c2", scopeType: "company", scopeId: "c2", amount: 99999 });
|
||||
db.budget.saveBudgetPolicy({ companyId: "c2", scopeType: "company", scopeId: "c2", amount: 99999 });
|
||||
|
||||
const result = db.getActivePoliciesForRun("c1", "a1", "p1");
|
||||
const result = db.budget.getActivePoliciesForRun("c1", "a1", "p1");
|
||||
expect(result).toHaveLength(3);
|
||||
expect(result.map((p) => p.scopeType).sort()).toEqual(["agent", "company", "project"]);
|
||||
});
|
||||
|
||||
it("returns empty array when no policies exist (D-02: no policy = unlimited)", () => {
|
||||
const result = db.getActivePoliciesForRun("c1", "a1", null);
|
||||
const result = db.budget.getActivePoliciesForRun("c1", "a1", null);
|
||||
expect(result).toEqual([]);
|
||||
});
|
||||
|
||||
it("excludes project scope when projectId is null", () => {
|
||||
db.saveBudgetPolicy({ companyId: "c1", scopeType: "company", scopeId: "c1", amount: 50000 });
|
||||
db.saveBudgetPolicy({ companyId: "c1", scopeType: "project", scopeId: "p1", amount: 20000 });
|
||||
db.budget.saveBudgetPolicy({ companyId: "c1", scopeType: "company", scopeId: "c1", amount: 50000 });
|
||||
db.budget.saveBudgetPolicy({ companyId: "c1", scopeType: "project", scopeId: "p1", amount: 20000 });
|
||||
|
||||
const result = db.getActivePoliciesForRun("c1", "a1", null);
|
||||
const result = db.budget.getActivePoliciesForRun("c1", "a1", null);
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]!.scopeType).toBe("company");
|
||||
});
|
||||
@@ -261,7 +259,7 @@ describe("getSpentInWindow", () => {
|
||||
amount: 100000, warnPercent: 80, hardStopEnabled: true, notifyEnabled: true,
|
||||
isActive: true, createdAt: now.toISOString(), updatedAt: now.toISOString(),
|
||||
};
|
||||
const spent = db.getSpentInWindow(policy);
|
||||
const spent = db.budget.getSpentInWindow(policy);
|
||||
expect(spent).toBe(380); // (1.50 + 2.30) * 100 = 380 cents
|
||||
});
|
||||
|
||||
@@ -278,7 +276,7 @@ describe("getSpentInWindow", () => {
|
||||
amount: 100000, warnPercent: 80, hardStopEnabled: true, notifyEnabled: true,
|
||||
isActive: true, createdAt: now.toISOString(), updatedAt: now.toISOString(),
|
||||
};
|
||||
const spent = db.getSpentInWindow(policy);
|
||||
const spent = db.budget.getSpentInWindow(policy);
|
||||
expect(spent).toBe(500); // Only a1's $5.00 = 500 cents
|
||||
});
|
||||
|
||||
@@ -295,7 +293,7 @@ describe("getSpentInWindow", () => {
|
||||
amount: 100000, warnPercent: 80, hardStopEnabled: true, notifyEnabled: true,
|
||||
isActive: true, createdAt: now.toISOString(), updatedAt: now.toISOString(),
|
||||
};
|
||||
const spent = db.getSpentInWindow(policy);
|
||||
const spent = db.budget.getSpentInWindow(policy);
|
||||
expect(spent).toBe(750); // Only p1's $7.50 = 750 cents
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user