mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-31 14:16:39 +01:00
Implements the five §3.x spec-completion items flagged in PAP-10735: 1. Runs row subtitle (§3.6): rebuild RunsSection on <EntityRow> with a subtitle showing inline variable values for successful runs and the failure reason for failed runs; de-dupe the redundant trigger label when label === kind (new ui/src/lib/routine-run-display.ts). 2. Runs filter chips (§3.6): Source/Status/Date selects + <FilterBar> active pills + Clear, with a filtered-empty state. 3. Delivery next-5-fires preview (§3.5): new tz-aware ui/src/lib/cron-fires.ts plus a pure previewFirePolicies() that annotates each fire with how the chosen concurrency policy treats it (queued/coalesced/skipped). 4. Secrets (§3.4): extend EnvVarEditor with recentlyUsedSecrets quick-bind chips and replace the native <select>s with shadcn <Select> for parity. 5. Triggers (§3.2): convert the always-open add form into a + New trigger expand-on-click drawer. Tests: new cron-fires + routine-run-display unit suites (30 cases); existing routine/EnvVarEditor-consumer tests stay green; tsc clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
89 lines
3.3 KiB
TypeScript
89 lines
3.3 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { nextCronFires, parseCronExpression, previewFirePolicies } from "./cron-fires";
|
|
|
|
describe("parseCronExpression", () => {
|
|
it("parses a standard 5-field expression", () => {
|
|
const parsed = parseCronExpression("0 14 * * 1-5");
|
|
expect(parsed).not.toBeNull();
|
|
expect(parsed?.minutes).toEqual([0]);
|
|
expect(parsed?.hours).toEqual([14]);
|
|
expect(parsed?.daysOfWeek).toEqual([1, 2, 3, 4, 5]);
|
|
});
|
|
|
|
it("returns null for malformed expressions", () => {
|
|
expect(parseCronExpression("not a cron")).toBeNull();
|
|
expect(parseCronExpression("0 14 * *")).toBeNull();
|
|
expect(parseCronExpression("")).toBeNull();
|
|
expect(parseCronExpression(null)).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("nextCronFires", () => {
|
|
it("computes the next N daily fires in UTC", () => {
|
|
const after = new Date("2026-06-09T10:00:00Z");
|
|
const fires = nextCronFires("0 14 * * *", 3, { after, timeZone: "UTC" });
|
|
expect(fires.map((d) => d.toISOString())).toEqual([
|
|
"2026-06-09T14:00:00.000Z",
|
|
"2026-06-10T14:00:00.000Z",
|
|
"2026-06-11T14:00:00.000Z",
|
|
]);
|
|
});
|
|
|
|
it("skips weekends for a weekday schedule", () => {
|
|
// 2026-06-12 is a Friday; the next weekday fire after Fri is Mon 2026-06-15.
|
|
const after = new Date("2026-06-12T15:00:00Z");
|
|
const fires = nextCronFires("0 14 * * 1-5", 2, { after, timeZone: "UTC" });
|
|
expect(fires.map((d) => d.toISOString())).toEqual([
|
|
"2026-06-15T14:00:00.000Z",
|
|
"2026-06-16T14:00:00.000Z",
|
|
]);
|
|
});
|
|
|
|
it("interprets cron fields in the trigger timezone", () => {
|
|
// 14:00 in New York (EDT, UTC-4 in June) is 18:00 UTC.
|
|
const after = new Date("2026-06-09T10:00:00Z");
|
|
const fires = nextCronFires("0 14 * * *", 1, { after, timeZone: "America/New_York" });
|
|
expect(fires[0]?.toISOString()).toBe("2026-06-09T18:00:00.000Z");
|
|
});
|
|
|
|
it("returns an empty list for an unparseable expression", () => {
|
|
expect(nextCronFires("garbage", 5)).toEqual([]);
|
|
expect(nextCronFires("0 14 * * *", 0)).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("previewFirePolicies", () => {
|
|
const fires = [
|
|
new Date("2026-06-09T14:00:00Z"),
|
|
new Date("2026-06-10T14:00:00Z"),
|
|
new Date("2026-06-11T14:00:00Z"),
|
|
];
|
|
|
|
it("always queues the first fire regardless of policy", () => {
|
|
for (const policy of ["coalesce_if_active", "always_enqueue", "skip_if_active"]) {
|
|
expect(previewFirePolicies(fires, policy)[0]?.disposition).toBe("queued");
|
|
}
|
|
});
|
|
|
|
it("coalesces subsequent fires under coalesce_if_active", () => {
|
|
const preview = previewFirePolicies(fires, "coalesce_if_active");
|
|
expect(preview.map((e) => e.disposition)).toEqual(["queued", "coalesced", "coalesced"]);
|
|
expect(preview[1]?.label).toBe("would be coalesced");
|
|
});
|
|
|
|
it("skips subsequent fires under skip_if_active", () => {
|
|
const preview = previewFirePolicies(fires, "skip_if_active");
|
|
expect(preview.map((e) => e.disposition)).toEqual(["queued", "skipped", "skipped"]);
|
|
});
|
|
|
|
it("queues every fire under always_enqueue", () => {
|
|
const preview = previewFirePolicies(fires, "always_enqueue");
|
|
expect(preview.every((e) => e.disposition === "queued")).toBe(true);
|
|
});
|
|
|
|
it("defaults unknown policies to coalesce", () => {
|
|
const preview = previewFirePolicies(fires, "mystery");
|
|
expect(preview[1]?.disposition).toBe("coalesced");
|
|
});
|
|
});
|