Skip to content

feat(docs): add reference map flags#1547

Merged
fangshuyu-768 merged 1 commit into
mainfrom
codex/fetch-doc-user-cite-reference-map
Jun 30, 2026
Merged

feat(docs): add reference map flags#1547
fangshuyu-768 merged 1 commit into
mainfrom
codex/fetch-doc-user-cite-reference-map

Conversation

@SunPeiYang996

@SunPeiYang996 SunPeiYang996 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add public docs +update --reference-map as the write-side sidecar for content that uses external reference_map entries.
  • Keep docs +fetch without a --reference-map CLI field; fetch now sends extra_param={"enable_user_cite_reference_map":true} by default.
  • Keep return_html5_block_data and legacy reference_map_mode out of the docs fetch/update reference-map path, and keep drive markdown export on its no-extra_param path.

Changes

  • Fetch: do not expose a public --reference-map flag; always include extra_param={"enable_user_cite_reference_map":true} in docs +fetch request body.
  • Update: parse --reference-map as a non-empty JSON object and send it as request body reference_map; support direct JSON, relative @reference-map.json, and stdin via the existing flag input resolver.
  • Update validation: --reference-map must be used with content-bearing update commands and must accompany --content.
  • Skill docs and CLI help: remove --reference-map from fetch docs; keep generic update reference_map sidecar wording aligned with docs +update --help.
  • Tests: unit and dry-run E2E coverage for fetch default extra_param, fetch not exposing --reference-map, update request body reference_map, invalid update reference-map input, and drive markdown non-impact.

Test Plan

  • Remote: go test ./shortcuts/doc -run "TestDocsFetchV2ReferenceMapFlagIsNotAvailable|TestBuildFetchBodyIncludesFetchExtraParamByDefault|TestDocsUpdateV2ReferenceMapFlagIsPublicFileInput|TestBuildUpdateBodyIncludesReferenceMap|TestValidateUpdateV2RejectsInvalidReferenceMap" -count=1 && make build >/tmp/lark-cli-fetch-default-extra-param-build.log && ! ./lark-cli docs +fetch --help | grep -F -- "--reference-map" && ./lark-cli docs +update --help | grep -F "@reference-map.json" | grep -F "相对路径"
  • Remote: make build >/tmp/lark-cli-fetch-default-extra-param-e2e-build.log && go test ./tests/cli_e2e/docs -run "TestDocs_DryRunDefaultsToV2OpenAPI" -count=1
  • Remote: make build >/tmp/lark-cli-fetch-default-extra-param-unknown-build.log; then ./lark-cli docs +fetch --doc doxcnDryRunE2E --reference-map --dry-run exits 2 with unknown flag "--reference-map" for "lark-cli docs +fetch".
  • Remote: go test ./shortcuts/drive -run "TestDriveExportMarkdownWritesFile|TestDriveExportMarkdownUsesProvidedFileName|TestDriveExportDryRunIncludesLocalFileNameMetadata|TestDriveExportMarkdownFallsBackToTokenWhenTitleLookupFails" -count=1
  • Remote: make build >/tmp/lark-cli-drive-export-e2e-build.log && go test ./tests/cli_e2e/drive -run "TestDriveExportDryRun_MarkdownFetchAPI" -count=1
  • Remote real write: created a temporary document, then ran docs +update --reference-map "{...}" and docs +update --reference-map @reference-map.json without --dry-run; both returned result=success, and a follow-up docs +fetch found both appended markers.
  • Ran skill quick validation for skills/lark-doc; it currently fails on the repository-existing version frontmatter key, which is present across the lark skill set and unrelated to the new --reference-map text.

Related Issues

  • None

Summary by CodeRabbit

  • New Features
    • Added a v2 docs +update option --reference-map to send a structured reference mapping in the request body.
    • Enabled default fetch v2 behavior by including an extra_param toggle for citation reference handling.
  • Bug Fixes
    • Validate --reference-map input (only allowed for supported update commands, requires non-empty --content, and rejects invalid/empty JSON).
    • Ensure markdown export/fetch requests do not send fetch-only extra_param.
  • Documentation
    • Updated docs +update parameter docs and refreshed dry-run/coverage expectations for fetch and update.

@github-actions github-actions Bot added domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact labels Jun 23, 2026
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5ae7ffee-fda4-4591-82a0-411871e13b28

📥 Commits

Reviewing files that changed from the base of the PR and between 65fb8b5 and e21b714.

📒 Files selected for processing (10)
  • shortcuts/doc/docs_fetch_v2.go
  • shortcuts/doc/docs_fetch_v2_test.go
  • shortcuts/doc/docs_update_test.go
  • shortcuts/doc/docs_update_v2.go
  • shortcuts/drive/drive_export_test.go
  • skills/lark-doc/references/lark-doc-update.md
  • tests/cli_e2e/docs/coverage.md
  • tests/cli_e2e/docs/docs_update_dryrun_test.go
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_export_dryrun_test.go
✅ Files skipped from review due to trivial changes (2)
  • tests/cli_e2e/docs/coverage.md
  • tests/cli_e2e/drive/coverage.md
🚧 Files skipped from review as they are similar to previous changes (8)
  • tests/cli_e2e/drive/drive_export_dryrun_test.go
  • skills/lark-doc/references/lark-doc-update.md
  • shortcuts/doc/docs_fetch_v2.go
  • tests/cli_e2e/docs/docs_update_dryrun_test.go
  • shortcuts/drive/drive_export_test.go
  • shortcuts/doc/docs_fetch_v2_test.go
  • shortcuts/doc/docs_update_test.go
  • shortcuts/doc/docs_update_v2.go

📝 Walkthrough

Walkthrough

Adds extra_param to the v2 docs fetch request body and introduces a v2 --reference-map update flag with JSON validation, command gating, and request-body injection. Drive export tests assert that markdown fetch does not include extra_param.

Changes

Reference-map support for docs v2 flows

Layer / File(s) Summary
Fetch extra_param constant and body wiring
shortcuts/doc/docs_fetch_v2.go, shortcuts/doc/docs_fetch_v2_test.go
Defines docsFetchExtraParam, adds extra_param to buildFetchBody, and tests the default fetch payload plus v2 fetch flag exposure.
Update --reference-map flag, validation, and body builder
shortcuts/doc/docs_update_v2.go
Registers --reference-map, validates allowed commands and required content, parses JSON into reference_map, and uses the new update body builder in dry-run and execution paths.
Update unit tests for flag, validation, and body shape
shortcuts/doc/docs_update_test.go
Tests flag metadata, body conversion, invalid-input validation, and test runtime wiring for reference-map.
Drive export assertions: extra_param absence
shortcuts/drive/drive_export_test.go, tests/cli_e2e/drive/drive_export_dryrun_test.go, tests/cli_e2e/drive/coverage.md
Adds markdown export assertions that the Docs AI fetch request body omits extra_param and updates dry-run coverage notes.
E2e dry-run assertions and documentation updates
tests/cli_e2e/docs/docs_update_dryrun_test.go, tests/cli_e2e/docs/coverage.md, skills/lark-doc/references/lark-doc-update.md
Extends docs dry-run assertions for extra_param and reference_map, and updates coverage plus user-facing reference docs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • larksuite/cli#948: Both PRs touch the v2 docs_ai markdown fetch path used by drive export.
  • larksuite/cli#1428: Both PRs modify shortcuts/doc/docs_fetch_v2_test.go around v2 fetch test setup and flag behavior.
  • larksuite/cli#1550: Both PRs change v2 docs fetch request construction in shortcuts/doc/docs_fetch_v2.go.

Suggested labels

feature

Suggested reviewers

  • fangshuyu-768
  • liangshuo-1

🐇 I nibbled the JSON, then hopped away,
extra_param sparkles in fetch today.
--reference-map found its proper trail,
With tidy checks and a bounded tail.
The carrot patch hums, the payloads align,
A rabbit-approved hop, crisp and fine. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.67% which is insufficient. The required threshold is 80.00%. 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 is concise and accurately reflects the main docs reference-map change.
Description check ✅ Passed The description matches the template with Summary, Changes, Test Plan, and Related Issues filled in.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fetch-doc-user-cite-reference-map

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.

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.44444% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.71%. Comparing base (ebb0b6f) to head (e21b714).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
shortcuts/doc/docs_update_v2.go 83.72% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1547   +/-   ##
=======================================
  Coverage   74.71%   74.71%           
=======================================
  Files         810      810           
  Lines       81839    81881   +42     
=======================================
+ Hits        61142    61178   +36     
- Misses      16131    16135    +4     
- Partials     4566     4568    +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@e21b7144d18f8e9698e5fe08a4960bfd13baa62c

🧩 Skill update

npx skills add larksuite/cli#codex/fetch-doc-user-cite-reference-map -y -g

@SunPeiYang996 SunPeiYang996 force-pushed the codex/fetch-doc-user-cite-reference-map branch 3 times, most recently from 8061f01 to 48aed20 Compare June 26, 2026 10:10
@SunPeiYang996 SunPeiYang996 changed the title feat(docs): enable user cite reference map on fetch feat(docs): add fetch reference map flag Jun 26, 2026
@SunPeiYang996 SunPeiYang996 force-pushed the codex/fetch-doc-user-cite-reference-map branch from 48aed20 to b13b7e0 Compare June 29, 2026 07:10
@SunPeiYang996 SunPeiYang996 changed the title feat(docs): add fetch reference map flag feat(docs): add reference map flags Jun 29, 2026
@SunPeiYang996 SunPeiYang996 force-pushed the codex/fetch-doc-user-cite-reference-map branch 9 times, most recently from 83753a6 to 65fb8b5 Compare June 29, 2026 13:27

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
shortcuts/doc/docs_update_test.go (1)

119-166: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert cause preservation on the invalid-JSON case.

parseUpdateReferenceMap wraps JSON decode failures with .WithCause(err), but this table test only verifies the validation subtype/param. A regression that drops errors.Unwrap semantics would still pass here. As per coding guidelines, "Error-path tests must assert typed metadata via errs.ProblemOf (category / subtype / param) and cause preservation, not message substrings alone".

Suggested test tightening
+import "errors"
...
 	tests := []struct {
 		name     string
 		setFlags map[string]string
+		wantCause bool
 	}{
 		{
 			name: "invalid json",
 			setFlags: map[string]string{
 				"reference-map": "{",
 			},
+			wantCause: true,
 		},
...
 			err := validateUpdateV2(context.Background(), runtime)
 			if err == nil {
 				t.Fatal("validateUpdateV2() succeeded, want error")
 			}
 			assertValidationContract(t, err, errs.SubtypeInvalidArgument, "--reference-map")
+			if tt.wantCause && errors.Unwrap(err) == nil {
+				t.Fatal("validateUpdateV2() error lost underlying JSON cause")
+			}
 		})
 	}
 }
🤖 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_test.go` around lines 119 - 166, The invalid-JSON
case in TestValidateUpdateV2RejectsInvalidReferenceMap only checks subtype and
param, so it can miss regressions where parseUpdateReferenceMap stops preserving
the underlying decode error. Tighten the table test for the "invalid json" input
by also asserting cause preservation with errors.Unwrap or equivalent on the
returned error, while keeping the existing errs.ProblemOf-style metadata checks
via assertValidationContract for validateUpdateV2 and --reference-map.

Source: Coding guidelines

🤖 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_test.go`:
- Around line 119-166: The invalid-JSON case in
TestValidateUpdateV2RejectsInvalidReferenceMap only checks subtype and param, so
it can miss regressions where parseUpdateReferenceMap stops preserving the
underlying decode error. Tighten the table test for the "invalid json" input by
also asserting cause preservation with errors.Unwrap or equivalent on the
returned error, while keeping the existing errs.ProblemOf-style metadata checks
via assertValidationContract for validateUpdateV2 and --reference-map.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 14686fc5-ddee-4d0b-9d6a-0d87891bd02e

📥 Commits

Reviewing files that changed from the base of the PR and between 48aed20 and 65fb8b5.

📒 Files selected for processing (10)
  • shortcuts/doc/docs_fetch_v2.go
  • shortcuts/doc/docs_fetch_v2_test.go
  • shortcuts/doc/docs_update_test.go
  • shortcuts/doc/docs_update_v2.go
  • shortcuts/drive/drive_export_test.go
  • skills/lark-doc/references/lark-doc-update.md
  • tests/cli_e2e/docs/coverage.md
  • tests/cli_e2e/docs/docs_update_dryrun_test.go
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/drive/drive_export_dryrun_test.go
✅ Files skipped from review due to trivial changes (2)
  • tests/cli_e2e/drive/coverage.md
  • tests/cli_e2e/docs/coverage.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • tests/cli_e2e/docs/docs_update_dryrun_test.go
  • tests/cli_e2e/drive/drive_export_dryrun_test.go
  • shortcuts/drive/drive_export_test.go
  • shortcuts/doc/docs_update_v2.go

@fangshuyu-768

Copy link
Copy Markdown
Collaborator

Non-blocking test suggestion: for the invalid JSON case of --reference-map, it would be nice to also assert that the underlying JSON decode error is preserved, e.g. errors.Unwrap(err) != nil. parseUpdateReferenceMap currently wraps decode failures with .WithCause(err), but the table test only verifies the validation subtype and param, so this would guard that contract more directly.

@SunPeiYang996 SunPeiYang996 force-pushed the codex/fetch-doc-user-cite-reference-map branch from 65fb8b5 to e21b714 Compare June 30, 2026 03:15
@fangshuyu-768 fangshuyu-768 merged commit 22108c3 into main Jun 30, 2026
48 of 50 checks passed
@fangshuyu-768 fangshuyu-768 deleted the codex/fetch-doc-user-cite-reference-map branch June 30, 2026 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/ccm PR touches the ccm domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants