An open source design system that's fully customizable and agent ready
TypeScript
fix(cli): write canonical palette candidate JSON (#6531)
Joey55bbaaff9924
diff --git a/.changeset/cli-spec-palette-canonical-json.md b/.changeset/cli-spec-palette-canonical-json.mdnew file mode 100644index 0000000000..bf1d7f6a0f--- /dev/null+++ b/.changeset/cli-spec-palette-canonical-json.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] `astryx theme palette generate` now writes candidate JSON in the canonical form the `astryx-oklch-v1` recipe pins, so a JSON candidate and the `candidateSha256` in its receipt match the recipe's reference fixtures byte for byte. Before, the `stops` array was printed on one line, which changed the bytes and the digest of every JSON candidate.++@josephfarinadiff --git a/packages/cli/api/theme/palette/generate/generate.mjs b/packages/cli/api/theme/palette/generate/generate.mjsindex 381685fe99..d2cd98a035 100644--- a/packages/cli/api/theme/palette/generate/generate.mjs+++ b/packages/cli/api/theme/palette/generate/generate.mjs@@ -86,7 +86,8 @@ function serializePalette(palette, indentation = 0) {/** @param {TonalPaletteCandidate} candidate */export function serializePaletteCandidate(candidate) {- return `{\n "schemaVersion": 1,\n "status": "candidate",\n "recipe": ${JSON.stringify(candidate.recipe)},\n "black": ${JSON.stringify(candidate.black)},\n "white": ${JSON.stringify(candidate.white)},\n "stops": ${JSON.stringify(candidate.stops)},\n "palette": ${serializePalette(candidate.palette, 2)}\n}\n`;+ const stops = candidate.stops.map(stop => ` ${JSON.stringify(stop)}`);+ return `{\n "schemaVersion": 1,\n "status": "candidate",\n "recipe": ${JSON.stringify(candidate.recipe)},\n "black": ${JSON.stringify(candidate.black)},\n "white": ${JSON.stringify(candidate.white)},\n "stops": [\n${stops.join(',\n')}\n ],\n "palette": ${serializePalette(candidate.palette, 2)}\n}\n`;}/** @param {TonalPaletteCandidate} candidate @param {string} outputPath */diff --git a/packages/cli/api/theme/palette/generate/generate.test.mjs b/packages/cli/api/theme/palette/generate/generate.test.mjsindex 06191b2b87..c426a67303 100644--- a/packages/cli/api/theme/palette/generate/generate.test.mjs+++ b/packages/cli/api/theme/palette/generate/generate.test.mjs@@ -1,5 +1,6 @@// Copyright (c) Meta Platforms, Inc. and affiliates.+import {createHash} from 'node:crypto';import * as fs from 'node:fs';import * as os from 'node:os';import * as path from 'node:path';@@ -102,6 +103,81 @@ describe('themePaletteGenerate', () => {expect(result.data.receipt).toBe('ocean.palette.receipt.json');});+ it('writes candidate JSON byte-identical to the recipe fixtures', () => {+ const families = [+ {id: 'neutral', name: 'Neutral', seed: '#777777', kind: 'neutral'},+ {id: 'blue', name: 'Blue', seed: '#0074e2'},+ {id: 'orange', name: 'Orange', seed: '#d57113'},+ ];+ const fixtures = [+ [+ {families},+ 3755,+ '11c40191d508274d89d631bb4e1cb662f70ff0dce6c0dec101c317f9f69d3e25',+ ],+ [+ {+ modeStrategy: 'light-only',+ stops: [20, 50, 80],+ families: [+ {+ id: 'blue',+ name: 'Blue',+ seed: '#0074e2',+ anchors: [+ {mode: 'light', stop: 50, color: '#1682d5', policy: 'exact'},+ ],+ },+ ],+ },+ 327,+ 'c42929be3c4b5cb857cada078f62bb5a2242c1a22cfa4ae7546a18592540f7f3',+ ],+ [+ {+ modeStrategy: 'dark-only',+ stops: [40],+ families: [{id: 'red', name: 'Red', seed: '#d62830'}],+ },+ 258,+ '88d3d69865c74c7fb14347b9967575285a7d44ab893087a08bc842bb66b29bbb',+ ],+ [+ {+ stops: [60, 80, 95],+ families: [+ {id: 'green', name: 'Green', seed: '#358a3a'},+ {id: 'teal', name: 'Teal', seed: '#0c7365'},+ {id: 'cyan', name: 'Cyan', seed: '#0c6f82'},+ ],+ },+ 910,+ '873821574fdbe3357304dbc06986bd2e5ec88af80d0f36305626fd826c3cf07b',+ ],+ ];++ for (const [request, bytes, sha256] of fixtures) {+ const cwd = fixture();+ fs.writeFileSync(+ path.join(cwd, 'palette.config.json'),+ JSON.stringify(request),+ );++ const printed = themePaletteGenerate('palette.config.json', {}, {cwd});+ expect(printed.data.generationReceipt.candidateSha256).toBe(sha256);++ const result = themePaletteGenerate(+ 'palette.config.json',+ {out: 'candidate.json'},+ {cwd},+ );+ const written = fs.readFileSync(path.join(cwd, 'candidate.json'));+ expect(written.length).toBe(bytes);+ expect(createHash('sha256').update(written).digest('hex')).toBe(sha256);+ expect(result.data.generationReceipt.candidateSha256).toBe(sha256);+ }+ });+it('preserves mixed decimal and integer stop order in every artifact', () => {const cwd = fixture();fs.writeFileSync(