Skip to main content

Module snapshot_prep

Module snapshot_prep 

Source
Expand description

Make a fresh snapshot runnable: carry the untracked files a suite needs, then prepare its JavaScript dependencies.

A snapshot is a checkout, not a workspace — no node_modules, no .env — and a gate started there fails having tested nothing. Both steps run in crate::pushed_tree::PushedTree::prepare, before greengate.snapshotPrepare (the escape hatch), and a failure in either is the snapshot’s failure: no suite runs, nothing is stamped.

§What a stamp may rest on

A stamp claims the gate passed on the COMMITTED content. So nothing here may put content from the developer’s tree where committed content lives: a carried path must be untracked in the snapshot’s own index, and the dependencies must be the ones the committed lockfile describes.

The default, install, is what CI does: npm ci, pnpm install --frozen-lockfile, yarn install --frozen-lockfile (yarn 1) or --immutable (berry, told apart by the lockfile’s __metadata: block). A bun lockfile is recognised and refused with the fix named, never installed: a gate run over no dependencies fails every workspace at once and reads like a broken branch. reuse (pnpm and npm; yarn and bun always install, see voucher) clones the working tree’s node_modules and keeps the clone only when the manager vouches for it: pnpm by its isolated layout and a frozen offline install, npm by a dry-run install that would add, remove and change nothing. Both catch a missing or wrong-version package, a stray directory, and a manifest the lockfile does not satisfy; npm also catches a version raised in place with its timestamps set back. NEITHER catches a file edited in place without a version change: the mtime scan covers that only while the edit is newer than the install. That limit is why reuse is opt-in.

Every question about a manifest goes to the package manager, through exit codes and parseable output: this crate is dependency-free and has no JSON or YAML parser, and a hand-rolled one reading workspaces would be a second, divergent answer to a question npm already answers.

Structs§

Unit
One installation unit: a directory holding a tracked lockfile, and the manager that reads it.

Enums§

DepsMode
greengate.snapshotDeps.
Manager

Functions§

carry
Copy the untracked files greengate.snapshotCarry names from source into snapshot.
carry_list
greengate.snapshotCarry, split on whitespace and commas.
changed_since_upstream
The files tip changes relative to where it forked from its upstream — what the push is about. None when git cannot say (no upstream, a tip it does not know): the caller then prepares everything.
declared_manager
The packageManager field of a package.json, by a targeted scan of that one key — the manager it names (npm@…, pnpm@…, yarn@…, bun@…) when it names one without ambiguity, None otherwise.
deps
Prepare the dependencies of every unit the push needs in snapshot.
deps_mode
is_berry_lock
Is this yarn.lock yarn 2+’s? Berry writes a __metadata: block at the top of every lockfile; yarn 1 writes # yarn lockfile v1 and never that key. Read from the SNAPSHOT’s lockfile, so the pushed commit decides.
lockfile_dirs_in
The directories of files named exactly name, repo-relative ("" for the root), sorted and deduplicated. Pure: the caller decides WHICH index the list comes from — the snapshot’s, for a snapshot.
run
Carry → dependencies → nothing else; snapshotPrepare runs after this, in PushedTree::prepare. Dependencies are skipped when a snapshotPrepare command exists: that command owns them.
select_units
Which units a snapshot needs: the root one, and every unit that is the NEAREST enclosing unit of a changed file. A unit the push does not touch cannot hold a failure the push introduced — and nothing the gates run for this push reads it — so installing it is pure cost (website-builder: seven spikes, an install each, on every snapshot). changed is None when the range is unknown, and then every unit is kept.
snapshot_files
The snapshot’s own tracked files, -z, with git’s environment stripped: a hook’s GIT_DIR/GIT_INDEX_FILE would otherwise answer for the developer’s repository, and the pushed tip — not HEAD, not the index the developer is staging into — decides what the snapshot holds.
units
Every installation unit in files. A directory holding MORE THAN ONE manager’s lockfile is settled by packageManager, or refused: guessing would install the wrong tree and test it as if it were the right one.