Skip to content

test(htmlgen): cover failure paths with whole-document fixtures (4/4) - #261

Merged
sthanikan2000 merged 1 commit into
OpenNSW:mainfrom
chathura-de-silva:feat/htmlgen-failures
Oct 6, 2026
Merged

sthanikan2000 merged 1 commit into
OpenNSW:mainfrom
chathura-de-silva:feat/htmlgen-failures

Conversation

@chathura-de-silva

@chathura-de-silva chathura-de-silva commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

#260 pins what a correct template produces. Nothing yet pins what a broken one produces: the error a template author gets for each kind of mistake, and that Validate and Generate agree on it.

Changes

TestGolden_InvalidTemplates renders every template in testdata/invalid/ with both Validate and Generate (against the permit data from #260) and requires the same sentinel error from each:

Fixture Mistake Error
syntax-error.tmpl {{ .name left unclosed ErrParseTemplate
unknown-function.tmpl calls a resolver that was not supplied ErrParseTemplate
branch-context.tmpl an {{ if }} whose branches end in different HTML contexts ErrUnsafeTemplate
unclosed-attribute.tmpl an attribute value whose closing quote is missing ErrUnsafeTemplate

The test requires an expected error for every file in testdata/invalid/, so a fixture cannot be added without one.

Testing

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

Race-clean, 0 lint issues.

Related

Stacked chain — 4 of 4, review in order:

#258 core → #259 helpers and resolvers → #260 golden fixtures → this PR

Depends on #260; until it, #259 and #258 merge, this diff includes them.

Summary by CodeRabbit

  • Tests
    • Expanded coverage for invalid templates, including syntax errors, unsafe branch contexts, incomplete attributes, and unknown functions. Both template validation and generation are checked against expected errors.

@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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: 74b672ff-03ab-4ae8-a616-b29a53c0a232

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a5728abf-88bc-444e-920b-6484e23a60f2
📥 Commits

Reviewing files that changed from the base of the PR and between d8b9036 and 4857580.

📒 Files selected for processing (5)
  • htmlgen/golden_test.go
  • htmlgen/testdata/invalid/branch-context.tmpl
  • htmlgen/testdata/invalid/syntax-error.tmpl
  • htmlgen/testdata/invalid/unclosed-attribute.tmpl
  • htmlgen/testdata/invalid/unknown-function.tmpl

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The change adds four invalid template fixtures and a test that checks their expected errors through both htmlgen.Validate and htmlgen.Generate.

Changes

Invalid template checks

Layer / File(s) Summary
Invalid fixtures and error checks
htmlgen/testdata/invalid/*, htmlgen/golden_test.go
The fixtures cover malformed syntax, an unclosed attribute, conditional opening markup, and an unknown function. The test checks that each fixture has an expected error and that both Validate and Generate return it.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 48575

The invalid-template fixtures exercise the intended errors; no actionable merge-blocking risk remains after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (4 skipped: 4… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding tests for invalid HTML templates.
Description check ✅ Passed The description explains the problem, changes, fixtures and expected errors, testing, and related PRs. It omits the Type of Change and Checklist sections, but the core information is complete.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (4 skipped: 4 unsupported.)

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@chathura-de-silva
chathura-de-silva marked this pull request as draft October 2, 2026 06:47
@chathura-de-silva
chathura-de-silva marked this pull request as ready for review October 6, 2026 08:29

@sthanikan2000 sthanikan2000 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Pins the error each broken template in testdata/invalid produces from
both Validate and Generate: a syntax error and an unknown function
(ErrParseTemplate), and a branch that ends in different contexts and an
unclosed attribute (ErrUnsafeTemplate). Every invalid fixture must have
an expected error, so a new one cannot be added untested.
@sthanikan2000
sthanikan2000 force-pushed the feat/htmlgen-failures branch from 4857580 to c10532b Compare October 6, 2026 12:04
@sthanikan2000
sthanikan2000 merged commit 218d28c into OpenNSW:main Oct 6, 2026
25 checks passed
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