* fix(#2789): scope the emitted-drift ack to the diff that introduced it Every input to `diffEmitted` is base-relative -- `baseline` vs `current`, `changedPaths` from `git diff base...HEAD` -- except the ack set, which was read absolutely, from the working tree only. A differential machine consulting a non-differential input. So `staleAcks` asks exactly one question, "did a delta consume you?", and that cannot distinguish an ack that never explained anything (an authoring mistake) from one whose ripple is now absorbed into the base (the ack's SUCCESS condition). After merge an ack is in the second state but reports as the first. The trigger is ordinary. Actions sets GITHUB_BASE_REF on pull_request events only, so a push to `next` falls through to origin/next -- the very commit under test. Both sides build identical content, no deltas remain, and every live ack is reported stale. PR #2768 acked a deliberate 40866 -> 42020 byte growth, was green on its own lane, and reddened `next` the moment it merged. It also reds every PR branching off the poisoned base, and since publish-emitted-baseline is gated on the test job, it blocked baseline publication too. Give the ack the base side it was missing. `diffEmitted` now takes `baseAck` -- the same document at the base ref, via `readAckFileAtRef`. An entry already present there is SPENT: it may no longer consume a delta and is never reported stale, only surfaced as `spentAcks` for tidying. An entry new or reworded in this diff stays live, and if nothing consumes it that genuinely fails, with blame on the author who just wrote it. This closes a hazard the IMPLEMENTATION named but could not prevent -- a leftover ack silently pre-clearing the next ripple on its path. (ADR-2719 §3 asserted only that TOUCHING the file is the alarm; its residual-risk list never covered pre-clearing, and §3 now carries an amendment.) Verified against the two-PR laundering sequence -- land an innocuous ack, then change the artifact -- which passed silently before and now fails on both the hash pass and the size ratchet. Three things the design has to get right, each of which was wrong first: - A read failure on the base document THROWS; only absence-at-the-ref returns null. Returning null on error LOOKS armed (every entry stays live) but a live entry's defining power is that it CONSUMES a delta, so null is armed on the staleness axis and DISARMED on consumption -- silently the whole pre-#2789 gate. `git show` cannot tell absence from fault, so absence is established with `ls-tree`. - Re-arming a spent ack costs actual PROSE. Internal whitespace and the zero-width family collapse, and `runtime` is not compared: a doubled space, an invisible character, or a decorative field would otherwise re-arm an ack whose justification still describes the previous ripple, showing a reviewer nothing. - `baseAck` is REQUIRED once an ack declares entries -- omission is an error, not a silent "inherit nothing" -- so a dropped argument fails loudly instead of quietly restoring this bug with the suite green. Because a corrupt document ON THE BASE is expensive (the loud base-side failure reds every ack-carrying PR), scripts/lint-emitted-drift-ack.cjs blocks one from landing. It is standalone rather than importing parseAck -- scripts/ ships in the npm package and tests/ does not -- so a parity test runs both surfaces over one corpus and fails on divergence; it caught one immediately, a `null` document, now classed as policy rather than schema. Deadlock is separately foreclosed: a tree carrying no ack never reads the base, so the PR that DELETES a corrupt file still lands. `readAckFileAtRef` takes an injected git runner so all four branches are tested deterministically; it never executes in the remote runner, where the real-tree test skips for want of a base ref. It also refuses an option-shaped ref, since execFileSync's array form stops shell metacharacters but not git's own option parsing. Rejected: skipping the differential when base == HEAD. It treats the symptom, costs real coverage on the push-to-next lane, and does nothing about the downstream PRs the same flaw was reddening. Deletes the now-spent tests/emitted-drift-ack.json, and updates the CONTEXT.md canon and ADR-2719 §3: presence is no longer the alarm -- a LIVE entry is, and a spent one is inert. Closes #2789 * chore(#2789): backfill changeset PR number
This commit is contained in:
@@ -45,7 +45,13 @@ const {
|
||||
} = require('./install-shared.cjs');
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '..', '..');
|
||||
const ACK_PATH = path.join(REPO_ROOT, 'tests', 'emitted-drift-ack.json');
|
||||
/**
|
||||
* Repo-relative and POSIX-separated on every platform: this form is what `git show
|
||||
* <ref>:<path>` requires, and git speaks only forward slashes regardless of host OS.
|
||||
* `ACK_PATH` derives from it so the two can never name different files.
|
||||
*/
|
||||
const ACK_REPO_PATH = 'tests/emitted-drift-ack.json';
|
||||
const ACK_PATH = path.join(REPO_ROOT, ...ACK_REPO_PATH.split('/'));
|
||||
const FIXTURE_SUBDIR = 'tests/fixtures/golden-install-parity';
|
||||
|
||||
/**
|
||||
@@ -291,6 +297,78 @@ function resolveBaseSha(base = 'origin/next') {
|
||||
return git(['rev-parse', base]).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* The acknowledgment document AS IT EXISTS AT `base` — the base side of the ack
|
||||
* lifecycle (#2789). An entry already present there is SPENT: its ripple is absorbed
|
||||
* into the base, so it may no longer clear a delta and is never reported stale.
|
||||
*
|
||||
* ── Why "inherit nothing" is NOT a safe default ──────────────────────────────
|
||||
* Absent at that ref is the healthy steady state and returns `null`. Every OTHER failure
|
||||
* THROWS, and the distinction is load-bearing in the direction that is easy to get
|
||||
* backwards. Returning `null` on a read error looks armed — nothing is inherited, so
|
||||
* every entry stays live — but a LIVE entry's defining power is that it CONSUMES a
|
||||
* delta. So `null` is armed on the staleness axis and DISARMED on the consumption axis,
|
||||
* which is the axis a gate over shipped artifacts actually cares about: a genuinely new,
|
||||
* unexplained ripple on a path carrying an already-merged ack would come back `acked`
|
||||
* instead of `unattributable`. That is silently the whole pre-#2789 behavior, including
|
||||
* the pre-clearing hazard this change exists to close.
|
||||
*
|
||||
* So this follows the same law as `resolveChangedPaths` above — a failed git read is an
|
||||
* ERROR, not an empty set — and matches the head-side `readAckFile`, which already
|
||||
* throws on a document that exists but will not parse. Being more forgiving about the
|
||||
* base copy of the same file would be strictly worse: it is the copy we cannot see in
|
||||
* the diff.
|
||||
*
|
||||
* `git show` alone cannot make the distinction — a bogus ref and an absent path produce
|
||||
* the same "does not exist in" message — so absence is established with `ls-tree`, which
|
||||
* exits 0 with empty output when the path is simply not there and non-zero on a real
|
||||
* fault.
|
||||
*/
|
||||
function readAckFileAtRef(base, { cwd = REPO_ROOT, run = git } = {}) {
|
||||
// `execFileSync`'s array form stops SHELL metacharacters but not git's own option
|
||||
// parsing: a ref beginning with `-` is read as an option token, and `git show` honors
|
||||
// diff options including `--output=<file>`, which writes. Today every caller passes a
|
||||
// resolved 40-hex sha, but this function is exported and validated nothing itself —
|
||||
// the guard belonged with the argument, not with the one caller that happens to be safe.
|
||||
if (typeof base !== 'string' || base === '' || base.startsWith('-')) {
|
||||
throw new Error(
|
||||
`emitted-attribution: refusing to read the ack at ${JSON.stringify(base)} — a base ref `
|
||||
+ 'must be a non-empty string that does not begin with "-", which git would parse as an option.',
|
||||
);
|
||||
}
|
||||
|
||||
let listing;
|
||||
try {
|
||||
listing = run(['ls-tree', '--name-only', base, '--', ACK_REPO_PATH], { cwd });
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
`emitted-attribution: could not list the ack at "${base}": ${err.message}. This is a `
|
||||
+ 'hard error on purpose — treating an unreadable base as "nothing inherited" would '
|
||||
+ 'leave every ack able to consume a delta, which is the pre-#2789 gate.',
|
||||
);
|
||||
}
|
||||
if (listing.trim() === '') return null; // genuinely absent at that ref — the steady state
|
||||
|
||||
let raw;
|
||||
try {
|
||||
raw = run(['show', `${base}:${ACK_REPO_PATH}`], { cwd });
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
`emitted-attribution: ${ACK_REPO_PATH} exists at "${base}" but could not be read: ${err.message}`,
|
||||
);
|
||||
}
|
||||
if (raw.trim() === '') {
|
||||
throw new Error(`emitted-attribution: ${ACK_REPO_PATH} is present at "${base}" but empty`);
|
||||
}
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
`emitted-attribution: ${ACK_REPO_PATH} at "${base}" is not valid JSON: ${err.message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base-ref candidates, most-specific first.
|
||||
*
|
||||
@@ -597,6 +675,8 @@ function readAckFile(ackPath = ACK_PATH) {
|
||||
module.exports = {
|
||||
REPO_ROOT,
|
||||
ACK_PATH,
|
||||
ACK_REPO_PATH,
|
||||
readAckFileAtRef,
|
||||
FIXTURE_SUBDIR,
|
||||
MANIFEST_FAMILIES,
|
||||
MINIMUM_MANIFEST_FAMILIES,
|
||||
|
||||
Reference in New Issue
Block a user