Skip to content

Commit cfdd4dc

Browse files
committed
test(chat): read the right rule, and assert the invariant instead of a proxy
Review on #85, two distinct points and both correct. THE SELECTOR COULD DRIFT TO THE WRONG RULE. `.lc-ascii-wrap` is declared BEFORE `.lc-ascii` and `.lc-ascii-sub` immediately after it, and the old pattern — `\.lc-ascii[^{]*\{[^}]*font-size:…cqi` — matched the right one only because -wrap happens to declare no font-size. Luck of content, not construction. Demonstrated rather than asserted: giving .lc-ascii-wrap a `clamp(5px, 9.9cqi, 13px)`, the old regex reads 9.9 and the new one still reads 4.6. The rule is now anchored with a negative lookahead so a hyphenated sibling cannot match, and the cqi is read from the captured body rather than from a span that could cross rules. THE FILL PERCENTAGE WAS FAKE PRECISION. It multiplied in a hard-coded 0.6em cell width to report a tidy "88% of its container", but that factor is a property of whatever font the editor resolves — it differs between Monaco and SF Mono — so the number dressed the real invariant in an accuracy it does not have. The contract is `cols x cqi`: the art's width in columns and the font size as a percentage of the container are two halves of one value, and their product is what stays constant. 41x3.6 and 32x4.6 both land on ~147. That is what the test asserts now, and what the failure message reports. Guards, each bypass-verified by reverting the fix: - the decoy cqi on .lc-ascii-wrap, which the old pattern read and this one ignores - the cqi left at the old 41-column value (115.2); raised too far (192.0) - the art widened without the cqi (193.2) - sizing no longer container-relative at all 33 tests in webviewCss, 34 suites green.
1 parent b315f45 commit cfdd4dc

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

extensions/levelcode-ai/test/webviewCss.test.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -602,13 +602,25 @@ test('WORDMARK: the mark and its cqi scale factor stay in agreement', () => {
602602
// without lowering the factor and it overflows; narrow it without raising the factor and it shrinks
603603
// to a stamp floating in white space. The 41-column mark used 3.6cqi; this 32-column one uses 4.6
604604
// precisely to land in the same place.
605-
const cqi = /\.lc-ascii[^{]*\{[^}]*font-size:\s*clamp\(\s*\d+px\s*,\s*([\d.]+)cqi/.exec(css);
605+
// The selector is anchored with a negative lookahead because `.lc-ascii-wrap` is declared BEFORE
606+
// `.lc-ascii` and `.lc-ascii-sub` right after it. A looser `\.lc-ascii[^{]*\{` reads the right rule
607+
// today only because -wrap happens to declare no font-size — luck of content, not construction, and
608+
// it would silently start measuring the wrong rule the day one of them gains a cqi clamp.
609+
const rule = /\.lc-ascii(?![-\w])[^{]*\{([^}]*)\}/.exec(css);
610+
assert.ok(rule, 'the .lc-ascii rule is gone');
611+
const cqi = /font-size:\s*clamp\(\s*\d+px\s*,\s*([\d.]+)cqi/.exec(rule[1]);
606612
assert.ok(cqi, 'the wordmark is no longer sized from its container');
607-
// A monospace cell is ~0.6em wide, so the mark occupies cols * 0.6 * (cqi/100) of the container.
608-
const fill = cols * 0.6 * Number(cqi[1]) / 100;
609-
assert.ok(fill > 0.8 && fill < 0.95,
610-
'the mark would fill ' + Math.round(fill * 100) + '% of its container — ' + cols + ' columns at '
611-
+ cqi[1] + 'cqi. Below ~80% it reads as a stamp; above ~95% it touches the edges and can overflow.');
613+
614+
// Asserted on cols x cqi directly, which IS the contract: the art width in columns and the font
615+
// size as a percentage of the container are two halves of one number, and their product is what
616+
// stays constant. The previous version multiplied in a hard-coded 0.6em cell width to report a
617+
// tidy "fill %", but that factor is a property of whatever font the editor resolves — it differs
618+
// between Monaco and SF Mono — so it dressed the real invariant in a precision it does not have.
619+
const product = cols * Number(cqi[1]);
620+
assert.ok(product > 132 && product < 162,
621+
'cols x cqi is ' + product.toFixed(1) + ' (' + cols + ' columns at ' + cqi[1] + 'cqi). '
622+
+ 'It must stay near 147 — the value both shipped marks share (41x3.6, 32x4.6). Lower and the '
623+
+ 'mark shrinks to a stamp in white space; higher and it touches the edges and can overflow.');
612624

613625
assert.ok(lines.length <= 14,
614626
'the wordmark is ' + lines.length + ' lines; it has to leave room for the prompt and starters beneath it');

0 commit comments

Comments
 (0)