Skip to content

test(xmlgen): cover failure paths with whole-document fixtures (4/4) - #200

Open
sthanikan2000 wants to merge 1 commit into
feature/xmlgen-goldenfrom
feature/xmlgen-failure-tests
Open

sthanikan2000 wants to merge 1 commit into
feature/xmlgen-goldenfrom
feature/xmlgen-failure-tests

Conversation

@sthanikan2000

@sthanikan2000 sthanikan2000 commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Problem

The golden fixtures in #202 prove the conversions work, but only on the happy path. Nothing shows what a failure looks like on a document of realistic size — and an error that says only "invalid XML" is of no use against a hundred-element declaration.

Changes

Eight deliberately broken templates under testdata/invalid/, each a mistake somebody could plausibly commit, rendered against the real invoice data:

Fixture Mistake Expected
two-roots.tmpl a range at the top level with nothing wrapping it ErrMultipleRoots
unclosed-element.tmpl </Header> forgotten ErrMalformedXML
undeclared-prefix.tmpl soapp: typed one letter wrong ErrUndeclaredNamespace
doctype.tmpl a DOCTYPE Go ignores but a receiving parser will not ErrDoctypeNotAllowed
unknown-function.tmpl a resolver never supplied ErrParseTemplate
syntax-error.tmpl an if with no end ErrParseTemplate
raw-bypass.tmpl raw on a value containing & ErrMalformedXML
object-as-text.tmpl a whole object printed where text belongs ErrUnsupportedValue

Each case asserts the message names what went wrong — soapp, codelist, Header — so it can be found in the template.

For bad data, the real invoice.json is patched at one point rather than duplicated per case: a date in the wrong layout, a non-numeric amount, an object where text belongs, a table that is not a table, and bytes that are not JSON at all. That keeps the broken value beside its assertion and stops these drifting out of step with the fixture.

A second test records which faults Validate catches without data — the parse-time ones — and which can only surface from Generate. That is the difference between a template failing when it is stored and failing when someone presses submit.

Testing

cd xmlgen
go test -race ./...
golangci-lint run -c ../.golangci.yml --timeout=5m ./...

180 subtests cumulative (25 added), race-clean, 0 lint issues. Statement coverage is unchanged at 88.7%, which is the expected result: these paths were already exercised. What is new is proof the errors are legible on a realistic document rather than a one-element toy.

Writing these found a real defect in #202's fixture — under WithStrictKeys the invoice template tripped on a key deliberately left absent, so the fixture could not pass strict mode at all. That fix lives in #202, which is also what keeps this PR purely additive: 9 new files, zero modifications.

Related

Implements #189. Stacked chain — 4 of 4:

#199 engine → #201 helpers and resolvers → #202 golden fixtures → #200 (this)

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: ec97baa6-cff7-4561-9aea-bb934b22c708


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sthanikan2000
sthanikan2000 force-pushed the feature/xmlgen-failure-tests branch from a0b4ac9 to 88c4f3c Compare September 15, 2026 10:30
@sthanikan2000 sthanikan2000 changed the title test(xmlgen): cover failure paths with whole-document fixtures test(xmlgen): cover failure paths with whole-document fixtures (4/4) Sep 15, 2026
@sthanikan2000
sthanikan2000 changed the base branch from feature/xmlgen to feature/xmlgen-golden September 15, 2026 10:32
@sthanikan2000
sthanikan2000 added this pull request to stack #204 September 16, 2026 04:55
@sthanikan2000 sthanikan2000 self-assigned this Sep 16, 2026
@sthanikan2000
sthanikan2000 force-pushed the feature/xmlgen-failure-tests branch from 88c4f3c to c8dab27 Compare September 17, 2026 09:12
@sthanikan2000
sthanikan2000 force-pushed the feature/xmlgen-failure-tests branch from c8dab27 to 2843f72 Compare September 17, 2026 09:58
@sthanikan2000
sthanikan2000 force-pushed the feature/xmlgen-failure-tests branch from 2843f72 to d3c8b6a Compare September 17, 2026 10:06
@sthanikan2000
sthanikan2000 force-pushed the feature/xmlgen-failure-tests branch from d3c8b6a to 1293adc Compare September 17, 2026 10:16
@sthanikan2000
sthanikan2000 force-pushed the feature/xmlgen-failure-tests branch from 1293adc to 938e02b Compare September 17, 2026 10:35
@sthanikan2000
sthanikan2000 force-pushed the feature/xmlgen-failure-tests branch from 938e02b to 195de80 Compare September 17, 2026 15:50
@sthanikan2000 sthanikan2000 reopened this Sep 17, 2026
@sthanikan2000
sthanikan2000 force-pushed the feature/xmlgen-failure-tests branch from 7814517 to eceaa3c Compare September 17, 2026 15:56
@sthanikan2000
sthanikan2000 force-pushed the feature/xmlgen-failure-tests branch from eceaa3c to 86cd6c5 Compare September 17, 2026 16:08
The golden fixtures proved the conversions work, but only on the happy path.
Nothing showed what a failure looks like on a document of realistic size,
and an error that says only "invalid XML" is of no use against a
hundred-element declaration.

Adds eight deliberately broken templates under testdata/invalid/, each a
mistake somebody could plausibly commit -- a range at the top level with
nothing wrapping it, an element never closed, a namespace prefix typed one
letter wrong, a DOCTYPE, an unsupplied resolver, an if with no end, raw used
on a value containing an ampersand, and a whole object printed where text
belongs. Each is rendered against the real invoice data, and each case
asserts the message names what went wrong, so it can be found in the
template.

For bad data, the real invoice fixture is patched at one point rather than
duplicated per case: a date in the wrong layout, a non-numeric amount, an
object where text belongs, a table that is not a table. That keeps the
broken value beside its assertion and stops these drifting out of step with
invoice.json.

A second test records which faults Validate catches without data -- the
parse-time ones -- and which can only surface from Generate. That is the
difference between a template failing when it is stored and failing when
someone presses submit.

Refs #189

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@sthanikan2000
sthanikan2000 force-pushed the feature/xmlgen-failure-tests branch from 86cd6c5 to 4bfb09f Compare September 18, 2026 10:27
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.

1 participant