@astryxdesign/cli 0.6.5-canary.c3016f8 → 0.6.5-canary.c8d8a1d
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/build/_adapter.d.mts +36 -2
- package/api/build/_adapter.mjs +41 -10
- package/api/build/build.doc.mjs +2 -2
- package/api/build/build.test.mjs +38 -2
- package/api/build/kit/kit.mjs +65 -21
- package/api/build/kit/rank.d.mts +24 -8
- package/api/build/kit/rank.mjs +277 -97
- package/api/build/kit/rank.test.mjs +231 -48
- 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 +246 -24
- package/api/integration/add-theme.test.mjs +214 -1
- 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.mjs +12 -3
- package/api/integration/pack-check.test.mjs +52 -3
- 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.d.mts +24 -0
- package/api/search/search.mjs +71 -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-integration.test.mjs +14 -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/icons.doc.mjs +1 -0
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/add-a-topic.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +2 -2
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/sections-and-placement.doc.mjs +1 -1
- package/assets/docs/tree/template-doc-overview.doc.mjs +13 -1
- package/assets/docs/tree/troubleshooting.doc.mjs +9 -5
- package/assets/docs/tree/versioning.doc.mjs +7 -6
- package/assets/templates/pages/ai-chat/template.doc.mjs +16 -1
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +9 -1
- package/assets/templates/pages/blank/template.doc.mjs +3 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +9 -1
- package/assets/templates/pages/centered-hero/template.doc.mjs +3 -1
- package/assets/templates/pages/checkout-wizard/template.doc.mjs +1 -0
- package/assets/templates/pages/classic-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +16 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +15 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +23 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-comparison/template.doc.mjs +9 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +10 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +17 -1
- package/assets/templates/pages/dashboard-scorecard/template.doc.mjs +2 -1
- package/assets/templates/pages/detail-page/template.doc.mjs +8 -0
- package/assets/templates/pages/documentation/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +10 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +10 -1
- package/assets/templates/pages/editor/template.doc.mjs +9 -1
- package/assets/templates/pages/file-explorer/template.doc.mjs +3 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +17 -1
- package/assets/templates/pages/form-wizard/template.doc.mjs +14 -1
- package/assets/templates/pages/form-wizard-dialog/template.doc.mjs +1 -0
- package/assets/templates/pages/gallery-hero/template.doc.mjs +10 -1
- package/assets/templates/pages/ide/template.doc.mjs +9 -1
- package/assets/templates/pages/incident-console/template.doc.mjs +10 -1
- package/assets/templates/pages/kanban-board/template.doc.mjs +11 -1
- package/assets/templates/pages/library/template.doc.mjs +15 -1
- package/assets/templates/pages/login/template.doc.mjs +10 -1
- package/assets/templates/pages/login-card/template.doc.mjs +11 -1
- package/assets/templates/pages/login-split/template.doc.mjs +10 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +10 -1
- package/assets/templates/pages/messaging-shell/template.doc.mjs +11 -1
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/payment-form/template.doc.mjs +3 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +9 -1
- package/assets/templates/pages/product-gallery/template.doc.mjs +10 -1
- package/assets/templates/pages/settings/template.doc.mjs +3 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +9 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +9 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +10 -1
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +14 -1
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +11 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +3 -1
- package/assets/templates/pages/table/template.doc.mjs +11 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +21 -1
- package/assets/templates/pages/table-grouped/template.doc.mjs +15 -1
- package/assets/templates/pages/table-inbox/template.doc.mjs +18 -6
- package/assets/templates/pages/table-page/template.doc.mjs +20 -1
- package/assets/templates/pages/table-tree/template.doc.mjs +14 -1
- package/assets/templates/pages/theme-showcase/template.doc.mjs +10 -1
- package/assets/templates/pages/work-item-detail/template.doc.mjs +10 -0
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/authoring/doctypes/template/parse.d.mts +2 -0
- package/authoring/doctypes/template/parse.mjs +1 -0
- package/authoring/doctypes/template/parse.test.mjs +21 -0
- package/authoring/doctypes/template/template.doc.mjs +6 -0
- package/authoring/doctypes/template/type.ts +10 -0
- 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 +14 -0
- package/foundation/discovery/template-adapter.fixture-refs.test.mjs +37 -1
- package/foundation/discovery/template-adapter.mjs +21 -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 +57 -13
- package/foundation/integrations/cli-requirement.mjs +84 -22
- package/foundation/integrations/cli-requirement.test.mjs +135 -8
- package/foundation/response/response-types.doc.d.mts +5 -5
- package/foundation/response/response-types.doc.mjs +13 -13
- package/package.json +9 -9
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file Colocated tests for the `search` leaf (api/search/search.mjs), run
|
|
5
|
+
* against the real @astryxdesign/core registry. `search` had no api-level tests;
|
|
6
|
+
* this locks the envelope, ranking invariants, the `--type`/limit handling, and
|
|
7
|
+
* the error paths.
|
|
8
|
+
*
|
|
9
|
+
* The API validates its own inputs (not just the CLI): a non-positive/non-integer
|
|
10
|
+
* `limit`, an empty query, and a bad `--type` all throw AstryxError with the
|
|
11
|
+
* ERR_INVALID_ARGUMENT code, so a direct `@astryxdesign/cli/api` caller gets the
|
|
12
|
+
* same contract as `astryx search` on the command line.
|
|
13
|
+
*
|
|
14
|
+
* The last describe block covers integration-contributed components, using the
|
|
15
|
+
* same temp-consumer harness as template-integration.test.mjs. Before this,
|
|
16
|
+
* `search`/`build` only ever scanned @astryxdesign/core — an integration's own
|
|
17
|
+
* components were invisible to both, even though `component --list` and
|
|
18
|
+
* `component <Name>` already resolved them. The two discovery paths silently
|
|
19
|
+
* disagreed.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import {describe, it, expect} from 'vitest';
|
|
23
|
+
import * as fs from 'node:fs';
|
|
24
|
+
import * as os from 'node:os';
|
|
25
|
+
import * as path from 'node:path';
|
|
26
|
+
import {fileURLToPath} from 'node:url';
|
|
27
|
+
import {docs} from '../docs/docs.mjs';
|
|
28
|
+
import {
|
|
29
|
+
headingWithPhrase,
|
|
30
|
+
titleInQuery,
|
|
31
|
+
search,
|
|
32
|
+
scoreCandidate,
|
|
33
|
+
scoreQuery,
|
|
34
|
+
tokenizeQuery,
|
|
35
|
+
SEARCH_DOMAINS,
|
|
36
|
+
} from './search.mjs';
|
|
37
|
+
|
|
38
|
+
const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../..');
|
|
39
|
+
const cwd = REPO;
|
|
40
|
+
const SLOW = 30_000;
|
|
41
|
+
|
|
42
|
+
describe('search leaf — envelope + ranking', () => {
|
|
43
|
+
it('returns a `search` envelope with query + results', async () => {
|
|
44
|
+
const r = await search('button', {cwd});
|
|
45
|
+
expect(r.type).toBe('search');
|
|
46
|
+
expect(r.data.query).toBe('button');
|
|
47
|
+
expect(Array.isArray(r.data.results)).toBe(true);
|
|
48
|
+
expect(r.data.results.length).toBeGreaterThan(0);
|
|
49
|
+
}, SLOW);
|
|
50
|
+
|
|
51
|
+
it('keeps tokenizer coverage out of the public result shape', async () => {
|
|
52
|
+
const r = await search('table of contents', {cwd});
|
|
53
|
+
expect(r.data.results.length).toBeGreaterThan(0);
|
|
54
|
+
for (const result of r.data.results) {
|
|
55
|
+
expect(result).not.toHaveProperty('matchedTerms');
|
|
56
|
+
expect(result).not.toHaveProperty('queryTerms');
|
|
57
|
+
}
|
|
58
|
+
}, SLOW);
|
|
59
|
+
|
|
60
|
+
it('returns an empty result set (not an error) for a no-match query', async () => {
|
|
61
|
+
const r = await search('zzznomatch99', {cwd});
|
|
62
|
+
expect(r.type).toBe('search');
|
|
63
|
+
expect(r.data.results).toEqual([]);
|
|
64
|
+
}, SLOW);
|
|
65
|
+
|
|
66
|
+
it('defaults to at most 20 results', async () => {
|
|
67
|
+
const r = await search('button', {cwd});
|
|
68
|
+
expect(r.data.results.length).toBeLessThanOrEqual(20);
|
|
69
|
+
}, SLOW);
|
|
70
|
+
|
|
71
|
+
it('caps results to a positive limit', async () => {
|
|
72
|
+
const r = await search('button', {cwd, limit: 2});
|
|
73
|
+
expect(r.data.results.length).toBeLessThanOrEqual(2);
|
|
74
|
+
}, SLOW);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('search leaf — per-domain result fields', () => {
|
|
78
|
+
it('carries import for components and hooks, title for docs, displayName and kind for templates', async () => {
|
|
79
|
+
const r = await search('theme', {cwd, limit: 60});
|
|
80
|
+
expect(new Set(r.data.results.map(res => res.domain))).toEqual(
|
|
81
|
+
new Set(SEARCH_DOMAINS),
|
|
82
|
+
);
|
|
83
|
+
for (const res of r.data.results) {
|
|
84
|
+
expect(typeof res.command).toBe('string');
|
|
85
|
+
expect(typeof res.description).toBe('string');
|
|
86
|
+
if (res.domain === 'component' || res.domain === 'hook') {
|
|
87
|
+
expect(res.import).toMatch(/\S/);
|
|
88
|
+
} else if (res.domain === 'doc') {
|
|
89
|
+
expect(res.title).toMatch(/\S/);
|
|
90
|
+
const read = `astryx docs ${res.name}`;
|
|
91
|
+
expect([read, `${read} --index`, `${read} ${res.section}`]).toContain(res.command);
|
|
92
|
+
} else {
|
|
93
|
+
expect(res.displayName).toMatch(/\S/);
|
|
94
|
+
expect(['page', 'block']).toContain(res.kind);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}, SLOW);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe('search leaf — docs at the grain a reader reads them', () => {
|
|
101
|
+
it(
|
|
102
|
+
'finds one section of a guide, and a docs-tree leaf by its own name',
|
|
103
|
+
async () => {
|
|
104
|
+
const guide = await search('when a codemod runs', {cwd, type: 'doc'});
|
|
105
|
+
// Found by the section's own title, wherever the guide sits in the tree.
|
|
106
|
+
const hit = guide.data.results
|
|
107
|
+
.slice(0, 3)
|
|
108
|
+
.find(result => result.section === 'which-codemods-run');
|
|
109
|
+
expect(hit).toMatchObject({
|
|
110
|
+
domain: 'doc',
|
|
111
|
+
name: expect.stringMatching(/^cli\/integrations\/(?:.+\/)?codemods$/),
|
|
112
|
+
title: expect.stringMatching(/ › Codemods › Choose when a codemod runs$/),
|
|
113
|
+
});
|
|
114
|
+
expect(hit.parent).toBe(`astryx docs ${hit.name} --index`);
|
|
115
|
+
expect(hit.command).toBe(`astryx docs ${hit.name} which-codemods-run`);
|
|
116
|
+
const block = await search('token-ref', {cwd});
|
|
117
|
+
expect(block.data.results[0]).toMatchObject({
|
|
118
|
+
name: 'authoring',
|
|
119
|
+
section: 'reference-doc',
|
|
120
|
+
command: 'astryx docs authoring reference-doc',
|
|
121
|
+
});
|
|
122
|
+
const fn = await search('assertResponse', {cwd, type: 'doc'});
|
|
123
|
+
expect(fn.data.results[0]).toMatchObject({
|
|
124
|
+
name: 'cli/api/functions/assert-response',
|
|
125
|
+
title: 'Astryx CLI › API › Functions › assertResponse()',
|
|
126
|
+
parent: 'astryx docs cli/api/functions',
|
|
127
|
+
command: 'astryx docs cli/api/functions/assert-response',
|
|
128
|
+
});
|
|
129
|
+
expect(fn.data.results[0]).not.toHaveProperty('section');
|
|
130
|
+
},
|
|
131
|
+
SLOW,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
it(
|
|
135
|
+
'finds the integration guides for the ways people ask to make one',
|
|
136
|
+
async () => {
|
|
137
|
+
// "make", "build", and "an" are stopwords, so each of the first three
|
|
138
|
+
// tokenizes to `integration` alone; the phrase still matches the
|
|
139
|
+
// keywords and the title the guides declare. A namespace's own
|
|
140
|
+
// keywords count, and a plural name is the name.
|
|
141
|
+
for (const [query, route] of [
|
|
142
|
+
['make an integration', /^cli\/integrations$/],
|
|
143
|
+
['build an integration', /^cli\/integrations$/],
|
|
144
|
+
['create an integration', /^cli\/integrations$/],
|
|
145
|
+
['integration', /^cli\/integrations$/],
|
|
146
|
+
['publish an integration', /^cli\/integrations$/],
|
|
147
|
+
// The troubleshooting guide, wherever the tree places it.
|
|
148
|
+
['troubleshoot integration', /^cli\/integrations\/(?:.+\/)?troubleshooting$/],
|
|
149
|
+
]) {
|
|
150
|
+
const r = await search(query, {cwd, type: 'doc'});
|
|
151
|
+
const names = r.data.results.slice(0, 3).map(result => result.name);
|
|
152
|
+
expect(names.some(name => route.test(name)), `${query}: ${names.join(', ')}`).toBe(true);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
SLOW,
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
it(
|
|
159
|
+
'gives a top-level namespace hit the topic list as its parent',
|
|
160
|
+
async () => {
|
|
161
|
+
for (const [query, route] of [['unorganized', 'unorganized'], ['Astryx CLI', 'cli']]) {
|
|
162
|
+
const r = await search(query, {cwd, type: 'doc'});
|
|
163
|
+
expect(r.data.results).toContainEqual(
|
|
164
|
+
expect.objectContaining({
|
|
165
|
+
name: route,
|
|
166
|
+
command: `astryx docs ${route}`,
|
|
167
|
+
parent: 'astryx docs',
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
SLOW,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
it(
|
|
176
|
+
'points a topic hit at its index, never a whole-topic read',
|
|
177
|
+
async () => {
|
|
178
|
+
// A guide the tree places, read from the tree rather than named.
|
|
179
|
+
const {data: integrations} = await docs('cli/integrations');
|
|
180
|
+
const guide = integrations.slots
|
|
181
|
+
.flatMap(slot => slot.children)
|
|
182
|
+
.find(child => child.kind === 'generic').route;
|
|
183
|
+
const r = await search(guide, {cwd, type: 'doc'});
|
|
184
|
+
expect(r.data.results[0]).toMatchObject({
|
|
185
|
+
name: guide,
|
|
186
|
+
command: `astryx docs ${guide} --index`,
|
|
187
|
+
});
|
|
188
|
+
expect(r.data.results[0]).not.toHaveProperty('section');
|
|
189
|
+
},
|
|
190
|
+
SLOW,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
it(
|
|
194
|
+
'searches docs where @astryxdesign/core is not installed',
|
|
195
|
+
async () => {
|
|
196
|
+
const bare = fs.mkdtempSync(
|
|
197
|
+
path.join(os.tmpdir(), 'astryx-search-bare-'),
|
|
198
|
+
);
|
|
199
|
+
try {
|
|
200
|
+
const r = await search('assertResponse', {cwd: bare, type: 'doc'});
|
|
201
|
+
expect(r.data.results[0].name).toBe(
|
|
202
|
+
'cli/api/functions/assert-response',
|
|
203
|
+
);
|
|
204
|
+
} finally {
|
|
205
|
+
fs.rmSync(bare, {recursive: true, force: true});
|
|
206
|
+
}
|
|
207
|
+
},
|
|
208
|
+
SLOW,
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
describe('search leaf — matchCount is the total, not the cap', () => {
|
|
213
|
+
it('reports every match while `results` stays bounded by the limit', async () => {
|
|
214
|
+
// The regression: `matchCount` used to be `results.length`, so a query
|
|
215
|
+
// matching 57 things reported 20 — the cap read back as the answer. Any
|
|
216
|
+
// consumer counting matches (the recorded run, a caller paginating) then
|
|
217
|
+
// could not tell a capped answer from an exactly-cap-sized one.
|
|
218
|
+
const capped = await search('button', {cwd, limit: 2});
|
|
219
|
+
expect(capped.data.results.length).toBe(2);
|
|
220
|
+
expect(capped.data.matchCount).toBeGreaterThan(2);
|
|
221
|
+
|
|
222
|
+
// Same query, no meaningful cap: the count is stable across limits, which
|
|
223
|
+
// is what makes it a count of MATCHES rather than of what was returned.
|
|
224
|
+
const full = await search('button', {cwd, limit: 500});
|
|
225
|
+
expect(full.data.matchCount).toBe(capped.data.matchCount);
|
|
226
|
+
expect(full.data.results.length).toBe(full.data.matchCount);
|
|
227
|
+
}, SLOW);
|
|
228
|
+
|
|
229
|
+
it('reports 0 for a no-match query', async () => {
|
|
230
|
+
const r = await search('zzznomatch99', {cwd});
|
|
231
|
+
expect(r.data.matchCount).toBe(0);
|
|
232
|
+
}, SLOW);
|
|
233
|
+
|
|
234
|
+
it('counts only the requested domain under --type', async () => {
|
|
235
|
+
const all = await search('button', {cwd, limit: 500});
|
|
236
|
+
const components = await search('button', {
|
|
237
|
+
cwd,
|
|
238
|
+
type: 'component',
|
|
239
|
+
limit: 500,
|
|
240
|
+
});
|
|
241
|
+
expect(components.data.matchCount).toBe(components.data.results.length);
|
|
242
|
+
expect(components.data.matchCount).toBeLessThanOrEqual(all.data.matchCount);
|
|
243
|
+
}, SLOW);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('search leaf — --type filter', () => {
|
|
247
|
+
it('restricts results to the requested domain', async () => {
|
|
248
|
+
const r = await search('button', {cwd, type: 'component'});
|
|
249
|
+
expect(r.data.results.every(x => x.domain === 'component')).toBe(true);
|
|
250
|
+
}, SLOW);
|
|
251
|
+
|
|
252
|
+
it('exposes the valid domain list', () => {
|
|
253
|
+
expect(SEARCH_DOMAINS).toEqual(expect.arrayContaining(['component', 'hook', 'doc', 'template']));
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe('search leaf — exact keyword phrase outranks incidental token matches (issue #5239)', () => {
|
|
258
|
+
it('surfaces Outline for its own declared keyword "table of contents", ranked first', async () => {
|
|
259
|
+
// Before the fix, "table" and "contents" each separately matched dozens
|
|
260
|
+
// of unrelated Table-related templates by coincidence, and their
|
|
261
|
+
// combined token-sum score outranked Outline's single exact match,
|
|
262
|
+
// pushing it out of the results entirely at the default limit.
|
|
263
|
+
const r = await search('table of contents', {cwd});
|
|
264
|
+
expect(r.data.results[0]?.name).toBe('Outline');
|
|
265
|
+
}, SLOW);
|
|
266
|
+
|
|
267
|
+
it('surfaces Outline for its own declared keyword "heading navigation", ranked first', async () => {
|
|
268
|
+
const r = await search('heading navigation', {cwd});
|
|
269
|
+
expect(r.data.results[0]?.name).toBe('Outline');
|
|
270
|
+
}, SLOW);
|
|
271
|
+
|
|
272
|
+
it('preserves query coverage metadata on the promoted exact phrase', () => {
|
|
273
|
+
const query = 'table of contents';
|
|
274
|
+
const tokens = tokenizeQuery(query);
|
|
275
|
+
expect(
|
|
276
|
+
scoreQuery(query, tokens, {
|
|
277
|
+
name: 'Outline',
|
|
278
|
+
keywords: [query],
|
|
279
|
+
}),
|
|
280
|
+
).toMatchObject({matched: tokens.length, total: tokens.length});
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it('still returns no results for a nonsense query (the fix does not loosen matching)', async () => {
|
|
284
|
+
const r = await search('zzzzqqqx', {cwd});
|
|
285
|
+
expect(r.data.results).toEqual([]);
|
|
286
|
+
}, SLOW);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
describe('search leaf — a whole-query phrase in a title or heading is top tier', () => {
|
|
290
|
+
/**
|
|
291
|
+
* @param {string} q
|
|
292
|
+
* @param {object} candidate
|
|
293
|
+
* @returns {number}
|
|
294
|
+
*/
|
|
295
|
+
const score = (q, candidate) => scoreQuery(q, tokenizeQuery(q), candidate)?.score ?? 0;
|
|
296
|
+
|
|
297
|
+
it('finds the whole query, in order, inside a title or heading', () => {
|
|
298
|
+
expect(headingWithPhrase('dark mode', ['Light/Dark Mode'])).toBe('Light/Dark Mode');
|
|
299
|
+
expect(headingWithPhrase('nested theme', ['Theme Props', 'Nested themes'])).toBe(
|
|
300
|
+
'Nested themes',
|
|
301
|
+
);
|
|
302
|
+
// A plural on either side is the same word.
|
|
303
|
+
expect(headingWithPhrase('data attributes selector', ['Data attribute selectors'])).toBe(
|
|
304
|
+
'Data attribute selectors',
|
|
305
|
+
);
|
|
306
|
+
// Out of order, split up, or one word: not a phrase.
|
|
307
|
+
expect(headingWithPhrase('mode dark', ['Light/Dark Mode'])).toBeNull();
|
|
308
|
+
expect(headingWithPhrase('dark mode', ['Dark sidebar and mode toggle'])).toBeNull();
|
|
309
|
+
expect(headingWithPhrase('dark', ['Light/Dark Mode'])).toBeNull();
|
|
310
|
+
expect(headingWithPhrase('dark mode', undefined)).toBeNull();
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('ranks a section titled with the phrase above an exact code-tick match of one word', () => {
|
|
314
|
+
// The reported miss: `search "dark mode"` put "Light/Dark Mode" at #28,
|
|
315
|
+
// under API enum docs that name `mode` in code ticks.
|
|
316
|
+
const section = {name: 'light-dark-mode', titles: ['Light/Dark Mode'], keywords: ['Light/Dark Mode']};
|
|
317
|
+
const enumDoc = {name: 'response-types', keywords: ['mode', 'dark'], description: 'mode'};
|
|
318
|
+
expect(score('dark mode', section)).toBe(170);
|
|
319
|
+
expect(score('dark mode', section)).toBeGreaterThan(score('dark mode', enumDoc));
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('ranks a question that names a whole title just below that', () => {
|
|
323
|
+
expect(titleInQuery('how do i add dark mode', ['Dark mode'])).toBe('Dark mode');
|
|
324
|
+
expect(titleInQuery('how do nested themes work', ['Nested themes'])).toBe('Nested themes');
|
|
325
|
+
// One-word titles are too common to count, and order still matters.
|
|
326
|
+
expect(titleInQuery('how do i theme my app', ['Theme'])).toBeNull();
|
|
327
|
+
expect(titleInQuery('mode dark please', ['Dark mode'])).toBeNull();
|
|
328
|
+
const section = {name: 'light-dark-mode', titles: ['Dark mode'], keywords: ['Dark mode']};
|
|
329
|
+
const named = score('how do i add dark mode', section);
|
|
330
|
+
expect(named).toBeGreaterThanOrEqual(160);
|
|
331
|
+
expect(named).toBeLessThan(170);
|
|
332
|
+
// Sections that share a title are ordered by how much of the rest of the
|
|
333
|
+
// question they answer.
|
|
334
|
+
const spacing = {name: 'best-practices', titles: ['Best Practices'], prose: ['Use spacing tokens']};
|
|
335
|
+
const color = {name: 'best-practices', titles: ['Best Practices'], prose: ['Use color tokens']};
|
|
336
|
+
expect(score('best practices for spacing', spacing)).toBeGreaterThan(
|
|
337
|
+
score('best practices for spacing', color),
|
|
338
|
+
);
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('reads a plural of a name as the name, and only a real plural', () => {
|
|
342
|
+
// One point under the exact spelling, so the doc named `tokens` outranks
|
|
343
|
+
// the Token component for `tokens`.
|
|
344
|
+
expect(scoreCandidate('integration', {name: 'integrations'})?.score).toBe(99);
|
|
345
|
+
expect(scoreCandidate('box', {name: 'boxes'})?.score).toBe(99);
|
|
346
|
+
expect(scoreCandidate('tabs', {name: 'tab'})?.score).toBe(99);
|
|
347
|
+
expect(scoreCandidate('tokens', {name: 'tokens'})?.score).toBe(100);
|
|
348
|
+
// `es` only follows s, x, z, ch, or sh.
|
|
349
|
+
expect(scoreCandidate('not', {name: 'notes'})?.score ?? 0).toBeLessThan(100);
|
|
350
|
+
expect(scoreCandidate('mod', {name: 'modes'})?.score ?? 0).toBeLessThan(100);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('keeps an exact name or keyword above a title phrase', () => {
|
|
354
|
+
const titled = {name: 'x', titles: ['Table of contents for long pages']};
|
|
355
|
+
const keyword = {name: 'Outline', keywords: ['table of contents']};
|
|
356
|
+
expect(score('table of contents', keyword)).toBeGreaterThan(score('table of contents', titled));
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('puts the dark mode section first for a docs search', async () => {
|
|
360
|
+
for (const query of ['dark mode', 'how do I add dark mode']) {
|
|
361
|
+
const r = await search(query, {cwd, type: 'doc'});
|
|
362
|
+
expect(r.data.results[0]).toMatchObject({name: 'theme', section: 'light-dark-mode'});
|
|
363
|
+
}
|
|
364
|
+
}, SLOW);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
describe('search leaf — a candidate that matches every word outranks a partial match', () => {
|
|
368
|
+
/**
|
|
369
|
+
* @param {string} q
|
|
370
|
+
* @param {object} candidate
|
|
371
|
+
* @returns {number}
|
|
372
|
+
*/
|
|
373
|
+
const score = (q, candidate) => scoreQuery(q, tokenizeQuery(q), candidate)?.score ?? 0;
|
|
374
|
+
|
|
375
|
+
it('ranks a doc with both words above a doc named after one of them', () => {
|
|
376
|
+
// The reported regression: `search troubleshoot integration` put the
|
|
377
|
+
// troubleshooting guide 30th, under docs that each match `integration`
|
|
378
|
+
// alone (by name, 108; in a code tick, 98).
|
|
379
|
+
const guide = {
|
|
380
|
+
name: 'troubleshooting',
|
|
381
|
+
keywords: ['Troubleshooting'],
|
|
382
|
+
description: 'What to check when an integration does not load.',
|
|
383
|
+
};
|
|
384
|
+
const byName = {name: 'integration', keywords: ['integration-add']};
|
|
385
|
+
const byCodeTick = {name: 'integration-add', keywords: ['integration']};
|
|
386
|
+
const q = 'troubleshoot integration';
|
|
387
|
+
expect(score(q, guide)).toBeGreaterThan(score(q, byName));
|
|
388
|
+
expect(score(q, guide)).toBeGreaterThan(score(q, byCodeTick));
|
|
389
|
+
expect(scoreQuery(q, tokenizeQuery(q), guide)).toMatchObject({matched: 2, total: 2});
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('holds for longer queries too, and stays below the title tiers', () => {
|
|
393
|
+
const all = {name: 'x', keywords: ['alphas'], description: 'alpha beta gamma delta'};
|
|
394
|
+
const threeOfFour = {name: 'alpha', keywords: ['beta', 'gamma']};
|
|
395
|
+
const q = 'alpha beta gamma delta';
|
|
396
|
+
expect(score(q, all)).toBeGreaterThan(score(q, threeOfFour));
|
|
397
|
+
expect(score(q, all)).toBeLessThan(160);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
// Among candidates that match every word, the stronger match should come
|
|
401
|
+
// first. Today every all-word match with a keyword hit gets the same score,
|
|
402
|
+
// so this records the order without enforcing it: it fails, as expected,
|
|
403
|
+
// until the scoring tells the two apart.
|
|
404
|
+
it.fails('ranks the stronger of two all-word matches first', () => {
|
|
405
|
+
const all = {name: 'x', keywords: ['alphas'], description: 'alpha beta gamma delta'};
|
|
406
|
+
const q = 'alpha beta gamma delta';
|
|
407
|
+
expect(score(q, {name: 'y', keywords: ['alpha'], description: 'beta gamma delta'})).toBeGreaterThan(
|
|
408
|
+
score(q, all),
|
|
409
|
+
);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('keeps passing mentions of every word below an exact hit on one word', () => {
|
|
413
|
+
// Mentions in prose, or the components a page happens to render, are
|
|
414
|
+
// breadth: a page that says "empty state" is not the EmptyState answer.
|
|
415
|
+
const mentions = {name: 'ai-chat-landing', description: 'A landing page with an empty state.'};
|
|
416
|
+
const keyword = {name: 'x', keywords: ['empty']};
|
|
417
|
+
expect(score('empty state', mentions)).toBeLessThan(score('empty state', keyword));
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('finds a component by its name typed as words, and a guide by its route', async () => {
|
|
421
|
+
for (const [query, name] of [
|
|
422
|
+
['command palette', 'CommandPalette'],
|
|
423
|
+
['empty state', 'EmptyState'],
|
|
424
|
+
]) {
|
|
425
|
+
const r = await search(query, {cwd});
|
|
426
|
+
expect(r.data.results[0], query).toMatchObject({domain: 'component', name});
|
|
427
|
+
}
|
|
428
|
+
const tokens = await search('tokens', {cwd});
|
|
429
|
+
expect(tokens.data.results[0]).toMatchObject({domain: 'doc', name: 'tokens'});
|
|
430
|
+
for (const [query, route] of [
|
|
431
|
+
['codemods', /^cli\/integrations\/(?:.+\/)?codemods$/],
|
|
432
|
+
['quick start', /^cli\/integrations\/(?:.+\/)?quick-start$/],
|
|
433
|
+
['test in an app', /^cli\/integrations\/(?:.+\/)?test-in-an-app$/],
|
|
434
|
+
]) {
|
|
435
|
+
const r = await search(query, {cwd, type: 'doc'});
|
|
436
|
+
// The guide is among the hits that share the top score: two guides
|
|
437
|
+
// that both declare the phrase tie, and the tie's order is not pinned.
|
|
438
|
+
const top = r.data.results
|
|
439
|
+
.filter(result => result.score === r.data.results[0].score)
|
|
440
|
+
.map(result => result.name);
|
|
441
|
+
expect(top.some(name => route.test(name)), `${query}: ${top.join(', ')}`).toBe(true);
|
|
442
|
+
}
|
|
443
|
+
}, SLOW);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
describe('search leaf — error paths (pinned)', () => {
|
|
447
|
+
it('throws ERR_INVALID_ARGUMENT when the query is empty/whitespace', async () => {
|
|
448
|
+
await expect(search(' ', {cwd})).rejects.toMatchObject({
|
|
449
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
450
|
+
message: expect.stringMatching(/query is required/i),
|
|
451
|
+
});
|
|
452
|
+
}, SLOW);
|
|
453
|
+
|
|
454
|
+
it('throws ERR_INVALID_ARGUMENT for an unknown --type', async () => {
|
|
455
|
+
await expect(
|
|
456
|
+
search('button', {cwd, type: /** @type {any} */ ('bogus')}),
|
|
457
|
+
).rejects.toMatchObject({code: 'ERR_INVALID_ARGUMENT'});
|
|
458
|
+
}, SLOW);
|
|
459
|
+
|
|
460
|
+
it('searches the docs without @astryxdesign/core, and throws for a domain that needs it', async () => {
|
|
461
|
+
const empty = fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-search-no-core-'));
|
|
462
|
+
try {
|
|
463
|
+
// An open search outside an app covers the docs, as `astryx docs` does.
|
|
464
|
+
const open = await search('make an integration', {cwd: empty});
|
|
465
|
+
expect(open.data.results.length).toBeGreaterThan(0);
|
|
466
|
+
expect(new Set(open.data.results.map(r => r.domain))).toEqual(
|
|
467
|
+
new Set(['doc']),
|
|
468
|
+
);
|
|
469
|
+
for (const type of ['component', 'hook', 'template']) {
|
|
470
|
+
await expect(
|
|
471
|
+
search('button', {cwd: empty, type: /** @type {any} */ (type)}),
|
|
472
|
+
).rejects.toMatchObject({code: 'ERR_CORE_NOT_FOUND'});
|
|
473
|
+
}
|
|
474
|
+
} finally {
|
|
475
|
+
fs.rmSync(empty, {recursive: true, force: true});
|
|
476
|
+
}
|
|
477
|
+
}, SLOW);
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
describe('search leaf — limit validation (API matches the CLI contract)', () => {
|
|
481
|
+
it('throws ERR_INVALID_ARGUMENT for a limit of 0 (no longer returns everything)', async () => {
|
|
482
|
+
await expect(search('button', {cwd, limit: 0})).rejects.toMatchObject({
|
|
483
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
484
|
+
});
|
|
485
|
+
}, SLOW);
|
|
486
|
+
|
|
487
|
+
it('throws ERR_INVALID_ARGUMENT for a negative limit', async () => {
|
|
488
|
+
await expect(search('button', {cwd, limit: -5})).rejects.toMatchObject({
|
|
489
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
490
|
+
});
|
|
491
|
+
}, SLOW);
|
|
492
|
+
|
|
493
|
+
it('throws ERR_INVALID_ARGUMENT for a non-integer limit', async () => {
|
|
494
|
+
await expect(search('button', {cwd, limit: 2.5})).rejects.toMatchObject({
|
|
495
|
+
code: 'ERR_INVALID_ARGUMENT',
|
|
496
|
+
});
|
|
497
|
+
}, SLOW);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
describe('search leaf — integration components', () => {
|
|
501
|
+
/**
|
|
502
|
+
* A minimal consumer project: a stub `@astryxdesign/core` (so `findCoreDir`
|
|
503
|
+
* resolves without needing the real package) plus an installed
|
|
504
|
+
* `@acme/widgets` integration that contributes one component.
|
|
505
|
+
*/
|
|
506
|
+
function makeConsumerWithIntegrationComponent() {
|
|
507
|
+
const dir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-search-it-'));
|
|
508
|
+
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({name: 'consumer'}));
|
|
509
|
+
fs.writeFileSync(
|
|
510
|
+
path.join(dir, 'astryx.config.mjs'),
|
|
511
|
+
`export default { integrations: ['@acme/widgets'] };\n`,
|
|
512
|
+
);
|
|
513
|
+
|
|
514
|
+
// Stub core: just needs to exist with an (empty) src/ so discoverComponents
|
|
515
|
+
// doesn't throw. Its own component list is irrelevant to this test.
|
|
516
|
+
const coreDir = path.join(dir, 'node_modules', '@astryxdesign', 'core');
|
|
517
|
+
fs.mkdirSync(path.join(coreDir, 'src'), {recursive: true});
|
|
518
|
+
|
|
519
|
+
const widgetsDir = path.join(dir, 'node_modules', '@acme', 'widgets');
|
|
520
|
+
fs.mkdirSync(path.join(widgetsDir, 'components'), {recursive: true});
|
|
521
|
+
fs.writeFileSync(
|
|
522
|
+
path.join(widgetsDir, 'package.json'),
|
|
523
|
+
JSON.stringify({name: '@acme/widgets', version: '1.0.0'}),
|
|
524
|
+
);
|
|
525
|
+
fs.writeFileSync(
|
|
526
|
+
path.join(widgetsDir, 'astryx.integration.mjs'),
|
|
527
|
+
`export default { components: './components' };\n`,
|
|
528
|
+
);
|
|
529
|
+
fs.writeFileSync(
|
|
530
|
+
path.join(widgetsDir, 'components', 'FancyGizmo.doc.mjs'),
|
|
531
|
+
`export default {
|
|
532
|
+
type: 'component',
|
|
533
|
+
name: 'FancyGizmo',
|
|
534
|
+
keywords: ['gizmo', 'widget'],
|
|
535
|
+
usage: {description: 'A fancy gizmo widget.'},
|
|
536
|
+
props: [],
|
|
537
|
+
};\n`,
|
|
538
|
+
);
|
|
539
|
+
fs.writeFileSync(
|
|
540
|
+
path.join(widgetsDir, 'components', 'FancyGizmo.tsx'),
|
|
541
|
+
`export function FancyGizmo() { return null; }\n`,
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
return dir;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
it('includes a component contributed by a configured integration', async () => {
|
|
548
|
+
const dir = makeConsumerWithIntegrationComponent();
|
|
549
|
+
try {
|
|
550
|
+
const r = await search('gizmo', {cwd: dir, type: 'component'});
|
|
551
|
+
expect(r.data.results.some(x => x.name === 'FancyGizmo')).toBe(true);
|
|
552
|
+
} finally {
|
|
553
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
554
|
+
}
|
|
555
|
+
}, SLOW);
|
|
556
|
+
|
|
557
|
+
it('reports the contributing package as the import hint', async () => {
|
|
558
|
+
const dir = makeConsumerWithIntegrationComponent();
|
|
559
|
+
try {
|
|
560
|
+
const r = await search('FancyGizmo', {cwd: dir, type: 'component'});
|
|
561
|
+
const hit = r.data.results.find(x => x.name === 'FancyGizmo');
|
|
562
|
+
expect(hit?.import).toBe('@acme/widgets');
|
|
563
|
+
} finally {
|
|
564
|
+
fs.rmSync(dir, {recursive: true, force: true});
|
|
565
|
+
}
|
|
566
|
+
}, SLOW);
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
describe('search scoring — multi-token aggregation is monotonic', () => {
|
|
570
|
+
/**
|
|
571
|
+
* @param {string} q
|
|
572
|
+
* @param {object} candidate
|
|
573
|
+
* @returns {number}
|
|
574
|
+
*/
|
|
575
|
+
const score = (q, candidate) => scoreQuery(q, tokenizeQuery(q), candidate)?.score ?? 0;
|
|
576
|
+
|
|
577
|
+
it('ranks matching both terms above matching only the stronger one', () => {
|
|
578
|
+
// The shipped regression: scoring averaged over MATCHED tokens, so the
|
|
579
|
+
// weaker second hit pulled the mean down further than the coverage bonus
|
|
580
|
+
// pushed it up. `build "file browser"` put two form wizards that matched
|
|
581
|
+
// only "file" (98) above the actual file browser that matched both (97),
|
|
582
|
+
// and 98 clears the confident-match gate.
|
|
583
|
+
const partial = {name: 'form-wizard-vertical', keywords: ['file']};
|
|
584
|
+
const complete = {
|
|
585
|
+
name: 'file-explorer',
|
|
586
|
+
keywords: ['file'],
|
|
587
|
+
description: 'Column browser for nested folders',
|
|
588
|
+
};
|
|
589
|
+
expect(score('file browser', complete)).toBeGreaterThan(score('file browser', partial));
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
it('never scores a superset of matched terms below a subset', () => {
|
|
593
|
+
const subset = {name: 'zzz-none', keywords: ['alpha']};
|
|
594
|
+
const supersets = [
|
|
595
|
+
{name: 'zzz-none', keywords: ['alpha'], description: 'beta things'},
|
|
596
|
+
{name: 'zzz-none', keywords: ['alpha', 'beta']},
|
|
597
|
+
{name: 'zzz-none', keywords: ['alpha'], weakKeywords: ['beta']},
|
|
598
|
+
];
|
|
599
|
+
for (const superset of supersets) {
|
|
600
|
+
expect(score('alpha beta', superset)).toBeGreaterThanOrEqual(score('alpha beta', subset));
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
it('still scores a verbose prompt on the concepts it did hit', () => {
|
|
605
|
+
// Guards the reason the mean was used: a long prompt matching one concept
|
|
606
|
+
// strongly must not be crushed by dividing across every query token.
|
|
607
|
+
const candidate = {name: 'kanban', keywords: ['kanban']};
|
|
608
|
+
expect(score('i need a kanban somewhere in this rambling request', candidate))
|
|
609
|
+
.toBeGreaterThanOrEqual(90);
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
describe('search scoring — derived keywords rank below authored ones', () => {
|
|
614
|
+
it('scores an authored keyword above a derived one', () => {
|
|
615
|
+
const authored = scoreCandidate('dialog', {name: 'x', keywords: ['Dialog']});
|
|
616
|
+
const derived = scoreCandidate('dialog', {name: 'x', weakKeywords: ['Dialog']});
|
|
617
|
+
expect(authored?.score).toBe(90);
|
|
618
|
+
expect(derived?.score).toBe(60);
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it('keeps one incidental derived match below the confident-match gate', () => {
|
|
622
|
+
// PAGE_DIRECT in api/build/kit is 95: at full keyword strength a page that
|
|
623
|
+
// renders one of everything got a 90-point shot per component and was
|
|
624
|
+
// returned as a confident match for queries it had nothing to do with.
|
|
625
|
+
const derived = scoreCandidate('dialog', {name: 'x', weakKeywords: ['Dialog']});
|
|
626
|
+
expect(derived?.score).toBeLessThan(95);
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
it('still surfaces a derived match above the page floor', () => {
|
|
630
|
+
// PAGE_FLOOR is 50 — weakening the signal must not make it invisible.
|
|
631
|
+
const derived = scoreCandidate('dialog', {name: 'x', weakKeywords: ['Dialog']});
|
|
632
|
+
expect(derived?.score).toBeGreaterThanOrEqual(50);
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
it('explains a derived hit as something the template renders', () => {
|
|
636
|
+
const derived = scoreCandidate('dialog', {name: 'x', weakKeywords: ['Dialog']});
|
|
637
|
+
expect(derived?.reason).toMatch(/renders Dialog/);
|
|
638
|
+
});
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
describe('search — usage guidance is indexed, a tier below description', () => {
|
|
642
|
+
// The vocabulary a reader types usually lives in a component's guidance, not
|
|
643
|
+
// in its one-line description. Banner calls itself "a persistent message";
|
|
644
|
+
// only its best practices name "caution", "problems", "form errors". Before
|
|
645
|
+
// this, none of those words found it.
|
|
646
|
+
const banner = {
|
|
647
|
+
name: 'Banner',
|
|
648
|
+
keywords: ['alert', 'notification'],
|
|
649
|
+
description: 'A persistent message shown above content.',
|
|
650
|
+
guidance: [
|
|
651
|
+
'Pick a status that matches the message: info for updates, warning for caution.',
|
|
652
|
+
'Use error for problems the reader must resolve before continuing.',
|
|
653
|
+
],
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
it('finds a term that appears ONLY in guidance', () => {
|
|
657
|
+
// Red before this change: guidance was never read, so this scored null.
|
|
658
|
+
const hit = scoreCandidate('caution', banner);
|
|
659
|
+
expect(hit).not.toBeNull();
|
|
660
|
+
expect(hit?.reason).toMatch(/guidance mentions "caution"/);
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
it('scores guidance BELOW description, so a component about X outranks one that merely mentions X', () => {
|
|
664
|
+
const own = scoreCandidate('persistent', banner);
|
|
665
|
+
const mention = scoreCandidate('caution', banner);
|
|
666
|
+
expect(own?.score).toBe(50);
|
|
667
|
+
expect(mention?.score).toBe(45);
|
|
668
|
+
expect(mention.score).toBeLessThan(own.score);
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
it('never lets guidance outrank a name or keyword hit', () => {
|
|
672
|
+
expect(scoreCandidate('banner', banner)?.score).toBe(100);
|
|
673
|
+
expect(scoreCandidate('notification', banner)?.score).toBe(90);
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
it('prefers the stronger signal when a term is in both description and guidance', () => {
|
|
677
|
+
const both = scoreCandidate('message', banner);
|
|
678
|
+
expect(both?.score).toBe(50);
|
|
679
|
+
expect(both?.reason).toMatch(/description mentions/);
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
it('stays below MIN_TOKEN_SCORE, so guidance never counts as a matched CONCEPT', () => {
|
|
683
|
+
// Measured regression this prevents: counting guidance as a matched term
|
|
684
|
+
// moved `nested menu` from SideNav to List, and `explain why a field is
|
|
685
|
+
// required` from Field to TextInput — in both cases a component whose
|
|
686
|
+
// guidance happens to mention the other word displaced the real answer.
|
|
687
|
+
// Guidance decides single-word queries; it must not win multi-word ones on
|
|
688
|
+
// breadth. Same reason weakKeywords are capped.
|
|
689
|
+
expect(scoreCandidate('caution', banner)?.score).toBeLessThan(50);
|
|
690
|
+
// Both words are in this candidate's guidance and nowhere else, so if
|
|
691
|
+
// guidance counted as a concept this would come back as a 2/2 match.
|
|
692
|
+
const multi = scoreQuery('caution problems', tokenizeQuery('caution problems'), banner);
|
|
693
|
+
expect(multi).toBeNull();
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
it('lets a real description hit still win the multi-word pass', () => {
|
|
697
|
+
// The floor must exclude guidance without muting the tiers above it.
|
|
698
|
+
const hit = scoreQuery('persistent message', tokenizeQuery('persistent message'), banner);
|
|
699
|
+
expect(hit?.reason).toMatch(/matches 2\/2 terms/);
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
it('tolerates the object-shaped bestPractices entries core actually ships', () => {
|
|
703
|
+
// Core writes `{guidance: true, description: '...'}`, not plain strings.
|
|
704
|
+
const hit = scoreCandidate('resolve', {
|
|
705
|
+
name: 'X',
|
|
706
|
+
guidance: ['Use error for problems the reader must resolve.'],
|
|
707
|
+
});
|
|
708
|
+
expect(hit?.score).toBe(45);
|
|
709
|
+
});
|
|
710
|
+
});
|