Add whole-document schema validation specs - #59
Open
HassanAkbar wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Adds whole-document XML schema compliance checks to the spec suite to ensure serialized output is actually valid against the vendored STS schemas (not just round-trip stable), while also improving schema-validation spec performance by compiling schemas once per process.
Changes:
- Introduces whole-document schema validation specs for key NISO STS Extended and ISOSTS fixtures (including validating both shipped fixtures and re-serialized output).
- Adds a shared
StsSchemashelper that compiles and memoizes Nokogiri schemas and enforces strict XML parsing to avoid libxml recovery masking invalid input. - Refactors the existing IsoSts fragment schema-validation spec to use the shared schema helper and avoids per-example schema recompilation /
Dir.chdir.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| TODO.sts-refactor/10-test-coverage.md | Marks schema validation tests as completed and documents the intentional scope limits. |
| spec/support/schemas.rb | Adds memoized schema compilation and strict parsing helpers for consistent schema validation across specs. |
| spec/sts_schema_compliance_spec.rb | Adds whole-document schema validation against vendored NISO Extended and ISOSTS schemas (fixture + re-serialized output). |
| spec/iso_sts/schema_validation_spec.rb | Switches existing fragment-level ISOSTS validation to the shared schema helper (no assertion changes). |
| Gemfile | Adds nokogiri for direct Nokogiri::XML::Schema use in the spec suite. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Round-trip specs prove the gem keeps what it read. They cannot prove the output is a legal STS document — a model that always drops the same element round-trips fine and still fails every schema.
Validates 4 fixtures against the NISO Extended XSD and
ISOSTS.xsd, checking both the shipped file and the re-serialized output. The shipped file is the control; without it a passing round-trip proves nothing.Adds
spec/support/schemas.rbto compile and cache the schemas, and movesspec/iso_sts/schema_validation_spec.rbonto it — that spec was recompiling a 0.5s schema in each of its 11 examples and callingDir.chdir. Its assertions are unchanged.Parsing is strict. libxml repairs damage by default, so a truncated file would otherwise compile clean and pass everything.
nokogirimoves into the Gemfile, since the specs callNokogiri::XML::Schemadirectly. It stays out of the gemspec —lib/does not use it.Interchange and NISO STS 1.2 are not covered. Neither schema is vendored, and a stub test for a missing schema is fake coverage.
bundle exec rspec: 5210 examples, 0 failures, 2 pending.bundle exec rubocop: clean. Runtime grows about 23s, nearly all of it re-parsing two 1MB fixtures.The 2 pending are
tbx-nisosts-0.2.xml, invalid as shipped — a<mml:semantics>with no<mml:annotation>. Raw and round-tripped output give the same error, so the fixture is at fault, not the model.Ticks the schema validation box in
TODO.sts-refactor/10-test-coverage.md.Metanorma PR checklist