The project contains a small utility for getting a summary for a query and a cache. The behavior on repeated calls needs to be fixed: data must be validated, query errors must not turn into a successful result, and different query variants must not be mixed in the cache.
Environment: TypeScript 5.8, strict=true, Node.js 22, ES modules. Test run — npm test, build — npm run build. No additional dependencies.
API contract:
normalizeQuery(input: unknown): string | null — returns a cleaned-up query or null.getQuerySummary(input: unknown): Promise<{ query: string; total: number; cached: boolean }> — uses an internal cache and fetchSummary.fetchSummary(query: string): Promise<{ total: number }> — network stub, may fail.Behavior requirements:
fetchSummary rejects, the error must be propagated to the caller.Reproduction:
normalizeQuery and verify that it does not pass as a query.getQuerySummary for two different queries and check that the cache does not mix them.fetchSummary and verify that it is not masked as a successful response.TypeScript 5.8 with strict=true, Node.js 22, ES modules. Execute with npm test and npm run build; no additional packages or runtime services required.
Use line comments to explain the problem, its impact, the fix and how to test it.