mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-26 00:48:44 +01:00
Add eleven sparse incoming and outgoing restrictions, human CLI/API administration, shared mutation enforcement, and pending-delivery checks. Preserve existing defaults, agent settings, and existing authorization boundaries. Co-Authored-By: Paperclip <noreply@paperclip.ing>
27 lines
1.8 KiB
TypeScript
27 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { Db } from "@paperclipai/db";
|
|
import type { AgentConfigurationRecord } from "../lib/agent-records.js";
|
|
import { prepareAgentConfiguration } from "../services/agent-configuration.js";
|
|
|
|
const existing = { id: "agent", companyId: "company", status: "idle", budgetMonthlyCents: 500 } as AgentConfigurationRecord;
|
|
// Preparation queues retention work through the database before reading the patch.
|
|
const fakeDb = () => ({
|
|
execute: async () => [],
|
|
select: () => ({ from: () => ({ where: () => ({
|
|
orderBy: async () => [{ id: "ceo", companyId: "company", permissions: {} }],
|
|
}) }) }),
|
|
}) as unknown as Db;
|
|
describe("budget authority in configuration preparation", () => {
|
|
it("rejects agent-originated budget changes before persistence or policy audit", async () => {
|
|
const db = fakeDb();
|
|
await expect(prepareAgentConfiguration(db, existing, { budgetMonthlyCents: 5000 }, { recordRevision: { createdByAgentId: "ceo" } })).rejects.toMatchObject({ status: 403 });
|
|
await expect(prepareAgentConfiguration(db, existing, { budgetMonthlyCents: 0 }, { recordRevision: { createdByAgentId: "ceo" } })).rejects.toMatchObject({ status: 403 });
|
|
});
|
|
it("removes an unchanged legacy budget from agent rollback so it cannot rewrite policy or invent a board actor", async () => {
|
|
expect(await prepareAgentConfiguration(fakeDb(), existing, { budgetMonthlyCents: 500 }, { recordRevision: { createdByAgentId: "ceo", source: "rollback" } })).toEqual({});
|
|
});
|
|
it("preserves the actual board-authorized amount for the existing policy writer", async () => {
|
|
expect(await prepareAgentConfiguration(fakeDb(), existing, { budgetMonthlyCents: 5000 }, { recordRevision: { createdByUserId: "operator-user" } })).toEqual({ budgetMonthlyCents: 5000 });
|
|
});
|
|
});
|