mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-08 19:56:31 +02: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>
142 lines
5.9 KiB
TypeScript
142 lines
5.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
BUILTIN_ROUTINE_VARIABLE_NAMES,
|
|
extractRoutineVariableNames,
|
|
getBuiltinRoutineVariableValues,
|
|
interpolateRoutineTemplate,
|
|
isBuiltinRoutineVariable,
|
|
isRoutineDateVariableName,
|
|
isValidRoutineDateString,
|
|
syncRoutineVariablesWithTemplate,
|
|
} from "./routine-variables.js";
|
|
|
|
describe("routine variable helpers", () => {
|
|
it("extracts placeholder names in first-appearance order", () => {
|
|
expect(
|
|
extractRoutineVariableNames("Review {{repo}} and {{priority}} for {{repo}}"),
|
|
).toEqual(["repo", "priority"]);
|
|
});
|
|
|
|
it("deduplicates placeholder names across the routine title and description", () => {
|
|
expect(
|
|
extractRoutineVariableNames([
|
|
"Triage {{repo}}",
|
|
"Review {{repo}} for {{priority}} bugs",
|
|
]),
|
|
).toEqual(["repo", "priority"]);
|
|
});
|
|
|
|
it("preserves existing metadata when syncing variables from a template", () => {
|
|
expect(
|
|
syncRoutineVariablesWithTemplate(["Triage {{repo}}", "Review {{repo}} and {{startDate}}"], [
|
|
{ name: "repo", label: "Repository", type: "text", defaultValue: "paperclip", required: true, options: [] },
|
|
{ name: "startDate", label: "Start", type: "text", defaultValue: "soon", required: false, options: [] },
|
|
]),
|
|
).toEqual([
|
|
{ name: "repo", label: "Repository", type: "text", defaultValue: "paperclip", required: true, options: [] },
|
|
{ name: "startDate", label: "Start", type: "text", defaultValue: "soon", required: false, options: [] },
|
|
]);
|
|
});
|
|
|
|
it("identifies routine date variable names by strict capital-Date suffix", () => {
|
|
expect(isRoutineDateVariableName("startDate")).toBe(true);
|
|
expect(isRoutineDateVariableName("endDate")).toBe(true);
|
|
expect(isRoutineDateVariableName("fooDate")).toBe(true);
|
|
expect(isRoutineDateVariableName("date")).toBe(false);
|
|
expect(isRoutineDateVariableName("startdate")).toBe(false);
|
|
expect(isRoutineDateVariableName("candidate")).toBe(false);
|
|
expect(isRoutineDateVariableName("Date")).toBe(false);
|
|
});
|
|
|
|
it("defaults newly synced capital-Date variables to date type", () => {
|
|
expect(
|
|
syncRoutineVariablesWithTemplate("Compare {{startDate}} to {{endDate}} with {{date}}", []),
|
|
).toEqual([
|
|
{ name: "startDate", label: null, type: "date", defaultValue: null, required: true, options: [] },
|
|
{ name: "endDate", label: null, type: "date", defaultValue: null, required: true, options: [] },
|
|
]);
|
|
});
|
|
|
|
it("validates YYYY-MM-DD routine date strings as real calendar dates", () => {
|
|
expect(isValidRoutineDateString("2024-02-29")).toBe(true);
|
|
expect(isValidRoutineDateString("2024-02-30")).toBe(false);
|
|
expect(isValidRoutineDateString("2023-02-29")).toBe(false);
|
|
expect(isValidRoutineDateString("2024-13-01")).toBe(false);
|
|
expect(isValidRoutineDateString("2024-1-01")).toBe(false);
|
|
});
|
|
|
|
it("interpolates provided variable values into the routine template", () => {
|
|
expect(
|
|
interpolateRoutineTemplate("Review {{repo}} for {{priority}}", {
|
|
repo: "paperclip",
|
|
priority: "high",
|
|
}),
|
|
).toBe("Review paperclip for high");
|
|
});
|
|
|
|
it("identifies built-in variable names", () => {
|
|
expect(isBuiltinRoutineVariable("date")).toBe(true);
|
|
expect(isBuiltinRoutineVariable("timestamp")).toBe(true);
|
|
expect(isBuiltinRoutineVariable("repo")).toBe(false);
|
|
expect(BUILTIN_ROUTINE_VARIABLE_NAMES.has("date")).toBe(true);
|
|
expect(BUILTIN_ROUTINE_VARIABLE_NAMES.has("timestamp")).toBe(true);
|
|
});
|
|
|
|
it("getBuiltinRoutineVariableValues returns date in YYYY-MM-DD format", () => {
|
|
const values = getBuiltinRoutineVariableValues();
|
|
expect(values.date).toMatch(/^\d{4}-\d{2}-\d{2}$/);
|
|
expect(values.date).toBe(new Date().toISOString().slice(0, 10));
|
|
});
|
|
|
|
it("getBuiltinRoutineVariableValues returns a human-readable timestamp with year, time, and UTC", () => {
|
|
const values = getBuiltinRoutineVariableValues();
|
|
const year = String(new Date().getUTCFullYear());
|
|
expect(values.timestamp).toContain(year);
|
|
expect(values.timestamp).toMatch(/\d{1,2}:\d{2}\s?(AM|PM)/);
|
|
expect(values.timestamp).toContain("UTC");
|
|
});
|
|
|
|
it("excludes built-in variables from syncRoutineVariablesWithTemplate", () => {
|
|
const result = syncRoutineVariablesWithTemplate(
|
|
"Daily report for {{date}} at {{timestamp}} — {{repo}}",
|
|
[],
|
|
);
|
|
expect(result).toEqual([
|
|
{ name: "repo", label: null, type: "text", defaultValue: null, required: true, options: [] },
|
|
]);
|
|
});
|
|
|
|
it("extracts snake_case variable names", () => {
|
|
expect(extractRoutineVariableNames("Open {{pr_url}} for review")).toEqual(["pr_url"]);
|
|
});
|
|
|
|
it("extracts variable names whose underscores were markdown-escaped by a WYSIWYG editor", () => {
|
|
// MDXEditor / mdast-util-to-markdown defensively escape intraword underscores
|
|
// when serializing rich-text back to markdown, so `{{pr_url}}` is stored as `{{pr\_url}}`.
|
|
expect(extractRoutineVariableNames("Open {{pr\\_url}} for review")).toEqual(["pr_url"]);
|
|
expect(extractRoutineVariableNames("{{pr\\_url\\_v2}}")).toEqual(["pr_url_v2"]);
|
|
});
|
|
|
|
it("syncRoutineVariablesWithTemplate handles markdown-escaped underscores", () => {
|
|
expect(
|
|
syncRoutineVariablesWithTemplate("Open {{pr\\_url}}", []),
|
|
).toEqual([
|
|
{ name: "pr_url", label: null, type: "text", defaultValue: null, required: true, options: [] },
|
|
]);
|
|
});
|
|
|
|
it("interpolates variables that appear with markdown-escaped underscores", () => {
|
|
expect(
|
|
interpolateRoutineTemplate("Open {{pr\\_url}}", { pr_url: "https://example.com" }),
|
|
).toBe("Open https://example.com");
|
|
});
|
|
|
|
it("interpolates built-in variables alongside user variables", () => {
|
|
const builtins = getBuiltinRoutineVariableValues();
|
|
const allVars = { ...builtins, repo: "paperclip" };
|
|
expect(
|
|
interpolateRoutineTemplate("Report for {{date}} ({{timestamp}}) on {{repo}}", allVars),
|
|
).toBe(`Report for ${builtins.date} (${builtins.timestamp}) on paperclip`);
|
|
});
|
|
});
|