Public: anyone can read this; the crew can change it.

Contained checks and gates install from the repository's shared bun cache, filled by the forge and bound read-only into the cell #7549

opened this

Merged 36d 0h ago, live in production

Contained checks and gates now install from the repository's shared bun cache, which the forge fills on the host first. The cell test was skipped here (no cells in this sandbox), and the warm-cache test probably exited early here too, so neither has run. I haven't run the install path end to end.

Notes

opened this

Contained checks and gates now install from the repository's shared bun cache, which the forge fills on the host first. The cell test was skipped here (no cells in this sandbox), and the warm-cache test probably exited early here too, so neither has run. I haven't run the install path end to end. tsc is clean and test/check-install.test.ts passes. The new cell test in test/contain.test.ts is one of the 30 skips, so the forge's check will be its first run.

What changed

  • prefillInstallCache in src/checks/install.ts fills the cache before a contained install.
    • It copies the checkout, minus node_modules and .git, into a scratch directory.
    • It runs bun install --frozen-lockfile --ignore-scripts there with BUN_INSTALL_CACHE_DIR set to the shared cache.
    • It holds the same withLock that uncontained installs hold.
    • A checkout with no lockfile logs that it filled nothing and goes on.
    • A failed fetch returns an error and frees the lock. Its timeout is half of LOCK_STALE_MS, so the lock never goes stale mid-fill.
  • In src/checks/service.ts the cell gets the cache through the existing reveal read-only bind, and BUN_INSTALL_CACHE_DIR points at it. contain.ts needed no new field, and writable stays [].
  • copying adds --backend=copyfile to a contained bun install, because hardlinks can't cross a read-only bind. It does this for every contained install, not only when the devices differ, and only when the command starts with bun install.
  • runJobStep is unchanged. A comment in service.ts says so.

Tests

  • A fill from a warm cache with the registry pointed at http://127.0.0.1:1 succeeds and reports no downloads. It first fills the cache from the real registry, and if that is unreachable the test returns early. That is probably what happened here, so the offline half has not been seen to pass.
  • A lockfile whose package can't be fetched fails and leaves no lock file behind.
  • copying and the no-lockfile case are covered.
  • The cell test (test/contain.test.ts) reads the cache from a cell with its data directory hidden, and a write into it is refused.

Left out

  • The "no downloads" and dead-proxy checks run on the host fill, not on the install inside the cell, because the sandbox has no cells.
  • The scratch copy takes the whole checkout apart from node_modules and .git, so workspace packages resolve. A large repository pays for that copy on each fill.

Closes #7543

3 earlier comments
commented

Contained checks and gates now install from the repository's shared bun cache, which the forge fills on the host first. The cell test was skipped here (no cells in this sandbox), and the warm-cache test probably exited early here too, so neither has run. I haven't run the install path end to end. tsc is clean and test/check-install.test.ts passes. The new cell test in test/contain.test.ts is one of the 30 skips, so the forge's check will be its first run.

What changed

  • prefillInstallCache in src/checks/install.ts fills the cache before a contained install.
    • It copies the checkout, minus node_modules and .git, into a scratch directory.
    • It runs bun install --frozen-lockfile --ignore-scripts there with BUN_INSTALL_CACHE_DIR set to the shared cache.
    • It holds the same withLock that uncontained installs hold.
    • A checkout with no lockfile logs that it filled nothing and goes on.
    • A failed fetch returns an error and frees the lock. Its timeout is half of LOCK_STALE_MS, so the lock never goes stale mid-fill.
  • In src/checks/service.ts the cell gets the cache through the existing reveal read-only bind, and BUN_INSTALL_CACHE_DIR points at it. contain.ts needed no new field, and writable stays [].
  • copying adds --backend=copyfile to a contained bun install, because hardlinks can't cross a read-only bind. It does this for every contained install, not only when the devices differ, and only when the command starts with bun install.
  • runJobStep is unchanged. A comment in service.ts says so.

Tests

  • A fill from a warm cache with the registry pointed at http://127.0.0.1:1 succeeds and reports no downloads. It first fills the cache from the real registry, and if that is unreachable the test returns early. That is probably what happened here, so the offline half has not been seen to pass.
  • A lockfile whose package can't be fetched fails and leaves no lock file behind.
  • copying and the no-lockfile case are covered.
  • The cell test (test/contain.test.ts) reads the cache from a cell with its data directory hidden, and a write into it is refused.

Left out

  • The "no downloads" and dead-proxy checks run on the host fill, not on the install inside the cell, because the sandbox has no cells.
  • The scratch copy takes the whole checkout apart from node_modules and .git, so workspace packages resolve. A large repository pays for that copy on each fill.
commented

The failing test was a spawn audit, and I've fixed it and pushed. I ran only that test, and it passes. I haven't seen the forge's full check re-run.

test/spawn-pipes.test.ts requires every Bun.spawn that pipes stdout or stderr to be listed with the reason it reads the pipe. The bun install spawn I added in prefillInstallCache (src/checks/install.ts) wasn't listed. The code was fine: it reads both streams to the end with Response.text() while it waits for the exit. I added an entry for src/checks/install.ts saying so. The test was missing the entry, not wrong about the code, and no source file changed.

The earlier description still holds, with one addition: the audit now lists that spawn.

commented

All four points are addressed and pushed. tsc is clean and test/check-install.test.ts passes, 17 of 17. I did not run the full suite. The cell path itself (reveal plus the read-only bind) is still only covered by the cell test, which is skipped without cells.

What changed

  1. Host-side fill (high). The fill no longer takes its registry or config from the pull.
    • Config stripped. bunfig.toml and .npmrc are left out of the scratch copy.
    • Registry pinned. The registry is pinned to the forge's BUN_CONFIG_REGISTRY, or https://registry.npmjs.org/ when that is unset.
    • Lockfile checked first. lockfileRefusal runs before anything is spawned. It refuses a binary-only bun.lockb, any URL in bun.lock outside the pinned registry, and git, github, gitlab, bitbucket and ssh dependencies.
    • Result. Everything the host fetches comes from the pinned registry and is integrity-checked against the lockfile, so a pull cannot make the forge fetch from an arbitrary host or put foreign content in the cache main reads.
    • Not done. I did not key the cache per pull. The cache stays shared, which keeps main's gate warm. Say so if you would rather have a pull-private cache promoted only for the default branch.
  2. No lockfile (medium). prefillInstallCache now returns whether it filled. When it did not (no lockfile, or a lockfile it refuses), the cell skips the reveal bind, the BUN_INSTALL_CACHE_DIR override and copying, and installs into its own cache. A refused lockfile logs cache not filled: <why>.
  3. Tests (medium). The dead-registry early return and the {} lockfile test are gone. The tests now use a loopback fixture registry that serves one package and records its requests, with a real lockfile generated against it.
    • A fill fetches from the pinned registry, and a second fill with the registry stopped still succeeds.
    • An unfetchable package fails, and the output is not a lockfile mismatch. The lock file is freed.
    • A pull's bunfig.toml and .npmrc pointing at a decoy registry get zero hits.
    • A foreign URL or git dependency in the lockfile is refused, with no fetch and no cache created.
    • A new cellInstall function is the pure piece of the in-cell install path (the command, the cache env, and the fallback). It is tested in the check, without needing cells.
  4. copying (medium). It now rewrites every bun install in the command, so cd x && bun install copies too, and it leaves a command alone if that install already names --backend. I kept it on every contained install rather than probing for the device. Whether cache and cell share a device is host layout, and copying from a warm cache is cheap next to a network install. This is stated in the doc comment.
commented

I fixed items 1, 3, 4 and 5 and partly covered item 2. I did not extend the cell test to run bun, because cells are skipped in this sandbox. tsc is clean and test/check-install.test.ts passes, 19 of 19. I did not run the full suite, and I ran the tests only outside cells.

  1. Fill timeout. fillTimeoutMs now caps a fill at LOCK_STALE_MS / 2, so a long manifest.timeout can no longer outlast its lock. A test checks that a larger timeout is clamped.
  2. Read-only cache. The cache is filled from the fixture registry, made read-only with chmod -R a-w, and the registry is stopped. A real bun install --frozen-lockfile --backend=copyfile with BUN_INSTALL_CACHE_DIR pointing at it then exits 0 and links node_modules/fixture-pkg. This runs in the check without cells. It proves bun does not need to write to a filled cache. The test asserts the cache is not writable unless it runs as root, where file modes are ignored.
    • Not done. I did not extend contain.test.ts to run bun inside a cell, since I could not run a cell here. The bwrap bind and the reveal path stay covered only by the existing cell test, which still doesn't run bun. The read-only bind is a mount-level read-only, which the mode-based test approximates.
  3. Reading while another fill writes. The cell reads the cache without the lock. I believe this is safe because bun writes each package under a temp name and renames it into place, so a reader sees a whole entry or none. I did not verify that against bun's source. A later fill could only add entries, and every package this cell's lockfile names was filled before the cell started. That reasoning is now in the prefillInstallCache doc comment.
  4. Failure test. It now asserts the tarball was never served and the output is not a lockfile mismatch. The unused lines in the warm-cache test is gone.
  5. Style. In src/checks/service.ts, once builds base, from and a named revealed cell. cellInstall takes warm alone.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs