mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-27 11:40:00 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - The scheduled-routine journey checks creation, timed execution,
saved output and pause.
> - The routine page redesign changed its form and schedule controls.
> - The journey still used the old title placeholder, Responsible picker
and trigger editor.
> - It stopped before it could measure scheduling, even after the New
routine button fix.
> - This pull request follows the current controls and adds a
production-component browser regression.
> - The benefit is a usable schedule test with the same independent
behavior checks.
## Linked Issues or Issue Description
Refs #22182 and #22205. Related open #22340 changes other routine page
details; it does not update this journey.
**What happened?**
The scheduled-routine journey opens New routine, then times out on the
removed Routine title placeholder. The current form labels that field
Title. It has a Default agent picker and a separate Project picker. The
old journey also expects the removed Schedule trigger region and Enable
trigger control.
**Expected behavior**
The journey must use the current form, resume its owned schedule,
observe one attributed scheduled run, pause it, and check the next full
schedule boundary.
**Steps to reproduce**
Run the new credential-free browser control against the previous UI
actions. It renders the production RoutineEditDialog and fails waiting
for the old Routine title placeholder. The same control passes with this
repair.
**Paperclip version or commit**
Reproduced from master at d128e2db6f.
Published on current master after checking that all four existing
changed files were unchanged.
**Deployment mode**
Local Chromium production-component control, with no app server, model
or testing credentials. The observed staging failure supplied the
original report. This PR has no fresh full-stack staging pass.
## What Changed
- Extract the routine browser actions into a small journey-owned module.
- Fill Title and Instructions by accessible name. Open the agent and
project pickers explicitly.
- Use the schedule popover's Resume and Pause controls. Wait for each
exact trigger PATCH.
- Read created-task history on the base routine page. Keep configuration
version history separate.
- Add a Chromium control using the actual form, entity selectors and
routine page. It checks exact owner/project selection, missing-choice
refusal and the two owned trigger mutations. Unrelated display/editor
boundaries are stubbed.
- Keep the scheduler, native run, output, reload, duplicate-run,
deadline and cleanup oracles intact.
- Document the control and its limited acceptance scope.
## Verification
- Red: the production-component browser control timed out on
`getByPlaceholder("Routine title")` with the original actions.
- Green: `BROWSER_EXECUTABLE_PATH=/usr/bin/chromium node --import
/tmp/pap5819-tools/node_modules/tsx/dist/loader.mjs
tests/runner-e2e/product-journeys/routine-schedule-ui.browser.mjs`
passes.
- Focused Vitest: all 17 tests in routine-schedule-entry,
routine-schedule-evidence and routine-schedule-flow pass. The temporary
config selects only those suites.
- Local tools: Node 25.9.0, Vitest 5.0.3, Playwright 1.62.1 and system
Chromium. Dependencies were installed outside the checkout; no lockfile
changed.
- `pnpm verify` could not select tests: the managed Git storage guard
rejects `git ls-files`. This attempt has no verification verdict. The
first head passed selected CI. Those results do not qualify the revised
head; fresh CI and review remain pending.
- No new paid run, protected test-harness pin change or staging
deployment was made. Full scheduled acceptance remains separate.
- Review regression: the production route resolver rejects the old
/history task read; all 17 focused tests pass after the correction.
- Isolated dependency layout: the previous browser check cannot resolve
React without root React/React DOM. The revised check resolves UI-owned
peers and passes in that layout.
## Risks
- These actions target the current redesigned routine UI. An old UI
paired with this harness would not match the controls.
- The browser regression stubs unrelated display/editor boundaries. It
proves the real control actions, not a complete scheduler or
native-provider run.
- The fixture owns one schedule. Multiple matching schedule controls
cause an error rather than selecting an arbitrary trigger.
> 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 GPT-6 in Codex, with tool use for source edits, Chromium, local
tests and GitHub API operations.
## 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
- [ ] All Paperclip CI gates are green
- [ ] 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>
159 lines
11 KiB
TypeScript
159 lines
11 KiB
TypeScript
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { createHash } from "node:crypto";
|
|
import { afterEach, expect, it, vi } from "vitest";
|
|
import { runScheduledRoutine } from "./routine-schedule-flow.js";
|
|
import { resolveRoutineAddress } from "../../../ui/src/components/routine-page/routine-routes.js";
|
|
import type { JourneyContext, JourneyEvidence, TargetSession } from "./types.js";
|
|
|
|
// Browser rendering is covered by the real Routines component tests. This entry
|
|
// control keeps the API reads and the production attribution grade intact.
|
|
vi.mock("@playwright/test", () => ({ expect: Object.assign(() => ({ toBeVisible: async () => {} }), {
|
|
poll: (load: () => Promise<unknown>) => ({ toBe: async (value: unknown) => expect(await load()).toBe(value) }),
|
|
}) }));
|
|
type Row = Record<string, any>;
|
|
const directories: string[] = [];
|
|
afterEach(async () => { await Promise.all(directories.splice(0).map(directory => rm(directory, { recursive: true, force: true }))); });
|
|
|
|
async function fixture(fault: "body" | "document-author" | "revision-run" | "creation-description" | "creation-project" | null = null, disableFailure = false) {
|
|
const campaignId = "journey-1-campaign", expectedBody = `scheduled-${campaignId}\nSchedule check complete.`;
|
|
const agent = { id: "agent", name: "Owned QA agent", provider: "opencode", model: "configured-model", runtimeMode: "native" };
|
|
const project = { id: "project", companyId: "company", name: `Journey QA routine project ${campaignId}` };
|
|
const trigger = { id: "trigger", companyId: "company", routineId: "routine", kind: "schedule", cronExpression: "* * * * *",
|
|
timezone: "America/Chicago", enabled: false, updatedAt: new Date(60_000).toISOString() };
|
|
const invocation = { id: "invocation", companyId: "company", routineId: "routine", triggerId: "trigger", source: "schedule",
|
|
status: "completed", linkedIssueId: "task", routineRevisionId: "routine-revision", triggeredAt: new Date(61_000).toISOString() };
|
|
const task = { id: "task", identifier: "QA-1", companyId: "company", projectId: "project", assigneeAgentId: agent.id,
|
|
status: "done", originKind: "routine_execution", originId: "routine", originRunId: "invocation" };
|
|
const run = { id: "native-run", companyId: "company", issueId: task.id, agentId: agent.id, status: "succeeded", runtimeMode: "native",
|
|
contextSnapshot: { paperclipEnvironment: { id: "environment" } },
|
|
runnerProfileJson: { nativeExecutionInput: { provider: { kind: agent.provider, model: agent.model } } } };
|
|
const body = fault === "body" ? expectedBody.slice(0, -1) : expectedBody;
|
|
const document = { id: "document", companyId: "company", issueId: task.id, latestRevisionId: "revision", body,
|
|
createdByAgentId: fault === "document-author" ? "foreign-agent" : agent.id, createdByUserId: null };
|
|
const revision = { id: "revision", documentId: document.id, body, createdByAgentId: agent.id,
|
|
createdByRunId: fault === "revision-run" ? "foreign-run" : run.id };
|
|
const reads: string[] = [];
|
|
const visited: string[] = [];
|
|
let instructions = "", pastes = 0, triggerCreated = false, responseResolver: ((value: unknown) => void) | undefined;
|
|
const routine = () => ({ id: "routine", companyId: "company", title: `Journey QA scheduled routine ${campaignId}`,
|
|
projectId: fault === "creation-project" ? "foreign-project" : project.id, assigneeAgentId: agent.id,
|
|
createdByUserId: "user", createdByAgentId: null,
|
|
description: fault === "creation-description" ? instructions.replaceAll("`", "\\`") : instructions,
|
|
concurrencyPolicy: "always_enqueue", triggers: triggerCreated ? [trigger] : [] });
|
|
const locator = (name = ""): any => ({ first() { return this; }, getByRole: (_role: string, options: { name?: string } = {}) => locator(options.name),
|
|
getByPlaceholder: () => locator(), focus: async () => {}, locator: () => ({
|
|
fill: async (value: string) => { instructions = value; }, focus: async () => {},
|
|
// The real MDX browser discriminator covers serialization. Keep this unit
|
|
// editor boundary separate from the production API reads and grade.
|
|
evaluate: async (_action: unknown, text?: string) => {
|
|
if (text === undefined) return false;
|
|
pastes += 1; instructions = text;
|
|
},
|
|
}),
|
|
fill: async (value: string) => { if (name === "Instructions") instructions = value; },
|
|
evaluate: async (_action: unknown, text?: string) => {
|
|
if (text === undefined) return false;
|
|
pastes += 1; instructions = text;
|
|
}, click: async () => {
|
|
if (name === "Resume") { trigger.enabled = true; responseResolver?.({ status: () => 200, json: async () => ({ ...trigger }) }); }
|
|
if (name === "Pause") { trigger.enabled = false; responseResolver?.({ status: () => 200 }); }
|
|
if (name === "Create routine") responseResolver?.({ status: () => 201, json: async () => routine() });
|
|
} });
|
|
const api = { origin: "https://qa.example.test", async post(route: string) {
|
|
if (route === "/api/companies/company/projects") return project;
|
|
expect(route).toBe("/api/routines/routine/triggers"); triggerCreated = true; return { trigger: { ...trigger } };
|
|
}, async patch(route: string, input: Row) {
|
|
if (route === "/api/routine-triggers/trigger") {
|
|
if (disableFailure) throw new Error("Private transport error must not replace attribution");
|
|
trigger.enabled = input.enabled;
|
|
}
|
|
},
|
|
async get(route: string) {
|
|
reads.push(route);
|
|
if (route === "/api/routines/routine") return routine();
|
|
if (route === "/api/routines/routine/runs") return [invocation];
|
|
if (route === "/api/issues/task") return task;
|
|
if (route === "/api/issues/task/runs") return [{ runId: run.id }];
|
|
if (route === "/api/heartbeat-runs/native-run") return run;
|
|
if (route === "/api/issues/task/comments?order=asc" || route === "/api/issues/task/interactions") return [];
|
|
if (route === "/api/issues/task/documents/scheduled-summary") return document;
|
|
if (route === "/api/issues/task/documents/scheduled-summary/revisions/revision") return revision;
|
|
throw new Error(`Unexpected fixture read ${route}`);
|
|
} };
|
|
const page = { getByRole: (role: string, options: { name?: string } = {}) => {
|
|
if (role === "link" && options.name === task.identifier) {
|
|
// Stop at the task-link assertion, independently of the address chosen.
|
|
// The test below checks that address using the production route resolver.
|
|
throw new Error("Stop the positive control before the real pause window");
|
|
}
|
|
return locator(options.name);
|
|
}, getByPlaceholder: () => locator(),
|
|
async goto(url: string) { visited.push(url); }, async reload() {},
|
|
waitForResponse: () => new Promise(resolve => { responseResolver = resolve; }) };
|
|
const context = { api, page, company: { id: "company", issuePrefix: "QA" }, user: { id: "user" }, agent, environmentId: "environment" } as unknown as JourneyContext;
|
|
const directory = await mkdtemp(path.join(os.tmpdir(), "routine-attribution-")); directories.push(directory);
|
|
const evidence = { checks: [] } as unknown as JourneyEvidence;
|
|
return { expectedBody, body, instructions: () => instructions, pastes: () => pastes, evidence, trigger, directory, reads, visited,
|
|
run: () => runScheduledRoutine(context, { async own() {} } as unknown as TargetSession, campaignId, evidence,
|
|
{ directory, deadlineAt: Date.now() + 10_000 }) };
|
|
}
|
|
|
|
it.each(["creation-description", "creation-project"] as const)("retains closed %s evidence before the unchanged creation failure", async fault => {
|
|
const f = await fixture(fault);
|
|
await expect(f.run()).rejects.toMatchObject({ code: "routine_browser_created" });
|
|
const receipt = JSON.parse(await readFile(path.join(f.directory, "scheduled-routine-creation.json"), "utf8"));
|
|
expect(receipt.matches).toEqual({ company: true, title: true, project: fault !== "creation-project", assignee: true,
|
|
userCreator: true, agentCreatorNull: true, description: fault !== "creation-description", concurrency: true, zeroTriggers: true });
|
|
expect(receipt.expectedDescription.sha256).toBe(createHash("sha256").update(f.instructions()).digest("hex"));
|
|
expect(receipt.savedDescription.backslashCount).toBe(fault === "creation-description" ? 6 : 0);
|
|
expect(JSON.stringify(receipt)).not.toContain("Schedule check complete");
|
|
expect(f.evidence.checks).toEqual([{ id: "routine-browser-created", passed: false }]);
|
|
expect(f.reads.some(route => route.includes("heartbeat-runs"))).toBe(false);
|
|
});
|
|
|
|
it.each(["body", "document-author", "revision-run"] as const)("retains closed %s attribution evidence before preserving the failed grade", async fault => {
|
|
const f = await fixture(fault);
|
|
await expect(f.run()).rejects.toMatchObject({ code: "routine_result_attributed" });
|
|
const receipt = JSON.parse(await readFile(path.join(f.directory, "scheduled-routine-result.json"), "utf8"));
|
|
expect(receipt.matches).toMatchObject({ documentExactBody: fault !== "body", documentAuthor: fault !== "document-author", revisionRun: fault !== "revision-run" });
|
|
expect(Object.values(receipt.matches).every(Boolean)).toBe(false);
|
|
expect(receipt.documentBody.sha256).toBe(createHash("sha256").update(f.body).digest("hex"));
|
|
expect(receipt.revision.createdByRunId).toBe(fault === "revision-run" ? "foreign-run" : "native-run");
|
|
expect(JSON.stringify(receipt)).not.toContain("Schedule check complete");
|
|
expect(f.evidence.checks.at(-1)).toEqual({ id: "routine-result-attributed", passed: false });
|
|
expect(f.trigger.enabled).toBe(false);
|
|
});
|
|
|
|
it("keeps the real journey attribution failure when final trigger disabling also fails", async () => {
|
|
const f = await fixture("body", true);
|
|
await expect(f.run()).rejects.toMatchObject({ code: "routine_result_attributed" });
|
|
expect(f.evidence.checks.at(-1)).toEqual({ id: "routine-result-attributed", passed: false });
|
|
const receipt = JSON.parse(await readFile(path.join(f.directory, "scheduled-routine-cleanup-failure.json"), "utf8"));
|
|
expect(receipt).toMatchObject({ code: "routine_trigger_disable_failed", primaryFailurePreserved: true });
|
|
expect(JSON.stringify(receipt)).not.toContain("Private transport");
|
|
});
|
|
|
|
it("sends the unchanged exact two-line body as a delimited instruction and accepts valid attribution", async () => {
|
|
const f = await fixture();
|
|
await expect(f.run()).rejects.toMatchObject({ code: "routine_open_history_failed" });
|
|
const historyUrl = new URL(f.visited.at(-1)!);
|
|
const section = historyUrl.pathname.split("/")[4];
|
|
expect(resolveRoutineAddress({ routineId: "routine", section }).view).toBe("routine");
|
|
expect(historyUrl.pathname).toBe("/QA/routines/routine");
|
|
const block = f.instructions().match(/```text\n([\s\S]*?)\n```/);
|
|
expect(block?.[1]).toBe(f.expectedBody);
|
|
expect(f.instructions()).toContain("including the final period");
|
|
expect(f.instructions()).toContain("document body.\n\n```text\n");
|
|
expect(f.instructions()).toContain("\n```\n\nThen finish the task.");
|
|
expect(f.pastes()).toBe(1);
|
|
const creation = JSON.parse(await readFile(path.join(f.directory, "scheduled-routine-creation.json"), "utf8"));
|
|
expect(Object.values(creation.matches).every(Boolean)).toBe(true);
|
|
expect(creation.savedDescription.sha256).toBe(createHash("sha256").update(f.instructions()).digest("hex"));
|
|
const receipt = JSON.parse(await readFile(path.join(f.directory, "scheduled-routine-result.json"), "utf8"));
|
|
expect(Object.values(receipt.matches).every(Boolean)).toBe(true);
|
|
expect(f.evidence.checks.at(-1)).toEqual({ id: "routine-result-attributed", passed: true });
|
|
expect(f.trigger.enabled).toBe(false);
|
|
});
|