Skip to content

Commit 1e996b0

Browse files
committed
fix(pm): record-recognisers answers every card a tie holds, beside the pairing that still refuses one
deliveredCardsAtStrongest returns the delivered cards at the strongest grade, in body order, from the same enumeration deliveredCardNumber answers from. deliveredCardNumber is unchanged: it still yields no card on a tie, so the queue guard's record pairing does not move. Co-authored-by: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgVv6gTt6GofcDEN2Bd
1 parent 598a34d commit 1e996b0

1 file changed

Lines changed: 69 additions & 16 deletions

File tree

‎scripts/pm/record-recognisers.mjs‎

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*
2222
* locateReviewOfRecord the record on this head, on the PR thread or its card
2323
* deliveredCardNumber which card thread a pull request's record may sit on
24+
* deliveredCardsAtStrongest every card a pull request delivers at its strongest grade, for a reader that reads them all
2425
* readServedTier the `Served-tier:` line, and `servedTierStands` on it — at the tier its face maps to
2526
* reviewFace / REVIEW_FACES which face made the review owed, and the ONE tier NAME it stands at
2627
* reviewScopeHits the at-tier review's scope floor — `reviewFace`'s `hits`, the record's `Scope:` line
@@ -2208,28 +2209,15 @@ export const DELIVERY_EVIDENCE_PRECEDENCE = Object.freeze(['closing-keyword', 'p
22082209
* @returns {{ card: number, evidence: string } | { card: null, reason: string }}
22092210
*/
22102211
export function deliveredCardNumber(pr) {
2211-
const body = String(pr?.body ?? '');
2212-
const candidates = new Set([
2213-
...closingKeywordTargets(body).keys(),
2214-
...partOfTargets(body).keys(),
2215-
...[branchNameTarget(pr?.head?.ref)].filter((n) => n !== null && n !== undefined),
2216-
]);
2217-
const delivered = [];
2218-
for (const n of candidates) {
2219-
const evidence = deliveryEvidence(pr, n);
2220-
if (evidence === null) continue;
2221-
delivered.push({ card: Number(n), evidence, rank: DELIVERY_EVIDENCE_PRECEDENCE.indexOf(evidence) });
2222-
}
2223-
if (delivered.length === 0) {
2212+
const strongest = strongestDeliveredRows(pr);
2213+
if (strongest.length === 0) {
22242214
return {
22252215
card: null,
22262216
reason:
22272217
'its body names no card (no closing keyword and no `Part of` declaration) and its branch is not '
22282218
+ 'the protocol dev-branch shape, so no card thread could be located for it',
22292219
};
22302220
}
2231-
const best = Math.min(...delivered.map((row) => row.rank));
2232-
const strongest = delivered.filter((row) => row.rank === best);
22332221
if (strongest.length > 1) {
22342222
return {
22352223
card: null,
@@ -2242,6 +2230,51 @@ export function deliveredCardNumber(pr) {
22422230
return { card: strongest[0].card, evidence: strongest[0].evidence };
22432231
}
22442232

2233+
/**
2234+
* The delivered cards at the STRONGEST grade any of them carries, in the order the body names them — the ONE
2235+
* enumeration `deliveredCardNumber` and `deliveredCardsAtStrongest` both answer from, so the two can never
2236+
* disagree on which cards a tie holds. Each row is a card `deliveryEvidence` accepts, with its grade and rank.
2237+
*/
2238+
function strongestDeliveredRows(pr) {
2239+
const body = String(pr?.body ?? '');
2240+
const candidates = new Set([
2241+
...closingKeywordTargets(body).keys(),
2242+
...partOfTargets(body).keys(),
2243+
...[branchNameTarget(pr?.head?.ref)].filter((n) => n !== null && n !== undefined),
2244+
]);
2245+
const delivered = [];
2246+
for (const n of candidates) {
2247+
const evidence = deliveryEvidence(pr, n);
2248+
if (evidence === null) continue;
2249+
delivered.push({ card: Number(n), evidence, rank: DELIVERY_EVIDENCE_PRECEDENCE.indexOf(evidence) });
2250+
}
2251+
if (delivered.length === 0) return [];
2252+
const best = Math.min(...delivered.map((row) => row.rank));
2253+
return delivered.filter((row) => row.rank === best);
2254+
}
2255+
2256+
/**
2257+
* EVERY card a pull request delivers at its strongest grade — the cards `deliveredCardNumber` refuses to choose
2258+
* between when there is more than one, as numbers in the order the body names them, with that grade.
2259+
*
2260+
* ⭐ DERIVED THROUGH `deliveryEvidence` exactly as `deliveredCardNumber` is: the same enumeration
2261+
* (`strongestDeliveredRows`), so a card here is a card that relation accepts, and one card here is the one card
2262+
* `deliveredCardNumber` answers. ⛔ Never a second parser.
2263+
*
2264+
* ⛔ NOT a tie-break, and NOT for a reader that searches ONE thread. `deliveredCardNumber` stays the answer to
2265+
* "which thread may this pull request's record sit on", and it still answers `card: null` on a tie. This is for a
2266+
* reader that reads EVERY tied card and judges over all of them, so its verdict cannot depend on which card is
2267+
* read first: `label-write.mjs --land`'s dogfood gate on a folded pull whose body carries one closing keyword per
2268+
* card. The order is the reading order and nothing else; no reader may rank by it.
2269+
*
2270+
* @param {object} pr — a REST pull row: `body`, and `head.ref` for the fallback
2271+
* @returns {{ cards: number[], evidence: string | null }} — `cards` empty and `evidence` null when none is delivered
2272+
*/
2273+
export function deliveredCardsAtStrongest(pr) {
2274+
const strongest = strongestDeliveredRows(pr);
2275+
return { cards: strongest.map((row) => row.card), evidence: strongest[0]?.evidence ?? null };
2276+
}
2277+
22452278
/**
22462279
* EVERY card a pull request NAMES through a channel the card relations read, as numbers in ascending
22472280
* order: each closing keyword's target, each `Part of` target (at the declaration position or inline),
@@ -2812,6 +2845,9 @@ const SELF_TEST_BATTERIES = Object.freeze({
28122845
'⭐ the signature line: the reader reads LANE#N · ACCOUNT · SESSION exactly, and one leading signature changes no first-line reading': 22,
28132846
'⭐ the `Contract-review-claim:` line — session, FULL head, time; lapses on a moved head or after two hours; the earliest live claim holds': 24,
28142847
'⭐ the `Contract-review-hold:` line — session, head, reason, until; a new head clears it; at 24 hours it reads overdue and still holds': 23,
2848+
// The tie relation: the cards a fold's equal closing keywords deliver, for the `--land` dogfood gate, which reads
2849+
// every one of them; `deliveredCardNumber`'s pairing stays refusing on a tie.
2850+
'⭐ the tie relation: `deliveredCardsAtStrongest` answers every card a tie holds, in body order, from the ONE enumeration `deliveredCardNumber` answers from — which still yields no card on a tie': 8,
28152851
});
28162852

28172853
// DELETING an entry silences that battery's floor exactly as effectively as
@@ -2836,7 +2872,8 @@ const SELF_TEST_BATTERIES = Object.freeze({
28362872
// Raised 16 → 17 with the hold-line battery (the maintainer's lane-hold rule): one battery, one row.
28372873
// Raised 17 → 18 with the knock-signature battery (#33789 item 3, split to #34013): one battery, one row.
28382874
// Raised 18 → 19 with the card-thread delegate battery (#34013 remainder 2): one battery, one row.
2839-
const SELF_TEST_BATTERY_FLOOR = 19;
2875+
// Raised 19 → 20 with the tie-relation battery (`deliveredCardsAtStrongest`): one battery, one row.
2876+
const SELF_TEST_BATTERY_FLOOR = 20;
28402877

28412878
// The key an assertion is filed under when no battery is open. It is not a
28422879
// declared battery, so it reds by the same set difference rather than silently
@@ -3936,6 +3973,22 @@ export async function selfTest() {
39363973
t('⛔ CONTROL: the ranking belongs to `deliveryEvidence` -- every grade it answers is ranked here, none invented', DELIVERY_EVIDENCE_PRECEDENCE.every((kind) => deliveryEvidenceNote(kind) !== 'evidence unread') && new Set(DELIVERY_EVIDENCE_PRECEDENCE).size === DELIVERY_EVIDENCE_PRECEDENCE.length);
39373974
t('…and it is ranked in the order that function applies, measured pair by pair', DELIVERY_EVIDENCE_PRECEDENCE.indexOf(deliveryEvidence(PIN_PULL(`Fixes #1\nPart of #2`), '1')) < DELIVERY_EVIDENCE_PRECEDENCE.indexOf(deliveryEvidence(PIN_PULL(`Fixes #1\nPart of #2`), '2')) && DELIVERY_EVIDENCE_PRECEDENCE.indexOf('part-of') < DELIVERY_EVIDENCE_PRECEDENCE.indexOf('branch-name'));
39383975

3976+
// `deliveredCardsAtStrongest` -- the cards a tie holds, for a reader that reads them ALL (the `--land` dogfood
3977+
// gate). It answers from the same enumeration as `deliveredCardNumber`, which still refuses to choose.
3978+
battery('⭐ the tie relation: `deliveredCardsAtStrongest` answers every card a tie holds, in body order, from the ONE enumeration `deliveredCardNumber` answers from — which still yields no card on a tie');
3979+
{
3980+
const tie = (body, ref) => deliveredCardsAtStrongest(PIN_PULL(body, ref));
3981+
const same = (actual, expected) => JSON.stringify(actual) === JSON.stringify(expected);
3982+
t('⭐ two closing keywords: BOTH cards, at that grade, in the order the body names them -- never sorted', same(tie('Fixes #5555\nFixes #4444'), { cards: [5555, 4444], evidence: 'closing-keyword' }), JSON.stringify(tie('Fixes #5555\nFixes #4444')));
3983+
t('⛔ …and on that same body `deliveredCardNumber` still yields NO card: the record pairing is unchanged on a tie', (() => { const r = deliveredCardNumber(PIN_PULL('Fixes #5555\nFixes #4444')); return r.card === null && r.reason.includes('same strength') && r.reason.indexOf('#5555') < r.reason.indexOf('#4444'); })());
3984+
t('two `Part of` declarations and no keyword are a tie at `part-of`', same(tie('Part of #4444\nPart of #5555'), { cards: [4444, 5555], evidence: 'part-of' }), JSON.stringify(tie('Part of #4444\nPart of #5555')));
3985+
t('a STRONGER grade still leaves one card: a `Part of` beside a keyword is not in the tie', same(tie('Fixes #4444\nPart of #5555'), { cards: [4444], evidence: 'closing-keyword' }), JSON.stringify(tie('Fixes #4444\nPart of #5555')));
3986+
t('a branch named for a third card adds nothing once the body speaks', same(tie('Fixes #4444\nFixes #5555', 'claude/issue-6666-x'), { cards: [4444, 5555], evidence: 'closing-keyword' }), JSON.stringify(tie('Fixes #4444\nFixes #5555', 'claude/issue-6666-x')));
3987+
t('⛔ a body naming NO card is no tie: no cards and no grade', same([tie('nothing here'), deliveredCardsAtStrongest(null)], [{ cards: [], evidence: null }, { cards: [], evidence: null }]), JSON.stringify([tie('nothing here'), deliveredCardsAtStrongest(null)]));
3988+
t('⛔ CONTROL: one card here is exactly the card `deliveredCardNumber` answers, and none here is its null -- on every fixture above', ['Fixes #5555\nFixes #4444', 'Part of #4444\nPart of #5555', 'Fixes #4444\nPart of #5555', `Part of #${PIN_CARD}`, 'nothing here'].every((body) => { const all = deliveredCardsAtStrongest(PIN_PULL(body)); const one = deliveredCardNumber(PIN_PULL(body)); return all.cards.length === 1 ? one.card === all.cards[0] && one.evidence === all.evidence : one.card === null; }) && deliveredCardNumber(PIN_PULL('nothing', `claude/issue-${PIN_CARD}-x`)).card === tie('nothing', `claude/issue-${PIN_CARD}-x`).cards[0]);
3989+
t('structural: both relations answer from the ONE enumeration, and neither grades evidence itself', (() => { const own = readFileSync(fileURLToPath(import.meta.url), 'utf8'); const body = (name) => own.slice(own.indexOf(`export function ${name}(`), own.indexOf('\n}\n', own.indexOf(`export function ${name}(`))); return ['deliveredCardNumber', 'deliveredCardsAtStrongest'].every((name) => body(name).includes('strongestDeliveredRows(pr)') && !body(name).includes('deliveryEvidence(')); })());
3990+
}
3991+
39393992
// -- The floor: every declared battery RAN, and ran its cases (#13489) -----
39403993
//
39413994
// Evaluated after every battery has had its chance and BEFORE the verdict, so

0 commit comments

Comments
 (0)