@astryxdesign/cli 0.6.5-canary.7a6a637 → 0.6.5-canary.822d452

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.
@@ -4,7 +4,9 @@
4
4
  /**
5
5
  * Collect the effective handler set in delivery order: project config first,
6
6
  * then integrations in config order. Valid handlers dedupe by handle identity;
7
- * malformed integration exports retain their position as failed deliveries.
7
+ * malformed integration exports and integrations that failed to load retain
8
+ * their position as failed deliveries. An unloadable integration may export a
9
+ * handler, so it never counts as an empty set that enables the fallback.
8
10
  *
9
11
  * @param {Project} project
10
12
  * @returns {HandlerEntry[]}
@@ -189,7 +189,9 @@ async function selectTarget(project, component, packageName) {
189
189
  /**
190
190
  * Collect the effective handler set in delivery order: project config first,
191
191
  * then integrations in config order. Valid handlers dedupe by handle identity;
192
- * malformed integration exports retain their position as failed deliveries.
192
+ * malformed integration exports and integrations that failed to load retain
193
+ * their position as failed deliveries. An unloadable integration may export a
194
+ * handler, so it never counts as an empty set that enables the fallback.
193
195
  *
194
196
  * @param {Project} project
195
197
  * @returns {HandlerEntry[]}
@@ -214,7 +216,15 @@ export function collectGapReportHandlers(project) {
214
216
  }
215
217
 
216
218
  for (const integration of project.loadedIntegrations) {
217
- if (integration.__loadError) continue;
219
+ if (integration.__loadError) {
220
+ entries.push({
221
+ kind: 'malformed',
222
+ handlerType: 'integration',
223
+ handlerName: integration.name,
224
+ error: `Integration failed to load, so it could not receive this report: ${integration.__loadError}. Fix the package or remove it from integrations in astryx.config, then rerun.`,
225
+ });
226
+ continue;
227
+ }
218
228
  if (integration.__gapReportError) {
219
229
  entries.push({
220
230
  kind: 'malformed',
@@ -105,6 +105,45 @@ function addIntegration({
105
105
  return {dir};
106
106
  }
107
107
 
108
+ /**
109
+ * Add an integration whose module throws on import, so it never loads.
110
+ * @param {string} name
111
+ */
112
+ function addBrokenIntegration(name) {
113
+ const dir = packageDir(name);
114
+ fs.mkdirSync(dir, {recursive: true});
115
+ fs.writeFileSync(
116
+ path.join(dir, 'package.json'),
117
+ JSON.stringify({name, version: '1.0.0', type: 'module'}),
118
+ );
119
+ fs.writeFileSync(
120
+ path.join(dir, 'astryx.integration.mjs'),
121
+ "throw new Error('intentional integration load failure');\n",
122
+ );
123
+ }
124
+
125
+ /**
126
+ * Put a fake `gh` first on PATH that records its arguments if it is called.
127
+ * @returns {string} the file the fake writes when invoked
128
+ */
129
+ function stubGh() {
130
+ const binDir = path.join(projectDir, 'bin');
131
+ const argsFile = path.join(projectDir, 'gh-args.json');
132
+ fs.mkdirSync(binDir, {recursive: true});
133
+ fs.writeFileSync(
134
+ path.join(binDir, 'gh'),
135
+ `#!/usr/bin/env node
136
+ import fs from 'node:fs';
137
+ fs.writeFileSync(${JSON.stringify(argsFile)}, JSON.stringify(process.argv.slice(2)));
138
+ console.log('https://github.com/acme/core/issues/42');
139
+ `,
140
+ {mode: 0o755},
141
+ );
142
+ fs.chmodSync(path.join(binDir, 'gh'), 0o755);
143
+ vi.stubEnv('PATH', `${binDir}${path.delimiter}${process.env.PATH ?? ''}`);
144
+ return argsFile;
145
+ }
146
+
108
147
  const reportOptions = {
109
148
  category: 'missing_variant',
110
149
  reason: 'Need a compact size',
@@ -681,6 +720,73 @@ describe('gapReport handler isolation', () => {
681
720
  });
682
721
  });
683
722
 
723
+ it('an integration that fails to load is a failed delivery, not a missing handler', async () => {
724
+ addBrokenIntegration('@test/broken');
725
+ configure(['@test/broken'], {
726
+ issuesUrl: 'https://github.com/acme/core/issues/new',
727
+ });
728
+
729
+ const result = await gapReport('General', {
730
+ ...reportOptions,
731
+ cwd: projectDir,
732
+ });
733
+
734
+ expect(result.data.status).toBe('failed');
735
+ expect(result.data.deliveries).toEqual([
736
+ {
737
+ handlerType: 'integration',
738
+ handler: '@test/broken',
739
+ audience: null,
740
+ status: 'failed',
741
+ url: null,
742
+ message: expect.stringContaining(
743
+ 'intentional integration load failure',
744
+ ),
745
+ },
746
+ ]);
747
+ });
748
+
749
+ it('an integration that fails to load keeps the public fallback off, even with consent', async () => {
750
+ addBrokenIntegration('@test/broken');
751
+ configure(['@test/broken'], {
752
+ issuesUrl: 'https://github.com/acme/core/issues/new',
753
+ });
754
+ const argsFile = stubGh();
755
+
756
+ const result = await gapReport('General', {
757
+ ...reportOptions,
758
+ confirmPublic: true,
759
+ cwd: projectDir,
760
+ });
761
+
762
+ expect(result.data.status).toBe('failed');
763
+ expect(result.data.deliveries.map(d => d.handlerType)).toEqual([
764
+ 'integration',
765
+ ]);
766
+ expect(fs.existsSync(argsFile)).toBe(false);
767
+ });
768
+
769
+ it('an integration that fails to load keeps its place beside working handlers', async () => {
770
+ addBrokenIntegration('@test/broken');
771
+ addIntegration({
772
+ name: '@test/valid',
773
+ audience: 'internal',
774
+ handleBody: "return {status: 'filed', message: 'ok'};",
775
+ });
776
+ configure(['@test/broken', '@test/valid']);
777
+
778
+ const result = await gapReport('General', {
779
+ ...reportOptions,
780
+ cwd: projectDir,
781
+ });
782
+
783
+ expect(result.data.status).toBe('partial');
784
+ expect(result.data.deliveries.map(d => [d.handler, d.status])).toEqual([
785
+ ['@test/broken', 'failed'],
786
+ ['@test/valid', 'filed'],
787
+ ]);
788
+ });
789
+
684
790
  it('invalid handler receipt is recorded as failed delivery', async () => {
685
791
  addIntegration({
686
792
  name: '@test/bad-receipt',
@@ -0,0 +1,117 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Icon preservation through multiple generations of built themes.
5
+ * @input Real themeBuild calls and registries imported under the same local
6
+ * binding name from separate base and child theme directories.
7
+ * @output A native ESM load verifies inherited and overridden React icons
8
+ * survive when a grandchild extends the child's generated artifact.
9
+ * @position Direct API regression for persisted icon inheritance in #5058.
10
+ * The node project's global setup supplies the compiled core package.
11
+ */
12
+
13
+ import {expect, it} from 'vitest';
14
+ import {execFileSync} from 'node:child_process';
15
+ import * as fs from 'node:fs';
16
+ import * as path from 'node:path';
17
+ import {themeBuild} from './build.mjs';
18
+
19
+ it('preserves merged icon lineage through a built child with colliding import names', async () => {
20
+ const tmpDir = fs.mkdtempSync(
21
+ path.resolve(import.meta.dirname, '../../..', '.tmp-icon-lineage-'),
22
+ );
23
+ try {
24
+ for (const directory of ['base', 'child']) {
25
+ fs.mkdirSync(path.join(tmpDir, directory));
26
+ }
27
+ const write = (file, source) =>
28
+ fs.writeFileSync(path.join(tmpDir, file), source);
29
+ const writeRegistry = (file, labels) => {
30
+ write(
31
+ file,
32
+ `import {createElement} from 'react';
33
+ export const icons = {
34
+ ${Object.entries(labels)
35
+ .map(
36
+ ([key, label]) =>
37
+ ` ${JSON.stringify(key)}: createElement('svg', {'data-icon': ${JSON.stringify(label)}}),`,
38
+ )
39
+ .join('\n')}
40
+ };
41
+ `,
42
+ );
43
+ };
44
+
45
+ writeRegistry('base/icons.mjs', {
46
+ check: 'base-check',
47
+ close: 'base-close',
48
+ });
49
+ writeRegistry('child/icons.mjs', {
50
+ add: 'child-add',
51
+ close: 'child-close',
52
+ });
53
+ write(
54
+ 'base/source.mjs',
55
+ `import {defineTheme} from '@astryxdesign/core/theme';
56
+ import {icons} from './icons.mjs';
57
+ export const baseTheme = defineTheme({
58
+ name: 'base', tokens: {'--color-bg': '#fff'}, icons,
59
+ });
60
+ `,
61
+ );
62
+ write(
63
+ 'child/source.mjs',
64
+ `import {defineTheme} from '@astryxdesign/core/theme';
65
+ import {baseTheme} from '../base/source.mjs';
66
+ import {icons} from './icons.mjs';
67
+ export default defineTheme({
68
+ name: 'child', extends: baseTheme, tokens: {}, icons,
69
+ });
70
+ `,
71
+ );
72
+ const child = await themeBuild('child/source.mjs', {}, {cwd: tmpDir});
73
+ expect(child?.type).toBe('theme.build');
74
+
75
+ write(
76
+ 'grandchild.mjs',
77
+ `import {defineTheme} from '@astryxdesign/core/theme';
78
+ import {childTheme} from './child/child.js';
79
+ export default defineTheme({name: 'grandchild', extends: childTheme, tokens: {}});
80
+ `,
81
+ );
82
+ const grandchild = await themeBuild('grandchild.mjs', {}, {cwd: tmpDir});
83
+ expect(grandchild?.type).toBe('theme.build');
84
+ const checked = await themeBuild(
85
+ 'grandchild.mjs',
86
+ {check: true},
87
+ {cwd: tmpDir},
88
+ );
89
+ expect(checked?.data.upToDate).toBe(true);
90
+
91
+ // Native imports catch invalid aliases and incorrect relative specifiers
92
+ // that the source loader could otherwise resolve or transform away.
93
+ execFileSync(
94
+ process.execPath,
95
+ [
96
+ '--input-type=module',
97
+ '--eval',
98
+ `import assert from 'node:assert/strict';
99
+ import {isValidElement} from 'react';
100
+ import {childTheme} from './child/child.js';
101
+ import {grandchildTheme} from './grandchild.js';
102
+ const expected = {check: 'base-check', close: 'child-close', add: 'child-add'};
103
+ assert.deepEqual(Object.keys(grandchildTheme.icons).sort(), Object.keys(expected).sort());
104
+ for (const [key, label] of Object.entries(expected)) {
105
+ const icon = grandchildTheme.icons[key];
106
+ assert.ok(isValidElement(icon), key + ' must remain a React element');
107
+ assert.equal(icon.type, 'svg');
108
+ assert.equal(icon.props['data-icon'], label);
109
+ assert.equal(icon, childTheme.icons[key], key + ' must retain its imported identity');
110
+ }`,
111
+ ],
112
+ {cwd: tmpDir, stdio: 'pipe', timeout: 10000},
113
+ );
114
+ } finally {
115
+ fs.rmSync(tmpDir, {recursive: true, force: true});
116
+ }
117
+ });