fix: warn when <pre> tags lack <code> children in XML content#1344
fix: warn when <pre> tags lack <code> children in XML content#1344fangshuyu-768 wants to merge 1 commit into
Conversation
The Lark Docs API silently drops <pre> blocks that do not contain <code> children. Add client-side validation that emits a warning to stderr when this pattern is detected, helping users avoid silent data loss. Also add a hint to block_insert_after / block_copy_insert_after / append responses suggesting users fetch the document to discover newly inserted block IDs.
📝 WalkthroughWalkthroughThis PR adds XML validation and user guidance to document operations. A new validation module detects ChangesXML Pre-Tag Validation and Integration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1344 +/- ##
==========================================
+ Coverage 71.58% 71.61% +0.03%
==========================================
Files 689 690 +1
Lines 65521 65552 +31
==========================================
+ Hits 46901 46946 +45
+ Misses 14972 14955 -17
- Partials 3648 3651 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@3c24f2ef768995f22cc2924d7e91f21d3f688463🧩 Skill updatenpx skills add larksuite/cli#fix/doc-pre-code-validation -y -g |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
shortcuts/doc/docs_update_v2.go (1)
110-115: 💤 Low valueMinor redundancy in content check (acceptable).
The
content != ""check on line 111 is redundant sincevalidatePreTagsalready returnsnilfor empty content (xml_validate.go:22-24). However, this is harmless defensive coding that avoids an unnecessary function call. Note thatdocs_create_v2.go:36doesn't include this check, creating a slight inconsistency, but both approaches work correctly.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@shortcuts/doc/docs_update_v2.go` around lines 110 - 115, The code redundantly checks content != "" before calling validatePreTags (which already returns nil for empty content); to remove this minor inconsistency, drop the content != "" condition so the block only checks runtime.Str("doc-format") == "xml" && runtime.Factory != nil and then calls validatePreTags(content) and emitPreWarnings(...) when warnings are returned; update the surrounding if to mirror docs_create_v2.go behavior and keep validatePreTags, emitPreWarnings and the runtime checks intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@shortcuts/doc/docs_update_v2.go`:
- Around line 110-115: The code redundantly checks content != "" before calling
validatePreTags (which already returns nil for empty content); to remove this
minor inconsistency, drop the content != "" condition so the block only checks
runtime.Str("doc-format") == "xml" && runtime.Factory != nil and then calls
validatePreTags(content) and emitPreWarnings(...) when warnings are returned;
update the surrounding if to mirror docs_create_v2.go behavior and keep
validatePreTags, emitPreWarnings and the runtime checks intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1b9516cf-c63b-4582-b809-87d6ded8e0e0
📒 Files selected for processing (6)
shortcuts/doc/docs_create_test.goshortcuts/doc/docs_create_v2.goshortcuts/doc/docs_update_test.goshortcuts/doc/docs_update_v2.goshortcuts/doc/xml_validate.goshortcuts/doc/xml_validate_test.go
|
Closing: the validation should be fixed server-side in the docs_ai API rather than with client-side regex. Will re-submit with only the _hint UX improvement. |
Summary
Fixes two issues discovered during real-world usage of lark-cli for document generation:
1.
<pre>tags without<code>children are silently dropped (HIGH)The Lark Docs API silently discards
<pre>blocks that don't contain<code>child elements. This PR adds client-side validation that emits a warning to stderr when this pattern is detected in XML content for bothdocs +createanddocs +update.Before:
<pre lang="text">content</pre>→ content silently lost, no warningAfter:
<pre lang="text">content</pre>→ stderr warning: "