Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,8 @@ jobs:
# success. The filter holds the inputs of the build, its outputs, and the files whose colors the
# design tests check. npm installs the lock outside the checkout, so no node_modules shows in
# the diff. The design tests run in one process: they take seconds, and pytest workers take
# longer to start. Each step limit is shorter than the job limit.
# longer to start. Each step limit is shorter than the job limit, and the bound of one design
# test is shorter than its step, so pytest-timeout names a test that hangs.
design-tokens:
name: Design Tokens
if: github.event_name == 'pull_request'
Expand Down Expand Up @@ -1013,7 +1014,7 @@ jobs:
- name: Run the Design Tests
if: steps.changes.outputs.design == 'true'
timeout-minutes: 2
run: uv run pytest tests/design -n 0
run: uv run pytest tests/design -n 0 --timeout 60

# Resolves each image that an Argo CD Application pins when a pull request changes the
# manifests, the command or this workflow, so a wrong tag fails the pull request and not the
Expand Down
13 changes: 7 additions & 6 deletions docs/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Renovate opens a pull request for each new release of Style Dictionary, and the

### Change a token

1. Edit the token in `design/tokens/`. A color token in a theme file needs the same name in the other theme file.
1. Edit the token in `design/tokens/`. A color token in a theme file needs the same name in the other theme file. Give a color the same value in `components` and in `hex`: the build reads only `components`.
2. Run `make design-tokens`.
3. Run `uv run pytest tests/design`.
4. Commit the source and the outputs together.
Expand All @@ -69,11 +69,12 @@ Renovate opens a pull request for each new release of Style Dictionary, and the
- **The CI job "Design Tokens"** runs on a pull request that changes a file of its path filter: `design/`, the lock, `src/devops_cli/design/`, `docs/assets/css/`, `k8s/startpage/`, `k8s/monitoring/dashboards/`, `.github/labels.yml`, the `Makefile` or `ci.yml`. It installs the lock, runs `make design-tokens`, fails when an output is not the build, and runs `tests/design`. It takes less than 1 minute.
- **`tests/design`** checks with coloraide:
1. The light and the dark theme hold the same names in the sources, in the flat JSON and in each CSS file.
2. Each contrast rule holds in both themes: 37 rules for each theme, 74 in total.
3. The categorical colors pass the gates of [Categorical colors](#categorical-colors).
4. The sequential ramp has a monotonic lightness (`L*`), and the diverging ramp is red at step 1 and blue at step 9 in both themes.
5. Each width in an `@media` rule of this spec and of the CSS of the package is `breakpoint.md` or `breakpoint.lg`.
6. The dash patterns of the package are the patterns of [Line patterns](#line-patterns).
2. The `hex` of each source color is the color of its `components`.
3. Each contrast rule holds in both themes: 37 rules for each theme, 74 in total.
4. The categorical colors pass the gates of [Categorical colors](#categorical-colors).
5. The sequential ramp has a monotonic lightness (`L*`), and the diverging ramp is red at step 1 and blue at step 9 in both themes.
6. Each width in an `@media` rule of this spec and of the CSS of the package is `breakpoint.md` or `breakpoint.lg`.
7. The dash patterns of the package are the patterns of [Line patterns](#line-patterns).
- **The ast-grep rule `css-color-literal`** rejects a hex color, a call of a CSS color function and a CSS named color in the hand-written CSS of `src/devops_cli/design/css/`. The docs site item (#4745) and the start page item (#4598) extend the rule to their CSS when they remove its color literals.

## Palette
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-11-12
skip_specs: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Design

## Decisions

- **The test bound is an option of the step.** The step gives `--timeout 60` to pytest. The global bound of `pyproject.toml` (600 s) stays for the other test runs. The contract test asserts the exact command and that the bound is more than 0 and shorter than the step limit in seconds.
- **The source keeps `hex`, and a test compares it with `components`.** The `hex` value lets a person read a color in the source and in a diff, and the Palette table of `docs/DESIGN.md` gives the same hex values. The test converts the `components` with coloraide and compares the result with `hex` in lowercase, so a check of a valid uppercase hex does not fail.

## Rejected alternatives

- **Remove `hex` from the sources.** DTCG 2025.10 makes `hex` optional, so this removes the duplicate. It was rejected because a person then reads and edits only floats such as `0.9647`, and the change rewrites 66 tokens in the three source files that other open items also change.
- **Set a lower global bound in `pyproject.toml`.** This changes the bound of every test run, which is not the problem of this item.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Proposal: #4906

## Why

The review of the design token build found two gaps in its checks. Closes #4906.

1. The CI step "Run the Design Tests" has a limit of 2 minutes, but the bound of one test is 600 s (`timeout = 600` in `pyproject.toml`). ARCHITECTURE.md, "Nested Time Limits", says: "Set the bound of one test shorter than its step." When a design test hangs, the runner stops the step at 120 s, and pytest-timeout gives no diagnostic.
2. Each DTCG source color holds its value two times, in `components` and in `hex`. Style Dictionary reads only `components`, and no check compares the two. When a person edits only `hex`, the outputs do not change, the CI diff step passes, and the source shows a color that no output has.

## What Changes

- The step "Run the Design Tests" of the job `design-tokens` runs `uv run pytest tests/design -n 0 --timeout 60`. The bound of one test (60 s) is shorter than the step (120 s).
- The contract test of the job asserts that the bound of one design test is more than 0 and shorter than its step.
- A new test in `tests/design/test_tokens.py` asserts that the `hex` of each of the 66 source colors is the color of its `components`.
- `docs/DESIGN.md` tells a person to give a color the same value in `components` and in `hex`, and lists the new check.

The change alters no behavior that a consumer observes: it changes tests, a CI workflow and a document. It has no spec delta and sets `skip_specs: true`.

## Capabilities

None. The change adds checks to the existing `design-tokens` build and changes no requirement.

## Impact

- `.github/workflows/ci.yml`: the job `design-tokens`.
- `tests/invariants/test_workflow_contracts.py`, `tests/design/test_tokens.py`.
- `docs/DESIGN.md`: "Change a token" and "Checks".

The change fits one pull request.

## Feasibility

- `grep -n -A3 "Run the Design Tests" .github/workflows/ci.yml` on `main` shows `timeout-minutes: 2` and no `--timeout`. `pyproject.toml` sets `timeout = 600`. The pytest-timeout option `--timeout` overrides the ini value for one run.
- `uv run pytest tests/design -n 0 --durations=3` takes 10.7 s for the 16 tests, and 0.8 s at most for one test. A bound of 60 s leaves a large margin and is half of the step limit.
- With the locked Style Dictionary 5.8.0, a change of `"hex": "#ffffff"` of `color.bg` in `design/tokens/light.tokens.json` to `#fffffe`, then `make design-tokens`, changes only the source file. The build reads `components`.
- All 66 source colors are `srgb` with 3 components and a 7-character `hex`. coloraide 8.14.1 gives the same hex from the components of each of them, so the new test passes on `main` and fails on the changed `hex`.

## Existing Tool Considered

- pytest-timeout, already a test dependency, sets the bound of one test with `--timeout`. The change adds no tool.
- coloraide, already a test dependency, converts the `components` of a DTCG color to hex. The test uses it and adds no color math of its own.
- The change deletes no internal code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Tasks

## 1. Workflow: the bound of one design test

- [x] 1.1 Make the contract test of the job `design-tokens` assert the command `uv run pytest tests/design -n 0 --timeout 60` and a test bound that is more than 0 and shorter than the step limit.
- Verification: `$ uv run devops ci test tests/invariants/test_workflow_contracts.py`
- [x] 1.2 Give the step "Run the Design Tests" the option `--timeout 60`, and say in the comment of the job that the test bound is shorter than the step.
- Verification: `$ uv run devops ci test tests/invariants/test_workflow_contracts.py`

## 2. Tests: the hex of each source color

- [x] 2.1 Add a test to `tests/design/test_tokens.py` that compares the `hex` of each of the 66 source colors with the hex of its `components`.
- Verification: `$ uv run devops ci test tests/design/test_tokens.py`

## 3. Documents

- [x] 3.1 In `docs/DESIGN.md`, tell a person in "Change a token" to give a color the same value in `components` and in `hex`, and list the new check in "Checks".
- Verification: `$ uv run devops ci docs`
25 changes: 25 additions & 0 deletions tests/design/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

from __future__ import annotations

from coloraide import Color

from devops_cli.design import THEME_MODES, tokens
from devops_cli.roadmap.workflow_labels import LabelColor
from tests.support.design_tokens import (
CSS_FILES,
DOCS_TOKEN_CSS_DIR,
PACKAGE_DESIGN_DIR,
SOURCE_FILES,
css_variables,
source_tokens,
)
Expand Down Expand Up @@ -55,6 +58,28 @@ def test_the_light_and_dark_themes_hold_the_same_token_names() -> None:
) == (True, True, {}, 38)


def test_the_hex_of_each_source_color_is_the_color_of_its_components() -> None:
"""A DTCG source color holds its value in `components` and again in `hex`. The build reads
only `components`, so a `hex` that differs shows a color that no output has (docs/DESIGN.md,
"Change a token")."""
colors = [
(f"{file}:{dotted}", node["$value"])
for file in SOURCE_FILES
for dotted, node in source_tokens(file).items()
if isinstance(node["$value"], dict) and "components" in node["$value"]
]

assert (
len(colors),
{
name: value["hex"]
for name, value in colors
if Color(value["colorSpace"], value["components"]).to_string(hex=True)
!= value["hex"].lower()
},
) == (66, {})


def test_the_docs_site_and_the_package_hold_the_same_token_css() -> None:
"""Jekyll cannot run the build, so the build writes each CSS file twice: one copy for the
docs site and one as package data."""
Expand Down
11 changes: 9 additions & 2 deletions tests/invariants/test_workflow_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,12 +1500,17 @@ def test_the_design_tokens_job_builds_the_tokens_only_when_a_path_of_its_filter_
"""docs/DESIGN.md, "Token pipeline": the job builds the tokens with the pinned Style Dictionary
and fails when a committed output is not the build. It runs for every pull request and does
its steps only when a path of its filter changed. Each step limit is shorter than the job
limit, so the step that hangs stops first and shows its name. The diff step names a directory
limit, so the step that hangs stops first and shows its name, and the bound of one design test
is shorter than its step, so pytest-timeout names the test that hangs (ARCHITECTURE.md,
"Nested Time Limits"). The diff step names a directory
that holds each output of each Style Dictionary config, so an output that the diff does not
see cannot be added."""
job = _load_workflow(WORKFLOWS_DIR / "ci.yml")["jobs"]["design-tokens"]
detect, *steps = job["steps"]
runs = {step["name"]: step.get("run", "") for step in steps}
design_tests = next(step for step in steps if step["name"] == "Run the Design Tests")
words = shlex.split(design_tests["run"])
test_bound = int(words[words.index("--timeout") + 1]) if "--timeout" in words else 0
diff = next(text for text in runs.values() if "git diff --exit-code" in text)
checked = [PurePosixPath(path) for path in shlex.split(diff.splitlines()[-1].split(" -- ")[1])]
outputs = [
Expand All @@ -1528,6 +1533,7 @@ def test_the_design_tokens_job_builds_the_tokens_only_when_a_path_of_its_filter_
if step.get("timeout-minutes", 0) >= job["timeout-minutes"]
],
[runs[name] for name in ("Build the Design Tokens", "Run the Design Tests")],
0 < test_bound < design_tests["timeout-minutes"] * 60,
len(outputs),
[str(path) for path in outputs if not any(path.is_relative_to(root) for root in checked)],
) == (
Expand All @@ -1538,7 +1544,8 @@ def test_the_design_tokens_job_builds_the_tokens_only_when_a_path_of_its_filter_
{"design": DESIGN_FILTER},
{"steps.changes.outputs.design == 'true'"},
[],
["make design-tokens", "uv run pytest tests/design -n 0"],
["make design-tokens", "uv run pytest tests/design -n 0 --timeout 60"],
True,
11,
[],
)
Expand Down