Skip to main content

Module gate_stamp

Module gate_stamp 

Source
Expand description

The record that turns “a declaration exists” into “the check ran”.

Moving a gate entry to commit time (docs/checks.md, “Moving a gate entry earlier”) makes the push gate skip a script because a pre-commit declaration covers it. A declaration is a promise on paper: a commit made with --no-verify, from a libgit2 client that runs no hooks, or on a machine without amont was never judged by it — and until this module existed, push time had no way to tell those commits from checked ones.

Three hooks share one record:

  1. pre-commit (record) writes a one-shot marker into $GIT_DIR naming the gate scripts that actually ran, bound to the tree the commit is about to write (git write-tree — during pre-commit the index IS the commit’s content; staged_only parks only the working tree).
  2. post-commit (bind_to_head) consumes the marker and, when the marker’s tree matches HEAD^{tree}, stamps the commit in a notes ref. --no-verify skips pre-commit but NOT post-commit, so an unchecked commit arrives here with no marker and gets no stamp — which is the entire point. The tree comparison makes an aborted commit’s leftover marker harmless, and a retried commit of the SAME tree correctly stamped: the check really did run on exactly that content.
  3. pre-push (stamps_for) reads the stamps back and suppresses a gate script only for pushes whose relevant commits all carry it.
  4. pre-push, on the way out (stamp_push) writes the push-time gates that PASSED onto each pushed tip — and amont run pre-push, which drives the same dispatcher, writes the same stamp for HEAD. The next push of that tree finds the stamp and skips the gate. That is what lets the suite run BEFORE git opens its connection: a rehearsal stamps, the push verifies. And a push that passed the gate but died on the wire — a remote that dropped the idle session while the suite ran — retries in seconds instead of minutes. Push-time tokens are full ids (pre-push-run-tests-js), commit-time ones are script names (test); the two share a note and never collide.

Every failure mode points the same direction: no marker, a mismatched tree, a missing note, a rewritten hash — all mean “no stamp”, and no stamp means the push gate RUNS. Nothing here can let an unchecked commit through; it can only cost a redundant gate run.

§The second half of the note: what a run COST, and how it ENDED

The token line above answers one question — may this gate be skipped for this content — and it is deliberately a set, with no history in it. A stamp says a gate passed; it cannot say a gate has been passing in four seconds since the day its test runner stopped finding any tests.

So the note carries optional extra lines, one per RUN:

greengate-gate-v1 pre-push-cargo-test
run 1726900000 pre-push-cargo-test pass 412391
run 1726903600 pre-push-audit-js fail 903

Additive on purpose, and in the only direction that is safe: every reader that existed before these lines did reads body.lines().next() and is unaffected, and an amont old enough to rewrite the note without them loses history — never a verdict. The run lines are EVIDENCE, read by crate::gate_evidence; nothing in this module’s skip decisions consults them, so a corrupted or forged one cannot make a check be skipped.

One more kind of line, and the one exception to that rule (ADR-0013):

deferred cargo-test

A commit-time gate the busy policy deferred to CI. Pre-push reads it (deferred_for) so the gate’s push twin defers too instead of running the suite with the remote’s connection held open. It can only ever move a gate to CI — it is never a token, never stamps, never attests — so a forged line makes CI run more, never less. Kept apart from the run history, whose [MAX_RUNS] trim must not forget it.

The note’s key is the tree, which makes the record a per-FINGERPRINT one for free: two runs of one gate against one tree are two lines in one note, and if they disagree the gate is flaky on content that did not change.

Why a notes ref and not config: notes are keyed by commit, garbage-collect with unreachable commits (an greengate.checked.<hash> config key would outlive every rebase forever), stay local (notes refs are not pushed by default), and stay out of git log (only refs/notes/commits displays by default). amont uninstall deletes the ref; see uninstall_repo_hooks.

Structs§

Note
A parsed note body: the skip tokens, and the runs recorded against this key.
Run
One run of one gate: when, which, how it ended, how long it took.

Enums§

Completion
How a gate completed without passing (ADR-0018). The kind is part of the record, so each answers only for as long as it should.
RunOutcome
How a single run of one gate ended.

Constants§

CLUSTER_FULL_REF
CLUSTER_REF
Where CLUSTER passes are recorded (ADR-0016): the same note format, keyed by the judged tree, holding tokens of gate_identity::cluster_token. Never greengate-gate (ADR-0015): a local token here would let the laptop sign a pass it never ran.
DONE_FULL_REF
DONE_REF
Where a gate that COMPLETED without passing is recorded (ADR-0018): a warn-severity failure, or a gate that could not run. The same note format, keyed by the tree, holding gate_identity tokens. Never greengate-gate: a completion is not a pass, and nothing reads this ref to attest or to skip a gate in an inline push. Only the refusing push (greengate.pushGates refuse) and land’s own push read it, so that what a rehearsal or land’s pre-stage already ran is not refused as “not run”.
FORMAT
First token of the marker file and of every note body. Versioned like staged_only::FORMAT: a future amont that changes the shape bumps this, and an old record is ignored rather than misread.
INPUTS_FULL_REF
INPUTS_REF
The second ref: stamps keyed by a gate’s declared-input fingerprint (.github/greensummit-inputs, see crate::attest_inputs) instead of by the whole tree. A gate whose inputs a repository declares is reused on any tree where those inputs are byte-identical — the closing plan commit changes the tree and none of them. Every key there is an oid that is not an object, as in attest’s own inputs ref, so git notes prune on it would drop everything: never run it, and never merge the ref with cat_sort_uniq.
NOTES_FULL_REF
The same ref, fully qualified — what git update-ref -d needs. A literal, not derived from [WRITE]; a test holds it equal to refs/notes/{NOTES_REF}.
NOTES_REF
The notes ref, spelled the way git notes --ref wants it.
PROVENANCE
The reserved first word of a provenance line: where a token came from (platform, observed imageID, Job UID). Never a token, never a run, and every reader of tokens drops it.

Functions§

bind_to_head
post-commit: consume the marker; stamp HEAD when the tree still matches.
commit_stamps_enabled
Does this repository reuse a gate’s verdict across commit attempts of one tree?
deferred_for
Which of commits carry a deferral of gate on their tree’s note (or their own). Read only to defer a push twin, never to skip one: a commit in this set still has no stamp.
deferred_on
The commit-time gates the busy policy deferred on tree, by script name. What amont stamps reports as deferred; never a token.
done_on_every
Did the gate behind token complete without passing on the tree of every one of commits, by a record that still answers under severity? An unreadable tree or note is “no”, the direction that refuses rather than skips.
forget
uninstall: forget everything this module ever wrote here.
forget_in
The same, for a repository this process is not standing in.
is_provenance
Is line a PROVENANCE line? Every token reader asks, so a line that says where a pass came from can never be read as the pass itself.
push_stamps_enabled
Does this repository reuse push-time stamps?
record
pre-commit: record that scripts ran clean against the tree the commit will carry.
record_deferred
pre-commit: record on tree (the staged tree, which is the commit’s) that the busy policy deferred gates, by their commit-time script names. Best-effort and silent: a lost line runs the push twin, the safe way.
record_done
Record on tree that the gates behind tokens completed there without passing, as how (ADR-0018). Merged into the note; an Unavailable or Deferred record replaces the one of its kind before it for the same gate, so a tree’s note does not grow by a word per run. The error names the tree, for the caller to say: a record that was not written costs a refused push.
record_runs
Record what a gate run COST and how it ENDED, against the content it ran on.
stamp_push
pre-push, after every block gate passed: record that gates passed against tree, the content of commit — MERGING with whatever the note already says, because a commit-time stamp (test) may already sit there and notes add -f would otherwise erase it.
stamp_tree
Add tokens to the gate note on tree — how a rehearsal records tree gates it proved in its snapshot of exactly that tree. Merged, never rendered from the tokens alone, so evidence already on the note survives.
stamps_for
pre-push: which of commits carry a stamp, and for which scripts.
tree_tokens
The stamp tokens on tree (a tree object id). Tree gates are read here and only here (ADR-0024): tree:<name> on the pushed tree proves the gate on exactly that content, whichever commit carried it.
vouched_for_staged_tree
pre-commit, before a gate runs: the scripts a previous run already vouched for against the tree this commit is about to seal.