Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

test(cli): the main searcher's test checks the count contract per query (#9996)

Christopher Chedeauf8a309da00a2
diff --git a/.changeset/search-count-contract-test.md b/.changeset/search-count-contract-test.md
new file mode 100644
index 0000000000..8fb018c3f4
--- /dev/null
+++ b/.changeset/search-count-contract-test.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[chore] Internal: the main searcher's test checks the count contract for each query, not a byte total over eight queries.
+
+@vjeux
diff --git a/packages/cli/api/search/_main-searcher.mjs b/packages/cli/api/search/_main-searcher.mjs
index 18ed2600a9..af6fa7b2d6 100644
--- a/packages/cli/api/search/_main-searcher.mjs
+++ b/packages/cli/api/search/_main-searcher.mjs
@@ -8,7 +8,7 @@
* domain the query wants. Its weights are static numbers in
* _main-searcher.weights.json.
* @input {query, options} and the gathered catalog with its static data
- * @output the search response, the lexical response's shape and size
+ * @output the search response, the lexical response's shape and count
* @position api/search; a child of the root dispatcher in tree.mjs
*/
diff --git a/packages/cli/api/search/_main-searcher.test.mjs b/packages/cli/api/search/_main-searcher.test.mjs
index bbbb7984b3..8bd06a4cc0 100644
--- a/packages/cli/api/search/_main-searcher.test.mjs
+++ b/packages/cli/api/search/_main-searcher.test.mjs
@@ -2,9 +2,9 @@
/**
* @file Tests for the main searcher (_main-searcher.mjs) through search():
- * it ranks by plain signals, answers the same every time, never grows the
- * response past the lexical ranker's, and touches no network. Run against the
- * real @astryxdesign/core.
+ * it ranks by plain signals, answers the same every time, answers only with
+ * lexical matches and never more of them, and touches no network. Run against
+ * the real @astryxdesign/core.
*/
import {describe, it, expect, vi, afterEach} from 'vitest';
@@ -32,6 +32,8 @@ const QUERIES = [
/** @param {unknown} r */
const top = r =>
/** @type {any} */ (r).data.results.map(x => `${x.domain}:${x.name}`);
+/** @param {any} r */
+const keyOf = r => `${r.domain}:${r.name}:${r.command}`;
afterEach(() => vi.restoreAllMocks());
@@ -70,23 +72,26 @@ describe('main searcher', () => {
});
it(
- 'never returns more results or more bytes than the lexical ranker',
+ 'answers each query with lexical matches, never more of them',
{timeout: 120_000},
async () => {
- let mine = 0;
- let core = 0;
for (const q of QUERIES) {
- const [a, b] = [
+ const [mine, lexical, every] = [
await search(q, {cwd: REPO}),
await searchCore(q, {cwd: REPO}),
+ await searchCore(q, {cwd: REPO, limit: Number.MAX_SAFE_INTEGER}),
];
- expect(a.data.results.length).toBeLessThanOrEqual(
- b.data.results.length,
+ expect(mine.data.results.length).toBeLessThanOrEqual(
+ lexical.data.results.length,
);
- mine += JSON.stringify(a).length;
- core += JSON.stringify(b).length;
+ expect(mine.data.matchCount).toBe(lexical.data.matchCount);
+ const byKey = new Map(every.data.results.map(r => [keyOf(r), r]));
+ for (const r of mine.data.results) {
+ const own = byKey.get(keyOf(r));
+ expect(own, `${q}: ${keyOf(r)} is a lexical match`).toBeDefined();
+ expect([r.score, r.reason]).toEqual([own?.score, own?.reason]);
+ }
}
- expect(mine).toBeLessThanOrEqual(core);
},
);