@astryxdesign/cli 0.6.5-canary.eb58bba → 0.6.5-canary.f261d2f

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 (41) hide show
  1. package/README.md +11 -12
  2. package/api/error.d.mts +0 -22
  3. package/api/error.mjs +0 -42
  4. package/api/integration/authoring-checks.mjs +7 -10
  5. package/api/integration/authoring-checks.type.d.mts +0 -8
  6. package/api/integration/authoring-checks.type.mjs +3 -7
  7. package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
  8. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  9. package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
  10. package/api/integration/validate-integration.d.mts +2 -4
  11. package/api/integration/validate-integration.mjs +2 -7
  12. package/api/integration/validate-integration.test.mjs +0 -55
  13. package/api/integration/validate-integration.type.d.mts +0 -5
  14. package/api/integration/validate-integration.type.mjs +1 -5
  15. package/api/integration/validateIntegration.doc.mjs +1 -1
  16. package/api/swizzle/copy/copy.mjs +3 -66
  17. package/api/swizzle/swizzle.doc.mjs +0 -4
  18. package/api/template/copy/copy.mjs +5 -9
  19. package/api/template/show/show.mjs +4 -15
  20. package/api/template/template.doc.mjs +1 -5
  21. package/api/template/template.type.d.mts +0 -1
  22. package/api/template/template.type.mjs +0 -1
  23. package/api/upgrade/run/run.mjs +3 -20
  24. package/api/upgrade/run/run.test.mjs +1 -45
  25. package/api/upgrade/upgrade.doc.mjs +1 -1
  26. package/api/upgrade/upgrade.type.d.mts +0 -1
  27. package/api/upgrade/upgrade.type.mjs +0 -1
  28. package/clients/cli/commands/doctor.mjs +4 -4
  29. package/clients/cli/commands/template.mjs +2 -11
  30. package/clients/cli/commands/upgrade.ascii-output.test.mjs +0 -14
  31. package/clients/cli/lib/manifest.mjs +165 -44
  32. package/clients/cli/lib/manifest.test.mjs +7 -98
  33. package/foundation/discovery/template-adapter.d.mts +0 -13
  34. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +1 -37
  35. package/foundation/discovery/template-adapter.mjs +1 -16
  36. package/foundation/response/response-types.doc.d.mts +5 -5
  37. package/foundation/response/response-types.doc.mjs +11 -11
  38. package/package.json +9 -9
  39. package/api/template/show/show.test.mjs +0 -76
  40. package/clients/cli/commands/template.show-media.test.mjs +0 -62
  41. package/clients/cli/commands/write-failure.test.mjs +0 -175
@@ -14,46 +14,11 @@
14
14
  * surfaces emit valid, enriched JSON.
15
15
  */
16
16
 
17
- import * as fs from 'node:fs';
18
- import * as os from 'node:os';
19
- import * as path from 'node:path';
20
- import {fileURLToPath, pathToFileURL} from 'node:url';
21
17
  import {describe, it, expect} from 'vitest';
22
18
  import {program, JSON_SUPPORTED} from '../index.mjs';
23
- import {buildManifest} from './manifest.mjs';
19
+ import {buildManifest, RESPONSE_TYPES} from './manifest.mjs';
24
20
  import {runCli} from '../../../test-utils/run-cli.mjs';
25
21
 
26
- const HERE = path.dirname(fileURLToPath(import.meta.url));
27
-
28
- /**
29
- * Import every `*.doc.mjs` under `dir` whose doc has the given type, keyed by
30
- * its `name`.
31
- * @param {string} dir @param {string} type @returns {Promise<Map<string, any>>}
32
- */
33
- async function loadDocs(dir, type) {
34
- const out = new Map();
35
- for (const entry of fs.readdirSync(dir, {withFileTypes: true, recursive: true})) {
36
- if (!entry.isFile() || !entry.name.endsWith('.doc.mjs')) continue;
37
- const file = path.join(entry.parentPath, entry.name);
38
- const {doc} = await import(pathToFileURL(file).href);
39
- if (doc?.type === type) out.set(doc.name, doc);
40
- }
41
- return out;
42
- }
43
-
44
- const commandDocs = await loadDocs(path.join(HERE, '../commands'), 'command');
45
- const functionDocs = await loadDocs(path.join(HERE, '../../../api'), 'function');
46
-
47
- /**
48
- * Envelopes built in the CLI layer, which no FunctionDoc can declare. Pinned so
49
- * an entry is dropped once its type moves behind an API function.
50
- */
51
- const CLI_LAYER_TYPES = {
52
- manifest: ['manifest'],
53
- 'theme build': ['theme.build.batch'],
54
- 'theme add': ['theme.list'],
55
- };
56
-
57
22
  const manifest = buildManifest(program, {jsonSupported: JSON_SUPPORTED, version: '0.0.0-test'});
58
23
 
59
24
  /** Flatten the manifest command tree into fully-qualified names. */
@@ -99,73 +64,17 @@ describe('manifest: drift guards', () => {
99
64
 
100
65
  it('declares response types for every JSON-supported command', () => {
101
66
  for (const name of JSON_SUPPORTED) {
102
- const entry = allEntries.find((c) => c.name === name);
103
67
  expect(
104
- entry?.responseTypes?.length,
105
- `JSON-supported command "${name}" has no response types`,
106
- ).toBeGreaterThan(0);
107
- expect(manifest.responseTypes[name]).toEqual(entry.responseTypes);
68
+ RESPONSE_TYPES[name],
69
+ `JSON-supported command "${name}" has no response-type entry`,
70
+ ).toBeDefined();
71
+ expect(RESPONSE_TYPES[name].length).toBeGreaterThan(0);
108
72
  }
109
73
  });
110
74
 
111
75
  it('has no response-type entry for a command that does not exist', () => {
112
- for (const name of Object.keys(manifest.responseTypes)) {
113
- expect(allNames.has(name), `responseTypes key "${name}" is not a real command`).toBe(true);
114
- }
115
- });
116
-
117
- it('takes every command example from its CommandDoc', () => {
118
- for (const [name, doc] of commandDocs) {
119
- const entry = allEntries.find((c) => c.name === name);
120
- expect(entry, `CommandDoc "${name}" has no manifest entry`).toBeDefined();
121
- expect(entry.examples ?? [], name).toEqual((doc.examples ?? []).map((e) => e.cli));
122
- }
123
- });
124
-
125
- it('lists every response type the wrapped API function returns', () => {
126
- for (const [name, doc] of commandDocs) {
127
- if (!doc.fn) continue;
128
- const entry = allEntries.find((c) => c.name === name);
129
- for (const {type} of functionDocs.get(doc.fn).returns) {
130
- expect(entry.responseTypes, `${name} can emit ${type}`).toContain(type);
131
- }
132
- }
133
- });
134
-
135
- it('lists upgrade.registry, which `upgrade --registry --json` emits', async () => {
136
- const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-manifest-'));
137
- fs.writeFileSync(path.join(cwd, 'package.json'), '{"name":"app","version":"1.0.0"}');
138
- const {status, stdout} = await runCli(['--json', 'upgrade', '--registry'], {cwd});
139
- expect(status).toBe(0);
140
- expect(JSON.parse(stdout).type).toBe('upgrade.registry');
141
- expect(manifest.responseTypes.upgrade).toContain('upgrade.registry');
142
- });
143
-
144
- it('lists theme.list for theme add, which lists themes when given no slug', async () => {
145
- const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-manifest-'));
146
- fs.writeFileSync(path.join(cwd, 'package.json'), '{"name":"app","version":"1.0.0"}');
147
- const {status, stdout} = await runCli(['--json', 'theme', 'add'], {cwd});
148
- expect(status).toBe(0);
149
- expect(JSON.parse(stdout).type).toBe('theme.list');
150
- expect(manifest.responseTypes['theme add']).toContain('theme.list');
151
- });
152
-
153
- it('takes response types from the wrapped FunctionDoc, plus CLI-layer envelopes', () => {
154
- for (const [name, doc] of commandDocs) {
155
- const entry = allEntries.find((c) => c.name === name);
156
- const returns = doc.fn ? functionDocs.get(doc.fn).returns.map((r) => r.type) : [];
157
- const expected = [...returns, ...(CLI_LAYER_TYPES[name] ?? [])];
158
- expect(entry.responseTypes ?? [], name).toEqual(expected);
159
- }
160
- });
161
-
162
- it('pins only CLI-layer envelopes that no FunctionDoc declares', () => {
163
- for (const [name, types] of Object.entries(CLI_LAYER_TYPES)) {
164
- const fn = commandDocs.get(name)?.fn;
165
- const declared = fn ? functionDocs.get(fn).returns.map((r) => r.type) : [];
166
- for (const type of types) {
167
- expect(declared, `${type} is declared by ${fn}(); unpin it`).not.toContain(type);
168
- }
76
+ for (const name of Object.keys(RESPONSE_TYPES)) {
77
+ expect(allNames.has(name), `RESPONSE_TYPES key "${name}" is not a real command`).toBe(true);
169
78
  }
170
79
  });
171
80
 
@@ -49,19 +49,6 @@ export function effectiveTemplateDiscovery(templates: DiscoveredTemplate[]): Dis
49
49
  * @returns {string} Source with demo asset references replaced.
50
50
  */
51
51
  export function stripTemplateAssetRefs(source: string): string;
52
- /**
53
- * {@link stripTemplateAssetRefs}, plus how many references it replaced: one per
54
- * replaced reference, however many fixture paths its URL carries (a reference
55
- * is replaced whole, query included), and none for a prose mention or a
56
- * third-party URL left as written. That count is what a receipt discloses.
57
- *
58
- * @param {string} source - Template source code.
59
- * @returns {{source: string, demoMediaReplaced: number}}
60
- */
61
- export function replaceDemoMedia(source: string): {
62
- source: string;
63
- demoMediaReplaced: number;
64
- };
65
52
  /**
66
53
  * List the core page-template directory names (sorted). The `template --list`
67
54
  * view discovers far more; this is the minimal core-page set `init` scaffolds
@@ -5,7 +5,7 @@ import * as fs from 'node:fs';
5
5
  import * as path from 'node:path';
6
6
  import {fileURLToPath} from 'node:url';
7
7
  import jscodeshift from 'jscodeshift';
8
- import {replaceDemoMedia, stripTemplateAssetRefs} from './template-adapter.mjs';
8
+ import {stripTemplateAssetRefs} from './template-adapter.mjs';
9
9
 
10
10
  const PLACEHOLDER = stripTemplateAssetRefs("'/template-assets/x.png'").slice(
11
11
  1,
@@ -212,42 +212,6 @@ describe('stripTemplateAssetRefs fixture references', () => {
212
212
  });
213
213
  });
214
214
 
215
- describe('replaceDemoMedia', () => {
216
- it('counts a reference once, however many fixture paths its URL carries', () => {
217
- const source =
218
- "const hero = '/template-assets/a.png?f=/template-assets/b.png';";
219
- expect(replaceDemoMedia(source)).toEqual({
220
- source: stripTemplateAssetRefs(source),
221
- demoMediaReplaced: 1,
222
- });
223
- });
224
-
225
- it('counts a poster and a video as two references', () => {
226
- const source =
227
- '<video poster="/template-assets/poster.jpg" src="/template-assets/clip.mp4" />';
228
- const result = replaceDemoMedia(source);
229
- expect(result).toEqual({
230
- source: stripTemplateAssetRefs(source),
231
- demoMediaReplaced: 2,
232
- });
233
- expect(result.source).not.toContain('/template-assets/');
234
- });
235
-
236
- it.each([
237
- [
238
- 'a prose mention',
239
- '<p>Demo media lives under /template-assets/ in the docsite.</p>',
240
- ],
241
- [
242
- 'a third-party URL',
243
- "const u = 'https://example.com/template-assets/a.png';",
244
- ],
245
- ['source with no fixture', 'const x = 1;'],
246
- ])('counts nothing for %s it leaves as written', (_label, source) => {
247
- expect(replaceDemoMedia(source)).toEqual({source, demoMediaReplaced: 0});
248
- });
249
- });
250
-
251
215
  describe('shipped templates', () => {
252
216
  it('copy with every fixture replaced and still parse', () => {
253
217
  const root = path.resolve(
@@ -321,23 +321,9 @@ function toPosixPath(p) {
321
321
  * @returns {string} Source with demo asset references replaced.
322
322
  */
323
323
  export function stripTemplateAssetRefs(source) {
324
- return replaceDemoMedia(source).source;
325
- }
326
-
327
- /**
328
- * {@link stripTemplateAssetRefs}, plus how many references it replaced: one per
329
- * replaced reference, however many fixture paths its URL carries (a reference
330
- * is replaced whole, query included), and none for a prose mention or a
331
- * third-party URL left as written. That count is what a receipt discloses.
332
- *
333
- * @param {string} source - Template source code.
334
- * @returns {{source: string, demoMediaReplaced: number}}
335
- */
336
- export function replaceDemoMedia(source) {
337
324
  const needle = `/${FIXTURE_SEGMENT}`;
338
325
  let output = '';
339
326
  let copied = 0;
340
- let demoMediaReplaced = 0;
341
327
  /** @type {Array<[number, number]> | undefined} */
342
328
  let comments;
343
329
  let at = source.indexOf(needle);
@@ -358,11 +344,10 @@ export function replaceDemoMedia(source) {
358
344
  if (edit) {
359
345
  output += source.slice(copied, start) + edit.text;
360
346
  copied = edit.end;
361
- demoMediaReplaced += 1;
362
347
  }
363
348
  at = source.indexOf(needle, end);
364
349
  }
365
- return {source: output + source.slice(copied), demoMediaReplaced};
350
+ return output + source.slice(copied);
366
351
  }
367
352
 
368
353
  /** @param {string | undefined} char */
@@ -3,11 +3,11 @@
3
3
 
4
4
  /**
5
5
  * @file EnumDoc for the `type` discriminant carried on every --json success
6
- * envelope. The vocabulary equals the manifest's response types (each
7
- * command's FunctionDoc returns; see `clients/cli/lib/manifest.mjs`) plus
8
- * ROOT_RESPONSE_TYPES (help, version) there; a consumer switches on `type` to
9
- * narrow the `data` payload. Descriptions follow the currently published
10
- * response projection, not a future package-version boundary.
6
+ * envelope. The vocabulary mirrors the RESPONSE_TYPES map (each command's
7
+ * `jsonOut(...)` call sites) plus ROOT_RESPONSE_TYPES (help, version) in
8
+ * `clients/cli/lib/manifest.mjs`; a consumer switches on `type` to narrow the
9
+ * `data` payload. Descriptions follow the currently published response
10
+ * projection, not a future package-version boundary.
11
11
  *
12
12
  * @input Public response discriminants and their currently released payloads.
13
13
  * @output Generated consumer reference for every typed JSON success response.
@@ -2,11 +2,11 @@
2
2
 
3
3
  /**
4
4
  * @file EnumDoc for the `type` discriminant carried on every --json success
5
- * envelope. The vocabulary equals the manifest's response types (each
6
- * command's FunctionDoc returns; see `clients/cli/lib/manifest.mjs`) plus
7
- * ROOT_RESPONSE_TYPES (help, version) there; a consumer switches on `type` to
8
- * narrow the `data` payload. Descriptions follow the currently published
9
- * response projection, not a future package-version boundary.
5
+ * envelope. The vocabulary mirrors the RESPONSE_TYPES map (each command's
6
+ * `jsonOut(...)` call sites) plus ROOT_RESPONSE_TYPES (help, version) in
7
+ * `clients/cli/lib/manifest.mjs`; a consumer switches on `type` to narrow the
8
+ * `data` payload. Descriptions follow the currently published response
9
+ * projection, not a future package-version boundary.
10
10
  *
11
11
  * @input Public response discriminants and their currently released payloads.
12
12
  * @output Generated consumer reference for every typed JSON success response.
@@ -184,7 +184,7 @@ export const doc = {
184
184
  {
185
185
  value: 'template.show',
186
186
  description:
187
- "The resolved template's source, exactly as a copy writes it, plus its description, kind, the component names it composes, and demoMediaReplaced (how many Astryx demo media references were replaced with placeholders for you to swap for your own media).",
187
+ "The resolved template's raw source plus its description, kind, and the component names it composes.",
188
188
  },
189
189
  {
190
190
  value: 'template.skeleton',
@@ -276,7 +276,7 @@ export const doc = {
276
276
  {
277
277
  value: 'upgrade.run',
278
278
  description:
279
- 'The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors.',
279
+ 'The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, and (apply mode) filesChanged, transformsApplied, and per-codemod errors.',
280
280
  },
281
281
 
282
282
  // manifest
@@ -320,22 +320,22 @@ export const doc = {
320
320
  {
321
321
  value: 'integration.validate',
322
322
  description:
323
- 'The validation result: validated (false when no integration manifest was found, so nothing was checked and the empty issues list proves nothing), the package name and version (both null when validated is false) plus issues, an AstryxIntegrationIssue[] of {code, severity: warning | error, message}.',
323
+ 'The validation result: the package name and version (both null when no local manifest is found) plus issues, an AstryxIntegrationIssue[] of {code, severity: warning | error, message}.',
324
324
  },
325
325
  {
326
326
  value: 'integration.template-conflicts',
327
327
  description:
328
- 'validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and non-blocking Core template-id conflicts as {id, severity: warning, integrationPackage, integrationType, integrationName, coreMatches, message, command}.',
328
+ 'The integration identity, structural issues, and non-blocking Core template-id conflicts as {id, severity: warning, integrationPackage, integrationType, integrationName, coreMatches, message, command}.',
329
329
  },
330
330
  {
331
331
  value: 'integration.component-conflicts',
332
332
  description:
333
- 'validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and non-blocking conflicts where an integration component name is also owned by Core; each conflict includes the exact package-qualified command.',
333
+ 'The integration identity, structural issues, and non-blocking conflicts where an integration component name is also owned by Core; each conflict includes the exact package-qualified command.',
334
334
  },
335
335
  {
336
336
  value: 'integration.doc-conflicts',
337
337
  description:
338
- 'validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and Core doc overlaps. Each finding includes `severity` (`info` | `error`) and `relationship` (`replaces` | `extends` | `accidental`).',
338
+ 'The integration identity, structural issues, and Core doc overlaps. Each finding includes `severity` (`info` | `error`) and `relationship` (`replaces` | `extends` | `accidental`).',
339
339
  },
340
340
 
341
341
  // layout (XLE/XLO)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.6.5-canary.eb58bba",
3
+ "version": "0.6.5-canary.f261d2f",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -101,10 +101,10 @@
101
101
  "zod": "^4.4.3"
102
102
  },
103
103
  "peerDependencies": {
104
- "@astryxdesign/charts": "0.6.5-canary.eb58bba",
105
- "@astryxdesign/core": "0.6.5-canary.eb58bba",
106
- "@astryxdesign/lab": "0.6.5-canary.eb58bba",
107
- "@astryxdesign/theme-neutral": "0.6.5-canary.eb58bba"
104
+ "@astryxdesign/charts": "0.6.5-canary.f261d2f",
105
+ "@astryxdesign/core": "0.6.5-canary.f261d2f",
106
+ "@astryxdesign/lab": "0.6.5-canary.f261d2f",
107
+ "@astryxdesign/theme-neutral": "0.6.5-canary.f261d2f"
108
108
  },
109
109
  "peerDependenciesMeta": {
110
110
  "@astryxdesign/charts": {
@@ -121,10 +121,10 @@
121
121
  }
122
122
  },
123
123
  "devDependencies": {
124
- "@astryxdesign/charts": "0.6.5-canary.eb58bba",
125
- "@astryxdesign/core": "0.6.5-canary.eb58bba",
126
- "@astryxdesign/lab": "0.6.5-canary.eb58bba",
127
- "@astryxdesign/theme-neutral": "0.6.5-canary.eb58bba",
124
+ "@astryxdesign/charts": "0.6.5-canary.f261d2f",
125
+ "@astryxdesign/core": "0.6.5-canary.f261d2f",
126
+ "@astryxdesign/lab": "0.6.5-canary.f261d2f",
127
+ "@astryxdesign/theme-neutral": "0.6.5-canary.f261d2f",
128
128
  "@heroicons/react": "^2.2.0",
129
129
  "@stylexjs/stylex": "^0.19.0",
130
130
  "@types/babel__core": "^7.20.5",
@@ -1,76 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Colocated tests for the template.show leaf — the source it returns is
5
- * the source template.copy writes. An agent that prints a template and pastes
6
- * it must end up with the same file as one that scaffolds it, demo media
7
- * included (spec:AST-028 FR7).
8
- */
9
-
10
- import {describe, it, expect, beforeAll, afterAll} from 'vitest';
11
- import * as fs from 'node:fs';
12
- import * as os from 'node:os';
13
- import * as path from 'node:path';
14
- import {discoverAll, template} from '../template.mjs';
15
- import {templateCopy} from '../copy/copy.mjs';
16
- import {templateShow} from './show.mjs';
17
-
18
- const SLOW = 60_000;
19
- /** Astryx's demo-media namespace: only its own previews serve these files. */
20
- const FIXTURE = '/template-assets/';
21
- const FIXTURE_IMAGE = /\/template-assets\/[^'"`\s]+\.(png|jpe?g|webp)/i;
22
-
23
- const read = (/** @type {string} */ file) => fs.readFileSync(file, 'utf-8');
24
-
25
- describe('template.show', () => {
26
- /** @type {string} */
27
- let dir;
28
- /** @type {Awaited<ReturnType<typeof discoverAll>>} */
29
- let templates;
30
- beforeAll(async () => {
31
- dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-show-'));
32
- templates = await discoverAll(dir);
33
- }, SLOW);
34
- afterAll(() => fs.rmSync(dir, {recursive: true, force: true}));
35
-
36
- it('returns exactly the source copy writes, for every template', () => {
37
- let withFixtures = 0;
38
- templates.forEach((match, index) => {
39
- if (read(match.filePath).includes(FIXTURE)) withFixtures += 1;
40
- const shown = templateShow(match).data.source;
41
- const copied = templateCopy(match, {targetPath: `out-${index}`, cwd: dir});
42
- const written = read(
43
- path.join(dir, copied.data.outputDir, copied.data.fileName),
44
- );
45
- expect(shown, match.dirName).toBe(written);
46
- });
47
- // The templates with demo media are the ones that used to differ.
48
- expect(withFixtures).toBeGreaterThan(0);
49
- }, SLOW);
50
-
51
- it('reports a replaced count when the source changed, and 0 when it did not', () => {
52
- let reported = 0;
53
- for (const match of templates) {
54
- const raw = read(match.filePath);
55
- const {source, demoMediaReplaced} = templateShow(match).data;
56
- if (source === raw) expect(demoMediaReplaced, match.dirName).toBe(0);
57
- else expect(demoMediaReplaced, match.dirName).toBeGreaterThan(0);
58
- reported += demoMediaReplaced;
59
- }
60
- expect(reported).toBeGreaterThan(0);
61
- }, SLOW);
62
-
63
- it('prints a placeholder where a template shows a demo image', async () => {
64
- const match = templates.find(
65
- t => t.type === 'page' && FIXTURE_IMAGE.test(read(t.filePath)),
66
- );
67
- expect(match).toBeDefined();
68
- if (!match) return;
69
- const res = await template(match.dirName, {type: 'page', cwd: dir});
70
- expect(res.type).toBe('template.show');
71
- if (res.type !== 'template.show') return;
72
- expect(res.data.source).not.toContain(FIXTURE);
73
- expect(res.data.source).toContain('data:image/svg+xml,');
74
- expect(res.data.demoMediaReplaced).toBeGreaterThan(0);
75
- }, SLOW);
76
- });
@@ -1,62 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file `astryx template <name>` says how many demo media references it
5
- * replaced: in `--json` as `demoMediaReplaced`, and in text on stderr, so that
6
- * stdout stays exactly the source a copy writes and can be piped into a file.
7
- */
8
-
9
- import {describe, it, expect, beforeAll, afterAll} from 'vitest';
10
- import * as fs from 'node:fs';
11
- import * as os from 'node:os';
12
- import * as path from 'node:path';
13
- import {runCli} from '../../../test-utils/run-cli.mjs';
14
- import {discoverTemplates} from '../../../api/template/template.mjs';
15
-
16
- const SLOW = 60_000;
17
-
18
- /** A page template whose source carries demo media, and one that carries none. */
19
- async function pickPages() {
20
- const pages = /** @type {Array<{dirName: string, type: string, filePath: string}>} */ (
21
- await discoverTemplates()
22
- ).filter(t => t.type === 'page' && fs.existsSync(t.filePath));
23
- const hasMedia = (/** @type {{filePath: string}} */ t) =>
24
- /\/template-assets\/[\w.-]+\.\w+/.test(fs.readFileSync(t.filePath, 'utf-8'));
25
- const withMedia = pages.find(hasMedia);
26
- const without = pages.find(t => !hasMedia(t));
27
- if (!withMedia || !without) throw new Error('catalog lacks a page with and without demo media');
28
- return {withMedia: withMedia.dirName, without: without.dirName};
29
- }
30
-
31
- describe('template show discloses replaced demo media', () => {
32
- /** @type {string} */
33
- let dir;
34
- beforeAll(() => {
35
- dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-show-cli-'));
36
- });
37
- afterAll(() => fs.rmSync(dir, {recursive: true, force: true}));
38
-
39
- it('--json carries demoMediaReplaced, and text states it on stderr with stdout left as the source', async () => {
40
- const {withMedia} = await pickPages();
41
- const json = await runCli(['template', withMedia, '--type', 'page', '--json'], dir);
42
- expect(json.status).toBe(0);
43
- const {data} = JSON.parse(json.stdout);
44
- expect(data.demoMediaReplaced).toBeGreaterThan(0);
45
-
46
- const human = await runCli(['template', withMedia, '--type', 'page'], dir);
47
- expect(human.status).toBe(0);
48
- expect(human.stdout.trimEnd()).toBe(data.source.trimEnd());
49
- expect(human.stderr).toContain(
50
- `Replaced ${data.demoMediaReplaced} Astryx demo media reference`,
51
- );
52
- }, SLOW);
53
-
54
- it('says nothing about media when none was replaced', async () => {
55
- const {without} = await pickPages();
56
- const json = await runCli(['template', without, '--type', 'page', '--json'], dir);
57
- expect(JSON.parse(json.stdout).data.demoMediaReplaced).toBe(0);
58
- const human = await runCli(['template', without, '--type', 'page'], dir);
59
- expect(human.status).toBe(0);
60
- expect(human.stderr).not.toMatch(/demo media/i);
61
- }, SLOW);
62
- });