Skip to content

fix(tests): resolve contradictory layout resolution test assertions#2

Merged
zeroedin merged 1 commit into
mainfrom
fix/layout-test-contradictions
Apr 12, 2026
Merged

fix(tests): resolve contradictory layout resolution test assertions#2
zeroedin merged 1 commit into
mainfrom
fix/layout-test-contradictions

Conversation

@zeroedin

Copy link
Copy Markdown
Owner

Summary

  • Each layout fallback chain test now creates its own temp directory with specific layout files, so each test independently controls which candidates exist on disk
  • Eliminates the contradiction where identical inputs (same page, layoutsDir, engine, permalinkCfg) expected different return values from a deterministic function
  • Added missing coverage: index page filename fallback (index.liquid when blog.liquid absent) and taxonomy subdirectory fallback (tags.liquid when taxonomies/tags.liquid absent)

Root cause

The tests described the fallback chain ordering (post.liquid → my-post.liquid → default.liquid → error) but all shared the same BeforeEach state. Since ResolveLayout is deterministic, only one test per group could ever pass — the others were structurally impossible to satisfy.

Test plan

  • go vet ./... — all packages compile cleanly
  • go test ./internal/template/... — layout tests that match the first candidate pass; tests requiring filesystem-aware fallback correctly fail (red phase)
  • No other test files modified — change is scoped to layout_test.go only

Closes #1

🤖 Generated with Claude Code

Each fallback chain test now creates its own temp directory with specific
layout files, so tests control which candidates exist on disk. This
eliminates the contradiction where identical inputs expected different
return values from a deterministic function.

Added coverage for index page filename fallback and taxonomy subdirectory
fallback that were previously untested chain steps.

Closes #1

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zeroedin
zeroedin merged commit f104b8c into main Apr 12, 2026
zeroedin added a commit that referenced this pull request Apr 15, 2026
…uildWithContent

Address PR #87 review feedback:

Blocking: Phase 2 SSR transform was positioned after Stage 6 output
writing, so transformed HTML never reached disk. Move the entire Phase 2
block before output writing per spec §6 ordering (Phase 1 → Phase 2 →
Phase 3 output).

Non-blocking #1: Wire Phase 2 into BuildWithContent so tests with
cfg.SSR configured get transformed output instead of silently skipping.

Non-blocking #2: Remove redundant SSRSkipped = false assignment by
tracking SSR state via a local ssrSkipped bool set before the result
is constructed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Apr 25, 2026
Reviewer items:
- Use MarkdownOptions.Hooks field instead of separate function (#1)
- Tests use []byte(input) matching RenderMarkdown signature (#2)
- Heading ID uses slugify: "My Section" → "my-section" (#3)
- Protocol-relative URLs intentionally not external for v1 (#4)
- Render hooks follow engine choice (Liquid vs Go templates) (#5)
- Add blockquote and table tests (#6)

Copilot items:
- Clarify Alloy registers renderers, not goldmark auto-detecting
- Add template tag escaping note for custom hook output structures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Jul 24, 2026
P1 #1: Fix duplicate step 19 in PLAN.md pipeline stages — renumber
steps 20-25 after inserting onFormatRendered at step 19. Update hook
table step numbers (onAssetProcess 22+, onBuildComplete 25).

P1 #2: Add content mutation write-back assertion to single non-HTML
page test — verifies page.SetRenderedBody path is wired, not just
FormatBodies.

P2 #3: Fix test count 12 → 14 in IMPLEMENTATION.md (was 13, now 14
with new test).

P2 #4: Add test for HTML in non-first position of outputs array
(outputs: ["json", "html"]) — catches page.Outputs[0] == "html"
implementations.

P2 #5: Add second plugin to read-only fields test that verifies
frontMatter immutability end-to-end — throws if first plugin's
frontMatter mutation was applied back.

P3 #6: Add BuildIncremental parity note for onFormatRendered in both
PLAN.md and IMPLEMENTATION.md.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Jul 24, 2026
- Fix test count 8→9 in IMPLEMENTATION.md (#1)
- Pick single outbound approach: GetOwnPropertyNames + property walk (#2)
- Use extractGoMap helper in first test instead of inline logic (#3)
- Inline toOrderedMap into extractGoMap (#4)
- Extract buildBenchHTML helper to deduplicate benchmark HTML construction (#5)
- Add path assertion to HookTransformPayload test (#11)
- Add toc outbound verification to HookTransformPayload result (#12)
- Add url, path, frontMatter assertions to identity return test (#13)
- Fix 800KB benchmark: reduce to 4300 iterations for ~800KB actual size (#14)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Jul 25, 2026
- P1 #6: Updated summary table (Phase 5: ~129, cumulative downstream)
- P2 #1: Added multi-byte character table entry (CJK, emoji) —
  validates X-Body-Length is byte count not rune count
- P2 #7: Added \r\n suffix to X-Body-Length assertion to prevent
  decimal-prefix false match (50 matching 500)
- P3 #2: Use parsed headers map from parseSplitFrame, assert
  header value matches actual raw body byte count
- P3 #3: Added empty split field test — falls back to single-header
- P3 #4: Added dual-key map priority test — html over content
- P3 #5: Added caller map immutability guard test

12 total tests (was 8). Test counts updated in IMPLEMENTATION.md
(section header, node.go description, impl guidance, summary table).
PLAN.md updated with empty-field fallback, dual-key priority, and
map immutability constraints.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Jul 25, 2026
- P0 #1: Update bridge.js inbound parser to handle split-body frames
  (X-Body-Length/X-Body-Field headers) and outbound sendMessage to
  produce split-body frames for hook results with html/content fields
- P0 #2-3: Add bounds and negative-value validation on Content-Length
  and X-Body-Length in both DecodeMessage and Send before slicing or
  allocating
- P1 #4: Require X-Body-Field header when X-Body-Length is present;
  error on empty field name
- P1 #5: Restore stdout pollution detection — first header line in
  Send must start with "Content-Length:", rejecting "debug: ..." lines
- P1 #6: Switch stripField to JSON round-trip (marshal struct → unmarshal
  to map → delete key) per IMPLEMENTATION.md spec, so new struct fields
  are automatically included
- P1 #7: DecodeMessage split-body injection prefers Result map, falls
  back to Payload map when Result is nil, per spec
- P2 #8: Use len(fieldValue) directly in EncodeMessage instead of
  allocating []byte(fieldValue) copy for byte-length measurement

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Jul 25, 2026
- P2 #1: Restore per-type manual map construction in stripField for the
  three known payload types (avoids marshaling the 800KB field just to
  delete it). JSON round-trip kept as default fallback for future types.
- P3 #2: Add log.Printf warnings on stripField marshal/unmarshal error
  paths so silent optimization skips are diagnosable.
- CodeRabbit: Add mismatched split-body header validation in bridge.js
  (X-Body-Length present but X-Body-Field missing → error response).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Jul 25, 2026
P2 #1: Hoist setupQuickJSWithHook to outer Describe scope, remove
duplicate setupQuickJSWithHookFor1186. Both #1180 and #1186 sections
now share the same helper.

P2 #2: Extract checkGlobalIsFunction closure — three existence tests
are now one-liners calling the shared helper.

P2 #3: Add *qjs.Value lifetime note to IMPLEMENTATION.md — stored
function references must be Free()d in Close() before context teardown.

P2 #4: Add lazy FM test for HookFormatRenderedPayload (onFormatRendered)
to verify setPayloadFrontMatter is wired consistently across all three
payload types.

P2 #9 (addendum): Fix null sentinel collision in __installLazyFM and
__installLazyTOC JS snippets — use unique sentinel object instead of
null so page.frontMatter = null sticks. Add corresponding test.

P3 #5: Add configurable: true test for lazy frontMatter property.

P3 #6: Add lazy TOC setter test for parity with frontMatter setter.

P3 #7: Add no-globals disambiguation test — verifies invokeHookFastPath
uses ctx.Invoke (no __callInput/__callHookName globals) vs ctx.Eval.

Test count: 9 → 14 (7 RED, 7 GREEN).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Jul 25, 2026
- P1 #1: Fix hook chain misrouting onContentTransformed payloads — check
  for toc key alongside html to disambiguate payloadTransform vs
  payloadRendered, preventing silent TOC data loss in multi-hook chains
- P1 #2: Log marshal errors in lazy __resolveFM/__resolveTOC callbacks
  instead of silently returning empty object/undefined
- P2 #3: Use NewFloat64 for int values in callHookMapPayload to avoid
  int32 narrowing truncation on timestamps and large counts
- P2 #4: Wire up SetRenderedHTML at 3 hook apply-back call sites in
  hooks.go (onContentTransformed html/string, onPageRendered html)
- P2 #5: Log warning on marshal failure in callHookMapPayload default
  case instead of silent continue
- P2 #6: Document thread-safety assumption on convertedFrontMatter
  in-place mutation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Jul 25, 2026
- Clear pendingFM/pendingTOC after invokeHookFastPath returns (P1 #1,
  IMPLEMENTATION.md step 6)
- Add log.Printf warning on marshal error paths in __resolveFM/__resolveTOC
  callbacks (P2 #2)
- Type pendingTOC as []content.TOCEntry instead of interface{} (P2 #3)
- Add enumerable: true to all lazy getter descriptors so frontMatter/toc
  remain visible to Object.keys, spread, and JSON.stringify

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Jul 25, 2026
- P2 #2: Add log.Printf on both error paths in extractStructuredProperty
  (JSONStringify and Unmarshal failures), consistent with extractHookResult

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
zeroedin added a commit that referenced this pull request Jul 25, 2026
P1 #1: Update stale test count at IMPLEMENTATION.md:760 from "5 spec
tests" to "6 spec tests", append "SetRenderedBody-after-SetRenderedHTML
cache invalidation" to enumerated list.

P2 #2: Align issue tag at IMPLEMENTATION.md:759 — changed
"(issue #1185)" to "(issues #1185, #1189)" since #1185 introduced
the method and #1189 added the cache invalidation test.

P3 #3: Trim verbose block comment to one-line separator.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

Layout resolution tests: contradictory assertions for same input

1 participant