Skip to content

fix(diff): include motion tokens in the token diff - #197

Draft
dajiaohuang wants to merge 1 commit into
google-labs-code:mainfrom
dajiaohuang:fix/diff-motion-tokens
Draft

dajiaohuang wants to merge 1 commit into
google-labs-code:mainfrom
dajiaohuang:fix/diff-motion-tokens

Conversation

@dajiaohuang

Copy link
Copy Markdown

What was wrong

design.md diff reports tokens.colors, tokens.typography, tokens.rounded, tokens.spacing, and tokens.components. It never reported motion. The motion token category was added to the spec, the parser, and the model in #182, and the linter resolves it (state.motion is a Map<string, ResolvedMotion>), but the diff command was not updated with it. A motion token that changed, was added, or was removed between two files produced no output at all, and regression could not react to a motion-only change.

This is the same shape as #50 / #51, where components was missing from the same object.

Evidence

Two files that differ only under motion (state-change goes from 100ms/ease-out to 400ms/linear, and surface-exit is added):

bun run src/index.ts diff before.md after.md

Before the change, tokens had no motion key at all and exit code was 0:

{
  "tokens": {
    "colors": { "added": [], "removed": [], "modified": [] },
    "typography": { "added": [], "removed": [], "modified": [] },
    "rounded": { "added": [], "removed": [], "modified": [] },
    "spacing": { "added": [], "removed": [], "modified": [] },
    "components": { "added": [], "removed": [], "modified": [] }
  },
  "regression": false
}

After the change:

"motion": {
  "added": [
    "surface-exit"
  ],
  "removed": [],
  "modified": [
    "state-change"
  ]
}

Contract violated

docs/spec.md lists motion as a top-level token category of the document schema, alongside colors, typography, rounded, spacing and components. The diff command's job is to report token-level changes between two DESIGN.md files; leaving a schema category out of that report means a real change to a project's tokens is invisible to the tool and to any CI gate built on it.

Fix

packages/cli/src/commands/diff.ts now passes both motion maps through the same diffMaps helper as the other primitive categories. motion is optional on DesignSystemState, so an absent map is compared as an empty one rather than being skipped. No new helper and no new branch in the linter or model.

Tests

Added three cases to the existing packages/cli/src/commands/diff.test.ts, driving the real command entry point (diffCommand.run), which is the pattern already used in commands/spec.test.ts:

  • a modified motion token is reported under modified
  • an added and a removed motion token are reported under added and removed
  • two files with identical motion tokens report three empty lists

All three fail against the previous diff.ts (output.tokens.motion is undefined) and pass with the change.

Checks run

  • bun run lint (tsc --noEmit): exit 0
  • bun test src/commands/diff.test.ts: 7 pass, 0 fail
  • bun test (packages/cli): 403 pass, 1 skip, 5 fail. The same 5 tests fail on the untouched base commit with the change stashed, so they are pre-existing on this machine and unrelated to this diff. Details:
    • 4 tests in cli-errors.test.ts / export-exit-code.test.ts spawn the CLI via Bun.spawnSync(['bun', ...]), and the child process reports 'bun' is not recognized as an internal or external command on this Windows host. Running the same CLI commands directly in a shell gives the expected exit codes (2 for a missing file, 1 with the INVALID_FORMAT envelope for a bad --format).
    • 1 test in linter/tailwind/handler.test.ts fails with Cannot find package 'postcss' from ... tailwindcss/lib/index.js.

Docs

The diff output example in README.md gains the motion key so the documented shape matches what the command emits.

Related: #50, #51 (the same omission for components), #182 (which added the motion category).

`diff` builds `tokens` from colors, typography, rounded, spacing, and
components. The `motion` category added in google-labs-code#182 was never wired in, so a
motion token that changed, was added, or was removed between two files
produced no output at all.

The fix passes both motion maps through the existing `diffMaps` helper,
next to the other primitive categories. `motion` is optional on
`DesignSystemState`, so an absent map is compared as empty.

Tests cover a modified token, added and removed tokens, and the identical
case through `diffCommand.run`; all three fail on the previous
`diff.ts`. The README `diff` output example gains the `motion` key so the
documented shape matches the emitted one.
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.

1 participant