Skip to content

Add whole-document schema validation specs - #59

Open
HassanAkbar wants to merge 1 commit into
mainfrom
test/schema-validation-specs
Open

Add whole-document schema validation specs#59
HassanAkbar wants to merge 1 commit into
mainfrom
test/schema-validation-specs

Conversation

@HassanAkbar

Copy link
Copy Markdown
Member

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.rb to compile and cache the schemas, and moves spec/iso_sts/schema_validation_spec.rb onto it — that spec was recompiling a 0.5s schema in each of its 11 examples and calling Dir.chdir. Its assertions are unchanged.

Parsing is strict. libxml repairs damage by default, so a truncated file would otherwise compile clean and pass everything.

nokogiri moves into the Gemfile, since the specs call Nokogiri::XML::Schema directly. 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 StsSchemas helper 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.

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.

2 participants