test(doc): harden markdown_fix pipeline with invariant tests#576
Conversation
Adds 5 invariant-level tests on top of larksuite#469's transforms: - TestFixExportedMarkdownIdempotent — f(f(x)) == f(x) across rich fixtures (kitchen sink, CJK, nested containers). Protects the core round-trip promise from future transform interactions that rewrite their own output. - TestFixExportedMarkdownPreservesFencedCodeByteForByte — packs every pipeline-touching shape into a fence and asserts byte-identical output. Code samples must never be silently rewritten by a formatting pass. - TestFixExportedMarkdownPreservesCRLF — CRLF input preserves line endings AND still triggers transforms. Windows-authored markdown should not be silently LF-normalized. - TestFixExportedMarkdownTransformInteractions — composition regressions: nested-list + trailing-space bold, text→list transition, callout containing list with emphasis, heading vs paragraph bold. - TestNormalizeNestedListIndentationDocumentedSkips — locks in the deliberate no-op branches (odd-space indent, blank-line loose-list sibling, 4-space indented code block, parentless two-space) as an explicit spec so future heuristic tweaks surface in the test diff. All transforms, fixtures, and expectations are derived from the head of PR larksuite#469. No production code changes.
📝 WalkthroughWalkthroughA new test file Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/doc/markdown_fix_hardening_test.go (1)
129-147: Optional: renamecloselocal to avoid shadowing the builtin.
closeis a Go built-in. Shadowing it in a helper works but is a common lint nit and reduces readability. ConsiderendIdxorcloseIdx.♻️ Proposed rename
- close := strings.Index(rest, "\n"+fence) - if close < 0 { + closeIdx := strings.Index(rest, "\n"+fence) + if closeIdx < 0 { return "", false } - return rest[:close], true + return rest[:closeIdx], true🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@shortcuts/doc/markdown_fix_hardening_test.go` around lines 129 - 147, In extractFirstFenceContent, the local variable named close shadows the built-in close; rename that identifier (e.g., closeIdx or endIdx) and update its single use in the function (the search and the slice return) so the code reads closeIdx := strings.Index(rest, "\n"+fence) and return rest[:closeIdx], true — keep all other logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@shortcuts/doc/markdown_fix_hardening_test.go`:
- Around line 129-147: In extractFirstFenceContent, the local variable named
close shadows the built-in close; rename that identifier (e.g., closeIdx or
endIdx) and update its single use in the function (the search and the slice
return) so the code reads closeIdx := strings.Index(rest, "\n"+fence) and return
rest[:closeIdx], true — keep all other logic unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b92bdbdd-f2fb-4e72-bf29-271dc7b9b323
📒 Files selected for processing (1)
shortcuts/doc/markdown_fix_hardening_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #576 +/- ##
=======================================
Coverage 60.42% 60.42%
=======================================
Files 393 393
Lines 33657 33657
=======================================
+ Hits 20336 20338 +2
+ Misses 11433 11432 -1
+ Partials 1888 1887 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Follow-up to #469 (merged in 293a9f8). Adds 5 invariant-level tests that exercise the markdown-fix pipeline that #469 introduced / reworked. Pure test coverage — no production code changes.
What's added
TestFixExportedMarkdownIdempotentf(f(x)) == f(x)across kitchen-sink / CJK / nested-container fixtures — the round-trip promise #469 is built onTestFixExportedMarkdownPreservesFencedCodeByteForByteTestFixExportedMarkdownPreservesCRLFTestFixExportedMarkdownTransformInteractionsTestNormalizeNestedListIndentationDocumentedSkipsnormalizeNestedListIndentation(odd-space indent, blank-line loose-list sibling, 4-space indented code block, parentless 2-space indent) — freezes them as an explicit specWhy
The existing table-driven tests in
markdown_fix_test.gocover eachFix*function in isolation. These new tests target structural invariants that are easy to violate in a future refactor:strings.Containsassertions: compares byte-by-byte. Pipeline's strongest invariant (user code samples must never be silently modified).Fix*functions are well-tested in isolation; composition was not.Test plan
go test ./shortcuts/doc/...— all tests pass (existing + 13 new sub-tests)gofmtcleangolangci-lint run— no new issues introduced by this filemainafter fix(doc): preserve round-trip formatting in fetch output #469 was squash-merged (commit 293a9f8)Context
Originally opened against GaoSSR's PR branch as
GaoSSR/cli#1while #469 was still in review, so the tests could land together with the implementation. Now that #469 is merged, that PR has been closed and this is the direct follow-up againstmain.Summary by CodeRabbit