@astryxdesign/cli 0.6.3-canary.29be688 → 0.6.3-canary.2bb99ed
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 +2 -0
- package/api/docs/detail/section/section.mjs +9 -15
- package/api/docs/detail/section/section.test.mjs +15 -6
- package/api/doctor/doctor.mjs +1 -1
- package/api/doctor/doctor.test.mjs +6 -6
- package/api/upgrade/_adapter.d.mts +22 -4
- package/api/upgrade/_adapter.mjs +19 -6
- package/api/upgrade/run/run.mjs +355 -59
- package/api/upgrade/upgrade.doc.mjs +5 -1
- package/api/upgrade/upgrade.type.d.mts +34 -0
- package/api/upgrade/upgrade.type.mjs +15 -0
- package/assets/codemods/__tests__/runner.test.mjs +330 -8
- package/assets/codemods/integration-runner.mjs +56 -4
- package/assets/codemods/integration-runner.protection.test.mjs +153 -0
- package/assets/codemods/run-codemod.mjs +177 -34
- package/assets/codemods/runner.mjs +248 -110
- package/assets/codemods/transforms/next/__tests__/migrate-native-picker-to-presentation.test.mjs +63 -0
- package/assets/codemods/transforms/next/__tests__/migrate-theme-catalog-to-descriptors.test.mjs +4 -0
- package/assets/codemods/transforms/next/index.mjs +8 -0
- package/assets/codemods/transforms/next/migrate-native-picker-to-presentation.mjs +148 -0
- package/assets/docs/cli-integrations.doc.mjs +13 -0
- package/assets/templates/blocks/components/DateInput/DateInputDateRange.tsx +1 -1
- package/assets/templates/blocks/components/Item/ItemDocumentTabs.doc.mjs +14 -0
- package/assets/templates/blocks/components/Item/ItemDocumentTabs.tsx +100 -0
- package/assets/templates/blocks/components/TimeInput/TimeInputConstrained.tsx +1 -0
- package/authoring/codemod/type.ts +12 -0
- package/authoring/doctypes/_schema.d.mts +71 -141
- package/authoring/doctypes/_schema.mjs +29 -2
- package/authoring/doctypes/load-contract.test.mjs +1 -1
- package/authoring/doctypes/namespace/namespace.doc.mjs +2 -2
- package/authoring/doctypes/namespace/parse.test.mjs +23 -25
- package/authoring/doctypes/namespace/type.ts +5 -2
- package/authoring/doctypes/parse.mjs +3 -2
- package/authoring/doctypes/reference/reference.doc.mjs +5 -3
- package/authoring/doctypes/reference/type.ts +7 -8
- package/authoring/index.d.ts +1 -0
- package/clients/cli/commands/build-theme.mjs +10 -44
- package/clients/cli/commands/docs.mjs +15 -58
- package/clients/cli/commands/docs.test.mjs +11 -14
- package/clients/cli/commands/text-json-parity.test.mjs +718 -0
- package/clients/cli/commands/theme-targets.behavior.test.mjs +4 -3
- package/clients/cli/commands/upgrade.doc.mjs +2 -1
- package/clients/cli/commands/upgrade.file-protection.test.mjs +228 -0
- package/clients/cli/commands/upgrade.mjs +29 -7
- package/clients/cli/formatters/index.mjs +2 -0
- package/clients/cli/formatters/index.test.mjs +6 -0
- package/foundation/discovery/authoring-self-docs.test.mjs +3 -2
- package/foundation/discovery/docs-discovery.mjs +6 -5
- package/foundation/discovery/docs-discovery.test.mjs +7 -10
- package/foundation/discovery/docs-section-key.d.mts +19 -8
- package/foundation/discovery/docs-section-key.mjs +119 -32
- package/foundation/discovery/docs-section-key.test.mjs +41 -19
- package/foundation/doc-compiler/compile.mjs +5 -4
- package/foundation/fs/file-protection.d.mts +33 -0
- package/foundation/fs/file-protection.mjs +825 -0
- package/foundation/fs/file-protection.test.mjs +250 -0
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +2 -0
- package/foundation/response/error-codes.doc.mjs +10 -0
- package/foundation/response/error-codes.mjs +6 -0
- package/foundation/response/error-codes.test.mjs +55 -11
- package/package.json +10 -9
|
@@ -17,8 +17,9 @@ describe('astryx theme targets', () => {
|
|
|
17
17
|
const {status, stdout} = await runCli(['theme', 'targets', 'Switch']);
|
|
18
18
|
|
|
19
19
|
expect(status).toBe(0);
|
|
20
|
-
|
|
21
|
-
expect(stdout).toMatch(/^switch
|
|
20
|
+
// Inline layout: key component - props - states - className
|
|
21
|
+
expect(stdout).toMatch(/^switch\s+Switch - size - checked, disabled - astryx-switch$/m);
|
|
22
|
+
expect(stdout).toMatch(/^switch-thumb\s+Switch - size - checked - astryx-switch-thumb$/m);
|
|
22
23
|
expect(stdout).toMatch(/4 across 1 component/);
|
|
23
24
|
});
|
|
24
25
|
|
|
@@ -28,7 +29,7 @@ describe('astryx theme targets', () => {
|
|
|
28
29
|
expect(status).toBe(0);
|
|
29
30
|
expect(stdout).toMatch(/^popover\s{2,}Popover/m);
|
|
30
31
|
expect(stdout).toMatch(
|
|
31
|
-
/^popover-surface
|
|
32
|
+
/^popover-surface\s{2,}Popover - astryx-popover-surface - deprecated; use popover$/m,
|
|
32
33
|
);
|
|
33
34
|
});
|
|
34
35
|
|
|
@@ -101,13 +101,14 @@ export const doc = {
|
|
|
101
101
|
{label: 'Apply a migration', cli: 'astryx upgrade --from 0.1.0 --apply'},
|
|
102
102
|
],
|
|
103
103
|
exitCodes: [
|
|
104
|
-
{code: 0, when: 'success
|
|
104
|
+
{code: 0, when: 'success, including complete dry-run previews'},
|
|
105
105
|
{
|
|
106
106
|
code: 1,
|
|
107
107
|
when:
|
|
108
108
|
'missing or invalid --from, --registry with --list or a migration flag, a --path escape, ' +
|
|
109
109
|
'no installed @astryxdesign/core (or legacy @xds/core), jscodeshift missing and not installed by --install-deps, ' +
|
|
110
110
|
'an astryx.config that fails validation and that no pending config codemod repairs, ' +
|
|
111
|
+
'an unreadable or invalid protection declaration, a protected file that still requires a codemod change, ' +
|
|
111
112
|
'an unknown codemod, a codemod or post-codemod hook failure, or unresolved registry items',
|
|
112
113
|
},
|
|
113
114
|
],
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file End-to-end protection and regeneration behavior for `astryx upgrade`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {afterEach, beforeEach, describe, expect, it} from 'vitest';
|
|
8
|
+
import {spawnSync} from 'node:child_process';
|
|
9
|
+
import * as fs from 'node:fs';
|
|
10
|
+
import * as os from 'node:os';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import {fileURLToPath} from 'node:url';
|
|
13
|
+
|
|
14
|
+
const CLI = path.resolve(
|
|
15
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
16
|
+
'..',
|
|
17
|
+
'bin',
|
|
18
|
+
'astryx.mjs',
|
|
19
|
+
);
|
|
20
|
+
let root;
|
|
21
|
+
|
|
22
|
+
function write(relative, contents) {
|
|
23
|
+
const file = path.join(root, relative);
|
|
24
|
+
fs.mkdirSync(path.dirname(file), {recursive: true});
|
|
25
|
+
fs.writeFileSync(file, contents);
|
|
26
|
+
return file;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function run(args) {
|
|
30
|
+
const result = spawnSync(
|
|
31
|
+
process.execPath,
|
|
32
|
+
[CLI, '--json', 'upgrade', ...args],
|
|
33
|
+
{
|
|
34
|
+
cwd: root,
|
|
35
|
+
encoding: 'utf8',
|
|
36
|
+
timeout: 60_000,
|
|
37
|
+
env: {...process.env, FORCE_COLOR: '0', CI: ''},
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
return {...result, envelope: JSON.parse(result.stdout)};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function seed({hook = false} = {}) {
|
|
44
|
+
write('package.json', JSON.stringify({name: 'consumer', private: true}));
|
|
45
|
+
write(
|
|
46
|
+
'node_modules/@astryxdesign/core/package.json',
|
|
47
|
+
JSON.stringify({name: '@astryxdesign/core', version: '0.6.0'}),
|
|
48
|
+
);
|
|
49
|
+
write('.gitattributes', 'generated/** linguist-generated=true\n');
|
|
50
|
+
const source =
|
|
51
|
+
"import {useResizable} from '@astryxdesign/core';\n" +
|
|
52
|
+
'export const usePanel = () => useResizable({minSizePx: 200});\n';
|
|
53
|
+
write('src/owned.tsx', source);
|
|
54
|
+
write('generated/panel.tsx', `// @generated\n${source}`);
|
|
55
|
+
write(
|
|
56
|
+
'astryx.config.mjs',
|
|
57
|
+
hook
|
|
58
|
+
? `export default {hooks: {postCodemod: [{name: 'regenerate', buildCommand: () => ({command: process.execPath, args: ['-e', ${JSON.stringify("const fs=require('node:fs');const p='generated/panel.tsx';const s=fs.readFileSync(p,'utf8');fs.writeFileSync(p,s.replaceAll('minSizePx','minSize')); ")} ]})}]}};\n`
|
|
59
|
+
: 'export default {};\n',
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
root = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-protected-upgrade-'));
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
afterEach(() => {
|
|
68
|
+
fs.rmSync(root, {recursive: true, force: true});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const ARGS = [
|
|
72
|
+
'--from',
|
|
73
|
+
'0.5.0',
|
|
74
|
+
'--codemod',
|
|
75
|
+
'rename-resizable-pixel-bounds',
|
|
76
|
+
'--path',
|
|
77
|
+
'.',
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
describe('upgrade protected-file contract', () => {
|
|
81
|
+
it('reports the same protected candidate in dry-run and apply while retaining owned edits', () => {
|
|
82
|
+
seed();
|
|
83
|
+
|
|
84
|
+
const dry = run(ARGS);
|
|
85
|
+
expect(dry.status).toBe(1);
|
|
86
|
+
expect(dry.envelope).toMatchObject({
|
|
87
|
+
type: 'upgrade.run',
|
|
88
|
+
data: {
|
|
89
|
+
complete: false,
|
|
90
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
91
|
+
modifiedFiles: ['src/owned.tsx'],
|
|
92
|
+
protectedFiles: [
|
|
93
|
+
{
|
|
94
|
+
file: 'generated/panel.tsx',
|
|
95
|
+
reasons: ['generated'],
|
|
96
|
+
declarations: expect.arrayContaining([
|
|
97
|
+
'linguist-generated in .gitattributes:1',
|
|
98
|
+
'@generated in the leading comment block',
|
|
99
|
+
]),
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
expect(fs.readFileSync(path.join(root, 'src/owned.tsx'), 'utf8')).toContain(
|
|
105
|
+
'minSizePx',
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const applied = run([...ARGS, '--apply']);
|
|
109
|
+
expect(applied.status).toBe(1);
|
|
110
|
+
expect(applied.envelope.data.protectedFiles).toEqual(
|
|
111
|
+
dry.envelope.data.protectedFiles,
|
|
112
|
+
);
|
|
113
|
+
expect(fs.readFileSync(path.join(root, 'src/owned.tsx'), 'utf8')).toContain(
|
|
114
|
+
'minSize: 200',
|
|
115
|
+
);
|
|
116
|
+
expect(
|
|
117
|
+
fs.readFileSync(path.join(root, 'generated/panel.tsx'), 'utf8'),
|
|
118
|
+
).toContain('minSizePx');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('preserves a protected config migration when strict config loading fails', () => {
|
|
122
|
+
write('package.json', JSON.stringify({name: 'consumer', private: true}));
|
|
123
|
+
write(
|
|
124
|
+
'node_modules/@astryxdesign/core/package.json',
|
|
125
|
+
JSON.stringify({name: '@astryxdesign/core', version: '0.1.3'}),
|
|
126
|
+
);
|
|
127
|
+
write(
|
|
128
|
+
'astryx.config.mjs',
|
|
129
|
+
`// @generated\nexport default {layout: {components: {KpiCard: '@/KpiCard'}}};\n`,
|
|
130
|
+
);
|
|
131
|
+
write('src/index.ts', 'export {};\n');
|
|
132
|
+
|
|
133
|
+
const result = run([
|
|
134
|
+
'--from',
|
|
135
|
+
'0.1.2',
|
|
136
|
+
'--codemod',
|
|
137
|
+
'migrate-layout-components-to-experimental',
|
|
138
|
+
'--path',
|
|
139
|
+
'src',
|
|
140
|
+
'--apply',
|
|
141
|
+
]);
|
|
142
|
+
|
|
143
|
+
expect(result.status).toBe(1);
|
|
144
|
+
expect(result.envelope).toMatchObject({
|
|
145
|
+
type: 'upgrade.run',
|
|
146
|
+
data: {
|
|
147
|
+
complete: false,
|
|
148
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
149
|
+
protectedFiles: [expect.objectContaining({file: 'astryx.config.mjs'})],
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
expect(
|
|
153
|
+
fs.readFileSync(path.join(root, 'astryx.config.mjs'), 'utf8'),
|
|
154
|
+
).toContain('layout');
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('fails before writes when a protection declaration cannot be parsed', () => {
|
|
158
|
+
seed();
|
|
159
|
+
write('.hgignore', 'syntax: regexp\n[bad\n');
|
|
160
|
+
|
|
161
|
+
const result = run([...ARGS, '--apply']);
|
|
162
|
+
|
|
163
|
+
expect(result.status).toBe(1);
|
|
164
|
+
expect(result.envelope).toMatchObject({
|
|
165
|
+
code: 'ERR_CODEMOD_PROTECTION_SOURCE',
|
|
166
|
+
});
|
|
167
|
+
expect(result.envelope.error).toContain('.hgignore');
|
|
168
|
+
expect(fs.readFileSync(path.join(root, 'src/owned.tsx'), 'utf8')).toContain(
|
|
169
|
+
'minSizePx',
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('preserves protected-file facts when regeneration fails', () => {
|
|
174
|
+
seed();
|
|
175
|
+
write(
|
|
176
|
+
'astryx.config.mjs',
|
|
177
|
+
`export default {hooks: {postCodemod: [{name: 'regenerate', buildCommand: () => ({command: process.execPath, args: ['-e', 'process.exit(7)']})}]}};\n`,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const applied = run([...ARGS, '--apply']);
|
|
181
|
+
|
|
182
|
+
expect(applied.status).toBe(1);
|
|
183
|
+
expect(applied.envelope).toMatchObject({
|
|
184
|
+
type: 'upgrade.run',
|
|
185
|
+
data: {
|
|
186
|
+
complete: false,
|
|
187
|
+
errorCode: 'ERR_CODEMOD_PROTECTED',
|
|
188
|
+
protectedFiles: [
|
|
189
|
+
expect.objectContaining({file: 'generated/panel.tsx'}),
|
|
190
|
+
],
|
|
191
|
+
errors: [
|
|
192
|
+
expect.objectContaining({
|
|
193
|
+
codemod: 'post-codemod-hook',
|
|
194
|
+
error: expect.stringContaining('Post-codemod hook failed'),
|
|
195
|
+
}),
|
|
196
|
+
],
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('runs declared regeneration and clears a generated-file block after reevaluation', () => {
|
|
202
|
+
seed({hook: true});
|
|
203
|
+
|
|
204
|
+
const applied = run([...ARGS, '--apply']);
|
|
205
|
+
|
|
206
|
+
expect(applied.status, applied.stderr).toBe(0);
|
|
207
|
+
expect(applied.envelope).toMatchObject({
|
|
208
|
+
type: 'upgrade.run',
|
|
209
|
+
data: {
|
|
210
|
+
complete: true,
|
|
211
|
+
modifiedFiles: ['src/owned.tsx', 'generated/panel.tsx'],
|
|
212
|
+
protectedFiles: [],
|
|
213
|
+
declinedCandidates: [],
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
expect(fs.readFileSync(path.join(root, 'src/owned.tsx'), 'utf8')).toContain(
|
|
217
|
+
'minSize: 200',
|
|
218
|
+
);
|
|
219
|
+
expect(
|
|
220
|
+
fs.readFileSync(path.join(root, 'generated/panel.tsx'), 'utf8'),
|
|
221
|
+
).toContain('minSize: 200');
|
|
222
|
+
|
|
223
|
+
const second = run([...ARGS, '--apply']);
|
|
224
|
+
expect(second.status, second.stderr).toBe(0);
|
|
225
|
+
expect(second.envelope.data.complete).toBe(true);
|
|
226
|
+
expect(second.envelope.data.filesChanged).toBe(0);
|
|
227
|
+
});
|
|
228
|
+
});
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import {jsonOut, jsonError} from '../../../foundation/response/json.mjs';
|
|
16
|
+
import {emit, section, records} from '../formatters/index.mjs';
|
|
16
17
|
import {logger} from '../../../api/logger.mjs';
|
|
17
18
|
import {AstryxError} from '../../../api/error.mjs';
|
|
18
19
|
import {defineCommand} from '../lib/define-command.mjs';
|
|
@@ -33,27 +34,45 @@ export function registerUpgrade(program) {
|
|
|
33
34
|
*/
|
|
34
35
|
async options => {
|
|
35
36
|
const json = program.opts().json || false;
|
|
36
|
-
|
|
37
|
+
const isList = Boolean(options.list);
|
|
38
|
+
// Silence the logger for --list so the handler renders from the
|
|
39
|
+
// result (parity with --json), and for --json as before.
|
|
40
|
+
// Re-enable on error so handled failures still print.
|
|
41
|
+
logger.setSilent(json || isList);
|
|
37
42
|
|
|
38
43
|
/** @type {import('../../../api/upgrade/upgrade.type.mjs').UpgradeListResponse | import('../../../api/upgrade/upgrade.type.mjs').UpgradeRegistryResponse | import('../../../api/upgrade/upgrade.type.mjs').UpgradeStatusResponse | import('../../../api/upgrade/upgrade.type.mjs').UpgradeRunResponse} */
|
|
39
44
|
let result;
|
|
40
45
|
try {
|
|
41
46
|
result = await upgradeApi(options, {cwd: process.cwd()});
|
|
42
47
|
} catch (e) {
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
// top-level boundary in bin/astryx.mjs format it as before.
|
|
48
|
+
// Re-enable the logger so the error is visible in text mode.
|
|
49
|
+
// For --list the logger was silent; for other modes the API
|
|
50
|
+
// already printed the error before throwing.
|
|
51
|
+
logger.setSilent(json);
|
|
48
52
|
if (e instanceof AstryxError) {
|
|
49
53
|
if (json) jsonError(e.message, undefined, e.code);
|
|
50
|
-
else
|
|
54
|
+
else {
|
|
55
|
+
// The logger was silent only for --list; replay the error there.
|
|
56
|
+
// Non-list failures were already printed by the API.
|
|
57
|
+
if (isList) logger.error(e.message);
|
|
58
|
+
process.exitCode = 1;
|
|
59
|
+
}
|
|
51
60
|
return NO_RESULT_SET;
|
|
52
61
|
}
|
|
53
62
|
throw e;
|
|
54
63
|
}
|
|
55
64
|
|
|
56
65
|
if (json) jsonOut(result);
|
|
66
|
+
else if (result.type === 'upgrade.list') {
|
|
67
|
+
// Render the list from the result, not the API logger, so the text
|
|
68
|
+
// carries the same fields the JSON does (name, title, version, optional).
|
|
69
|
+
emit(
|
|
70
|
+
section('Available codemods'),
|
|
71
|
+
records(result.data, {
|
|
72
|
+
fields: ['name', 'title', 'version', 'optional'],
|
|
73
|
+
}),
|
|
74
|
+
);
|
|
75
|
+
}
|
|
57
76
|
|
|
58
77
|
const registrySummary =
|
|
59
78
|
result.type === 'upgrade.registry'
|
|
@@ -65,6 +84,9 @@ export function registerUpgrade(program) {
|
|
|
65
84
|
? result.data.registryCompositions
|
|
66
85
|
: undefined;
|
|
67
86
|
if (registrySummary && !registrySummary.ok) process.exitCode = 1;
|
|
87
|
+
if (result.type === 'upgrade.run' && result.data.complete === false) {
|
|
88
|
+
process.exitCode = 1;
|
|
89
|
+
}
|
|
68
90
|
|
|
69
91
|
// `--list` is the one lookup here: which migrations exist for the
|
|
70
92
|
// range. Everything else migrates the project — an effect, reported by
|
|
@@ -117,6 +117,12 @@ describe('ASCII normalization', () => {
|
|
|
117
117
|
expect(list(['Avatar \u2014 Group']).toString()).toBe('- Avatar - Group');
|
|
118
118
|
});
|
|
119
119
|
|
|
120
|
+
it('converts Unicode arrows to ASCII arrows', () => {
|
|
121
|
+
expect(text('Rename items \u2192 options').toString()).toBe('Rename items -> options');
|
|
122
|
+
expect(text('options \u2190 items').toString()).toBe('options <- items');
|
|
123
|
+
expect(record({title: 'a \u2192 b'}).toString()).toBe('title: a -> b');
|
|
124
|
+
});
|
|
125
|
+
|
|
120
126
|
it('leaves code verbatim (no normalization)', () => {
|
|
121
127
|
expect(code('a \u2014 b').toString()).toBe('a \u2014 b');
|
|
122
128
|
});
|
|
@@ -74,14 +74,15 @@ describe('what the authoring docs say about the unbuilt docs graph', () => {
|
|
|
74
74
|
expect(graphFieldsDoc.description).toMatch(/not built yet/);
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
-
it('
|
|
77
|
+
it('keeps graph blocks behind the separate GraphContentBlock type', () => {
|
|
78
78
|
const content = referenceDoc.fields
|
|
79
79
|
.flatMap(field => [field, ...(field.fields ?? [])])
|
|
80
80
|
.find(field => field.name === 'sections[].content');
|
|
81
|
+
expect(content.type).toBe('ReferenceContentBlock[]');
|
|
82
|
+
expect(content.description).toContain('GraphContentBlock');
|
|
81
83
|
for (const type of GRAPH_BLOCK_TYPES) {
|
|
82
84
|
expect(content.description).toContain(type);
|
|
83
85
|
}
|
|
84
|
-
expect(content.description).toMatch(/fails to load/);
|
|
85
86
|
});
|
|
86
87
|
|
|
87
88
|
it('says namespace docs are not loaded yet', () => {
|
|
@@ -37,7 +37,7 @@ import {CLI_PROVIDER_ID} from '../identity/providers.mjs';
|
|
|
37
37
|
import {parseReadableDoc} from '../doc-compiler/parse-readable.mjs';
|
|
38
38
|
import {
|
|
39
39
|
sectionKey,
|
|
40
|
-
|
|
40
|
+
sectionKeyErrors,
|
|
41
41
|
sourceTitle,
|
|
42
42
|
withSourceTitle,
|
|
43
43
|
} from './docs-section-key.mjs';
|
|
@@ -312,9 +312,10 @@ export function problemsInTopic(doc) {
|
|
|
312
312
|
);
|
|
313
313
|
},
|
|
314
314
|
);
|
|
315
|
-
//
|
|
316
|
-
//
|
|
317
|
-
|
|
315
|
+
// Explicit authored IDs are a new opt-in contract and remain strict. Topics
|
|
316
|
+
// that relied on 0.6.x title-only sections keep loading; the compiler assigns
|
|
317
|
+
// deterministic fallback/suffixed keys for the additive index API.
|
|
318
|
+
problems.push(...sectionKeyErrors(doc.sections));
|
|
318
319
|
return problems;
|
|
319
320
|
}
|
|
320
321
|
|
|
@@ -487,7 +488,7 @@ function findMergeTarget(sections, section) {
|
|
|
487
488
|
const sameTitle = sections.findIndex(
|
|
488
489
|
candidate => sourceTitle(candidate) === title,
|
|
489
490
|
);
|
|
490
|
-
return sameTitle
|
|
491
|
+
return sameTitle;
|
|
491
492
|
}
|
|
492
493
|
|
|
493
494
|
/**
|
|
@@ -180,7 +180,7 @@ describe('discoverIntegrationDocs', () => {
|
|
|
180
180
|
}),
|
|
181
181
|
);
|
|
182
182
|
expect(records).toEqual([]);
|
|
183
|
-
expect(errors[0].message).toContain('
|
|
183
|
+
expect(errors[0].message).toContain('Invalid discriminator value');
|
|
184
184
|
});
|
|
185
185
|
|
|
186
186
|
it('names a namespace doc instead of listing topic fields it lacks', async () => {
|
|
@@ -529,12 +529,10 @@ describe('problemsInTopic section keys', () => {
|
|
|
529
529
|
})),
|
|
530
530
|
});
|
|
531
531
|
|
|
532
|
-
it('
|
|
532
|
+
it('keeps legacy title-only key conflicts readable', () => {
|
|
533
533
|
expect(
|
|
534
534
|
problemsInTopic(doc([{title: 'Quick Start'}, {title: 'Quick-start'}])),
|
|
535
|
-
).toEqual([
|
|
536
|
-
expect.stringContaining('"quick-start" is already used by sections[0]'),
|
|
537
|
-
]);
|
|
535
|
+
).toEqual([]);
|
|
538
536
|
});
|
|
539
537
|
|
|
540
538
|
it('rejects an unsafe id', () => {
|
|
@@ -543,10 +541,8 @@ describe('problemsInTopic section keys', () => {
|
|
|
543
541
|
).toEqual([expect.stringContaining('is not a stable key')]);
|
|
544
542
|
});
|
|
545
543
|
|
|
546
|
-
it('
|
|
547
|
-
expect(problemsInTopic(doc([{title: '亮/暗模式'}]))).toEqual([
|
|
548
|
-
expect.stringContaining('Give the section an id'),
|
|
549
|
-
]);
|
|
544
|
+
it('keeps a legacy title that has no derived key readable', () => {
|
|
545
|
+
expect(problemsInTopic(doc([{title: '亮/暗模式'}]))).toEqual([]);
|
|
550
546
|
expect(
|
|
551
547
|
problemsInTopic(doc([{id: 'light-dark', title: '亮/暗模式'}])),
|
|
552
548
|
).toEqual([]);
|
|
@@ -580,7 +576,7 @@ describe('mergeTopic by section key', () => {
|
|
|
580
576
|
]);
|
|
581
577
|
});
|
|
582
578
|
|
|
583
|
-
it('
|
|
579
|
+
it('keeps a legacy title variant as a separate section', () => {
|
|
584
580
|
const merged = mergeTopic(base, {
|
|
585
581
|
sections: [
|
|
586
582
|
{title: 'Light-Dark Mode', content: [{type: 'prose', text: 'acme'}]},
|
|
@@ -588,6 +584,7 @@ describe('mergeTopic by section key', () => {
|
|
|
588
584
|
});
|
|
589
585
|
expect(titles(merged)).toEqual([
|
|
590
586
|
[null, 'Quick Start', 'base'],
|
|
587
|
+
[null, 'Light/Dark Mode', 'base'],
|
|
591
588
|
[null, 'Light-Dark Mode', 'acme'],
|
|
592
589
|
]);
|
|
593
590
|
});
|
|
@@ -31,9 +31,17 @@ export function sectionTitleKey(title: unknown): string;
|
|
|
31
31
|
*/
|
|
32
32
|
export function sectionKey(section: any): string;
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
34
|
+
* Fatal key problems: only an explicitly authored `id` can make a previously
|
|
35
|
+
* readable topic invalid. Derived-key collisions and titles with no Latin
|
|
36
|
+
* letters or digits are handled by {@link withSectionKeys} for 0.6.x
|
|
37
|
+
* compatibility.
|
|
38
|
+
* @param {any[]} sections
|
|
39
|
+
* @returns {string[]}
|
|
40
|
+
*/
|
|
41
|
+
export function sectionKeyErrors(sections: any[]): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Compatibility notices for section keys. These inputs loaded in 0.6.x, so
|
|
44
|
+
* readers keep accepting them and assign deterministic fallback keys.
|
|
37
45
|
* @param {any[]} sections
|
|
38
46
|
* @returns {string[]}
|
|
39
47
|
*/
|
|
@@ -49,13 +57,16 @@ export function withSectionKeys<T extends {
|
|
|
49
57
|
sections: any[];
|
|
50
58
|
}>(doc: T): T;
|
|
51
59
|
/**
|
|
52
|
-
* Find the section a reader asked for
|
|
53
|
-
*
|
|
54
|
-
*
|
|
60
|
+
* Find the section a reader asked for. The 0.6.x first-match title-substring
|
|
61
|
+
* lookup remains first in the authored-title view. In a localized view, an
|
|
62
|
+
* exact stable key resolves before translated title substrings because those
|
|
63
|
+
* translations cannot participate in language-stable key allocation. Generated
|
|
64
|
+
* keys avoid authored-title conflicts, and authored IDs that would shadow an
|
|
65
|
+
* authored legacy query are rejected.
|
|
55
66
|
* @param {any[]} sections
|
|
56
67
|
* @param {string} query
|
|
57
|
-
* @returns {{section: any | null, candidates: any[]}} `candidates` lists
|
|
58
|
-
*
|
|
68
|
+
* @returns {{section: any | null, candidates: any[]}} `candidates` lists every
|
|
69
|
+
* legacy title match when the query is ambiguous
|
|
59
70
|
*/
|
|
60
71
|
export function findDocSection(sections: any[], query: string): {
|
|
61
72
|
section: any | null;
|