Files
PaperClipAI/packages/plugins/sdk/tests/testing-lifecycle.test.ts
T
Nicky LeachandPaperclip 8f6ce2bf0f Expose a durable resource lifecycle inbox to plugins
Let plugins poll company-scoped resource lifecycle records and acknowledge
successful work. Keep progress per plugin and preserve resource ordering.
Add pagination so failed resources do not block later work.

Verified workspace typechecks, production build, and 164 targeted tests.
The full local test run is in progress.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-06 10:24:54 -07:00

29 lines
2.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { createTestHarness } from "../src/testing.js";
import type { PaperclipPluginManifestV1, ResourceLifecycleEvent } from "../src/types.js";
const manifest: PaperclipPluginManifestV1 = {
id: "fixture.lifecycle", apiVersion: 1, version: "1.0.0", displayName: "Lifecycle", description: "Fixture",
author: "Tests", categories: ["automation"], capabilities: ["events.subscribe"], entrypoints: {},
};
describe("Lifecycle inbox test harness", () => {
it("lets a plugin exercise retries, acknowledgment order, and company scope", async () => {
const harness = createTestHarness({ manifest });
const event: ResourceLifecycleEvent = { id: "1", companyId: "a", resourceType: "agent", resourceId: "agent", action: "create", createdAt: new Date(0).toISOString() };
harness.seed({ lifecycleEvents: [event, { ...event, id: "2", action: "pause" }, { ...event, id: "3", companyId: "b" }] });
expect(await harness.ctx.events.listLifecycle("a")).toEqual([event]);
expect(await harness.ctx.events.listLifecycle("a", 100, "1")).toEqual([]);
expect(await harness.ctx.events.listLifecycle("a")).toEqual([event]);
await expect(harness.ctx.events.acknowledgeLifecycle("a", "2")).rejects.toThrow("earlier lifecycle events");
await expect(harness.ctx.events.acknowledgeLifecycle("a", "3")).rejects.toThrow("not found");
await harness.ctx.events.acknowledgeLifecycle("a", "1");
await harness.ctx.events.acknowledgeLifecycle("a", "1");
expect(await harness.ctx.events.listLifecycle("a")).toEqual([expect.objectContaining({ action: "pause" })]);
expect(await harness.ctx.events.listLifecycle("b")).toEqual([expect.objectContaining({ id: "3" })]);
const denied = createTestHarness({ manifest, capabilities: [] });
await expect(denied.ctx.events.listLifecycle("a")).rejects.toThrow("events.subscribe");
await expect(denied.ctx.events.acknowledgeLifecycle("a", "1")).rejects.toThrow("events.subscribe");
});
});