mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-26 18:31:34 +01:00
## Thinking Path > - Paperclip is the open-source control plane people use to manage AI agents and their work. > - Its scheduler, routines, and heartbeat services decide when agents automatically begin work. > - Experimental per-worktree execution is useful for isolated development, but enabling it previously allowed automatic services to consider an existing backlog. > - A worktree activation must therefore create a durable eligibility boundary rather than merely toggle execution on. > - This pull request records an activation cutoff and applies it consistently to automatic routine and heartbeat dispatch. > - The result is that an enabled worktree executes only work created after its own activation, while non-worktree behavior remains unchanged. ## Linked Issues or Issue Description **Problem type:** Bug / safety regression **Summary:** Enabling experimental run execution in an existing worktree could start automatic scheduler, routine, watchdog, and heartbeat activity for work created before that worktree was explicitly armed. **Expected behavior:** A worktree that has execution enabled only considers automatically dispatched work created on or after its activation timestamp. Ambiguous activation state fails closed. Non-worktree instances keep their existing behavior. **Related public work:** Refs #8275 (runtime worktree policy gating); this PR adds an activation-time boundary for automatic execution rather than changing the general runtime policy. ## What Changed - Persist a worktree execution activation timestamp and originating instance ID; stamp them only when the experimental toggle changes from disabled to enabled. - Resolve activation state fail-closed when the cutoff is missing, invalid, disabled, or belongs to another instance. - Gate automatic routine scheduling, webhooks, watchdog activity, and heartbeat selection at the activation cutoff; manual runs remain available. - Share the canonical worktree truthy-environment helper across routine dispatch and agent inbox filtering. - Add cutoff and truthy-runtime regression coverage, plus experimental-settings UI states that explain armed and suppressed execution. ## Verification - `pnpm exec vitest run server/src/__tests__/routines-service.test.ts server/src/__tests__/instance-settings-service.test.ts` — passes: 2 files, 60 tests. - `pnpm --filter @paperclipai/server typecheck` — passes. - Existing CI completed successfully before the follow-up review fixes; this branch was rebased onto the latest `origin/master` before retesting. ## Risks - **Behavioral:** Automatic worktree execution is intentionally more restrictive; pre-existing work is suppressed until newly created after activation. - **Operational:** A malformed or cross-instance activation record fails closed, requiring an operator to disable and re-enable the experimental toggle on the intended worktree. - **Compatibility:** The worktree environment now accepts all canonical truthy values (`1`, `true`, `yes`, and `on`) consistently; non-worktree instances are unaffected. - **Branch metadata:** This existing execution-workspace branch predates the current naming rule and cannot be renamed under this task's workspace contract; the code and PR title do not include internal ticket references. > `ROADMAP.md` was checked; this targeted execution-safety fix does not duplicate planned core work. ## Model Used - Anthropic Claude Code — assisted with the original implementation; exact model identifier and context window were not recorded in the repository metadata. - OpenAI Codex CLI — assisted with PR preparation and review fixes; exact model identifier and context window are not exposed in this execution environment. Used with terminal tooling, code editing, and targeted test execution. ## 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) - [ ] 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> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
107 lines
4.0 KiB
TypeScript
107 lines
4.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
applyUiBranding,
|
|
getWorktreeUiBranding,
|
|
isWorktreeUiBrandingEnabled,
|
|
renderFaviconLinks,
|
|
renderRuntimeBrandingMeta,
|
|
} from "../ui-branding.js";
|
|
|
|
const TEMPLATE = `<!doctype html>
|
|
<head>
|
|
<!-- PAPERCLIP_RUNTIME_BRANDING_START -->
|
|
<!-- PAPERCLIP_RUNTIME_BRANDING_END -->
|
|
<!-- PAPERCLIP_FAVICON_START -->
|
|
<link rel="icon" href="/favicon.ico" sizes="48x48" />
|
|
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
|
|
<!-- PAPERCLIP_FAVICON_END -->
|
|
</head>`;
|
|
|
|
describe("ui branding", () => {
|
|
it("detects worktree mode from PAPERCLIP_IN_WORKTREE", () => {
|
|
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "true" })).toBe(true);
|
|
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "1" })).toBe(true);
|
|
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "false" })).toBe(false);
|
|
});
|
|
|
|
it("resolves name, color, and text color for worktree branding", () => {
|
|
const branding = getWorktreeUiBranding({
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_WORKTREE_NAME: "paperclip-pr-432",
|
|
PAPERCLIP_WORKTREE_COLOR: "#4f86f7",
|
|
});
|
|
|
|
expect(branding.enabled).toBe(true);
|
|
expect(branding.name).toBe("paperclip-pr-432");
|
|
expect(branding.color).toBe("#4f86f7");
|
|
expect(branding.textColor).toMatch(/^#[0-9a-f]{6}$/);
|
|
expect(branding.faviconHref).toContain("data:image/svg+xml,");
|
|
});
|
|
|
|
it("renders a dynamic worktree favicon when enabled", () => {
|
|
const links = renderFaviconLinks(
|
|
getWorktreeUiBranding({
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_WORKTREE_NAME: "paperclip-pr-432",
|
|
PAPERCLIP_WORKTREE_COLOR: "#4f86f7",
|
|
}),
|
|
);
|
|
expect(links).toContain("data:image/svg+xml,");
|
|
expect(links).toContain('rel="shortcut icon"');
|
|
});
|
|
|
|
it("renders runtime branding metadata for the ui", () => {
|
|
const meta = renderRuntimeBrandingMeta(
|
|
getWorktreeUiBranding({
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_WORKTREE_NAME: "paperclip-pr-432",
|
|
PAPERCLIP_WORKTREE_COLOR: "#4f86f7",
|
|
}),
|
|
);
|
|
expect(meta).toContain('name="paperclip-worktree-name"');
|
|
expect(meta).toContain('content="paperclip-pr-432"');
|
|
expect(meta).toContain('name="paperclip-worktree-color"');
|
|
});
|
|
|
|
it("surfaces the runtime instance id so the UI can fail closed on copied rows", () => {
|
|
const branding = getWorktreeUiBranding({
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_WORKTREE_NAME: "paperclip-pr-432",
|
|
PAPERCLIP_WORKTREE_COLOR: "#4f86f7",
|
|
PAPERCLIP_INSTANCE_ID: "inst-abc123",
|
|
});
|
|
expect(branding.instanceId).toBe("inst-abc123");
|
|
|
|
const meta = renderRuntimeBrandingMeta(branding);
|
|
expect(meta).toContain('name="paperclip-instance-id"');
|
|
expect(meta).toContain('content="inst-abc123"');
|
|
});
|
|
|
|
it("omits the instance-id meta when the runtime id is unset", () => {
|
|
const branding = getWorktreeUiBranding({
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_WORKTREE_NAME: "paperclip-pr-432",
|
|
PAPERCLIP_WORKTREE_COLOR: "#4f86f7",
|
|
});
|
|
expect(branding.instanceId).toBeNull();
|
|
expect(renderRuntimeBrandingMeta(branding)).not.toContain('name="paperclip-instance-id"');
|
|
});
|
|
|
|
it("rewrites the favicon and runtime branding blocks for worktree instances only", () => {
|
|
const branded = applyUiBranding(TEMPLATE, {
|
|
PAPERCLIP_IN_WORKTREE: "true",
|
|
PAPERCLIP_WORKTREE_NAME: "paperclip-pr-432",
|
|
PAPERCLIP_WORKTREE_COLOR: "#4f86f7",
|
|
});
|
|
expect(branded).toContain("data:image/svg+xml,");
|
|
expect(branded).toContain('name="paperclip-worktree-name"');
|
|
expect(branded).not.toContain('href="/favicon.svg"');
|
|
|
|
const defaultHtml = applyUiBranding(TEMPLATE, {});
|
|
expect(defaultHtml).toContain('href="/favicon.svg"');
|
|
expect(defaultHtml).not.toContain('name="paperclip-worktree-name"');
|
|
});
|
|
});
|