@astryxdesign/cli 0.6.5-canary.3f1bee4 → 0.6.5-canary.5d39f31
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.
- package/api/docs/docs.test.mjs +279 -0
- package/api/docs/integration-tree.test.mjs +572 -0
- package/api/docs/integrationDocs.test.mjs +336 -0
- package/api/search/search.test.mjs +710 -0
- package/clients/cli/commands/docs.test.mjs +383 -0
- package/foundation/agent-docs/agent-docs.test.mjs +1160 -0
- package/foundation/doc-compiler/tree.test.mjs +649 -0
- package/package.json +9 -9
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Dispatcher-level tests for docs() — the argument-shape routing that
|
|
5
|
+
* sits above the list/detail/section leaves. The leaves have their own tests;
|
|
6
|
+
* this pins the router: docs() -> list, docs(topic) -> detail,
|
|
7
|
+
* docs(topic, section) -> section, plus the unknown-topic/section error codes.
|
|
8
|
+
* Runs against the real CLI-bundled docs (no cwd/project needed).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {describe, it, expect} from 'vitest';
|
|
12
|
+
import {docs} from './docs.mjs';
|
|
13
|
+
import {AstryxError} from '../error.mjs';
|
|
14
|
+
|
|
15
|
+
const SLOW = 30_000;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The first guide a namespace places, read from the tree rather than named,
|
|
19
|
+
* so a restructure of the guides does not break the reads under test.
|
|
20
|
+
* @param {any} node the data of a docs.node read
|
|
21
|
+
* @returns {string}
|
|
22
|
+
*/
|
|
23
|
+
function placedGuide(node) {
|
|
24
|
+
const guide = node.slots
|
|
25
|
+
.flatMap((/** @type {any} */ slot) => slot.children)
|
|
26
|
+
.find((/** @type {any} */ child) => child.kind === 'generic');
|
|
27
|
+
if (guide == null) throw new Error(`${node.route} places no guide`);
|
|
28
|
+
return guide.route;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('docs() dispatcher routing', () => {
|
|
32
|
+
it('no topic -> docs.list', async () => {
|
|
33
|
+
const r = await docs();
|
|
34
|
+
expect(r.type).toBe('docs.list');
|
|
35
|
+
expect(Array.isArray(r.data)).toBe(true);
|
|
36
|
+
expect(r.data.length).toBeGreaterThan(0);
|
|
37
|
+
}, SLOW);
|
|
38
|
+
|
|
39
|
+
it('empty topic -> docs.list (falsy topic routes to list)', async () => {
|
|
40
|
+
expect((await docs('')).type).toBe('docs.list');
|
|
41
|
+
}, SLOW);
|
|
42
|
+
|
|
43
|
+
it('topic only -> docs.detail, the whole doc', async () => {
|
|
44
|
+
const {data} = await docs();
|
|
45
|
+
expect((await docs(data[0].topic)).type).toBe('docs.detail');
|
|
46
|
+
}, SLOW);
|
|
47
|
+
|
|
48
|
+
it('topic + index -> docs.index', async () => {
|
|
49
|
+
const {data} = await docs();
|
|
50
|
+
const r = await docs(data[0].topic, undefined, {index: true});
|
|
51
|
+
expect(r.type).toBe('docs.index');
|
|
52
|
+
}, SLOW);
|
|
53
|
+
|
|
54
|
+
it('reads a shortened section by its old key, which its title still derives', async () => {
|
|
55
|
+
const r = await docs(
|
|
56
|
+
'styling',
|
|
57
|
+
'stylex-build-setup-required-for-swizzled-components',
|
|
58
|
+
);
|
|
59
|
+
expect(r.type).toBe('docs.detail.section');
|
|
60
|
+
expect(r.data).toMatchObject({id: 'stylex-setup'});
|
|
61
|
+
}, SLOW);
|
|
62
|
+
|
|
63
|
+
it('topic + section -> docs.detail.section', async () => {
|
|
64
|
+
const {data} = await docs();
|
|
65
|
+
let routed = null;
|
|
66
|
+
for (const {topic} of data) {
|
|
67
|
+
const detail = await docs(topic);
|
|
68
|
+
const sections = detail.data.sections;
|
|
69
|
+
if (Array.isArray(sections) && sections.length > 0) {
|
|
70
|
+
routed = await docs(topic, sections[0].title);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
expect(routed).not.toBeNull();
|
|
75
|
+
expect(routed.type).toBe('docs.detail.section');
|
|
76
|
+
}, SLOW);
|
|
77
|
+
|
|
78
|
+
it('unknown topic -> ERR_UNKNOWN_TOPIC', async () => {
|
|
79
|
+
await expect(docs('zzz-not-a-real-topic')).rejects.toBeInstanceOf(AstryxError);
|
|
80
|
+
await expect(docs('zzz-not-a-real-topic')).rejects.toMatchObject({
|
|
81
|
+
code: 'ERR_UNKNOWN_TOPIC',
|
|
82
|
+
});
|
|
83
|
+
}, SLOW);
|
|
84
|
+
|
|
85
|
+
it('known topic + unknown section -> ERR_UNKNOWN_SECTION', async () => {
|
|
86
|
+
const {data} = await docs();
|
|
87
|
+
const topic = data[0].topic;
|
|
88
|
+
await expect(docs(topic, 'zzz-not-a-real-section')).rejects.toMatchObject({
|
|
89
|
+
code: 'ERR_UNKNOWN_SECTION',
|
|
90
|
+
});
|
|
91
|
+
}, SLOW);
|
|
92
|
+
|
|
93
|
+
it("lists the docs tree's namespaces in meta, so every data entry reads as a topic", async () => {
|
|
94
|
+
const res = await docs();
|
|
95
|
+
expect(res.meta.namespaces.map(entry => entry.topic)).toEqual(['cli', 'unorganized']);
|
|
96
|
+
for (const entry of res.data) {
|
|
97
|
+
expect((await docs(entry.topic)).type).toBe('docs.detail');
|
|
98
|
+
}
|
|
99
|
+
}, SLOW);
|
|
100
|
+
|
|
101
|
+
it('opens a route typed in another case', async () => {
|
|
102
|
+
const r = await docs('CLI/API');
|
|
103
|
+
expect(r.type).toBe('docs.node');
|
|
104
|
+
expect(r.data).toMatchObject({route: 'cli/api', links: {up: 'astryx docs cli'}});
|
|
105
|
+
}, SLOW);
|
|
106
|
+
|
|
107
|
+
it('a section of a typed doc -> ERR_UNKNOWN_SECTION, suggesting the doc itself', async () => {
|
|
108
|
+
const err = await docs('cli/api/functions/search', 'x').catch(e => e);
|
|
109
|
+
expect(err.code).toBe('ERR_UNKNOWN_SECTION');
|
|
110
|
+
expect(err.message).toContain('astryx docs cli/api/functions/search');
|
|
111
|
+
expect(err.suggestions.map(s => s.name)).toEqual(['cli/api/functions/search']);
|
|
112
|
+
}, SLOW);
|
|
113
|
+
|
|
114
|
+
it('a namespace route -> docs.node, one level of children', async () => {
|
|
115
|
+
const r = await docs('cli/api');
|
|
116
|
+
expect(r.type).toBe('docs.node');
|
|
117
|
+
expect(r.data).toMatchObject({
|
|
118
|
+
id: 'astryx:artifact:v1/%40astryxdesign%2Fcli/namespace/api',
|
|
119
|
+
route: 'cli/api',
|
|
120
|
+
kind: 'namespace',
|
|
121
|
+
package: '@astryxdesign/cli',
|
|
122
|
+
breadcrumb: [{route: 'cli', title: 'Astryx CLI'}],
|
|
123
|
+
content: [],
|
|
124
|
+
});
|
|
125
|
+
expect(r.data.slots.flatMap(slot => slot.children.map(c => c.route))).toEqual([
|
|
126
|
+
'cli/api/functions',
|
|
127
|
+
'cli/api/schemas',
|
|
128
|
+
'cli/api/enums',
|
|
129
|
+
]);
|
|
130
|
+
}, SLOW);
|
|
131
|
+
|
|
132
|
+
it('a typed doc route -> docs.node with its content', async () => {
|
|
133
|
+
const r = await docs('cli/api/functions/search');
|
|
134
|
+
expect(r.type).toBe('docs.node');
|
|
135
|
+
expect(r.data).toMatchObject({
|
|
136
|
+
id: 'astryx:artifact:v1/%40astryxdesign%2Fcli/function/search',
|
|
137
|
+
kind: 'function',
|
|
138
|
+
title: 'search()',
|
|
139
|
+
slots: [],
|
|
140
|
+
});
|
|
141
|
+
expect(r.data.breadcrumb.map(link => link.route)).toEqual([
|
|
142
|
+
'cli',
|
|
143
|
+
'cli/api',
|
|
144
|
+
'cli/api/functions',
|
|
145
|
+
]);
|
|
146
|
+
expect(JSON.stringify(r.data.content)).toContain(
|
|
147
|
+
'`astryx search` runs it. Read it with `astryx docs cli/commands/search`.',
|
|
148
|
+
);
|
|
149
|
+
}, SLOW);
|
|
150
|
+
|
|
151
|
+
it('a guide the tree places reads like a topic: the whole doc, its index, a section', async () => {
|
|
152
|
+
// cli/integrations is a namespace of short guides; each guide reads like a topic.
|
|
153
|
+
const integrations = await docs('cli/integrations');
|
|
154
|
+
expect(integrations.type).toBe('docs.node');
|
|
155
|
+
const guide = placedGuide(integrations.data);
|
|
156
|
+
expect((await docs(guide)).type).toBe('docs.detail');
|
|
157
|
+
const index = await docs(guide, undefined, {index: true});
|
|
158
|
+
expect(index).toMatchObject({type: 'docs.index', data: {name: guide}});
|
|
159
|
+
expect(index.data.sections.length).toBeGreaterThan(1);
|
|
160
|
+
expect((await docs(guide, index.data.sections[0].id)).type).toBe(
|
|
161
|
+
'docs.detail.section',
|
|
162
|
+
);
|
|
163
|
+
}, SLOW);
|
|
164
|
+
|
|
165
|
+
it('every read carries its moves (spec:AST-047)', async () => {
|
|
166
|
+
const root = (await docs('cli')).data;
|
|
167
|
+
expect(root.links).toEqual({up: 'astryx docs'});
|
|
168
|
+
const leaf = (await docs('cli/api/functions/search')).data;
|
|
169
|
+
expect(leaf.links.up).toBe('astryx docs cli/api/functions');
|
|
170
|
+
expect(leaf.links.previous).toMatch(/^astryx docs cli\/api\/functions\/[a-z-]+$/);
|
|
171
|
+
expect(leaf.links.next).toMatch(/^astryx docs cli\/api\/functions\/[a-z-]+$/);
|
|
172
|
+
const integrations = (await docs('cli/integrations')).data;
|
|
173
|
+
const guide = placedGuide(integrations);
|
|
174
|
+
const siblings = integrations.slots
|
|
175
|
+
.find(slot => slot.children.some(child => child.route === guide))
|
|
176
|
+
.children.map(child => child.route);
|
|
177
|
+
const at = siblings.indexOf(guide);
|
|
178
|
+
const index = await docs(guide, undefined, {index: true});
|
|
179
|
+
// A guide moves across its namespace's slot, as any tree node does.
|
|
180
|
+
expect(index.data.links).toEqual({
|
|
181
|
+
up: 'astryx docs cli/integrations',
|
|
182
|
+
...(at > 0 ? {previous: `astryx docs ${siblings[at - 1]}`} : {}),
|
|
183
|
+
...(at < siblings.length - 1
|
|
184
|
+
? {next: `astryx docs ${siblings[at + 1]}`}
|
|
185
|
+
: {}),
|
|
186
|
+
});
|
|
187
|
+
const first = (await docs(guide, index.data.sections[0].id)).data;
|
|
188
|
+
expect(first.links).toEqual({
|
|
189
|
+
up: `astryx docs ${guide} --index`,
|
|
190
|
+
next: `astryx docs ${guide} ${index.data.sections[1].id}`,
|
|
191
|
+
});
|
|
192
|
+
const last = index.data.sections.at(-1).id;
|
|
193
|
+
const end = (await docs(guide, last)).data;
|
|
194
|
+
expect(end.links.next).toBeUndefined();
|
|
195
|
+
expect(end.links.previous).toBe(
|
|
196
|
+
`astryx docs ${guide} ${index.data.sections.at(-2).id}`,
|
|
197
|
+
);
|
|
198
|
+
// A flat topic's home is the Unorganized level, and it moves across it.
|
|
199
|
+
const flat = (await docs('principles')).data.links;
|
|
200
|
+
expect(flat.up).toBe('astryx docs unorganized');
|
|
201
|
+
expect(flat.previous).toMatch(/^astryx docs [a-z-]+$/);
|
|
202
|
+
expect(flat.next).toMatch(/^astryx docs [a-z-]+$/);
|
|
203
|
+
const home = (await docs('unorganized')).data;
|
|
204
|
+
expect(home).toMatchObject({id: null, kind: 'namespace', links: {up: 'astryx docs'}});
|
|
205
|
+
expect(home.slots[0].children.map(child => child.route)).toEqual(
|
|
206
|
+
(await docs()).data.map(entry => entry.topic),
|
|
207
|
+
);
|
|
208
|
+
}, SLOW);
|
|
209
|
+
|
|
210
|
+
it('names a node by its doc identity; a generated level has id null', async () => {
|
|
211
|
+
const level = (await docs('cli/api/functions')).data;
|
|
212
|
+
expect(level).toHaveProperty('id', null);
|
|
213
|
+
expect(level.route).toBe('cli/api/functions');
|
|
214
|
+
}, SLOW);
|
|
215
|
+
|
|
216
|
+
it("offers a typed doc's related docs as moves", async () => {
|
|
217
|
+
const fn = (await docs('cli/api/functions/search')).data;
|
|
218
|
+
expect(fn.links.related).toContain('astryx docs cli/commands/search');
|
|
219
|
+
const cmd = (await docs('cli/commands/search')).data;
|
|
220
|
+
expect(cmd.links.related).toContain('astryx docs cli/api/functions/search');
|
|
221
|
+
}, SLOW);
|
|
222
|
+
|
|
223
|
+
it('a topic read returns the whole doc; index returns its sections', async () => {
|
|
224
|
+
expect((await docs('principles')).type).toBe('docs.detail');
|
|
225
|
+
const index = await docs('principles', undefined, {index: true});
|
|
226
|
+
expect(index.type).toBe('docs.index');
|
|
227
|
+
expect(index.data.sections.length).toBeGreaterThan(1);
|
|
228
|
+
expect((await docs('principles', undefined, {dense: true})).type).toBe(
|
|
229
|
+
'docs.detail',
|
|
230
|
+
);
|
|
231
|
+
}, SLOW);
|
|
232
|
+
|
|
233
|
+
it("the guide's old flat name is gone, and its error names the new route", async () => {
|
|
234
|
+
await expect(docs('cli-integrations')).rejects.toMatchObject({
|
|
235
|
+
code: 'ERR_UNKNOWN_TOPIC',
|
|
236
|
+
suggestions: [expect.objectContaining({name: 'cli/integrations'})],
|
|
237
|
+
});
|
|
238
|
+
expect((await docs()).data.map(entry => entry.topic)).not.toContain(
|
|
239
|
+
'cli-integrations',
|
|
240
|
+
);
|
|
241
|
+
}, SLOW);
|
|
242
|
+
|
|
243
|
+
it('a section of a namespace -> ERR_UNKNOWN_SECTION, naming its children', async () => {
|
|
244
|
+
const err = await docs('cli', 'commands').catch(e => e);
|
|
245
|
+
expect(err).toBeInstanceOf(AstryxError);
|
|
246
|
+
expect(err.code).toBe('ERR_UNKNOWN_SECTION');
|
|
247
|
+
// It names the namespace's children, in the order its slots list them.
|
|
248
|
+
const cli = (await docs('cli')).data;
|
|
249
|
+
expect(err.suggestions.map(s => s.name)).toEqual(
|
|
250
|
+
cli.slots.flatMap(slot => slot.children.map(child => child.route)),
|
|
251
|
+
);
|
|
252
|
+
expect(err.suggestions.map(s => s.name)).toContain('cli/commands');
|
|
253
|
+
}, SLOW);
|
|
254
|
+
|
|
255
|
+
it('an unknown route suggests the children of the deepest namespace it reaches', async () => {
|
|
256
|
+
const err = await docs('cli/api/functions/serch').catch(e => e);
|
|
257
|
+
expect(err.code).toBe('ERR_UNKNOWN_TOPIC');
|
|
258
|
+
expect(err.suggestions.map(s => s.name)).toContain('cli/api/functions/search');
|
|
259
|
+
expect(err.suggestions.every(s => s.name.startsWith('cli/api/functions/'))).toBe(true);
|
|
260
|
+
}, SLOW);
|
|
261
|
+
|
|
262
|
+
it('non-string topic -> ERR_UNKNOWN_TOPIC (not a raw TypeError)', async () => {
|
|
263
|
+
for (const bad of [123, {}, ['tokens'], true]) {
|
|
264
|
+
const err = await docs(/** @type {any} */ (bad)).catch(e => e);
|
|
265
|
+
expect(err).toBeInstanceOf(AstryxError);
|
|
266
|
+
expect(err.code).toBe('ERR_UNKNOWN_TOPIC');
|
|
267
|
+
}
|
|
268
|
+
}, SLOW);
|
|
269
|
+
|
|
270
|
+
it('non-string section -> ERR_UNKNOWN_SECTION (not a raw TypeError)', async () => {
|
|
271
|
+
const {data} = await docs();
|
|
272
|
+
const topic = data[0].topic;
|
|
273
|
+
for (const bad of [456, {}, ['x']]) {
|
|
274
|
+
const err = await docs(topic, /** @type {any} */ (bad)).catch(e => e);
|
|
275
|
+
expect(err).toBeInstanceOf(AstryxError);
|
|
276
|
+
expect(err.code).toBe('ERR_UNKNOWN_SECTION');
|
|
277
|
+
}
|
|
278
|
+
}, SLOW);
|
|
279
|
+
});
|