Repository navigation
test: parse unit-test fixtures from WIT text - #229
Conversation
The unit tests in exports.rs and imports.rs built wit_parser values (Function, TypeDef, World, Interface, Package) as struct literals, so every wit-parser release that added a field broke them: the bump to wit-parser 0.258 needed 25 additions across 22 literals. They could also describe states the parser never produces, such as a function named take_wide under the world key take-wide. A test-only Fixture parses a WIT document with Resolve::push_source, fills the type sizes, and looks up exported functions, interface functions and types by name. Each test now states its fixture as WIT and keeps its assertions; the two export assertions that named the function with underscores now use the kebab-case name gravity emits for real WIT. test_record_type_generation keeps its checks and drops its debug printing, asserting the self-referential alias it described instead of printing about it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Arcjet Review — 🟢 Low Risk
Decision: Checked
Rationale: The PR refactors test fixtures to parse real WIT text instead of manually constructing wit-parser structs, adds a cfg(test)-only helper module, and updates assertions to match parser-produced kebab-case names. The changes are confined to unit tests and test-only code, introduce no runtime behavior changes, no dependency changes, and no authentication, authorization, data handling, or injection-relevant paths. Security review found no hardcoded secrets or security-sensitive behavior.
Summary of Changes
Replaces hand-built wit_parser fixtures in codegen import/export tests with a new test-only Fixture helper that parses WIT text, fills size information, and provides lookup helpers for worlds, functions, exports, and types. Several tests are updated to use real WIT names and one record generation test now asserts the generated code does not contain a self-referential alias.
Notes
The diff appears to exceed the configured 500-line threshold, largely due to replacing verbose test fixture construction with WIT text. Automated review is still feasible because the changes are test-only, but human reviewers may want to skim the fixture helper and representative test conversions.
The AI assessed this PR as approvable, but the trust level (1) does not allow auto-approval. A human reviewer must approve this PR.
Review: 2035844d | Model: openai/gpt-5.5 | Powered by Arcjet Review
type_id returned the first type with a matching name, so a fixture that declared the same name in two interfaces would get whichever came first. It now panics unless exactly one type has the name, and a test covers the ambiguous case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve the conflict in exports.rs by keeping main's formatting of the code outside the test module and this branch's WIT-parsed test module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The unit tests in
exports.rsandimports.rsbuiltwit_parservalues as struct literals. Every wit-parser release that added a field broke them: the bump to 0.258 in #202 needed 25 field additions. The literals could also describe states the parser never produces, such as a function namedtake_wideunder the world keytake-wide.A test-only
Fixtureparses a WIT document withResolve::push_source, fills the type sizes, and looks up functions and types by name. Each test now states its fixture as WIT and keeps its assertions. The two export assertions that spelled function names with underscores now use the kebab-case names gravity emits for real WIT.test_record_type_generationnow asserts against the self-referential alias that it previously only printed a message about.🤖 Generated with Claude Code