mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 06:50:43 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - `docker.yml` and `docker-merge-group.yml` bundle the native macOS SSH runtime produced by `macos-runner-runtime.yml`, reusing a cached artifact by inputs digest when possible > - `scripts/macos-runner-runtime-cache.mjs` only reused an artifact when the entire `docker.yml` run concluded `success` > - Whenever a `master` `docker.yml` run was cancelled downstream (e.g., on a flaky post-merge test shard) after both `macos_runner_runtime / build` and `verify_linux_controller` already passed, the next build threw away the verified artifact and rebuilt from scratch for ~9.5 minutes on `macos-15` before `build-and-push` could start > - This pull request checks job-level verification (`macos_runner_runtime / build` and `macos_runner_runtime / verify_linux_controller` both `completed` + `success`) on trusted `master` `docker.yml` runs when the overall run did not conclude `success` > - The benefit is that `macos_runner_runtime` stays on its ~1m cache-hit path instead of repeatedly burning ~9.5m on the `docker.yml` critical path ## Linked Issues or Issue Description **What happened?** `scripts/macos-runner-runtime-cache.mjs` discards already-verified macOS runtime artifacts from `master` `docker.yml` runs whenever the workflow is cancelled or fails downstream, causing repeated ~9.5m `macos-15` rebuilds before `build-and-push` can begin. **Expected behavior** Keep the exact trust boundary (`paperclipai/paperclip`, `.github/workflows/docker.yml`, `event === "push"`, `head_branch === "master"`, 40-hex `head_sha`) and reuse the verified artifact either when the overall run concluded `success` (fast path) or when both `macos_runner_runtime / build` and `macos_runner_runtime / verify_linux_controller` concluded `success` in that run. **Steps to reproduce** 1. Merge a commit to `master` where `macos_runner_runtime / build` and `macos_runner_runtime / verify_linux_controller` succeed, then an unrelated downstream check cancels `docker.yml`. 2. Merge the next commit with identical Runner inputs. 3. Observe `Find an identical runtime from a successful master image build` miss and rebuild the macOS binary and provider pack from scratch on `macos-15`. ## What Changed - `scripts/macos-runner-runtime-cache.mjs`: add `isTrustedMacRuntimeWorkflowRun` and `hasVerifiedMacRuntimeJobs`, check job-level success on trusted `master` `docker.yml` runs whose overall conclusion is not `success`, and inspect up to 10 unexpired matching artifacts. - `scripts/macos-runner-runtime-cache.test.mjs`: add unit tests verifying reuse from a master run cancelled downstream when both macOS jobs succeeded and rejection when either job is incomplete, cancelled, or failed. ## Verification - `node --test scripts/macos-runner-runtime-cache.test.mjs scripts/macos-runner-runtime.test.mjs`: 12/12 passed. ## Risks - Low risk. Trust boundary stays strictly restricted to canonical `master` `push` runs of `.github/workflows/docker.yml`, requires both the macOS build/qualification job and Linux controller verification job to have succeeded, and the consuming run still verifies the downloaded artifact in `verify_linux_controller`. ## Model Used - Google Antigravity agent (Gemini / Antigravity coding harness with shell execution and tool use). ## 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
52 lines
3.6 KiB
JavaScript
52 lines
3.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { findMacRuntimeArtifact, hasVerifiedMacRuntimeJobs, isTrustedMacRuntimeProducer, isTrustedMacRuntimeWorkflowRun } from "./macos-runner-runtime-cache.mjs";
|
|
|
|
const repository = "paperclipai/paperclip", digest = `sha256:${"a".repeat(64)}`;
|
|
const good = { id: 123, repository: { full_name: repository }, path: ".github/workflows/docker.yml", event: "push", head_branch: "master", conclusion: "success", head_sha: "b".repeat(40) };
|
|
const verifiedJobs = [
|
|
{ name: "macos_runner_runtime / build", status: "completed", conclusion: "success" },
|
|
{ name: "macos_runner_runtime / verify_linux_controller", status: "completed", conclusion: "success" },
|
|
];
|
|
|
|
test("reuses only trusted master image builds from the protected repository", () => {
|
|
assert.equal(isTrustedMacRuntimeProducer(good, repository), true);
|
|
assert.equal(isTrustedMacRuntimeWorkflowRun({ ...good, conclusion: "cancelled" }, repository), true);
|
|
for (const change of [{ repository: { full_name: "fork/project" } }, { event: "pull_request" }, { head_branch: "feature" }, { conclusion: "failure" }, { path: ".github/workflows/macos-runner-runtime.yml" }]) {
|
|
assert.equal(isTrustedMacRuntimeProducer({ ...good, ...change }, repository), false);
|
|
}
|
|
assert.equal(hasVerifiedMacRuntimeJobs(verifiedJobs), true);
|
|
assert.equal(hasVerifiedMacRuntimeJobs([verifiedJobs[0]]), false);
|
|
assert.equal(hasVerifiedMacRuntimeJobs([verifiedJobs[0], { ...verifiedJobs[1], conclusion: "cancelled" }]), false);
|
|
assert.equal(hasVerifiedMacRuntimeJobs([verifiedJobs[0], { ...verifiedJobs[1], status: "in_progress", conclusion: null }]), false);
|
|
});
|
|
|
|
test("reuses a verified artifact from a master docker.yml run cancelled downstream, but rejects unverified jobs", async () => {
|
|
const name = `macos-runner-runtime-${digest.slice(7)}`;
|
|
const records = [201, 202].map(id => ({ name, workflow_run: { id }, digest: `sha256:${"c".repeat(64)}` }));
|
|
const fetchImpl = async url => ({
|
|
ok: true,
|
|
json: async () => {
|
|
if (url.includes("actions/artifacts")) return { artifacts: records };
|
|
if (url.endsWith("/actions/runs/201")) return { ...good, id: 201, conclusion: "cancelled" };
|
|
if (url.includes("/actions/runs/201/jobs")) return { jobs: [verifiedJobs[0], { ...verifiedJobs[1], conclusion: "cancelled" }] };
|
|
if (url.endsWith("/actions/runs/202")) return { ...good, id: 202, conclusion: "cancelled" };
|
|
if (url.includes("/actions/runs/202/jobs")) return { jobs: [...verifiedJobs, { name: "Watch exact-source verification", status: "completed", conclusion: "cancelled" }] };
|
|
throw Error(`unexpected url: ${url}`);
|
|
},
|
|
});
|
|
assert.deepEqual(await findMacRuntimeArtifact({ digest, repository, token: "fixture", fetchImpl }), { runId: 202, name });
|
|
});
|
|
|
|
test("a matching artifact from a pull request cannot replace the master runtime", async () => {
|
|
const name = `macos-runner-runtime-${digest.slice(7)}`;
|
|
const records = [12, 123].map(id => ({ name, workflow_run: { id }, digest: `sha256:${"c".repeat(64)}` }));
|
|
const fetchImpl = async url => ({ ok: true, json: async () => url.includes("actions/artifacts")
|
|
? { artifacts: records } : url.endsWith("/12") ? { ...good, id: 12, event: "pull_request" } : good });
|
|
assert.deepEqual(await findMacRuntimeArtifact({ digest, repository, token: "fixture", fetchImpl }), { runId: 123, name });
|
|
});
|
|
|
|
test("fork builds do not look up or trust another repository's artifacts", async () => {
|
|
assert.equal(await findMacRuntimeArtifact({ digest, repository: "fork/project", token: "fixture", fetchImpl: () => { throw Error("network forbidden"); } }), null);
|
|
});
|