Skip to content

Commit 98ed186

Browse files
authored
fix(gui): inset the Claude account-pool warning and threshold field (#2492)
* fix(gui): inset the Claude account-pool warning and threshold field `.card` carries no padding of its own — `.card-row`, `.card-sub` and `.setting-row` each supply the 16px inset. The experimental warning box and the threshold field are none of those, so in the Anthropic account-pool card they rendered flush against the card border while the title row and the rotation rows sat 16px in. Measured in the dashboard at 814px card width: title 17px from the card edge, warning box and threshold input 1px. The warning takes margin rather than padding: it draws its own border, so padding insets only its text and leaves the border on the card edge. The threshold field takes padding because the `.input` inside is full-width, so the field owns the inset for the label, the control and the help line. This is the same fix `.account-pool-strategy-card` already carries for the Codex pool card, applied to the card that still had the gap. Moving the box styles out of inline `style` is part of it: an inline `padding` outranks any stylesheet rule, so leaving it there would keep the inset unreachable. * fix(gui): keep the inset rationale in one place The stylesheet rule, the test file header, and three per-assertion comments each restated the same two facts — that `.card` has no padding and that the warning box needs margin rather than padding. CodeRabbit's slop detector flagged the repetition, and it was right: the explanation belongs on the CSS rule, where the values it justifies live. The test header now points at that rule and keeps only what is specific to the test — why the assertions read source text rather than measuring, and the browser measurements the contract is derived from. The comments that survive per assertion are the ones the CSS does not carry: why the rule regex is anchored, how a shorthand is read, and why an inline style would silently disable the fix.
1 parent 8c21b69 commit 98ed186

3 files changed

Lines changed: 124 additions & 14 deletions

File tree

‎gui/src/components/provider-workspace/AnthropicAccountPoolSettings.tsx‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default function AnthropicAccountPoolSettings({
145145
const toggleDisabled = loading || saving || loadError || (!enabled && accountCount < 2);
146146

147147
return (
148-
<div className="card" style={{ marginTop: 12 }} aria-busy={loading || saving}>
148+
<div className="card anthropic-pool-card" aria-busy={loading || saving}>
149149
<div className="card-row" style={{ alignItems: "flex-start", gap: 12 }}>
150150
<div style={{ flex: 1 }}>
151151
<strong>{t("anthropicPool.title")}</strong>
@@ -179,17 +179,7 @@ export default function AnthropicAccountPoolSettings({
179179
</button>
180180
</div>
181181

182-
<div
183-
role="alert"
184-
className="card-sub"
185-
style={{
186-
marginTop: 10,
187-
padding: "10px 16px",
188-
border: "1px solid var(--border, #c9a227)",
189-
borderRadius: 6,
190-
background: "color-mix(in srgb, var(--warn, #c9a227) 12%, transparent)",
191-
}}
192-
>
182+
<div role="alert" className="card-sub anthropic-pool-card__notice">
193183
{t("anthropicPool.experimentalWarning")}
194184
</div>
195185

@@ -199,7 +189,7 @@ export default function AnthropicAccountPoolSettings({
199189

200190
{enabled && state && (
201191
<>
202-
<label className="field" style={{ display: "block", marginTop: 12 }}>
192+
<label className="field anthropic-pool-card__field">
203193
<span className="field-label">{t("anthropicPool.threshold")}</span>
204194
<input
205195
className="input mono"

‎gui/src/styles.css‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,8 @@ dialog.modal-overlay::backdrop {
17321732
.account-pool-strategy-card > strong { display: block; margin: 0; }
17331733
.account-pool-strategy-card > .card-sub,
17341734
.account-pool-strategy-controls > .card-sub,
1735-
.account-pool-strategy-controls .field .card-sub {
1735+
.account-pool-strategy-controls .field .card-sub,
1736+
.anthropic-pool-card__field .card-sub {
17361737
/* Already inside the padded card — don't double-indent like account-card subs. */
17371738
margin: 0;
17381739
padding: 0;
@@ -1755,6 +1756,30 @@ dialog.modal-overlay::backdrop {
17551756
white-space: nowrap;
17561757
min-width: 0;
17571758
}
1759+
1760+
/*
1761+
* Claude account-pool card — the same inset `.account-pool-strategy-card` above already
1762+
* fixes, on the card that still had it. `.card` has no padding, so each child brings its
1763+
* own 16px: `.card-row`, `.card-sub` and `.setting-row` do, the warning box and the
1764+
* threshold field do not, so those two rendered flush against the card border.
1765+
*
1766+
* The warning takes margin, not padding: it is a bordered box, so its own padding insets
1767+
* the text and leaves the border itself on the card edge. The field takes padding — the
1768+
* `.input` inside is full-width, so the field owns the inset for the whole group.
1769+
*/
1770+
.anthropic-pool-card { margin-top: 12px; }
1771+
.anthropic-pool-card__notice {
1772+
margin: 10px 16px 0;
1773+
padding: 10px 16px;
1774+
border: 1px solid var(--border, #c9a227);
1775+
border-radius: 6px;
1776+
background: color-mix(in srgb, var(--warn, #c9a227) 12%, transparent);
1777+
}
1778+
.anthropic-pool-card__field {
1779+
display: block;
1780+
margin-top: 12px;
1781+
padding: 0 16px;
1782+
}
17581783
.api-active-keys-skeleton {
17591784
min-height: 96px;
17601785
border: 1px solid var(--border-soft);
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { expect, test } from "bun:test";
2+
3+
/**
4+
* Claude account-pool card inset contract. The rule comment on
5+
* `.anthropic-pool-card__notice` in `src/styles.css` explains why each value is what it is.
6+
*
7+
* Source-text assertions, not rendered measurements: happy-dom performs no layout, so a
8+
* getBoundingClientRect() here returns zeros and would prove nothing. Rendered proof was
9+
* captured in a real browser during the fix — the title sat 17px from the card's left edge
10+
* while the warning box and the threshold input sat at 1px.
11+
*/
12+
13+
const cssUrl = new URL("../src/styles.css", import.meta.url);
14+
const tsxUrl = new URL(
15+
"../src/components/provider-workspace/AnthropicAccountPoolSettings.tsx",
16+
import.meta.url,
17+
);
18+
19+
/** Strip comments so no assertion can pass on prose that quotes a value. */
20+
function withoutComments(css: string): string {
21+
return css.replace(/\/\*[\s\S]*?\*\//g, "");
22+
}
23+
24+
/**
25+
* Body of a top-level rule. Anchored with no leading whitespace on purpose: `.setting-row`
26+
* also appears indented inside an `@media` block that only sets `flex-wrap`, and matching
27+
* that one instead would read the inset off the wrong rule.
28+
*/
29+
function ruleBody(css: string, selector: string): string {
30+
const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
31+
const match = css.match(new RegExp(`(^|\\n)${escaped}\\s*\\{([^}]*)\\}`));
32+
if (!match) throw new Error(`rule not found: ${selector}`);
33+
return match[2];
34+
}
35+
36+
/** Horizontal component of a `margin`/`padding` shorthand, in px. */
37+
function horizontal(body: string, property: "margin" | "padding"): number {
38+
const match = body.match(new RegExp(`(?:^|;)\\s*${property}:\\s*([^;]+)`));
39+
if (!match) throw new Error(`${property} not found in: ${body.trim()}`);
40+
const parts = match[1].trim().split(/\s+/);
41+
// 1 value: all sides. 2-3 values: second is the horizontal one. 4: right, then left.
42+
const side = parts.length === 1 ? parts[0] : parts[1];
43+
const px = side.match(/^([\d.]+)(?:px)?$/);
44+
if (!px) throw new Error(`${property} value is not a px length: ${side}`);
45+
return Number(px[1]);
46+
}
47+
48+
/** The inset every padded row in this card already uses. */
49+
async function rowInset(): Promise<number> {
50+
const css = withoutComments(await Bun.file(cssUrl).text());
51+
const cardRow = horizontal(ruleBody(css, ".card-row"), "padding");
52+
const settingRow = horizontal(ruleBody(css, ".setting-row"), "padding");
53+
const cardSub = horizontal(ruleBody(css, ".card-sub"), "padding");
54+
// The three disagree only if the card's own baseline moved, which this contract cannot
55+
// silently follow — a mismatch means the target inset has to be re-decided, not guessed.
56+
expect(settingRow).toBe(cardRow);
57+
expect(cardSub).toBe(cardRow);
58+
return cardRow;
59+
}
60+
61+
test("the warning box is inset by the same amount as the card's padded rows", async () => {
62+
const css = withoutComments(await Bun.file(cssUrl).text());
63+
const notice = ruleBody(css, ".anthropic-pool-card__notice");
64+
expect(horizontal(notice, "margin")).toBe(await rowInset());
65+
});
66+
67+
test("the threshold field is inset by the same amount as the card's padded rows", async () => {
68+
const css = withoutComments(await Bun.file(cssUrl).text());
69+
const field = ruleBody(css, ".anthropic-pool-card__field");
70+
expect(horizontal(field, "padding")).toBe(await rowInset());
71+
});
72+
73+
test("the help line inside the threshold field is not indented twice", async () => {
74+
const css = withoutComments(await Bun.file(cssUrl).text());
75+
76+
const group = css.match(
77+
/(^|\n)([^{}]*\.anthropic-pool-card__field \.card-sub\s*)\{([^}]*)\}/,
78+
);
79+
expect(group).not.toBeNull();
80+
expect(horizontal(group![3], "padding")).toBe(0);
81+
});
82+
83+
test("the component styles the warning and the field by class, not inline", async () => {
84+
const tsx = await Bun.file(tsxUrl).text();
85+
86+
expect(tsx).toContain('className="card-sub anthropic-pool-card__notice"');
87+
expect(tsx).toContain('className="field anthropic-pool-card__field"');
88+
89+
// The inline box styles are what bypassed the inset: an inline `padding` also outranks
90+
// any stylesheet rule, so reintroducing one silently disables the fix above.
91+
expect(tsx).not.toContain('padding: "10px 16px"');
92+
expect(tsx).not.toContain("borderRadius");
93+
expect(tsx).not.toMatch(/style=\{\{[^}]*marginTop: 10/);
94+
expect(tsx).not.toMatch(/style=\{\{[^}]*display: "block"/);
95+
});

0 commit comments

Comments
 (0)