mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-04 21:21:27 +01:00
Replaces the legacy 853 MiB IDE-extension ACP bundle (agy_acp_server.par 1.5.2, localharness_external, and Python admission patching) and the separate 1.5.15 CLI pin with a single pinned agy 1.5.19 binary (1.5.19-4821414830800896, ~268 MiB on linux-x64) across ordinary turns, /swarm, sign-in, and model discovery. - Pin agy 1.5.19 across darwin-arm64, darwin-x64, linux-x64, and linux-arm64 and bump the Antigravity ACPX profile to v3 (regenerating TS and Rust profiles). - Add direct ACP runtime openAntigravityAcpRuntime for ordinary turns with OAuth and GEMINI_API_KEY auth, session/resume, plan mode, MCP bridge, setModel, and lineage retirement. - Stage file-backed OAuth tokens with AGY_CLI_FORCE_FILE_TOKEN_STORAGE=1, align --gemini-dir with agentHomeDirectory, and migrate login to agy acp --login. - Enable remote /swarm using --dangerously-skip-permissions and remove the input.remote refusal in antigravity-swarm.ts. - Regenerate the 25-model Antigravity catalog from agy 1.5.19. Tested with Runner unit/script/live suites, shared, UI, server, Rust cargo test, runner-e2e unit suites, and live E2E against real agy 1.5.19 on macOS and headless Linux Docker (--security-opt no-new-privileges). Co-Authored-By: Paperclip <noreply@paperclip.ing>
227 lines
11 KiB
JavaScript
227 lines
11 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { createHash } from "node:crypto";
|
|
import { chmod, copyFile, link, lstat, mkdir, mkdtemp, readFile, readdir, realpath, rm, symlink, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { test } from "node:test";
|
|
import { pathToFileURL } from "node:url";
|
|
import { gzipSync } from "node:zlib";
|
|
import { antigravityArchiveExecutable, antigravityDistribution } from "./materialize-antigravity-distribution.mjs";
|
|
|
|
const sha256 = bytes => createHash("sha256").update(bytes).digest("hex");
|
|
const sha512 = bytes => createHash("sha512").update(bytes).digest("hex");
|
|
const executable = Buffer.from("#!/bin/sh\necho antigravity unified fixture\n");
|
|
|
|
function tar({ name = "antigravity", content = executable, mode = 0o755, type = "0", members = [], trailer = Buffer.alloc(1024), magic = "ustar \0" } = {}) {
|
|
const block = (memberName, bytes, memberType, memberMode) => {
|
|
const header = Buffer.alloc(512);
|
|
header.write(memberName, 0, "utf8");
|
|
header.write(`${memberMode.toString(8).padStart(7, "0")}\0`, 100);
|
|
header.write("0000000\0", 108);
|
|
header.write("0000000\0", 116);
|
|
header.write(`${bytes.length.toString(8).padStart(11, "0")}\0`, 124);
|
|
header.write("15147300000\0", 136);
|
|
header.write(" ", 148);
|
|
header.write(memberType, 156);
|
|
header.write(magic, 257, "latin1");
|
|
let sum = 0;
|
|
for (const byte of header) sum += byte;
|
|
header.write(`${sum.toString(8).padStart(6, "0")}\0 `, 148);
|
|
const padding = Buffer.alloc((512 - (bytes.length % 512)) % 512);
|
|
return Buffer.concat([header, bytes, padding]);
|
|
};
|
|
return Buffer.concat([block(name, content, type, mode), ...members.map(member => block(member.name, member.content, member.type ?? "0", member.mode ?? 0o755)), trailer]);
|
|
}
|
|
const tarGz = options => gzipSync(tar(options));
|
|
|
|
async function fixture(t, { expectedContent = executable, archive = tarGz(), baseDirectory = tmpdir(), platform = "darwin", architecture = "arm64" } = {}) {
|
|
const target = `${platform}-${architecture}`;
|
|
const root = await realpath(await mkdtemp(join(baseDirectory, "paperclip-antigravity-provision-test-")));
|
|
t.after(() => rm(root, { recursive: true, force: true }));
|
|
const scripts = join(root, "scripts");
|
|
await mkdir(scripts);
|
|
for (const name of ["materialize-antigravity-distribution.mjs", "antigravity-provisioner-layout.mjs", "provision-antigravity.mjs"]) {
|
|
await copyFile(new URL(name, import.meta.url), join(scripts, name));
|
|
}
|
|
const entries = [{ path: "agy", sha256: sha256(expectedContent), size: expectedContent.length, executable: true }];
|
|
const closureSha256 = sha256(JSON.stringify(entries));
|
|
await writeFile(join(root, "antigravity-distributions.json"), JSON.stringify({
|
|
schema: "paperclip.antigravity_distribution.v1",
|
|
version: "1.5.19",
|
|
build: "1.5.19-4821414830800896",
|
|
environment: { AGY_CLI_DISABLE_AUTO_UPDATE: "1", AGY_CLI_FORCE_FILE_TOKEN_STORAGE: "1" },
|
|
platforms: {
|
|
[target]: {
|
|
url: `https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.19-4821414830800896/${target}/fixture.tar.gz`,
|
|
archiveFormat: "tar.gz",
|
|
archiveSize: archive.length,
|
|
archiveSha256: sha256(archive),
|
|
archiveSha512: sha512(archive),
|
|
archiveMember: "antigravity",
|
|
executable: "agy",
|
|
executableSha512: sha512(expectedContent),
|
|
closureSha256,
|
|
provisioning: "verified-closure",
|
|
args: ["acp"],
|
|
entries,
|
|
},
|
|
},
|
|
}));
|
|
const archivePath = join(root, "fixture.tar.gz");
|
|
await writeFile(archivePath, archive);
|
|
const api = await import(pathToFileURL(join(scripts, "materialize-antigravity-distribution.mjs")));
|
|
const provisioner = await import(pathToFileURL(join(scripts, "provision-antigravity.mjs")));
|
|
const home = join(root, "home");
|
|
const destination = join(home, ".paperclip/runtimes/antigravity", target, closureSha256);
|
|
const options = { platform, architecture, archivePath, destination };
|
|
const provision = () => provisioner.provisionAntigravityRuntime({
|
|
...options,
|
|
home,
|
|
moduleUrl: "file:///consumer/node_modules/@paperclipai/paperclip-runner/dist/cli/provision-antigravity.cjs",
|
|
});
|
|
return { root, destination, options, api, provision, distribution: await api.antigravityDistribution(platform, architecture) };
|
|
}
|
|
|
|
test("all four macOS and Linux 1.5.19 unified agy closures are pinned", async () => {
|
|
for (const [platform, architecture] of [["darwin", "arm64"], ["darwin", "x64"], ["linux", "x64"], ["linux", "arm64"]]) {
|
|
const pin = await antigravityDistribution(platform, architecture);
|
|
assert.equal(pin.version, "1.5.19");
|
|
assert.equal(pin.build, "1.5.19-4821414830800896");
|
|
assert.equal(pin.executable, "agy");
|
|
assert.deepEqual(pin.args, ["acp"]);
|
|
assert.deepEqual(pin.entries.map(entry => entry.path), ["agy"]);
|
|
assert.equal(sha256(JSON.stringify(pin.entries)), pin.closureSha256);
|
|
}
|
|
await assert.rejects(antigravityDistribution("win32", "x64"), /no pinned distribution/);
|
|
});
|
|
|
|
test("tar inspection rejects traversal, links, extra members, bad mode, and corrupt checksums", () => {
|
|
assert.deepEqual(antigravityArchiveExecutable(tar()), executable);
|
|
for (const bad of [
|
|
tar({ name: "../antigravity" }),
|
|
tar({ name: "agy" }),
|
|
tar({ type: "2" }),
|
|
tar({ type: "5" }),
|
|
tar({ mode: 0o4755 }),
|
|
tar({ mode: 0o644 }),
|
|
tar({ magic: "badmg\0" }),
|
|
tar({ members: [{ name: "extra", content: Buffer.from("x") }] }),
|
|
tar({ trailer: Buffer.concat([Buffer.alloc(1023), Buffer.from([1])]) }),
|
|
tar({ trailer: Buffer.alloc(0) }),
|
|
tar().subarray(0, 700),
|
|
]) {
|
|
assert.throws(() => antigravityArchiveExecutable(bad), /unsafe or unsupported tar/);
|
|
}
|
|
const corrupted = tar();
|
|
corrupted[0] ^= 1;
|
|
assert.throws(() => antigravityArchiveExecutable(corrupted), /unsafe or unsupported tar/);
|
|
});
|
|
|
|
test("a corrupted archive never installs and its temporary directory is removed", async t => {
|
|
const { api, options, destination } = await fixture(t);
|
|
await writeFile(options.archivePath, "corrupt archive");
|
|
await assert.rejects(api.materializePinnedAntigravityDistribution(options), /archive digest mismatch/);
|
|
await assert.rejects(lstat(destination), { code: "ENOENT" });
|
|
assert.deepEqual(await readdir(join(destination, "..")), []);
|
|
});
|
|
|
|
test("installation preserves and verifies the single-binary agy closure", async t => {
|
|
const { api, options, destination, distribution } = await fixture(t);
|
|
const result = await api.materializePinnedAntigravityDistribution(options);
|
|
assert.equal(result.executable, join(destination, "agy"));
|
|
assert.equal(result.closureSha256, distribution.closureSha256);
|
|
assert.deepEqual(await readFile(join(destination, "agy")), executable);
|
|
assert.equal((await lstat(join(destination, "agy"))).mode & 0o777, 0o500);
|
|
assert.equal((await api.verifyAntigravityDistribution(destination, distribution)).sha256, distribution.closureSha256);
|
|
assert.deepEqual(await readdir(join(destination, "..")), [distribution.closureSha256]);
|
|
await assert.rejects(api.materializePinnedAntigravityDistribution(options), /already exists/);
|
|
});
|
|
|
|
test("a failed full-closure check leaves no partial installation", async t => {
|
|
const { api, options, destination } = await fixture(t, { expectedContent: Buffer.from("different binary\n") });
|
|
await assert.rejects(api.materializePinnedAntigravityDistribution(options), /full execution closure digest mismatch/);
|
|
await assert.rejects(lstat(destination), { code: "ENOENT" });
|
|
assert.deepEqual(await readdir(join(destination, "..")), []);
|
|
});
|
|
|
|
test("repeated setup verifies installed bytes and refuses corruption without download or replacement", async t => {
|
|
const { provision, destination, options } = await fixture(t);
|
|
await provision();
|
|
await rm(options.archivePath);
|
|
await provision();
|
|
const binary = join(destination, "agy");
|
|
await chmod(binary, 0o700);
|
|
await writeFile(binary, "corrupted native binary");
|
|
await assert.rejects(provision(), /full execution closure digest mismatch/);
|
|
assert.equal(await readFile(binary, "utf8"), "corrupted native binary");
|
|
});
|
|
|
|
test("rewriting the cached record or passing altered pins cannot authorize changed bytes", async t => {
|
|
const { provision, api, destination, distribution } = await fixture(t);
|
|
await provision();
|
|
const recordPath = join(destination, api.ANTIGRAVITY_TREE_MANIFEST);
|
|
await chmod(recordPath, 0o600);
|
|
await writeFile(recordPath, JSON.stringify({ ...distribution, closureSha256: "a".repeat(64) }));
|
|
await assert.rejects(provision(), /cached closure record/);
|
|
await assert.rejects(api.verifyAntigravityDistribution(destination, { ...distribution, closureSha256: "a".repeat(64) }), /checked-in distribution pins/);
|
|
});
|
|
|
|
test("cached links, hardlinks, extra files and missing executable fail closed", async t => {
|
|
for (const kind of ["symlink", "hardlink", "extra", "missing", "record-link"]) {
|
|
const current = await fixture(t);
|
|
await current.provision();
|
|
const binary = join(current.destination, "agy");
|
|
if (kind === "extra") await writeFile(join(current.destination, "unexpected-native-child"), "unexpected");
|
|
else if (kind === "record-link") {
|
|
const record = join(current.destination, current.api.ANTIGRAVITY_TREE_MANIFEST);
|
|
const target = join(current.root, "record-copy.json");
|
|
await copyFile(record, target);
|
|
await rm(record);
|
|
await symlink(target, record);
|
|
} else {
|
|
const target = join(current.root, "native-binary-copy");
|
|
await copyFile(binary, target);
|
|
await rm(binary);
|
|
if (kind === "symlink") await symlink(target, binary);
|
|
if (kind === "hardlink") await link(target, binary);
|
|
}
|
|
await assert.rejects(current.provision(), /pinned native executable|links or special files/);
|
|
}
|
|
});
|
|
|
|
test("cached assets with shared write access and linked runtime roots fail closed", async t => {
|
|
const { provision, api, destination, distribution, root } = await fixture(t);
|
|
await provision();
|
|
const binary = join(destination, "agy");
|
|
await chmod(binary, 0o777);
|
|
await assert.rejects(provision(), /unsafe file permissions/);
|
|
await chmod(binary, 0o500);
|
|
const linked = join(root, "linked-runtime");
|
|
await symlink(destination, linked);
|
|
await assert.rejects(api.verifyAntigravityDistribution(linked, distribution), /real directory/);
|
|
await chmod(destination, 0o777);
|
|
await assert.rejects(provision(), /private write access/);
|
|
await chmod(destination, 0o700);
|
|
});
|
|
|
|
test("a private cached closure is rejected when another user could replace its parent entry", async t => {
|
|
const { provision, destination } = await fixture(t);
|
|
await provision();
|
|
const parent = join(destination, "..");
|
|
await chmod(parent, 0o777);
|
|
try { await assert.rejects(provision(), /ancestor.*write|unsafe.*ancestor/); }
|
|
finally { await chmod(parent, 0o700); }
|
|
});
|
|
|
|
test("canonical parent aliases keep a private owned installation valid", async t => {
|
|
const { api, options, distribution, root } = await fixture(t);
|
|
const home = join(root, "private-home");
|
|
await mkdir(home, { mode: 0o700 });
|
|
const alias = join(root, "home-alias");
|
|
await symlink(home, alias);
|
|
const destination = join(alias, "cache", distribution.closureSha256);
|
|
const result = await api.materializePinnedAntigravityDistribution({ ...options, destination });
|
|
assert.equal(result.destination, join(home, "cache", distribution.closureSha256));
|
|
await api.verifyAntigravityDistribution(result.destination, distribution);
|
|
});
|