From ca8f1dc4028742f6b29038979f5c5b58cdb6da7e Mon Sep 17 00:00:00 2001 From: EmergentTechGroup <356278375+EmergentTechGroup@users.noreply.github.com> Date: Mon, 30 Nov 2026 19:41:50 -0500 Subject: [PATCH] fix(search): reject unknown --family values and flags with no value `npm run search -- message --family action` printed "No matching elements." because the family is compared verbatim and the valid id is `actions`. During the duplicate check the ontology proposal template asks for, that reads as "this concept is not in the table". `--family Actions` failed the same way, and `--family` or `--symbol` with no value (or `--symbol=`) silently listed all 115 elements. The family is now lower-cased and checked against FAMILY_IDS, with the valid names in the error; a flag with no value exits 1 with "Missing value for --family/--symbol". The help text lists the families. Adds test/search.test.ts (8 cases, run against the real script), lists it in the README test inventory, and notes the fix under Unreleased. --- CHANGELOG.md | 9 +++++++ README.md | 2 ++ scripts/search.ts | 30 ++++++++++++++++++++--- test/search.test.ts | 59 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 test/search.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index d4aee4f..ca753bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `npm run search -- --family ` now rejects an unknown family (for example + `action` instead of `actions`) with the list of valid ones, and matches the name + case-insensitively. It used to print "No matching elements.", which reads as + "this concept is not in the table" during the duplicate check the ontology + proposal template asks for. `--family` or `--symbol` with no value now fails + instead of silently listing the whole table. + ## [0.7.0] - 2026-11-27 ### Added diff --git a/README.md b/README.md index b88d05c..d5ae02b 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,8 @@ enforced by tests rather than by convention: or the README test inventory drift from the shipped code. - `test/public-api.test.ts` — the loader, schema entry point, prompt builder, and an atom are reachable through the paths a package consumer uses. +- `test/search.test.ts` — `npm run search` filters by family and symbol, and + rejects an unknown family or a flag with no value instead of answering "no match". Run with `npm test`. No test framework dependency; `node:test` and `tsx` only. diff --git a/scripts/search.ts b/scripts/search.ts index 8e66700..3d60b8c 100644 --- a/scripts/search.ts +++ b/scripts/search.ts @@ -10,7 +10,7 @@ * before it is written. */ -import { loadOntology, type OntologyElement } from '../src/ontology.js'; +import { FAMILY_IDS, isFamilyId, loadOntology, type OntologyElement } from '../src/ontology.js'; interface Options { terms: string[]; @@ -19,6 +19,18 @@ interface Options { list: boolean; } +function fail(message: string): never { + process.stderr.write(`${message}\n`); + process.exit(1); +} + +/** The value after a flag, or an error: a flag left without one must not widen the search. */ +function flagValue(argv: string[], i: number, flag: string): string { + const value = argv[i + 1]; + if (value === undefined || value.startsWith('-')) fail(`Missing value for ${flag}`); + return value; +} + function parseArgs(argv: string[]): Options { const terms: string[] = []; let family: string | undefined; @@ -28,12 +40,12 @@ function parseArgs(argv: string[]): Options { for (let i = 0; i < argv.length; i += 1) { const arg = argv[i]; if (arg === '--family' || arg === '-f') { - family = argv[i + 1]; + family = flagValue(argv, i, arg); i += 1; } else if (arg?.startsWith('--family=')) { family = arg.slice('--family='.length); } else if (arg === '--symbol' || arg === '-s') { - symbol = argv[i + 1]; + symbol = flagValue(argv, i, arg); i += 1; } else if (arg?.startsWith('--symbol=')) { symbol = arg.slice('--symbol='.length); @@ -47,6 +59,16 @@ function parseArgs(argv: string[]): Options { } } + if (symbol === '') fail('Missing value for --symbol'); + if (family !== undefined) { + // An unknown family used to report "No matching elements.", which reads as + // "this concept is not in the table" and invites a duplicate proposal. + family = family.toLowerCase(); + if (!isFamilyId(family)) { + fail(`Unknown family "${family}". Expected one of: ${FAMILY_IDS.join(', ')}`); + } + } + return { terms, family, symbol, list }; } @@ -56,7 +78,7 @@ function printUsage(): void { 'Usage: npm run search -- [options] [terms...]', '', 'Options:', - ' -f, --family restrict to one family', + ` -f, --family restrict to one family (${FAMILY_IDS.join(', ')})`, ' -s, --symbol look up one exact symbol', ' -l, --list list every element', ' -h, --help show this message', diff --git a/test/search.test.ts b/test/search.test.ts new file mode 100644 index 0000000..1d5b22a --- /dev/null +++ b/test/search.test.ts @@ -0,0 +1,59 @@ +import assert from 'node:assert/strict'; +import { spawnSync } from 'node:child_process'; +import * as path from 'node:path'; +import { describe, it } from 'node:test'; +import { fileURLToPath } from 'node:url'; + +const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); +const SCRIPT = path.join(ROOT, 'scripts', 'search.ts'); + +function search(...args: string[]) { + const result = spawnSync(process.execPath, ['--import', 'tsx', SCRIPT, ...args], { + cwd: ROOT, + encoding: 'utf8', + }); + return { status: result.status, stdout: result.stdout, stderr: result.stderr }; +} + +/** + * `npm run search` is the duplicate check the ontology proposal template points + * to, so a mistyped flag must fail loudly rather than report "no match" (which + * reads as "this concept is missing") or silently list the whole table. + */ +describe('scripts/search.ts', () => { + it('finds an element within a family', () => { + const { status, stdout } = search('message', '--family', 'actions'); + assert.equal(status, 0); + assert.match(stdout, /\bMg\s+Message\s+actions\b/); + assert.doesNotMatch(stdout, /\bMs\s+Message\b/); + }); + + it('matches the family name case-insensitively', () => { + const { status, stdout } = search('message', '--family=Actions'); + assert.equal(status, 0); + assert.match(stdout, /\bMg\s+Message\b/); + }); + + it('rejects an unknown family and names the valid ones', () => { + const { status, stdout, stderr } = search('message', '--family', 'action'); + assert.equal(status, 1); + assert.equal(stdout, ''); + assert.match(stderr, /Unknown family "action"/); + assert.match(stderr, /objects, properties, actions, interfaces, intelligence, rules/); + }); + + for (const args of [['--family'], ['--family', '--list'], ['--symbol'], ['--symbol=']]) { + it(`rejects a flag with no value: ${args.join(' ')}`, () => { + const { status, stdout, stderr } = search(...args); + assert.equal(status, 1); + assert.equal(stdout, ''); + assert.match(stderr, /Missing value for --(family|symbol)/); + }); + } + + it('looks up a symbol case-insensitively', () => { + const { status, stdout } = search('--symbol', 'tk'); + assert.equal(status, 0); + assert.match(stdout, /\bTk\s+Task\s+objects\b/); + }); +});