Skip to content

Commit 89d710a

Browse files
committed
test(chat): the margin guard must read every declaration, not the first
Review on #88: the guard used `.exec()` without /g on each rule body, so it inspected only the FIRST `margin:` shorthand and the FIRST direct inline-margin longhand. A body that declares a safe one and then an unsafe one would pass — and CSS applies the LAST declaration, so the bar would sit against the window edge with a green test. Correct, and reproduced before fixing. Injecting exactly the shape the reviewer named: #ctxBar { margin: 6px auto; margin: 0 8px 6px; } the suite passed. That is the bug this test exists to catch, live, undetected. Both scans are now matchAll over the whole body. The shorthand loop keeps the slot parsing ([all] / [block inline] / [top inline bottom] / [top right bottom left]); the longhand loop moved to strictEqual so it reads as "every one of these must be auto" rather than "the first is not non-auto". Same class of mistake as two others this session — an `indexOf` that found the wrong `case 'listSessions'`, and an ordering assertion that passed when its subject was absent. All three are a partial read standing in for a total one. Re-verified, each by reverting the fix: - the review's case: safe shorthand then the bug - safe longhand then a bad longhand; safe shorthand then a bad longhand - the six original bypasses (reported bug, reviewBar, bgTasksBar, 4-slot asymmetric, direct margin-inline, shell column dropping margin-inline) - three controls still pass: `margin: 6px auto`, two auto shorthands in a row, and margin-inline: auto beside margin-block 34 suites green.
1 parent 8a6f1b1 commit 89d710a

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,18 +753,22 @@ test('SHELL COLUMN: no member re-declares an inline margin, which would un-centr
753753
// A shorthand is only a problem when its INLINE slot is not auto. `margin: 8px auto`
754754
// re-states the centring and is fine; `margin: 0 8px 6px` destroys it. Slots are
755755
// [all] / [block inline] / [top inline bottom] / [top right bottom left].
756-
const sh = /(?:^|;)\s*margin\s*:\s*([^;}]+)/.exec(body);
757-
if (sh) {
756+
//
757+
// EVERY declaration, not the first: a single .exec() would read `margin: 6px auto`
758+
// and stop, never reaching a `margin: 0 8px 6px` later in the same body — and CSS
759+
// applies the LAST one, so the guard would pass while the bar sat against the edge.
760+
for (const sh of body.matchAll(/(?:^|;)\s*margin\s*:\s*([^;}]+)/g)) {
758761
const p = sh[1].trim().split(/\s+/);
759762
const inline = p.length === 1 ? [p[0]] : p.length === 4 ? [p[1], p[3]] : [p[1]];
760763
assert.ok(inline.every((v) => v === 'auto'),
761764
id + ' has `margin: ' + sh[1].trim() + '` — its inline slot is not auto, so it '
762765
+ 'resets margin-inline and pins the bar to one edge. Use margin-block; the width '
763766
+ 'calc already insets by --shell-x.');
764767
}
765-
const direct = /margin-(?:left|right|inline(?:-start|-end)?)\s*:\s*([^;}]+)/.exec(body);
766-
assert.ok(!direct || direct[1].trim() === 'auto',
767-
id + ' sets an inline margin directly, which beats the shell column\'s auto');
768+
for (const d of body.matchAll(/margin-(?:left|right|inline(?:-start|-end)?)\s*:\s*([^;}]+)/g)) {
769+
assert.strictEqual(d[1].trim(), 'auto',
770+
id + ' sets an inline margin directly, which beats the shell column\'s auto');
771+
}
768772
}
769773
}
770774
});

0 commit comments

Comments
 (0)