xspec.config.ts, a real spec file, a TypeScript source file that references it, and a CI-ready xspec coverage tested --check command that gates on full traceability.
1
Install xspec
xspec is not yet published to npm, so you install it directly from the source repository. You need Node.js 22 or later before you begin.Clone the repository, install dependencies, build the project, and link the binary onto your Verify the installation:
PATH:npm link creates a global symlink so you can run xspec from any directory. If you prefer not to use a global link, you can invoke the binary directly with node /path/to/xspec/dist/cli.js instead.2
Create your project config
Navigate to the root of the project you want to add xspec to and create The config above declares:
xspec.config.ts. This file tells xspec where your spec files live, where your application code lives, and how to define coverage profiles.- A
productspec group covering every MDX file underspecs/. - An
appcode group for your source files and atestsgroup for your test files. - A
testedcoverage profile that measures whichproductrequirements are reachable from thetestsboundary.
3
Write your first spec
Create a Each
specs/ directory at your project root and add your first MDX specification file. Use the <S> component to declare requirements; nest <S> elements to express hierarchy; use the tags prop to label requirements with cross-cutting concerns.id becomes a property path on the generated TypeScript module. Dotted segments (auth.login.valid) translate to nested property accesses (AUTH.auth.login.valid).4
Build the typed modules
Run This produces a
xspec build from your project root to compile the spec files into typed TypeScript modules and assemble the project graph:specs/AUTH.xspec file (and a Markdown file if markdown.emit is true in your config). The .xspec file is the typed module you import in application and test code.5
Reference requirements from TypeScript
Open (or create) a source file and import the generated module. Place a property access wherever you want to declare that a given piece of logic implements or exercises a requirement:The property access is the dependency marker. xspec records it in the graph at build time. If the requirement identifier changes in the spec, TypeScript will surface a type error here immediately.Add a corresponding reference in your test file so the
tested coverage profile can find a path from the tests boundary to the requirement:6
Measure and enforce coverage
Run To enforce full coverage as a CI gate — exiting with code Add this command to your CI pipeline to ensure every requirement is traced to at least one test before merging.
xspec coverage to see the current coverage report across all defined profiles:1 if any requirement in the tested profile is uncovered — use the --check flag: