Skip to content

Commit faa9b33

Browse files
build(html): say why each sweep finding is expected, and catch a stale one
The invariant sweep reported eight findings a reader had to re-derive every run, so a real divergence would have hidden among them. Each is now stated with its reason and counted apart; an entry matching nothing is reported as stale, since a divergence that is gone must lose its entry or the list stops saying anything true.
1 parent 381e7ff commit faa9b33

2 files changed

Lines changed: 106 additions & 4 deletions

File tree

‎tooling/compare-html-tools.js‎

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,56 @@ const invariantFixtures = () => {
13481348
return out;
13491349
};
13501350

1351+
/**
1352+
* What the sweep reports that the printer owes nothing for. Each entry states
1353+
* the reason, since a divergence with no reason beside it is one nobody can
1354+
* tell from a defect later.
1355+
* @type {readonly import("./compare-tools-harness").Expected[]}
1356+
*/
1357+
const EXPECTED = [
1358+
{
1359+
relation: "respelling references",
1360+
contains: " ",
1361+
why: "WHATWG 'escape a string' replaces U+00A0 with ` `, which is what `escapeAttribute` implements; the literal costs 32 raw bytes less over 939 documents and nothing compressed either way"
1362+
},
1363+
{
1364+
relation: "respelling quote-double",
1365+
contains: " ",
1366+
why: "the same escaping, reached through the delimiter the value is written in"
1367+
},
1368+
{
1369+
relation: "respelling quote-single",
1370+
contains: " ",
1371+
why: "the same escaping, reached through the delimiter the value is written in"
1372+
},
1373+
{
1374+
relation: "respelling unquote",
1375+
contains: " ",
1376+
why: "the same escaping, reached through a value written without quotes"
1377+
},
1378+
{
1379+
relation: "respelling quote-double",
1380+
contains: """,
1381+
source: "style-attribute",
1382+
why: "`"` for `"` is 3 raw bytes more and 11 gzip bytes less, and gzip decides"
1383+
},
1384+
{
1385+
relation: "respelling quote-double",
1386+
contains: "{%",
1387+
why: "a tag whose duplicate attribute names HTML parsing drops is echoed from source: rebuilding it would print the drop (#22013)"
1388+
},
1389+
{
1390+
relation: "respelling quote-single",
1391+
contains: "{%",
1392+
why: "the same echo, reached through the other delimiter"
1393+
},
1394+
{
1395+
relation: "respelling references",
1396+
contains: "{%",
1397+
why: "the same echo, which also leaves the tag's other values spelled as the source wrote them"
1398+
}
1399+
];
1400+
13511401
/**
13521402
* Sweep mode: hold the printer to its own invariants and report what it breaks.
13531403
* Nothing is installed and nothing is compared to, so this is the cheap half of
@@ -1359,7 +1409,7 @@ const invariants = (write) => {
13591409
const corpus = invariantFixtures().filter(([label]) => wantedFixture(label));
13601410
const presets = PRESETS.filter(([name]) => wantedPreset(name));
13611411
log(`sweeping ${corpus.length} documents under ${presets.length} presets …`);
1362-
const groups = findingGroups();
1412+
const groups = findingGroups(EXPECTED);
13631413
for (const [label, html] of corpus) {
13641414
for (const [preset, options] of presets) {
13651415
for (const report of sweepDocument(printerFor(options), html)) {

‎tooling/compare-tools-harness.js‎

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,12 +569,38 @@ const idempotence = ({ minify, source, says, repro }) => {
569569
};
570570
};
571571

572+
/**
573+
* A finding the printer owes nothing for, with the reason it is owed nothing.
574+
* `relation` and `contains` together name it; `source` narrows it to one
575+
* fixture where the same repro is a defect elsewhere.
576+
* @typedef {{ relation: string, contains: string, source?: string, why: string }} Expected
577+
*/
578+
579+
/**
580+
* Whether one expectation covers one group.
581+
* @param {Expected} expected the entry
582+
* @param {Report} report the finding
583+
* @param {Set<string>} sources the fixtures it was found in
584+
* @returns {boolean} true when the entry names this finding
585+
*/
586+
const _covers = (expected, report, sources) => {
587+
if (expected.relation !== report.relation) return false;
588+
if (!report.repro.includes(expected.contains)) return false;
589+
if (expected.source === undefined) return true;
590+
for (const source of sources) {
591+
if (source.includes(expected.source)) return true;
592+
}
593+
return false;
594+
};
595+
572596
/**
573597
* Findings gathered by the repro rather than by the source: one printer defect
574-
* reaches hundreds of files, and is one thing to fix.
598+
* reaches hundreds of files, and is one thing to fix. An expected finding is
599+
* counted apart, so the number a run reports is what is left to answer for.
600+
* @param {readonly Expected[]=} expected findings already answered for
575601
* @returns {{ add: (report: Report, preset: string, label: string) => void, write: (out: (text: string) => void) => number }} the collector
576602
*/
577-
const findingGroups = () => {
603+
const findingGroups = (expected = []) => {
578604
/** @type {Map<string, { report: Report, presets: Set<string>, sources: Set<string> }>} */
579605
const groups = new Map();
580606
return {
@@ -605,7 +631,18 @@ const findingGroups = () => {
605631
const ordered = [...groups.values()].sort(
606632
(a, b) => b.sources.size - a.sources.size
607633
);
634+
/** @type {Set<Expected>} */
635+
const matched = new Set();
636+
/** @type {typeof ordered} */
637+
const unexpected = [];
608638
for (const group of ordered) {
639+
const covering = expected.find((entry) =>
640+
_covers(entry, group.report, group.sources)
641+
);
642+
if (covering === undefined) unexpected.push(group);
643+
else matched.add(covering);
644+
}
645+
for (const group of unexpected) {
609646
const { relation, what, repro } = group.report;
610647
const sources = [...group.sources];
611648
const reach =
@@ -618,7 +655,22 @@ const findingGroups = () => {
618655
)}] ${reach}\n`
619656
);
620657
}
621-
return ordered.length;
658+
if (matched.size !== 0) {
659+
out(`\nexpected, and why — ${matched.size} of ${expected.length}\n`);
660+
for (const entry of expected) {
661+
if (matched.has(entry)) out(` ${entry.relation}: ${entry.why}\n`);
662+
}
663+
}
664+
// An entry matching nothing is the divergence it named being gone: the
665+
// list has to lose it, or it stops saying anything true.
666+
const stale = expected.filter((entry) => !matched.has(entry));
667+
if (stale.length !== 0) {
668+
out(`\nstale — ${stale.length} expectation(s) matched nothing\n`);
669+
for (const entry of stale) {
670+
out(` ${entry.relation}: ${entry.contains}\n`);
671+
}
672+
}
673+
return unexpected.length + stale.length;
622674
}
623675
};
624676
};

0 commit comments

Comments
 (0)