@astryxdesign/cli 0.6.5-canary.3f1bee4 → 0.6.5-canary.5d9940d
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/README.md +14 -13
- 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/error.d.mts +22 -0
- package/api/error.mjs +42 -0
- package/api/integration/add-contribution.d.mts +2 -1
- package/api/integration/add-contribution.mjs +7 -3
- package/api/integration/add-contribution.test.mjs +3 -3
- package/api/integration/add-theme.mjs +243 -22
- package/api/integration/add-theme.test.mjs +213 -0
- package/api/integration/authoring-checks.mjs +10 -7
- package/api/integration/authoring-checks.type.d.mts +8 -0
- package/api/integration/authoring-checks.type.mjs +7 -3
- package/api/integration/integration-authoring.type.d.mts +4 -1
- package/api/integration/integration-authoring.type.mjs +6 -1
- package/api/integration/integrationAdd.doc.mjs +6 -0
- package/api/integration/integrationAddTheme.doc.mjs +10 -0
- package/api/integration/integrationComponentConflicts.doc.mjs +1 -1
- package/api/integration/integrationDocConflicts.doc.mjs +1 -1
- package/api/integration/integrationTemplateConflicts.doc.mjs +1 -1
- package/api/integration/pack-check.test.mjs +7 -1
- package/api/integration/validate-integration.d.mts +4 -2
- package/api/integration/validate-integration.mjs +7 -2
- package/api/integration/validate-integration.test.mjs +55 -0
- package/api/integration/validate-integration.type.d.mts +5 -0
- package/api/integration/validate-integration.type.mjs +5 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/layout/expand/expand.mjs +12 -7
- package/api/layout/expand/expand.receipt.test.mjs +74 -0
- package/api/layout/layout.type.d.mts +1 -0
- package/api/layout/layout.type.mjs +1 -0
- package/api/layout/layoutExpand.doc.mjs +1 -1
- package/api/search/search.test.mjs +710 -0
- package/api/swizzle/copy/copy.mjs +66 -3
- package/api/swizzle/swizzle.doc.mjs +4 -0
- package/api/template/copy/copy.mjs +14 -8
- package/api/template/copy/copy.receipt.test.mjs +77 -0
- package/api/template/show/show.mjs +15 -4
- package/api/template/show/show.test.mjs +76 -0
- package/api/template/template.d.mts +1 -1
- package/api/template/template.doc.mjs +6 -2
- package/api/template/template.mjs +1 -0
- package/api/template/template.type.d.mts +2 -0
- package/api/template/template.type.mjs +2 -0
- package/api/theme/build/build.d.mts +24 -0
- package/api/theme/build/build.mjs +235 -8
- package/api/theme/build/build.project-core.test.mjs +165 -0
- package/api/upgrade/run/run.mjs +20 -3
- package/api/upgrade/run/run.test.mjs +45 -1
- package/api/upgrade/upgrade.doc.mjs +1 -1
- package/api/upgrade/upgrade.type.d.mts +1 -0
- package/api/upgrade/upgrade.type.mjs +1 -0
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
- package/assets/docs/tree/versioning.doc.mjs +4 -4
- package/clients/cli/commands/docs.test.mjs +383 -0
- package/clients/cli/commands/doctor.mjs +4 -4
- package/clients/cli/commands/integration-add.doc.mjs +10 -0
- package/clients/cli/commands/integration-authoring.test.mjs +12 -2
- package/clients/cli/commands/integration.mjs +3 -1
- package/clients/cli/commands/layout-expand.doc.mjs +3 -1
- package/clients/cli/commands/layout.expand-receipt.test.mjs +94 -0
- package/clients/cli/commands/layout.mjs +16 -0
- package/clients/cli/commands/template.copy-receipt.test.mjs +60 -0
- package/clients/cli/commands/template.mjs +19 -5
- package/clients/cli/commands/template.show-media.test.mjs +62 -0
- package/clients/cli/commands/upgrade.ascii-output.test.mjs +14 -0
- package/clients/cli/commands/write-failure.test.mjs +175 -0
- package/clients/cli/lib/manifest.mjs +44 -165
- package/clients/cli/lib/manifest.test.mjs +98 -7
- package/foundation/agent-docs/agent-docs.test.mjs +1160 -0
- package/foundation/discovery/template-adapter.d.mts +13 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +16 -1
- package/foundation/doc-compiler/doc-loads.test.mjs +2 -2
- package/foundation/doc-compiler/tree.test.mjs +649 -0
- package/foundation/integrations/cli-requirement.d.mts +14 -11
- package/foundation/integrations/cli-requirement.mjs +24 -19
- package/foundation/integrations/cli-requirement.test.mjs +60 -16
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +13 -13
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -303,11 +303,12 @@ Shape:
|
|
|
303
303
|
```
|
|
304
304
|
|
|
305
305
|
The manifest is **derived from Commander metadata** (commands, arguments, options)
|
|
306
|
-
so it can't drift from the real command definitions. The
|
|
307
|
-
|
|
308
|
-
the
|
|
309
|
-
|
|
310
|
-
|
|
306
|
+
so it can't drift from the real command definitions. The facts Commander doesn't
|
|
307
|
+
track come from each command's docs: examples from its CommandDoc, and emitted
|
|
308
|
+
response types from the returns of the FunctionDoc it wraps (plus the few
|
|
309
|
+
envelopes the CLI layer builds itself). `--json` support comes from the
|
|
310
|
+
`JSON_SUPPORTED` allowlist. Drift tests (`manifest.test.mjs`) fail CI when a
|
|
311
|
+
command is added without describing it.
|
|
311
312
|
|
|
312
313
|
**Backwards-compat:** the bare `astryx --json` envelope keeps `type: "help"` and its
|
|
313
314
|
original shallow fields (`name`, `version`, `commands` as a `string[]` of names,
|
|
@@ -450,9 +451,9 @@ Every response has a `type` discriminant. The full set is below (generated from
|
|
|
450
451
|
| `gap-report.categories` | The fixed gap category values and human-readable labels. |
|
|
451
452
|
| `gap-report.file` | An aggregate receipt: overall status, the selected package, issuesUrl (or null), deliveries in handler order, each {handlerType: project \| integration \| fallback, handler, audience, status, url, message}, and filedCount/routedOnlyCount totals. |
|
|
452
453
|
| `template.list` | The effective discovered TemplateListEntry[] for pages and blocks. A winning replacement entry includes optional `replaces`, naming the Core id omitted from the default list. |
|
|
453
|
-
| `template.show` | The resolved template's
|
|
454
|
+
| `template.show` | 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). |
|
|
454
455
|
| `template.skeleton` | A layout skeleton (structural tags with spatial annotations) plus the template's description and the components it composes. |
|
|
455
|
-
| `template.copy` | A scaffold receipt: template id, output directory, written file name, and
|
|
456
|
+
| `template.copy` | A scaffold receipt: template id, output directory, written file name, file count, and demoMediaReplaced (how many Astryx demo media references were replaced with placeholders for you to swap for your own media). |
|
|
456
457
|
| `template.cdn` | A write receipt for the no-build-step CDN starter page: the path (relative to cwd), the Astryx version every CDN URL was pinned to, whether it was written, and the reason it was not. `exists` when a file was already there, which is a success. |
|
|
457
458
|
| `hook.list` | The hook catalog grouped by category: `detail` (the level: names \| compact \| full) and `components`, the grouped map of hook names, brief entries, or a full HookDoc per entry. |
|
|
458
459
|
| `hook.detail` | One hook's full authored HookDoc. |
|
|
@@ -468,18 +469,18 @@ Every response has a `type` discriminant. The full set is below (generated from
|
|
|
468
469
|
| `upgrade.list` | Every available codemod, oldest→newest, as {name, title, version, optional}; returned for --list without running anything. |
|
|
469
470
|
| `upgrade.registry` | The copied-composition receipt for --registry: applied, ok, the counts (found, current, wouldUpdate, updated, wouldMerge, merged, wouldRefreshReceipt, receiptsRefreshed, conflicts, missing, invalid, failed), and items. |
|
|
470
471
|
| `upgrade.status` | A short-circuit outcome with no codemods run (up_to_date, no_codemods, or config_fixable), each carrying the agent-docs summary. |
|
|
471
|
-
| `upgrade.run` | The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, and (apply mode) filesChanged, transformsApplied, and per-codemod errors.
|
|
472
|
+
| `upgrade.run` | 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. |
|
|
472
473
|
| `manifest` | The CLI capability manifest: name, version, apiVersion, description, globalOptions, commands (each name, description, arguments, options, json, aliases?, responseTypes?, examples?, exitCodes? as [{code, when}], subcommands?), jsonSupported, and the flat responseTypes index. |
|
|
473
474
|
| `help` | Help, in one of two shapes. A bare `astryx --json` returns the root manifest: name, version, commands (the command names), jsonSupported, and manifest (the full payload `astryx manifest --json` returns). `--help --json` on any command, or `astryx help [command] --json`, returns that command's help: command, description, usage, options (each flags, description, and defaultValue and choices when set), and subcommands (each name and description). data.manifest marks the first shape; data.usage marks the second. |
|
|
474
475
|
| `version` | The CLI version, for `astryx --version --json`: {version}. |
|
|
475
476
|
| `doctor` | The health-check report: `checks` (each with id, label, status: pass \| warn \| fail \| info, a message, and an optional fix, always present on warn and fail) plus a `summary` of counts per status. |
|
|
476
477
|
| `integration.add` | A contribution-writer receipt: kind, name, optional root {path, created}, integration-manifest path, every affected project-relative path, written, and dryRun. |
|
|
477
478
|
| `integration.pack-check` | The packed-package check: name, version, packable, tarball {filename, fileCount, size, unpackedSize} or null, inventory {manifest, roots [{kind, path, expectedFiles, missingFiles, complete}], expectedFiles, packedFiles}, contributions {local, packed}, each null or {themes [{slug, exportName}], components, templates [{id, type, name}], codemods [{version, id}], docs, agentDocsAppend}, and issues [{code, severity, message}]. |
|
|
478
|
-
| `integration.validate` | The validation result: the package name and version (both null when
|
|
479
|
-
| `integration.template-conflicts` |
|
|
480
|
-
| `integration.component-conflicts` |
|
|
481
|
-
| `integration.doc-conflicts` |
|
|
482
|
-
| `layout.expand` | The expansion: parsed form, generated TSX code, componentsUsed, states (count of useState hooks scaffolded), todos, blocksReferenced (each {name, mode}), warnings,
|
|
479
|
+
| `integration.validate` | 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}. |
|
|
480
|
+
| `integration.template-conflicts` | 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}. |
|
|
481
|
+
| `integration.component-conflicts` | 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. |
|
|
482
|
+
| `integration.doc-conflicts` | 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`). |
|
|
483
|
+
| `layout.expand` | The expansion: parsed form, generated TSX code, componentsUsed, states (count of useState hooks scaffolded), todos, blocksReferenced (each {name, mode}), warnings, written (the output path, or null when nothing was written), and demoMediaReplaced (count of demo media placeholders). |
|
|
483
484
|
| `layout.check` | The validation result: a valid flag, the detected form, errors (each with line/col, message, formatted text, and suggestions), warnings, and the expression re-printed in both canonical surfaces (compact and outline). |
|
|
484
485
|
| `layout.grammar` | The XLE/XLO grammar cheatsheet: a text field with the full reference plus an aliases map (short name → canonical component) generated from this install's registry. |
|
|
485
486
|
|
|
@@ -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
|
+
});
|