Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): reject unknown palette neutral profiles up front (#6534)

Joey9c17243f736d
diff --git a/.changeset/cli-spec-palette-neutral-profile.md b/.changeset/cli-spec-palette-neutral-profile.md
new file mode 100644
index 0000000000..9602ece46c
--- /dev/null
+++ b/.changeset/cli-spec-palette-neutral-profile.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `astryx theme palette generate` and `generateTonalPalette()` now reject a `neutralProfile` the recipe does not define, even when the request has no neutral family. Before, such a request produced a candidate whose receipt recorded the unknown profile as part of the normalized request.
+
+@josephfarina
diff --git a/packages/cli/api/theme/palette/generate/generator.mjs b/packages/cli/api/theme/palette/generate/generator.mjs
index 44c3ef624d..9ad1752e5b 100644
--- a/packages/cli/api/theme/palette/generate/generator.mjs
+++ b/packages/cli/api/theme/palette/generate/generator.mjs
@@ -37,6 +37,7 @@ export const COMPACT_11_STOPS = Object.freeze([
const DARK_CHROMA_FACTOR = 0.85;
const RESERVED_FAMILY_IDS = new Set(['black', 'white']);
+const NEUTRAL_PROFILES = ['neutral-v1', 'warm-v1', 'cool-v1', 'custom'];
/** @param {number} value @param {number} minimum @param {number} maximum */
function clamp(value, minimum, maximum) {
@@ -665,11 +666,17 @@ export function normalizeGenerationRequest(input) {
anchors,
};
});
+ const neutralProfile = input.neutralProfile ?? 'neutral-v1';
+ // The receipt records this request, so an unknown profile fails even when no
+ // neutral family reads it.
+ if (!NEUTRAL_PROFILES.includes(neutralProfile)) {
+ throw new Error(`Unknown neutral profile: ${String(neutralProfile)}`);
+ }
/** @type {NormalizedRequest} */
const request = {
recipe: PALETTE_RECIPE,
vibrancy: input.vibrancy ?? 50,
- neutralProfile: input.neutralProfile ?? 'neutral-v1',
+ neutralProfile,
modeStrategy,
stops,
families: normalizedFamilies,
diff --git a/packages/cli/api/theme/palette/generate/generator.test.mjs b/packages/cli/api/theme/palette/generate/generator.test.mjs
index 102cc4b232..a331385594 100644
--- a/packages/cli/api/theme/palette/generate/generator.test.mjs
+++ b/packages/cli/api/theme/palette/generate/generator.test.mjs
@@ -293,6 +293,16 @@ describe('astryx-oklch-v1 palette generator', () => {
).toThrow('Anchor mode dark is not generated by mode strategy light-only');
});
+ it('rejects an unknown neutral profile even without a neutral family', () => {
+ expect(() =>
+ generatePaletteSet({neutralProfile: 'warm-v2', families: [families[1]]}),
+ ).toThrow('Unknown neutral profile: warm-v2');
+ expect(
+ generatePaletteSet({neutralProfile: 'warm-v1', families: [families[1]]})
+ .request.neutralProfile,
+ ).toBe('warm-v1');
+ });
+
it('normalizes anchor colors in the generation receipt', () => {
const result = generatePaletteSet({
modeStrategy: 'light-only',