@astryxdesign/cli 0.7.5-canary.04434e7 → 0.7.5-canary.07030cb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +1 -1
  2. package/api/template/tokenizer-showcase.test.mjs +47 -0
  3. package/api/theme/build/build.adaptation-enrollment.test.mjs +4 -0
  4. package/api/theme/build/build.icon-variants.test.mjs +105 -0
  5. package/api/theme/build/build.mjs +36 -7
  6. package/api/theme/build/build.test.mjs +27 -0
  7. package/api/upgrade/_adapter.d.mts +47 -2
  8. package/api/upgrade/_adapter.mjs +58 -2
  9. package/api/upgrade/run/failure-receipt.test.mjs +57 -0
  10. package/api/upgrade/run/outcomes.test.mjs +646 -0
  11. package/api/upgrade/run/run.d.mts +36 -0
  12. package/api/upgrade/run/run.mjs +509 -45
  13. package/api/upgrade/upgrade.doc.mjs +2 -2
  14. package/api/upgrade/upgrade.type.d.mts +24 -0
  15. package/api/upgrade/upgrade.type.mjs +15 -3
  16. package/assets/codemods/__tests__/runner.unparseable.test.mjs +457 -0
  17. package/assets/codemods/integration-runner.mjs +7 -1
  18. package/assets/codemods/integration-runner.protection.test.mjs +53 -0
  19. package/assets/codemods/outcome.mjs +79 -0
  20. package/assets/codemods/outcome.test.mjs +40 -0
  21. package/assets/codemods/parse.mjs +94 -0
  22. package/assets/codemods/run-codemod.mjs +92 -2
  23. package/assets/codemods/runner.mjs +38 -5
  24. package/assets/codemods/transforms/next/__tests__/migrate-codeblock-tokenizer-to-language.test.mjs +130 -0
  25. package/assets/codemods/transforms/next/index.mjs +11 -1
  26. package/assets/codemods/transforms/next/migrate-codeblock-tokenizer-to-language.mjs +315 -0
  27. package/assets/codemods/transforms/v0.1.3/__tests__/migrate-layout-components-to-experimental.test.mjs +216 -2
  28. package/assets/codemods/transforms/v0.1.3/migrate-layout-components-to-experimental.mjs +88 -6
  29. package/assets/codemods/transforms/v0.6.0/migrate-astryx-theme-selectors-to-data-attrs.mjs +4 -3
  30. package/assets/codemods/transforms/v0.7.0/__tests__/validate-data-token-ownership.test.mjs +24 -4
  31. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +44 -10
  32. package/assets/codemods/transforms/v0.7.0/validate-data-token-ownership.mjs +6 -3
  33. package/assets/docs/author-a-theme.doc.mjs +3 -1
  34. package/assets/docs/icons.doc.mjs +71 -1
  35. package/assets/docs/theme.doc.dense.mjs +8 -0
  36. package/assets/docs/theme.doc.mjs +16 -0
  37. package/assets/docs/theme.doc.zh.mjs +11 -0
  38. package/assets/docs/tree/template-styles.doc.mjs +1 -1
  39. package/assets/docs/tree/tokens-color.doc.mjs +145 -1
  40. package/assets/docs/tree/tokens.doc.mjs +1 -1
  41. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.doc.mjs +6 -4
  42. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherReviewFlow.tsx +61 -55
  43. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.doc.mjs +6 -4
  44. package/assets/templates/blocks/components/BottomSheet/BottomSheetSwitcherShowcase.tsx +68 -37
  45. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.doc.mjs +1 -1
  46. package/assets/templates/blocks/components/CodeBlock/CodeBlockBashCommand.tsx +10 -2
  47. package/assets/templates/blocks/components/Thumbnail/ThumbnailDisabled.doc.mjs +1 -1
  48. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +13 -6
  49. package/assets/templates/pages/dashboard-alert-rail/page.tsx +3 -3
  50. package/assets/templates/pages/library/page.tsx +1 -2
  51. package/assets/templates/pages/table-comparison/page.tsx +12 -3
  52. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +3 -2
  53. package/assets/templates/themes/butter/butterTheme.ts +47 -44
  54. package/assets/templates/themes/chocolate/chocolateTheme.ts +15 -2
  55. package/assets/templates/themes/gothic/gothicTheme.ts +21 -16
  56. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +1 -1
  57. package/assets/templates/themes/matcha/matchaTheme.ts +15 -2
  58. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +4 -4
  59. package/assets/templates/themes/neutral/neutralTheme.ts +24 -119
  60. package/assets/templates/themes/stone/stoneTheme.ts +46 -21
  61. package/assets/templates/themes/y2k/y2kTheme.ts +20 -16
  62. package/assets/theme.template.ts +18 -5
  63. package/authoring/codemod/type.ts +10 -0
  64. package/clients/cli/commands/build-theme.adaptations.test.mjs +110 -0
  65. package/clients/cli/commands/upgrade.doc.mjs +30 -2
  66. package/clients/cli/commands/upgrade.file-protection.test.mjs +146 -0
  67. package/clients/cli/commands/upgrade.outcomes.test.mjs +350 -0
  68. package/foundation/agent-docs/agent-docs.mjs +1 -0
  69. package/foundation/agent-docs/agent-docs.test.mjs +5 -0
  70. package/foundation/response/response-types.doc.mjs +1 -1
  71. package/package.json +10 -9
@@ -192,6 +192,18 @@ export const y2kTheme = defineTheme({
192
192
  '--color-on-error': [red.light[30], red.dark[20]],
193
193
  '--color-on-warning': [yellow.light[30], yellow.dark[20]],
194
194
 
195
+ '--color-info': [blue.light[40], blue.dark[75]],
196
+ '--color-info-muted': 'var(--color-background-blue)',
197
+
198
+ '--color-text-info': [blue.light[20], blue.dark[75]],
199
+ '--color-text-success': [green.light[30], green.dark[75]],
200
+ '--color-text-warning': [yellow.light[30], yellow.dark[85]],
201
+ '--color-text-error': [red.light[30], red.dark[75]],
202
+ '--color-on-info-muted': 'var(--color-text-blue)',
203
+ '--color-on-success-muted': 'var(--color-text-green)',
204
+ '--color-on-warning-muted': 'var(--color-text-yellow)',
205
+ '--color-on-error-muted': 'var(--color-text-red)',
206
+
195
207
  // Icon
196
208
  '--color-icon-accent': [neutral.light[15], neutral.dark[95]],
197
209
  '--color-icon-primary': [neutral.light[15], neutral.dark[95]],
@@ -393,28 +405,20 @@ export const y2kTheme = defineTheme({
393
405
  borderRadius: '0px',
394
406
  },
395
407
  'status:info': {
396
- backgroundColor: 'var(--color-background-blue)',
397
- '--color-text-primary': 'var(--color-text-blue)',
398
- '--color-text-secondary': 'var(--color-text-blue)',
399
- '--color-accent': 'var(--color-text-blue)',
408
+ '--color-info-muted': 'var(--color-background-blue)',
409
+ '--color-on-info-muted': 'var(--color-text-blue)',
400
410
  },
401
411
  'status:success': {
402
- backgroundColor: 'var(--color-background-green)',
403
- '--color-text-primary': 'var(--color-text-green)',
404
- '--color-text-secondary': 'var(--color-text-green)',
405
- '--color-success': 'var(--color-text-green)',
412
+ '--color-success-muted': 'var(--color-background-green)',
413
+ '--color-on-success-muted': 'var(--color-text-green)',
406
414
  },
407
415
  'status:warning': {
408
- backgroundColor: 'var(--color-background-yellow)',
409
- '--color-text-primary': 'var(--color-text-yellow)',
410
- '--color-text-secondary': 'var(--color-text-yellow)',
411
- '--color-warning': 'var(--color-text-yellow)',
416
+ '--color-warning-muted': 'var(--color-background-yellow)',
417
+ '--color-on-warning-muted': 'var(--color-text-yellow)',
412
418
  },
413
419
  'status:error': {
414
- backgroundColor: 'var(--color-background-red)',
415
- '--color-text-primary': 'var(--color-text-red)',
416
- '--color-text-secondary': 'var(--color-text-red)',
417
- '--color-error': 'var(--color-text-red)',
420
+ '--color-error-muted': 'var(--color-background-red)',
421
+ '--color-on-error-muted': 'var(--color-text-red)',
418
422
  },
419
423
  },
420
424
 
@@ -91,9 +91,11 @@ export const myTheme = defineTheme({
91
91
 
92
92
  /**
93
93
  * Start from another theme instead of the defaults. Tokens are copied then
94
- * overridden, `components` deep-merge, `icons` shallow-merge — but the scale
95
- * configs below REPLACE the base's rather than merging, because they are
96
- * inputs to a generator, not values.
94
+ * overridden, `components` deep-merge, `icons` shallow-merge — but the
95
+ * typography, radius and color scale configs below REPLACE the base's rather
96
+ * than merging, because they are inputs to a generator, not values. `motion`
97
+ * inherits field by field: `fast`, `medium` and `ratio` regenerate the fast
98
+ * and medium durations, and a `slow` or `easing` left unset keeps the base's.
97
99
  *
98
100
  * Reference: `astryx theme list` (themes you can install and extend).
99
101
  */
@@ -312,10 +314,21 @@ export const myTheme = defineTheme({
312
314
 
313
315
  /**
314
316
  * Swap the artwork behind semantic icon names — every component that asks
315
- * for `check`, `close`, `chevron-down` gets yours.
317
+ * for `check`, `close`, `chevron-down` gets yours. An entry may also be a
318
+ * pure function of `{size, variant}` that picks artwork for the size Icon
319
+ * renders at.
316
320
  * Reference: `astryx docs icons` lists the names.
317
321
  */
318
- // icons: {check: <MyCheck />, close: <MyClose />},
322
+ // icons: {check: <MyCheck />, info: ({size}) => <MyInfo bold={size === 'sm'} />},
323
+
324
+ /**
325
+ * The icon variant names this theme supports, listed once for the whole
326
+ * theme. An icon entry function receives `variant` typed as these names.
327
+ * A theme that sets the list replaces the one it would inherit; omit it to
328
+ * inherit the base's list.
329
+ * Reference: `astryx docs icons`.
330
+ */
331
+ // iconVariants: ['outline', 'filled'],
319
332
 
320
333
  /**
321
334
  * Replace the small components that DRAW control state — the checkbox box,
@@ -141,6 +141,16 @@ export interface CodemodRunResult {
141
141
  generated: boolean;
142
142
  command?: string;
143
143
  }>;
144
+ /**
145
+ * Protected files left for manual review because their own source does not
146
+ * parse, so no change can be proven in them. They do not fail the run.
147
+ */
148
+ declinedCandidates?: Array<{
149
+ file: string;
150
+ codemod: string;
151
+ location?: string;
152
+ reason: string;
153
+ }>;
144
154
  errors: Array<{file: string; codemod: string; error: string}>;
145
155
  }
146
156
 
@@ -95,6 +95,116 @@ describe('theme build adaptations', () => {
95
95
  );
96
96
  });
97
97
 
98
+ it('emits scoped status aliases in built CSS and preserves child extension parity', async () => {
99
+ const {defineTheme, generateThemeCSS} =
100
+ await import('@astryxdesign/core/theme');
101
+ const project = path.join(tmpDir, 'project');
102
+ const themesDir = path.join(project, 'themes');
103
+ const input = {
104
+ name: 'status-aliases',
105
+ tokens: {
106
+ '--color-info': '#225bff',
107
+ '--color-text-blue': '#203a6c',
108
+ },
109
+ adaptations: {
110
+ rules: [
111
+ {
112
+ when: {contrast: 'more'},
113
+ value: {
114
+ tokens: {'--color-text-success': '#123456'},
115
+ },
116
+ },
117
+ {
118
+ when: {pointer: 'coarse'},
119
+ value: {tokens: {'--color-text-green': '#abcdef'}},
120
+ },
121
+ ],
122
+ },
123
+ onDark: {
124
+ tokens: {'--color-text-blue': '#fefefe'},
125
+ },
126
+ };
127
+ const themeFile = writeTheme(themesDir, input.name, JSON.stringify(input));
128
+
129
+ const result = await build(project, themeFile);
130
+ expect(result.code, result.stderr).toBe(0);
131
+
132
+ const css = fs.readFileSync(
133
+ path.join(themesDir, 'status-aliases.css'),
134
+ 'utf8',
135
+ );
136
+ const mediaAlias = '--color-text-info: var(--color-text-blue);';
137
+ const adaptationAlias = '--color-text-success: var(--color-text-green);';
138
+ const authoredRole = '--color-text-success: #123456;';
139
+ // The authored Info fill is a concrete hue, so theme generation derives
140
+ // its content, text, and pale-fill content (theme-compilation INV17).
141
+ for (const role of ['on-info', 'text-info', 'on-info-muted']) {
142
+ expect(css).toMatch(
143
+ new RegExp(
144
+ `--color-${role}: light-dark\\(#[0-9A-F]{6}, #[0-9A-F]{6}\\);`,
145
+ ),
146
+ );
147
+ }
148
+ // The dark media surface that sets the hue rebinds the text alias.
149
+ expect(css).toContain(mediaAlias);
150
+ expect(css).toContain(adaptationAlias);
151
+ expect(css.split(authoredRole).length - 1).toBeGreaterThanOrEqual(2);
152
+ expect(css.lastIndexOf(authoredRole)).toBeGreaterThan(
153
+ css.lastIndexOf(adaptationAlias),
154
+ );
155
+
156
+ const {statusAliasesTheme: builtTheme} = await import(
157
+ pathToFileURL(path.join(themesDir, 'status-aliases.js')).href
158
+ );
159
+ const source = defineTheme(input);
160
+ const childInput = {
161
+ name: 'status-alias-child',
162
+ tokens: {'--color-text-blue': '#345678'},
163
+ };
164
+ const fromSource = defineTheme({...childInput, extends: source});
165
+ const fromBuilt = defineTheme({...childInput, extends: builtTheme});
166
+ expect(generateThemeCSS(fromBuilt)).toEqual(generateThemeCSS(fromSource));
167
+ });
168
+
169
+ it('derives a complete status set for a minimal theme in built CSS (INV17)', async () => {
170
+ const {defineTheme, generateThemeCSS} =
171
+ await import('@astryxdesign/core/theme');
172
+ const project = path.join(tmpDir, 'project');
173
+ const themesDir = path.join(project, 'themes');
174
+ const input = {
175
+ name: 'status-minimal',
176
+ tokens: {
177
+ '--color-success': '#3FB950',
178
+ '--color-warning': '#D29922',
179
+ '--color-error': '#F85149',
180
+ '--color-info': '#6E40C9',
181
+ },
182
+ };
183
+ const themeFile = writeTheme(themesDir, input.name, JSON.stringify(input));
184
+ const result = await build(project, themeFile);
185
+ expect(result.code, result.stderr).toBe(0);
186
+
187
+ const css = fs.readFileSync(
188
+ path.join(themesDir, 'status-minimal.css'),
189
+ 'utf8',
190
+ );
191
+ for (const status of ['success', 'warning', 'error', 'info']) {
192
+ expect(css).toMatch(
193
+ new RegExp(
194
+ `--color-text-${status}: light-dark\\(#[0-9A-F]{6}, #[0-9A-F]{6}\\);`,
195
+ ),
196
+ );
197
+ expect(css).toContain(
198
+ `--color-icon-${status}: var(--color-text-${status});`,
199
+ );
200
+ }
201
+ // Built and runtime output derive the same values.
202
+ const runtime = generateThemeCSS(defineTheme(input));
203
+ const derived = css.match(/--color-text-warning: [^;]+;/)?.[0];
204
+ expect(derived).toBeDefined();
205
+ expect(JSON.stringify(runtime)).toContain(derived);
206
+ });
207
+
98
208
  it.each([
99
209
  ['defined', writeTheme],
100
210
  ['plain', writePlainTheme],
@@ -108,14 +108,17 @@ export const doc = {
108
108
  ],
109
109
  outsideProject: 'own',
110
110
  exitCodes: [
111
- {code: 0, when: 'success, including complete dry-run previews'},
111
+ {
112
+ code: 0,
113
+ when: 'success, including complete dry-run previews and runs whose only findings are manual migrations',
114
+ },
112
115
  {
113
116
  code: 1,
114
117
  when:
115
118
  'missing or invalid --from, --registry with --list or a migration flag, a --path escape, ' +
116
119
  'no installed @astryxdesign/core (or legacy @xds/core), jscodeshift missing and not installed by --install-deps, ' +
117
120
  'an astryx.config that fails validation and that no pending config codemod repairs, ' +
118
- 'an unreadable or invalid protection declaration, a protected file that still requires a codemod change, ' +
121
+ 'an unreadable or invalid protection declaration, a protected file that still requires a codemod change, a generated file that must be regenerated, ' +
119
122
  'an unknown codemod, a codemod or post-codemod hook failure, or unresolved registry items',
120
123
  },
121
124
  ],
@@ -201,6 +204,31 @@ export const doc = {
201
204
  '`Command:` line in its header, such as `// Command: pnpm run gen:panel`; upgrade prints it as ' +
202
205
  '`Regenerate with: <command>` and lists it in `commands`.',
203
206
  },
207
+ {
208
+ type: 'prose',
209
+ text:
210
+ 'A protected file a codemod cannot parse, such as a vendored bundle written for another toolchain, cannot need a ' +
211
+ 'change the codemod can prove, and upgrade never writes it. upgrade skips it, lists it under ' +
212
+ '`declinedCandidates` with the parse error and where it occurred, and carries on; on its own it does not fail the run. ' +
213
+ 'If another codemod in the same upgrade still requires a change to that file (the 0.6.0 theme selector migration, for one, ' +
214
+ 'adds a TODO comment above a selector it cannot parse), the file is listed once, under `protectedFiles`, and the run is ' +
215
+ 'incomplete as for any protected file. A file upgrade owns that does not parse still fails the run with ERR_CODEMOD_FAILED.',
216
+ },
217
+ {type: 'heading', level: 3, text: 'Manual migrations and regeneration'},
218
+ {
219
+ type: 'prose',
220
+ text:
221
+ 'Some changes a codemod can find but not make. upgrade lists them in the result, so a script can keep the rest of the run and act on each. ' +
222
+ 'Code a codemod can identify but cannot migrate safely is a manual migration: upgrade lists each file with its line, ' +
223
+ 'the codemod and what to change, finishes the run, and exits 0. With --json they are in `declinedCandidates`, one row per file (each finding in `reason` starts with `manual migration needed (<codemod>):`, and a file with several findings lists them all, joined by `; `), and `complete` stays true. ' +
224
+ 'A generated file that must be rebuilt is listed in `regenerate` with the command that rebuilds it, such as `astryx theme build`: a protected generated file a codemod still needs to change ' +
225
+ '(also in `protectedFiles`), or a generated output a codemod found out of date (also in `protectedFiles`, with the rule that protects it, when the project marks it generated). With --apply, upgrade runs your `hooks.postCodemod` commands and checks again. ' +
226
+ 'If a protected file still needs rebuilding, the run is incomplete exactly as for any protected file: it exits 1 and the result says `complete: false` and `errorCode: "ERR_CODEMOD_PROTECTED"`. ' +
227
+ 'If a file nothing protects still needs rebuilding, no protected file is in the way: the codemod could not make a required change, so it is also in `errors` and the run fails with `ERR_CODEMOD_FAILED`, as described below. ' +
228
+ 'Either way, rebuild it, then run the same upgrade again. ' +
229
+ 'When a codemod also failed, the failure is reported as below, and the receipt it carries still lists `declinedCandidates` and `regenerate`, ' +
230
+ 'unless a protected file to regenerate also remains, in which case the run returns `ERR_CODEMOD_PROTECTED` with the failure in `errors`.',
231
+ },
204
232
  {type: 'heading', level: 3, text: 'A failed codemod'},
205
233
  {
206
234
  type: 'prose',
@@ -255,4 +255,150 @@ describe('upgrade protected-file contract', () => {
255
255
  expect(second.envelope.data.complete).toBe(true);
256
256
  expect(second.envelope.data.filesChanged).toBe(0);
257
257
  });
258
+
259
+ it('skips a vendored file that does not parse and completes the upgrade', () => {
260
+ seed();
261
+ write('.gitattributes', 'vendor/** linguist-vendored\n');
262
+ const bundle =
263
+ "/* minified */ import {useResizable} from '@astryxdesign/core';\n" +
264
+ 'export const x = useResizable({minSizePx: 200;\n';
265
+ write('vendor/bundle.js', bundle);
266
+ rmGenerated();
267
+
268
+ const applied = run([...ARGS, '--apply']);
269
+
270
+ expect(applied.status, applied.stderr).toBe(0);
271
+ expect(applied.envelope).toMatchObject({
272
+ type: 'upgrade.run',
273
+ data: {
274
+ complete: true,
275
+ modifiedFiles: ['src/owned.tsx'],
276
+ protectedFiles: [],
277
+ declinedCandidates: [
278
+ {
279
+ file: 'vendor/bundle.js',
280
+ location: '2:46',
281
+ reason:
282
+ 'unparseable protected file (vendored): Unexpected token, expected ","',
283
+ },
284
+ ],
285
+ },
286
+ });
287
+ expect(applied.envelope.data.errors ?? []).toEqual([]);
288
+ expect(fs.readFileSync(path.join(root, 'src/owned.tsx'), 'utf8')).toContain(
289
+ 'minSize: 200',
290
+ );
291
+ expect(fs.readFileSync(path.join(root, 'vendor/bundle.js'), 'utf8')).toBe(
292
+ bundle,
293
+ );
294
+
295
+ const text = spawnSync(process.execPath, [CLI, 'upgrade', ...ARGS], {
296
+ cwd: root,
297
+ encoding: 'utf8',
298
+ timeout: 60_000,
299
+ env: {...process.env, FORCE_COLOR: '0', CI: ''},
300
+ });
301
+ expect(text.status, text.stderr).toBe(0);
302
+ expect(`${text.stdout}${text.stderr}`).toContain(
303
+ '1 protected file was skipped because it does not parse',
304
+ );
305
+ const declinedLine = `${text.stdout}${text.stderr}`
306
+ .split('\n')
307
+ .find(line => line.includes('vendor/bundle.js:2:46'));
308
+ expect(declinedLine).toMatch(/^ {2}vendor\/bundle\.js:2:46 - /);
309
+ // cli-surface output is plain ASCII.
310
+ expect(declinedLine).toMatch(/^[\x20-\x7e]*$/);
311
+ });
312
+
313
+ it('still fails when an owned file does not parse', () => {
314
+ seed();
315
+ write(
316
+ 'lib/broken.js',
317
+ "import {useResizable} from '@astryxdesign/core';\n" +
318
+ 'export const x = useResizable({minSizePx: 200;\n',
319
+ );
320
+ rmGenerated();
321
+
322
+ const applied = run([...ARGS, '--apply']);
323
+
324
+ expect(applied.status).toBe(1);
325
+ expect(applied.envelope).toMatchObject({code: 'ERR_CODEMOD_FAILED'});
326
+ });
327
+
328
+ it('reports a stylesheet the 0.6 and 0.7 theme codemods both need once, as protected', () => {
329
+ write('package.json', JSON.stringify({name: 'consumer', private: true}));
330
+ write(
331
+ 'node_modules/@astryxdesign/core/package.json',
332
+ JSON.stringify({name: '@astryxdesign/core', version: CLI_VERSION}),
333
+ );
334
+ write('.gitattributes', 'vendor/** linguist-vendored\n');
335
+ write('vendor/bundle.css', 'a:: { color: red; }\n');
336
+
337
+ const result = run(['--from', '0.5.4', '--path', '.']);
338
+ const text = spawnSync(
339
+ process.execPath,
340
+ [CLI, 'upgrade', '--from', '0.5.4', '--path', '.'],
341
+ {
342
+ cwd: root,
343
+ encoding: 'utf8',
344
+ timeout: 60_000,
345
+ env: {...process.env, FORCE_COLOR: '0', CI: ''},
346
+ },
347
+ );
348
+ const output = `${text.stdout}${text.stderr}`;
349
+ expect(text.status).toBe(1);
350
+ expect(output).toContain('ERR_CODEMOD_PROTECTED');
351
+ expect(output).toMatch(/^ {2}vendor\/bundle\.css — /m);
352
+ expect(output).not.toContain('skipped because');
353
+ expect(output).not.toContain('unparseable protected file');
354
+
355
+ expect(result.status).toBe(1);
356
+ expect(result.envelope).toMatchObject({
357
+ type: 'upgrade.run',
358
+ data: {
359
+ complete: false,
360
+ errorCode: 'ERR_CODEMOD_PROTECTED',
361
+ protectedFiles: [expect.objectContaining({file: 'vendor/bundle.css'})],
362
+ declinedCandidates: [],
363
+ },
364
+ });
365
+ });
366
+
367
+ it('lists a generated file the hook regenerates into bytes that do not parse', () => {
368
+ seed();
369
+ const broken =
370
+ "// @generated\nimport {useResizable} from '@astryxdesign/core';\n" +
371
+ 'export const usePanel = () => useResizable({minSizePx: 200;\n';
372
+ write(
373
+ 'astryx.config.mjs',
374
+ `export default {hooks: {postCodemod: [{name: 'regenerate', buildCommand: () => ({command: process.execPath, args: ['-e', ${JSON.stringify(`require('node:fs').writeFileSync('generated/panel.tsx', ${JSON.stringify(broken)})`)}]})}]}};\n`,
375
+ );
376
+
377
+ const applied = run([...ARGS, '--apply']);
378
+
379
+ expect(applied.status, applied.stderr).toBe(0);
380
+ expect(applied.envelope).toMatchObject({
381
+ type: 'upgrade.run',
382
+ data: {
383
+ complete: true,
384
+ protectedFiles: [],
385
+ declinedCandidates: [
386
+ {
387
+ file: 'generated/panel.tsx',
388
+ location: expect.stringMatching(/^3:\d+$/),
389
+ reason: expect.stringMatching(
390
+ /^unparseable protected file \(generated\): /,
391
+ ),
392
+ },
393
+ ],
394
+ },
395
+ });
396
+ expect(
397
+ fs.readFileSync(path.join(root, 'generated/panel.tsx'), 'utf8'),
398
+ ).toBe(broken);
399
+ });
258
400
  });
401
+
402
+ function rmGenerated() {
403
+ fs.rmSync(path.join(root, 'generated'), {recursive: true, force: true});
404
+ }