mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-26 18:31:34 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Scheduled routines can prompt agents with variables that are filled in at dispatch time. > - Existing routine variable handling supported plain text-like values, but date inputs need a structured contract so routines can pass consistent date values. > - Operators also need date variables to be easy to configure and override from the routine UI. > - This pull request adds a date variable type across shared validation, server dispatch, and UI editing/run dialogs. > - The benefit is that routine authors can define date inputs once and agents receive validated ISO-style date values when routines run. ## Linked Issues or Issue Description Refs #219 Feature request: - Problem/motivation: Scheduled routines need first-class, typed date variables so operators can configure dates without relying on free-form text conventions. - Proposed solution: Add an `x-date` routine variable type with shared parsing/validation, server dispatch support, and UI date-picker controls in routine variable editors and run dialogs. - Alternatives considered: Continue treating dates as plain text, but that leaves validation and formatting to individual operators and agents. - Roadmap alignment: This is a focused improvement to the completed Scheduled Routines milestone and does not duplicate an active roadmap item. Related PR search: - Searched existing PRs/issues for `routine date picker`, `date variables`, and `scheduled routine date variable`; no direct duplicate PR was found. ## What Changed - Added the shared `x-date` routine variable contract, parsing, defaults, and validation coverage. - Extended routine dispatch to validate and pass date variable values. - Added date input controls to the routine variable editor and routine run variables dialog. - Added focused tests for shared validation, server dispatch, and the UI date controls. ## Verification - `git diff --check public/master...HEAD` - `pnpm run preflight:workspace-links && pnpm exec vitest run packages/shared/src/routine-variables.test.ts packages/shared/src/validators/routine.test.ts server/src/__tests__/routines-service.test.ts ui/src/components/RoutineRunVariablesDialog.test.tsx ui/src/components/RoutineVariablesEditor.test.tsx` - 5 test files passed - 68 tests passed ## Risks Low to medium risk. This adds a new routine variable type across shared/server/UI paths, so the main risk is compatibility with existing routine variable payloads. The change keeps existing variable types intact and adds targeted validation tests for the new date behavior. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used OpenAI Codex coding agent based on GPT-5, with terminal, git, GitHub CLI, and local test execution capabilities. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
114 lines
3.1 KiB
TypeScript
114 lines
3.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
routineRevisionSnapshotV1Schema,
|
|
routineVariableSchema,
|
|
updateRoutineSchema,
|
|
} from "./routine.js";
|
|
|
|
const routineId = "11111111-1111-4111-8111-111111111111";
|
|
const companyId = "22222222-2222-4222-8222-222222222222";
|
|
const triggerId = "33333333-3333-4333-8333-333333333333";
|
|
const baseRevisionId = "44444444-4444-4444-8444-444444444444";
|
|
|
|
describe("routine validators", () => {
|
|
it("accepts versioned routine revision snapshots with safe trigger metadata", () => {
|
|
const parsed = routineRevisionSnapshotV1Schema.parse({
|
|
version: 1,
|
|
routine: {
|
|
id: routineId,
|
|
companyId,
|
|
projectId: null,
|
|
goalId: null,
|
|
parentIssueId: null,
|
|
title: "Daily triage",
|
|
description: null,
|
|
assigneeAgentId: null,
|
|
priority: "medium",
|
|
status: "active",
|
|
concurrencyPolicy: "coalesce_if_active",
|
|
catchUpPolicy: "skip_missed",
|
|
variables: [],
|
|
},
|
|
triggers: [{
|
|
id: triggerId,
|
|
kind: "webhook",
|
|
label: "Inbound",
|
|
enabled: true,
|
|
cronExpression: null,
|
|
timezone: null,
|
|
publicId: "routine_webhook_123",
|
|
signingMode: "bearer",
|
|
replayWindowSec: 300,
|
|
}],
|
|
});
|
|
|
|
expect(parsed.triggers[0]?.publicId).toBe("routine_webhook_123");
|
|
});
|
|
|
|
it("rejects secret-bearing trigger fields in routine revision snapshots", () => {
|
|
expect(() => routineRevisionSnapshotV1Schema.parse({
|
|
version: 1,
|
|
routine: {
|
|
id: routineId,
|
|
companyId,
|
|
projectId: null,
|
|
goalId: null,
|
|
parentIssueId: null,
|
|
title: "Daily triage",
|
|
description: null,
|
|
assigneeAgentId: null,
|
|
priority: "medium",
|
|
status: "active",
|
|
concurrencyPolicy: "coalesce_if_active",
|
|
catchUpPolicy: "skip_missed",
|
|
variables: [],
|
|
},
|
|
triggers: [{
|
|
id: triggerId,
|
|
kind: "webhook",
|
|
label: "Inbound",
|
|
enabled: true,
|
|
cronExpression: null,
|
|
timezone: null,
|
|
publicId: "routine_webhook_123",
|
|
signingMode: "bearer",
|
|
replayWindowSec: 300,
|
|
secretId: "55555555-5555-4555-8555-555555555555",
|
|
}],
|
|
})).toThrow();
|
|
});
|
|
|
|
it("accepts optional base revision ids on routine updates", () => {
|
|
expect(updateRoutineSchema.parse({
|
|
title: "Daily triage",
|
|
baseRevisionId,
|
|
}).baseRevisionId).toBe(baseRevisionId);
|
|
});
|
|
|
|
it("accepts date variables with valid YYYY-MM-DD defaults", () => {
|
|
expect(routineVariableSchema.parse({
|
|
name: "startDate",
|
|
type: "date",
|
|
defaultValue: "2024-02-29",
|
|
})).toMatchObject({
|
|
name: "startDate",
|
|
type: "date",
|
|
defaultValue: "2024-02-29",
|
|
});
|
|
});
|
|
|
|
it("rejects date variables with non-calendar or non-string defaults", () => {
|
|
expect(() => routineVariableSchema.parse({
|
|
name: "startDate",
|
|
type: "date",
|
|
defaultValue: "2024-02-30",
|
|
})).toThrow(/YYYY-MM-DD/);
|
|
|
|
expect(() => routineVariableSchema.parse({
|
|
name: "startDate",
|
|
type: "date",
|
|
defaultValue: 20240229,
|
|
})).toThrow(/YYYY-MM-DD/);
|
|
});
|
|
});
|