Skip to content

Mechanize UI color token enforcement - #614

Open
ArthurArthurArthur0817 wants to merge 1 commit into
sysprog21:mainfrom
ArthurArthurArthur0817:check-css-tokens
Open

ArthurArthurArthur0817 wants to merge 1 commit into
sysprog21:mainfrom
ArthurArthurArthur0817:check-css-tokens

Conversation

@ArthurArthurArthur0817

@ArthurArthurArthur0817 ArthurArthurArthur0817 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem and behavior

UI colors must be defined as design tokens to ensure consistency across light and dark themes. To prevent hardcoded color literals from slipping into the codebase, this PR mechanizes the enforcement.

Per the maintainer's review, rather than introducing a standalone Python checker, this PR drops the Python script and strictly extends the existing tests/browser/theme.test.js to enforce CSS token usage across the repository.

Notes

The extended test suite now enforces the following strict zero-tolerance rules:

  • No Stacked Declarations: Prevents stacked var() declarations within the same component rule (i.e., a declaration must not shadow a token read in the same rule) to avoid cascade overrides.
  • Strict recording.css Scoping: Confines color literals in web/recording/recording.css strictly to its own :root block. Existing out-of-scope literals have been converted into semantic variables.
  • No Orphaned Tokens: Scans web/theme.css to ensure every declared token is read by at least one component or derived token, preventing unused tokens from accumulating.

Testing

Coverage is now integrated directly into tests/browser/theme.test.js. The tests will fail if a component sheet shadows a token read, if recording.css leaks literals outside its :root, or if theme.css leaves tokens unused.

Close #578

cubic-dev-ai[bot]

This comment was marked as resolved.

@ArthurArthurArthur0817
ArthurArthurArthur0817 force-pushed the check-css-tokens branch 2 times, most recently from 5b0898d to 64cdc76 Compare November 7, 2026 11:00
jserv

This comment was marked as outdated.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

cubic-dev-ai[bot]

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

jserv

This comment was marked as resolved.

Comment thread web/recording/recording.css Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved

@Shih-Hsuan Shih-Hsuan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff removes token-reference validation and leaves peer-interview timers stopped when a back/forward restore encounters a transient refresh failure.

Comment thread tests/browser/theme.test.js Resolved
Comment thread web/peer-interview.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread src/accounts/peer/rounds.rs Resolved
Comment thread src/web/peer/observer.rs Resolved
@jserv

jserv commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

This commit is built on an older tree and, merged as it is, would revert work already on main that has nothing to do with #578: the named replay flow, the strict check on the peer ready value, the observer that keeps running when the audio writer cannot open, and their docs and tests. The detail is on src/accounts/peer/rounds.rs. Rebuild the branch on current main so it carries only the theme test and recording.css changes.

Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread web/recording/recording.css Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
Comment thread tests/browser/theme.test.js Resolved
@jserv

jserv commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Some review comments on this pull request are not settled yet. Please refine the change per the review comments listed below, reply on each thread with what you changed or why you did not, and mark each thread resolved yourself once it is settled (Resolve conversation, at the bottom of the thread). The pull request stays blocked while review threads are open.

Not addressed at the current head:

Checked at ec13877.

@jserv

jserv commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

@ArthurArthurArthur0817 Three replies on this pull request say a change was made, and none of them is in the head, which is still 22f40054: the restored a component sheet neither redeclares a theme role nor reads an undeclared one test, the border-color and border-top/border-right/border-bottom/border-left entries in SHORTHAND_RESETS with the border-top case, and the box-shadow case. The replies came after the last commit, so they may be in a local commit that was not pushed. Please push it, or say here that it is not done. Then reply on each thread with what changed.

Comment on lines +261 to +265
assert.deepEqual(
unusedThemeTokens(`${theme}\n:root { --obsolete: #fff; }`, allCss),
["--obsolete"],
"orphan token in theme.css must be caught",
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing here reaches the fallback form that the var\(\s*(--[\w-]+)\s*(?=[,)]) pattern in unusedThemeTokens was widened for. No component sheet reads a theme token with a fallback today, so putting back var\((--[\w-]+)\) there still passes every test in this file. A case beside the orphan one keeps it covered. It passes at this head and fails with the old pattern:

Suggested change
assert.deepEqual(
unusedThemeTokens(`${theme}\n:root { --obsolete: #fff; }`, allCss),
["--obsolete"],
"orphan token in theme.css must be caught",
);
assert.deepEqual(
unusedThemeTokens(`${theme}\n:root { --obsolete: #fff; }`, allCss),
["--obsolete"],
"orphan token in theme.css must be caught",
);
assert.deepEqual(
unusedThemeTokens(
`${theme}\n:root { --fallback-read: #fff; }`,
`${allCss}\n.card { color: var(--fallback-read, currentColor); }`,
),
[],
"a token read with a fallback must count as read",
);

Per review, extend theme.test.js to enforce CSS token usage. Prevent
stacked var() declarations and strictly scope recording.css color
literals to its own :root.

Change-Id: I3e851d6f126e9ecb26499b8578373191d479e2d1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mechanize UI color token enforcement check

5 participants