mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-02 02:07:25 +08:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Its release pipeline publishes a set of npm packages from CI with npm trusted publishing (GitHub OIDC), gated by `scripts/release-package-manifest.json` > - A brand-new package name cannot be published by CI directly: the PR bootstrap gate requires the name to resolve on npm, and a trusted-publisher rule can only be configured after the package page exists > - The current bootstrap helper closes that gap by building the package locally and publishing its real output from a maintainer machine — before the PR that adds the package has passed CI or review > - This pull request replaces that flow: the helper now publishes a minimal deprecated placeholder at version `0.0.0` that only reserves the name, so every real version ships from CI > - The benefit is that unreviewed build output never reaches npm, and the bootstrap runs from any checkout (including `master`, before the new package's PR merges) with no local build ## Linked Issues or Issue Description **What existing behavior does this improve?** The one-time npm bootstrap for a brand-new release package (`pnpm run release:bootstrap-package`). **Current behavior** The helper builds the target package locally and publishes the real build output from a maintainer machine. That content has not passed repository CI or review at publish time. The helper also requires the new package to exist in the local workspace, so it must run from the (unmerged) PR branch that adds the package. **Proposed behavior** The helper publishes a three-file placeholder at version `0.0.0` (manifest, README, and an `index.js` that throws a descriptive error), waits for the registry to show the package, then deprecates it. The PR bootstrap gate (`scripts/check-release-package-bootstrap.mjs`) only requires the name to resolve on the registry, so the placeholder satisfies it. The first real calver release from CI supersedes the placeholder, and a stable release moves `latest` off it — the same `latest` window that existed under the old flow, but containing an explicit inert stub instead of unreviewed code. **Reason and benefit** Real package content only ever reaches npm from CI, after review and merge. The bootstrap becomes safer (scope guard refuses names outside `@paperclipai/`, already-published names are rejected) and simpler (no local build, no workspace state, runs from any checkout). **Breaking changes** None at runtime. The helper's CLI surface changes: it now takes a package name only (no directory selector) and drops `--skip-build`. `doc/PUBLISHING.md` is updated to match. ## What Changed - `scripts/bootstrap-npm-package.mjs`: replaced the build-and-publish flow with a placeholder publish — stages `package.json` + `README.md` + throwing `index.js` at version `0.0.0` in a temp directory, previews with `npm publish --dry-run`, and publishes only with `--publish`. One-time passwords are prompted interactively (never passed as arguments, since they are single-use and would land in shell history), with re-prompt on a rejected or expired code. After publishing, the helper polls the registry until the package is visible (a first publish can lag by minutes; verified live at ~5 minutes), requiring two consecutive sightings before prompting for a second code and deprecating the placeholder so accidental installs warn loudly; on timeout or failure it prints the exact manual `npm deprecate` command. Added an `@paperclipai/`-scope guard and a fail-fast error when `--publish` runs without an interactive terminal. Removed the workspace-plan dependency so it runs from any checkout. - `scripts/bootstrap-npm-package.test.mjs`: rewrote for the new interface — argument parsing, scope validation, the generated placeholder files (manifest shape, throwing entry point, README), the OTP re-prompt loop, and the registry poll (consecutive-sighting requirement, timeout, transient-error tolerance) via injected fakes. - `doc/PUBLISHING.md`: rewrote the "One-time bootstrap sequence for a new package" section for the placeholder flow, including the `latest` dist-tag window and the trusted-publishing setup ordering (placeholder publish → trusted publisher rule → `"publishFromCi": true`). - `.github/scripts/check-pr-release-bootstrap.mjs` (+ test, + wiring in `run-quality-gates.mjs`): new informational commitperclip notice on PRs that need this bootstrap. It fires when the PR newly release-enables a package that is missing from npm, or adds an unpublished `publishFromCi: false` package that published packages declare a `workspace:*` dependency on, and names the exact maintainer command — so contributors know the red `policy` check is not theirs to fix. It never fails the gate (the `policy` job remains the enforcer), only looks up scope-validated names on the registry, and stays quiet on registry errors. ## Verification - `node --test scripts/bootstrap-npm-package.test.mjs`: 13/13 pass - `node --test .github/scripts/tests/*.test.mjs`: 147/147 pass (10 new for the PR notice) - `pnpm run test:release-registry`: 82/82 pass - Replayed the new PR notice against a real historical PR's live API data (files, manifest at base and head refs): with the registry in its pre-bootstrap state it produces the exact maintainer instruction; with the package bootstrapped it stays silent - Full live end-to-end run: the flow bootstrapped `@paperclipai/adapter-kimi-local` for real — dry-run preview (634-byte, 3-file tarball), publish, registry visibility after ~5 minutes of propagation lag, deprecation confirmed via `npm view ... deprecated` - Guards verified live: an already-published name is rejected, an out-of-scope name (`left-pad`) is rejected, unknown options (including the removed `--otp`) are rejected, and `--publish` in a non-interactive shell fails fast before any network call ## Risks - The `latest` dist-tag points at the deprecated `0.0.0` placeholder until the first stable release supersedes it. This window also existed under the old flow (which parked `latest` at a locally built version); internal consumers are unaffected because release version rewrites pin exact calver versions. - The registry poll caps at ~10 minutes. If propagation is slower than that, the helper prints the exact `npm deprecate ... --otp <code>` command to run manually once `npm view` resolves. - The helper no longer validates the name against the workspace release plan, so a typo within the `@paperclipai/` scope would reserve a wrong name. The dry-run preview shows the exact name before any publish. ## Model Used - Anthropic, **Claude Fable 5** (`claude-fable-5`) via Claude Code, with repository, shell, and Git tooling. It analyzed the existing bootstrap flow and the release scripts (`release-package-map.mjs`, `check-release-package-bootstrap.mjs`, `release.sh` dist-tag handling), wrote the replacement script and tests, updated the documentation, and ran the verification above. ## 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
130 lines
4.5 KiB
JavaScript
130 lines
4.5 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
PLACEHOLDER_VERSION,
|
|
buildPlaceholderFiles,
|
|
parseArgs,
|
|
promptOtp,
|
|
validatePackageName,
|
|
waitForPackageVisible,
|
|
} from "./bootstrap-npm-package.mjs";
|
|
|
|
test("parseArgs recognizes the publish flag", () => {
|
|
assert.deepEqual(parseArgs(["@paperclipai/adapter-kimi-local", "--publish"]), {
|
|
help: false,
|
|
packageName: "@paperclipai/adapter-kimi-local",
|
|
publish: true,
|
|
});
|
|
});
|
|
|
|
test("parseArgs defaults to a dry run", () => {
|
|
assert.deepEqual(parseArgs(["@paperclipai/adapter-kimi-local"]), {
|
|
help: false,
|
|
packageName: "@paperclipai/adapter-kimi-local",
|
|
publish: false,
|
|
});
|
|
});
|
|
|
|
test("parseArgs rejects a second package name", () => {
|
|
assert.throws(() => parseArgs(["@paperclipai/a", "@paperclipai/b"]), /exactly one package name/);
|
|
});
|
|
|
|
test("parseArgs rejects unknown options", () => {
|
|
assert.throws(() => parseArgs(["@paperclipai/a", "--skip-build"]), /unknown option/);
|
|
assert.throws(() => parseArgs(["@paperclipai/a", "--otp", "123456"]), /unknown option/);
|
|
});
|
|
|
|
test("validatePackageName accepts @paperclipai scoped names", () => {
|
|
validatePackageName("@paperclipai/adapter-kimi-local");
|
|
validatePackageName("@paperclipai/plugin-workspace-diff");
|
|
});
|
|
|
|
test("validatePackageName rejects names outside the @paperclipai scope", () => {
|
|
assert.throws(() => validatePackageName("left-pad"), /@paperclipai scope/);
|
|
assert.throws(() => validatePackageName("@evil/adapter-kimi-local"), /@paperclipai scope/);
|
|
assert.throws(() => validatePackageName("@paperclipai/UPPER"), /@paperclipai scope/);
|
|
});
|
|
|
|
test("buildPlaceholderFiles produces a publishable manifest at the placeholder version", () => {
|
|
const files = buildPlaceholderFiles("@paperclipai/adapter-kimi-local");
|
|
const manifest = JSON.parse(files["package.json"]);
|
|
|
|
assert.equal(manifest.name, "@paperclipai/adapter-kimi-local");
|
|
assert.equal(manifest.version, PLACEHOLDER_VERSION);
|
|
assert.equal(manifest.publishConfig.access, "public");
|
|
assert.deepEqual(manifest.files, ["index.js"]);
|
|
assert.match(manifest.description, /[Pp]laceholder/);
|
|
});
|
|
|
|
test("buildPlaceholderFiles entry point throws with a pointer to the repo", () => {
|
|
const files = buildPlaceholderFiles("@paperclipai/adapter-kimi-local");
|
|
|
|
assert.match(files["index.js"], /^throw new Error\(/);
|
|
assert.match(files["index.js"], /placeholder/);
|
|
assert.match(files["index.js"], /github\.com\/paperclipai\/paperclip/);
|
|
// The entry point must be valid JS: evaluating it should throw our message,
|
|
// not a SyntaxError.
|
|
assert.throws(() => new Function(files["index.js"])(), /placeholder that reserves/);
|
|
});
|
|
|
|
test("buildPlaceholderFiles README explains the placeholder", () => {
|
|
const files = buildPlaceholderFiles("@paperclipai/adapter-kimi-local");
|
|
assert.match(files["README.md"], /placeholder publish/);
|
|
assert.match(files["README.md"], /release-bootstrap CI gate/);
|
|
});
|
|
|
|
test("promptOtp re-prompts until a non-empty code is entered", async () => {
|
|
const answers = ["", " ", " 123456 "];
|
|
const rl = { question: async () => answers.shift() ?? "" };
|
|
|
|
assert.equal(await promptOtp(rl, "publish"), "123456");
|
|
assert.equal(answers.length, 0);
|
|
});
|
|
|
|
test("waitForPackageVisible requires consecutive sightings before reporting success", async () => {
|
|
const states = [{ exists: false }, { exists: true }, { exists: false }, { exists: true }, { exists: true }];
|
|
let sleeps = 0;
|
|
|
|
const visible = await waitForPackageVisible("@paperclipai/x", {
|
|
attempts: 10,
|
|
consecutive: 2,
|
|
inspect: () => states.shift() ?? { exists: true },
|
|
sleep: async () => {
|
|
sleeps += 1;
|
|
},
|
|
});
|
|
|
|
assert.equal(visible, true);
|
|
// Five inspections happened; sleeps run between attempts, not before the first.
|
|
assert.equal(sleeps, 4);
|
|
});
|
|
|
|
test("waitForPackageVisible times out when the package never appears", async () => {
|
|
const visible = await waitForPackageVisible("@paperclipai/x", {
|
|
attempts: 3,
|
|
consecutive: 2,
|
|
inspect: () => ({ exists: false }),
|
|
sleep: async () => {},
|
|
});
|
|
|
|
assert.equal(visible, false);
|
|
});
|
|
|
|
test("waitForPackageVisible treats registry errors as misses and keeps polling", async () => {
|
|
let calls = 0;
|
|
const visible = await waitForPackageVisible("@paperclipai/x", {
|
|
attempts: 6,
|
|
consecutive: 2,
|
|
inspect: () => {
|
|
calls += 1;
|
|
if (calls <= 2) throw new Error("transient registry error");
|
|
return { exists: true };
|
|
},
|
|
sleep: async () => {},
|
|
});
|
|
|
|
assert.equal(visible, true);
|
|
assert.equal(calls, 4);
|
|
});
|