Skip to content

Extract ASSET_TYPE_MAP into its own module; add Vitest + parser test suite#10

Open
ArneshBanerjee wants to merge 2 commits into
ni5arga:mainfrom
ArneshBanerjee:chore/tests-and-cleanup
Open

Extract ASSET_TYPE_MAP into its own module; add Vitest + parser test suite#10
ArneshBanerjee wants to merge 2 commits into
ni5arga:mainfrom
ArneshBanerjee:chore/tests-and-cleanup

Conversation

@ArneshBanerjee

Copy link
Copy Markdown

Summary

Two structural improvements, no behavior change to the running app:

  1. refactor(types): Extract ASSET_TYPE_MAP and OPERATOR_ALIASES (~1000 lines of data) out of lib/types.ts into a new lib/asset-types.ts, with a shared AssetTypeConfig interface. lib/types.ts shrinks from 1079 → 54 lines and is now a pure types module. The constants are re-exported from lib/types.ts so existing imports still work; internal callers (parser.ts, overpass.ts) are updated to import from the new module directly.
  2. test: Add Vitest as the test runner (npm test, npm run test:watch) and a 23-test suite for lib/parser.ts covering both structured (type: / operator: / region: / country: / near: / radius:) and natural-language queries, plus validateQuery error paths. Pins down current parser behavior so future refactors can be done safely.

Why

  • lib/types.ts had grown into a giant data file; navigating types or adding a new asset type required scrolling past a thousand-line table. Splitting makes both files reviewable and lets the type-shape change independently of the data.
  • There are no tests in the repo today; the parser is the single biggest place where regressions can sneak in unnoticed.

Notes for review

  • I did not modify CI in this PR to avoid conflicting with PR Escape user operator input in Overpass queries; add typecheck and build to CI #9 (which already extends the workflow with typecheck/build). Once PR Escape user operator input in Overpass queries; add typecheck and build to CI #9 lands (or this one does — order doesn't matter), the test step (npm test) should be appended to the workflow. Happy to follow up with a tiny PR or rebase, whichever you prefer.
  • While writing tests I noted two latent parser bugs worth flagging for a future PR: (a) the substring-based operator matcher classifies aws data centers in virginia as the vodafone operator because "virginia" contains "vi" (a vodafone alias); (b) the broad \btowers?\b regex can shadow more specific patterns depending on order. Both are out of scope here.
  • I also audited lib/search-index.ts: it is not dead — it powers the autocomplete suggestions in SearchBar.tsx. It does maintain its own parallel asset-type list, which is a duplication worth consolidating later but is out of scope for this PR.

Test plan

  • npm run lint — clean
  • npx tsc --noEmit — clean
  • npm test — 23/23 passing
  • npm run build — clean
  • Confirmed lib/types.ts still exports ASSET_TYPE_MAP, OPERATOR_ALIASES, and AssetTypeConfig for backward compatibility.

🤖 Generated with Claude Code

Arnesh Banerjee and others added 2 commits June 6, 2026 21:30
…/asset-types

`lib/types.ts` was 1079 lines, the vast majority of which was the
ASSET_TYPE_MAP data table and the OPERATOR_ALIASES dictionary. Move
both constants (and introduce a shared `AssetTypeConfig` type alias)
into a new `lib/asset-types.ts`, leaving `lib/types.ts` to hold only
TS interfaces. Re-export the constants from `lib/types.ts` so
existing imports continue to work; internal consumers
(`lib/parser.ts`, `lib/overpass.ts`) are updated to import from the
new module directly.

No behavior change.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Wire up Vitest as the test runner (`npm test`, `npm run test:watch`)
and add 23 unit tests covering `lib/parser.ts`: structured-query
parsing (type/operator/region/country/near/radius, underscore
decoding, radius clamping), natural-language extraction (type, near,
in, radius via "within"), operator-alias normalization, empty/
whitespace input, and `validateQuery` error paths.

These lock in current parser behavior so a future refactor (e.g. the
substring-collision bug where "virginia" matches the `vi` alias of
vodafone, or the broad `\btowers?\b` pattern shadowing more specific
ones) can be done with confidence.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Someone is attempting to deploy a commit to the ni5arga's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant