40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { issueExecutionPolicySchema } from "@paperclipai/shared";
|
|
import { buildExecutionPolicy } from "./issue-execution-policy";
|
|
|
|
const AGENT_ID = "00000000-0000-4000-8000-000000000001";
|
|
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
|
|
describe("buildExecutionPolicy", () => {
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("generates schema-valid UUIDs when crypto.randomUUID is unavailable", () => {
|
|
vi.stubGlobal("crypto", {
|
|
getRandomValues: (bytes: Uint8Array) => {
|
|
for (let index = 0; index < bytes.length; index += 1) {
|
|
bytes[index] = index;
|
|
}
|
|
return bytes;
|
|
},
|
|
});
|
|
|
|
const policy = buildExecutionPolicy({
|
|
existingPolicy: null,
|
|
reviewerValues: [`agent:${AGENT_ID}`],
|
|
approverValues: ["user:local-board"],
|
|
});
|
|
|
|
expect(policy).not.toBeNull();
|
|
expect(issueExecutionPolicySchema.safeParse(policy).success).toBe(true);
|
|
expect(policy?.stages).toHaveLength(2);
|
|
|
|
for (const stage of policy?.stages ?? []) {
|
|
expect(stage.id).toMatch(UUID_PATTERN);
|
|
expect(stage.participants).toHaveLength(1);
|
|
expect(stage.participants[0]?.id).toMatch(UUID_PATTERN);
|
|
}
|
|
});
|
|
});
|