Files
PaperClipAI/packages/paperclip-runner/scripts/materialize-antigravity-distribution.test.mjs
T
DottaandClaude Fable 5.2 78e4f4f130 feat(runner): Antigravity on ACP 1.5.2 with Linux, API-key auth and Gemini 4 Neon (still pending) (#22591)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The native Runner starts each agent harness and owns its lifecycle,
credentials and recovery
> - Google Antigravity is Google's only first-party coding harness, and
it is the harness for Gemini 4 Neon
> - The Runner had an Antigravity integration, but only as a pending
candidate: ACP server 1.4.3, macOS ARM64 only, Google sign-in only,
closed unless an operator opened it for one company and one model
> - Cloud sandboxes run Linux and use API keys, so the candidate could
not run there, and it had one attended test cell
> - This pull request moves the integration to ACP server 1.5.2, makes
it run on Linux and with a Gemini API key, adds the tests the other ACPX
harnesses have, and removes the code paths that would block recovery
after release
> - The benefit is that the release of Antigravity becomes a small
declaration change after the live suites pass. The profile stays
`pending` in this pull request.

## Linked Issues or Issue Description

Refs #98
Refs #6559
Refs #8523
Refs #21121 (a separate legacy-style `agy_local` adapter that uses the
CLI print protocol; this pull request does not replace or include it)

## What Changed

**Runtime**
- Pin Antigravity ACP server 1.5.2 (was 1.4.3). Owned admission patch is
`1.5.2-paperclip.2`.
- Verified patched closures for `darwin-arm64`, `linux-x64` and
`linux-arm64`. `darwin-x64` stays inventory-only.
- The patcher reads Mach-O and ELF builds. It signs macOS output only.
One admission source serves all platforms.
- Platform gates in TypeScript, Rust, the sidecar schema and the server
admit each host that has a verified closure.

**Auth and models**
- Gemini API-key auth reaches an exact-model session receipt. Admission
accepts a model only when the base model and the thinking level both
match the requested ID.
- API-key connections get a model list on local and cloud environments.
The list is generated at build time from the pinned runtime. The server
starts no process to read it.
- Gemini 4 Neon, Carbon, Argon and Hydrogen are selectable. The picker
marks them "needs a paid Gemini API plan" for API-key connections.
- One shared module maps model ID to family and thinking level.
- `google/gemini-4-neon` is added to the OpenCode model list. A new
model audit is in `doc/adapter-model-audit-2026-11-22.md`.

**Lifecycle and failures**
- A provider error no longer completes the turn. The driver classifies
it: overloaded, rate limit, quota, auth rejected, model unavailable.
- Overload retries are bounded (3 attempts, about 14 seconds).
- A refused session reload maps to incompatible saved state, so the
automatic replacement conversation applies.
- Server gates that refused restart recovery, remote targets and shared
state for Antigravity now apply only while the profile is pending.
- A Google sign-in connection with a cloud environment is refused at
save and at Test, with a plain message.
- A released profile rejects candidate grants in TypeScript and in Rust.

**Launch cost and integrity (all native ACPX providers)**
- Each closure is verified one time into a sealed read-only store. Later
launches check file identities and hash the exact executable they start.
- Remote provider-pack verification is recorded per sandbox lease. Later
runs check kernel identity and fall back to the full hash on any
difference.
- Superseded stores are removed in the background after a launch.

**Provider pack and image**
- The provider pack carries Antigravity for `linux-x64` as a candidate
provider. It becomes an ordinary provider from the profile status alone.
- The Daytona image build accepts the candidate. A credential-free smoke
runs in the build.

**Tests and CI**
- New `antigravity-qualification` suite: 24 cells, local and Daytona.
- New model lineup suites: 14 API-key cells and 14 Gemini 4 cells. Each
cell requires the exact model in the Runner receipt.
- Antigravity can run the `chat-features` cases with `--profile
runner-acpx-antigravity`.
- `runner-full-stack-e2e.yml` passes `GEMINI_API_KEY` for the new
profile and derives candidate providers from the selected Daytona cells.

**Docs**
- `doc/plans/2026-11-22-antigravity-qualification.md` is the current
release contract, acceptance ledger and operator recipe.

## Verification

Commands that passed on the final revision:

- `pnpm build`
- Typecheck for all packages, including the runner-e2e test projects
- `pnpm test:e2e:runner:unit`: 11,665 Vitest tests passed, 25 skipped;
386 node tests passed
- `cargo test -p paperclip-runner-core -- --test-threads=4`: 1,199
passed, 2 failed. The 2 failures are Codex transport timing tests that
pass alone and on `master`.
- `cargo fmt --check`, `check:acpx-profiles`, `check:protocol-types`,
`node scripts/check-maps.mjs`
- Native patch tests: 9 of 9 on `darwin-arm64` and 9 of 9 on `linux-x64`
- UI picker tests: 397 of 397

Known failures that also fail on `master`:

- 11 runner package script tests (browser, Pi and package-boundary
checks)
- 6 `runtime-selection` tests that read an untracked local skill file

Live evidence, without a prompt:

- Clean provisioning on `darwin-arm64` and on `linux-x64` in a Daytona
sandbox. The closure digests reproduce. A changed or missing file is
rejected.
- `initialize` reports 1.5.2. An API-key session returns a receipt for
exactly `gemini-3.8-flash-low` and the exact instruction bytes, on both
platforms.
- All 28 model IDs (14 Gemini 3, 14 Gemini 4) return an exact receipt
under an API key.
- A session survives a process kill and resumes in a new process with
exact receipts, on both platforms.
- The server's remote path verifies the provider pack in a Daytona
sandbox.
- Run start to native `initialize`: 3.45 s to 1.46 s on macOS, 3.65 s to
1.74 s on Linux x64, before the per-launch executable hash was restored
(about 60 ms on macOS; not measured on Linux).
- Remote pack verification on a reused sandbox lease: about 4.3 s to
about 0.25 s.

Live evidence, with a prompt, on an already-released harness:

- Pi native, `pi-native.runner-acpx-pi.local.agent-files-fresh-run`, on
`darwin-arm64` at `427e9b088b`: 1 of 1 passed, 14 of 14 checks, both
native runs succeeded (25.5 s and 25.7 s). The process started from the
new launch store with no fallback warning.
- The same cell and `native-pending-controller-restart` failed in the
paid workflow on this branch and on `master` in the same way, before any
native start. The workflow does not install the Pi runtime for local
cells, so the agent setup check fails. That is a workflow gap, not part
of this change.

**Not run.** No Antigravity prompt completed on 1.5.2 on any platform.
The only Gemini key available is on the free tier, and Google returned
503 or 429 for each attempt on two days. These gates are open:

- All 24 `antigravity-qualification` cells
- Both model lineup suites, including inference on Gemini 4 Neon
- The attended Google sign-in journey on 1.5.2
- The chat cases under Antigravity
- Image pull time and startup time on a published image
- A native start on `linux-arm64`
- A live provider-death cell for Kimi, Pi or Copilot on the new launch
store (one ordinary Pi cell passed live; see above)

## Risks

- **The launch store changes how every native ACPX provider starts**
(Kimi, Copilot, Cursor, Pi), not only Antigravity. A review found two
defects in the first version (an executable swap was possible, and Pi
launches broke). Both are fixed with tests. One live Pi cell passed on
this branch on macOS. No live provider-death cell and no Linux cell ran
for those providers.
- The profile digest changes. Saved Antigravity candidate sessions and
existing candidate grants stop working. The new release refuses old
state by name and starts a replacement conversation.
- The Linux provider pack and the Daytona image grow by about 834 MB
(about 274 MB compressed) when Antigravity is included.
- The pack verification record is in server memory. The first run after
a server restart pays the full hash again.
- Antigravity 1.5.2 reads the workspace `GEMINI.md` and `AGENTS.md` as
user rules. This is deliberate and matches Codex. Any other rule file is
refused.
- Orchestrator mode is not available. ACP server 1.5.2 does not expose
it.
- Antigravity stays `pending`. Normal users cannot run it until a later
change removes the pending status.

## Model Used

- Claude Fable 5.2 (`claude-fable-5-2`) planned, briefed and integrated
the work, with tool use.
- Claude Opus 5.5 (`claude-opus-5-5`) subagents wrote the code and ran
the tests, with tool use and code 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)
- [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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 08:21:11 -06:00

357 lines
20 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 { antigravityArchiveEntries, antigravityDistribution } from "./materialize-antigravity-distribution.mjs";
const hash = bytes => createHash("sha256").update(bytes).digest("hex");
const files = [
{ path: "agy_acp_server.par", content: Buffer.from("native ACP server fixture\n") },
{ path: "localharness_external", content: Buffer.from("owned native child fixture\n") },
];
// A minimal stored ZIP fixture exercises the real inspector and filesystem.
// Integrity comes from the checked-in archive and complete-file SHA-256 pins.
function zip(entries = files) {
const locals = [];
const centrals = [];
let offset = 0;
for (const entry of entries) {
const name = Buffer.from(entry.path);
const content = entry.content ?? Buffer.from("fixture");
const local = Buffer.alloc(30);
local.writeUInt32LE(0x04034b50);
local.writeUInt16LE(20, 4);
local.writeUInt32LE(content.length, 18);
local.writeUInt32LE(content.length, 22);
local.writeUInt16LE(name.length, 26);
const central = Buffer.alloc(46);
central.writeUInt32LE(0x02014b50);
central.writeUInt16LE(0x314, 4);
central.writeUInt16LE(20, 6);
central.writeUInt32LE(content.length, 20);
central.writeUInt32LE(content.length, 24);
central.writeUInt16LE(name.length, 28);
central.writeUInt32LE(((entry.mode ?? 0o100755) << 16) >>> 0, 38);
central.writeUInt32LE(offset, 42);
locals.push(local, name, content);
centrals.push(central, name);
offset += local.length + name.length + content.length;
}
const central = Buffer.concat(centrals);
const end = Buffer.alloc(22);
end.writeUInt32LE(0x06054b50);
end.writeUInt16LE(entries.length, 8);
end.writeUInt16LE(entries.length, 10);
end.writeUInt32LE(central.length, 12);
end.writeUInt32LE(offset, 16);
return Buffer.concat([...locals, central, end]);
}
async function fixture(t, { expectedFiles = files, expectedVendorFiles = files, archive = zip(), patchSuffix = "", baseDirectory = tmpdir(), changeParentDuringPatch = false, 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 admissionSource = "# trusted test admission source\n";
const admissionSourceSha256 = hash(admissionSource);
await writeFile(join(scripts, "patch-antigravity-runtime.admission.py"), admissionSource);
await writeFile(join(scripts, "patch-antigravity-runtime.mjs"), `
import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
export const ANTIGRAVITY_PATCH_VERSION='1.5.2-paperclip.2';
export async function patchAntigravityRuntime({source,destination,target,vendorEntries}) {
await writeFile(${JSON.stringify(join(root, "patch.called"))},JSON.stringify({target,vendorEntries}));
await mkdir(destination,{mode:0o700});
for(const name of ['agy_acp_server.par','localharness_external']) {
const content=await readFile(join(source,name));
await writeFile(join(destination,name),name==='agy_acp_server.par'?Buffer.concat([content,Buffer.from(${JSON.stringify(patchSuffix)})]):content,{mode:0o500});
}
${changeParentDuringPatch ? `await chmod(${JSON.stringify(join(root, `home/.paperclip/runtimes/antigravity/${target}`))},0o777);` : ""}
return {version:ANTIGRAVITY_PATCH_VERSION,admissionSourceSha256:${JSON.stringify(admissionSourceSha256)}};
}
`);
const entries = expectedFiles.map(entry => ({ path: entry.path, sha256: hash(entry.content), size: entry.content.length, executable: true }));
const closureSha256 = hash(JSON.stringify(entries));
const vendorEntries = expectedVendorFiles.map(entry => ({ path: entry.path, sha256: hash(entry.content), size: entry.content.length, executable: true }));
// The code is copied into an isolated package so its normal fixed manifest
// read uses a tiny trusted fixture. Production has no manifest-path override.
await writeFile(join(root, "antigravity-distributions.json"), JSON.stringify({
schema: "paperclip.antigravity_distribution.v1", version: "1.5.2",
platforms: { [target]: {
url: `https://dl.google.com/agy-extensions/releases/${platform === "darwin" ? "macos" : "linux"}/fixture.zip`,
archiveSha256: hash(archive), closureSha256, vendorEntries, vendorClosureSha256: hash(JSON.stringify(vendorEntries)), patchVersion: "1.5.2-paperclip.2", admissionSourceSha256, provisioning: "verified-closure",
executable: "agy_acp_server.par", args: platform === "linux" ? ["--uid="] : [], entries,
} },
}));
const archivePath = join(root, "fixture.zip");
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("macOS ARM and both Linux closures are pinned; macOS Intel remains inventory-only", async () => {
for (const [platform, architecture] of [["darwin", "arm64"], ["linux", "x64"], ["linux", "arm64"]]) {
const pin = await antigravityDistribution(platform, architecture);
assert.equal(pin.version, "1.5.2");
assert.equal(pin.patchVersion, "1.5.2-paperclip.2");
assert.deepEqual(pin.entries.map(entry => entry.path), files.map(entry => entry.path));
assert.deepEqual(pin.vendorEntries.map(entry => entry.path), files.map(entry => entry.path));
assert.equal(hash(JSON.stringify(pin.entries)), pin.closureSha256);
assert.equal(hash(JSON.stringify(pin.vendorEntries)), pin.vendorClosureSha256);
assert.equal(pin.entries[1].sha256, pin.vendorEntries[1].sha256, "the helper ships unmodified");
assert.notEqual(pin.entries[0].sha256, pin.vendorEntries[0].sha256, "the server carries the owned patch");
// Linux keeps the exact file size; macOS replaces the vendor signature with an ad-hoc one.
if (platform === "linux") assert.equal(pin.entries[0].size, pin.vendorEntries[0].size, "the patch keeps the embedded archive size");
assert.deepEqual(pin.args, platform === "linux" ? ["--uid="] : []);
}
await assert.rejects(antigravityDistribution("darwin", "x64"), /inventory-only/);
await assert.rejects(antigravityDistribution("win32", "x64"), /no pinned distribution/);
});
test("ZIP inspection rejects traversal, absolute names, duplicates, links and partial closure", () => {
assert.deepEqual(antigravityArchiveEntries(zip()).map(entry => entry.path), files.map(entry => entry.path));
for (const entries of [
[{ ...files[0], path: "../agy_acp_server.par" }, files[1]],
[{ ...files[0], path: "/agy_acp_server.par" }, files[1]],
[{ ...files[0], path: "dir\\agy_acp_server.par" }, files[1]],
[files[0], files[0]],
[{ ...files[0], mode: 0o120755 }, files[1]],
[{ ...files[0], mode: 0o060755 }, files[1]],
[files[0]],
]) assert.throws(() => antigravityArchiveEntries(zip(entries)), /unsafe or unsupported ZIP/);
});
test("ZIP inspection rejects disagreeing headers and overlapping payloads", () => {
const disagreeing = zip();
disagreeing.writeUInt16LE(8, 8);
assert.throws(() => antigravityArchiveEntries(disagreeing), /unsafe or unsupported ZIP/);
const overlapping = zip();
const end = overlapping.length - 22;
const central = overlapping.readUInt32LE(end + 16);
const secondCentral = central + 46 + Buffer.byteLength(files[0].path);
overlapping.writeUInt32LE(0, secondCentral + 42);
assert.throws(() => antigravityArchiveEntries(overlapping), /unsafe or unsupported ZIP/);
});
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 complete two-binary closure", async t => {
const { api, options, destination, distribution } = await fixture(t);
const result = await api.materializePinnedAntigravityDistribution(options);
assert.equal(result.executable, join(destination, files[0].path));
assert.equal(result.closureSha256, distribution.closureSha256);
for (const file of files) {
assert.deepEqual(await readFile(join(destination, file.path)), file.content);
assert.equal((await lstat(join(destination, file.path))).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 expectedFiles = files.map(file => ({ ...file, content: Buffer.from(`wrong expected ${file.path}`) }));
const { api, options, destination } = await fixture(t, { expectedFiles });
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("verified vendor bytes are patched and only the separately pinned final closure is installed", async t => {
const patchSuffix = "\nowned native admission patch\n";
const expectedFiles = files.map((file, index) => ({ ...file, content: index === 0 ? Buffer.concat([file.content, Buffer.from(patchSuffix)]) : file.content }));
const { api, options, destination, root, distribution } = await fixture(t, { expectedFiles, patchSuffix });
await api.materializePinnedAntigravityDistribution(options);
assert.deepEqual(JSON.parse(await readFile(join(root, "patch.called"), "utf8")), { target: "darwin-arm64", vendorEntries: distribution.vendorEntries });
assert.notEqual(distribution.vendorClosureSha256, distribution.closureSha256);
assert.deepEqual(await readFile(join(destination, files[0].path)), expectedFiles[0].content);
assert.deepEqual(await readFile(join(destination, files[1].path)), files[1].content);
await api.verifyAntigravityDistribution(destination, distribution);
});
test("vendor closure mismatch stops before the owned patch executes", async t => {
const expectedVendorFiles = files.map(file => ({ ...file, content: Buffer.from(`wrong vendor ${file.path}`) }));
const { api, options, root, destination } = await fixture(t, { expectedVendorFiles });
await assert.rejects(api.materializePinnedAntigravityDistribution(options), /vendor execution closure digest mismatch/);
await assert.rejects(readFile(join(root, "patch.called")), { code: "ENOENT" });
await assert.rejects(lstat(destination), { code: "ENOENT" });
assert.deepEqual(await readdir(join(destination, "..")), []);
});
test("changed admission patch source is rejected before extraction or native execution", async t => {
const { api, options, root, destination } = await fixture(t);
await writeFile(join(root, "scripts/patch-antigravity-runtime.admission.py"), "# changed admission source\n");
await assert.rejects(api.materializePinnedAntigravityDistribution(options), /patch source digest mismatch/);
await assert.rejects(lstat(destination), { code: "ENOENT" });
await assert.rejects(readFile(join(root, "patch.called")), { code: "ENOENT" });
});
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, files[1].path);
await chmod(binary, 0o700);
await writeFile(binary, "corrupted native child");
await assert.rejects(provision(), /full execution closure digest mismatch/);
assert.equal(await readFile(binary, "utf8"), "corrupted native child");
});
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 children fail closed", async t => {
for (const kind of ["symlink", "hardlink", "extra", "missing", "record-link"]) {
const current = await fixture(t);
await current.provision();
const child = join(current.destination, files[1].path);
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-child-copy");
await copyFile(child, target);
await rm(child);
if (kind === "symlink") await symlink(target, child);
if (kind === "hardlink") await link(target, child);
}
await assert.rejects(current.provision(), /both native binaries|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, files[1].path);
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("publication refuses a replaceable cache parent before patching or creating a temporary installation", async t => {
const { api, options, destination, root } = await fixture(t);
const parent = join(destination, "..");
await mkdir(parent, { recursive: true, mode: 0o700 });
await chmod(parent, 0o777);
try {
await assert.rejects(api.materializePinnedAntigravityDistribution(options), /ancestor.*write|unsafe.*ancestor/);
await assert.rejects(readFile(join(root, "patch.called")), { code: "ENOENT" });
assert.deepEqual(await readdir(parent), []);
} finally { await chmod(parent, 0o700); }
});
test("package pin sources beneath a replaceable ancestor cannot authorize installation", async t => {
const { api, options, root } = await fixture(t);
await chmod(root, 0o777);
try { await assert.rejects(api.materializePinnedAntigravityDistribution(options), /ancestor.*write|unsafe.*ancestor/); }
finally { await chmod(root, 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);
await api.materializePinnedAntigravityDistribution({ ...options, destination });
assert.equal((await api.verifyAntigravityDistribution(destination, distribution)).sha256, distribution.closureSha256);
});
test("a root-owned sticky temporary ancestor protects the private installation", async t => {
const temporary = await realpath("/tmp");
const stat = await lstat(temporary);
if (stat.uid !== 0 || !(stat.mode & 0o1000)) return t.skip("requires the host's root-owned sticky temporary directory");
const { provision, api, destination, distribution } = await fixture(t, { baseDirectory: "/tmp" });
await provision();
assert.equal((await api.verifyAntigravityDistribution(destination, distribution)).sha256, distribution.closureSha256);
});
test("source and cached ownership are checked for the current execution principal", async t => {
const { api, provision, destination } = await fixture(t);
await provision();
const getuid = process.getuid;
if (!getuid || getuid() === 0) return t.skip("requires a non-root principal to model foreign ownership without changing filesystem privileges");
// Keep the real kernel metadata; model a different verifier principal rather
// than chowning files or running another user's process during the test.
process.getuid = () => getuid() + 1;
try {
await assert.rejects(api.antigravityDistributionClosure(destination), /untrusted filesystem owner/);
await assert.rejects(api.antigravityDistribution("darwin", "arm64"), /untrusted filesystem owner/);
} finally { process.getuid = getuid; }
});
test("a parent made replaceable while patching cannot receive a published runtime", async t => {
const { api, options, destination } = await fixture(t, { changeParentDuringPatch: true });
try {
await assert.rejects(api.materializePinnedAntigravityDistribution(options), /ancestor.*write|unsafe.*ancestor/);
await assert.rejects(lstat(destination), { code: "ENOENT" });
assert.deepEqual(await readdir(join(destination, "..")), []);
} finally { await chmod(join(destination, ".."), 0o700); }
});
test("a Linux closure is patched for its own target and verified like macOS", async t => {
for (const architecture of ["x64", "arm64"]) {
const patchSuffix = "\nowned native admission patch\n";
const expectedFiles = files.map((file, index) => ({ ...file, content: index === 0 ? Buffer.concat([file.content, Buffer.from(patchSuffix)]) : file.content }));
const { api, options, destination, root, distribution, provision } = await fixture(t, { expectedFiles, patchSuffix, platform: "linux", architecture });
assert.equal(destination.split("/").at(-2), `linux-${architecture}`);
await provision();
assert.deepEqual(JSON.parse(await readFile(join(root, "patch.called"), "utf8")), { target: `linux-${architecture}`, vendorEntries: distribution.vendorEntries });
assert.equal((await api.verifyAntigravityDistribution(destination, distribution)).sha256, distribution.closureSha256);
await rm(options.archivePath);
await provision();
const helper = join(destination, files[1].path);
await chmod(helper, 0o700);
await writeFile(helper, "tampered native child");
await chmod(helper, 0o500);
await assert.rejects(provision(), /full execution closure digest mismatch/);
await rm(helper);
await assert.rejects(provision(), /both native binaries/);
}
});