Role. You are a senior TypeScript test engineer. Your goal is to raise
@fhir-dsl/cli to production-grade unit-test coverage using vitest, without
modifying any source or introducing new runtime dependencies.
fhir-dsl is a type-safe FHIR query builder + code generator monorepo
(pnpm workspaces). The CLI — binary name fhir-gen — wraps
@fhir-dsl/generator behind Commander.js and exposes the generate subcommand
so end users can produce TypeScript types for any FHIR version or IG.
Monorepo layout: packages/<pkg>/src/ (source, colocated *.test.ts) and
packages/<pkg>/test/ (separate tree, also picked up by vitest). Tests you
write for this prompt go in packages/cli/test/.
- Entry point:
packages/cli/src/index.tswiresgenerateCommandinto a Commander program namedfhir-gen. - Sole subcommand today:
generateCommandinpackages/cli/src/commands/generate.ts. - Public surface: the CLI invoked from a shell; programmatically, only the
exported
generateCommandis consumed. - Runtime deps:
commander,@fhir-dsl/generator.
packages/cli/src/index.tspackages/cli/src/commands/generate.tspackages/cli/src/commands/generate.test.ts(existing coverage)packages/generator/src/generator.ts(signature of thegenerate()the CLI calls)
packages/cli/src/commands/generate.test.ts asserts that each option is
registered with the right required/optional flag and default. Do not
re-assert these. Focus on behavior — what the command does when invoked.
Write tests in packages/cli/test/ using vitest. Cover at minimum:
--resourcesparsing. Empty string, single value, comma-separated list, whitespace around values ("Patient , Observation "), duplicate entries, andundefined(flag absent) must all be handled correctly. Mockgenerate()from@fhir-dsl/generator(e.g.vi.mock) and assert on theresourcesfield passed to it.--validatoracceptance.nativeandzodare accepted; any other value must throw an Error whose message includes both the offending value and the legal values.- Path resolution.
--outand--srcmust be passed throughpath.resolveso relative paths become absolute. Assert on the value the CLI forwards togenerate(). - Flag forwarding. Each of
--ig,--cache,--expand-valuesets,--resolve-codesystems,--include-spec,--strict-extensible, and--versionreachesgenerate()under the expected key. --igmulti-value. Commander's<packages...>means repeating--igyields an array. Confirm the CLI does not double-wrap or split on commas.- Missing required flag. Omitting
--outor--versioncauses Commander to exit with a non-zero code and print a usage error. (Useprogram.exitOverride()/configureOutputto capture without killing the test process.) - Unknown flag. Passing
--unknown-flagsurfaces an error rather than being silently forwarded togenerate().
Read these before writing tests:
- Commander.js v12 docs:
https://github.com/tj/commander.js/tree/v12.x#readme — especially
exitOverride,configureOutput, parsingvariadicargs, andrequiredOption. - FHIR published versions list to confirm version strings the CLI accepts: https://www.hl7.org/fhir/directory.html.
- FHIR package registry URL format (IG packages like
hl7.fhir.us.core@6.1.0): https://registry.fhir.org/learn.
- vitest with
globals: true(you don't needimport { describe, it, ... }but keeping the imports for parity with the existing style is fine). - No emojis anywhere — source, tests, docstrings, commit messages.
- Mock
@fhir-dsl/generator'sgenerateexport at the module boundary. Do not monkey-patchgenerateCommanditself. - When you need to simulate argv, prefer
generateCommand.parseAsync(["node", "fhir-gen", "generate", ...])withexitOverrideset, so assertions run on Commander's thrownCommanderError/InvalidArgumentError. - Colocate new tests in
packages/cli/test/— pick descriptive filenames (generate-resources.test.ts,generate-validator.test.ts, …).
- Read the source + existing test files listed above.
- Scaffold a
vi.mock("@fhir-dsl/generator", ...)helper shared by tests. - Write each scenario as its own
it(...)block. One assertion per concept. - Run the gates from the repo root:
pnpm test --filter=@fhir-dsl/cli # or: pnpm test (full suite) pnpm lint pnpm -r typecheck
- Iterate until all three are green.
- Every scenario above has at least one
it(...)block. pnpm test,pnpm lint,pnpm -r typecheckall green.- No test hits the network or writes to disk.
- No source files under
packages/cli/src/are modified.
- Refactoring the CLI or its option schema.
- End-to-end tests that actually invoke
generate()against FHIR definitions (covered by thegeneratorprompt). - Adding new subcommands.