Skip to content

fix(base): resolve record-list --view-id by view name#258

Open
wwenrr wants to merge 3 commits intolarksuite:mainfrom
wwenrr:fix/issue-255-record-list-resolve-view-name
Open

fix(base): resolve record-list --view-id by view name#258
wwenrr wants to merge 3 commits intolarksuite:mainfrom
wwenrr:fix/issue-255-record-list-resolve-view-name

Conversation

@wwenrr
Copy link
Copy Markdown

@wwenrr wwenrr commented Apr 3, 2026

Summary

  • make base +record-list --view-id robust when users pass a view name instead of a raw vew_... ID
  • resolve view reference (view_id or view_name) to canonical view_id before records query
  • keep existing behavior unchanged when --view-id is already a vew_.../viw_... id

Why

Issue #255 reports that after +view-set-filter succeeds, +record-list --view-id can still appear to return full data in some usage flows.

A practical root cause addressed by this PR: users pass a view name, while record-list previously forwarded raw input as view_id query param.

Changes

  • shortcuts/base/record_ops.go
    • add resolveRecordListViewID(runtime, viewRef)
    • support id refs (vew_, viw_) directly
    • otherwise list views and resolve by view_id / view_name
    • paginate view scanning to avoid single-page truncation
    • fail clearly if a matched view has no canonical id
  • shortcuts/base/base_execute_test.go
    • TestBaseRecordExecuteListWithViewNameResolvesToViewID
    • TestBaseRecordResolveViewIDAcrossPages
    • TestBaseRecordResolveViewIDMissingCanonicalID
  • shortcuts/base/base_dryrun_ops_test.go
    • TestDryRunRecordListWithViewName

Verification

docker run --rm -v /tmp/larksuite-cli:/src -w /src golang:1.24 bash -lc "export PATH=/usr/local/go/bin:$PATH; gofmt -w shortcuts/base/record_ops.go shortcuts/base/base_dryrun_ops_test.go shortcuts/base/base_execute_test.go && go test ./shortcuts/base -run 'TestBaseRecordExecuteListWithViewNameResolvesToViewID|TestBaseRecordResolveViewIDAcrossPages|TestDryRunRecordListWithViewName|TestBaseRecordResolveViewIDMissingCanonicalID'"

Result: pass (ok github.com/larksuite/cli/shortcuts/base)

Additional evidence (real CLI terminal run)

To make behavior explicit, I captured real CLI dry-run outputs:

Observed:

  • +record-list without --view-id => request has only offset/limit
  • with --view-id Main => request includes resolved view placeholder in dry-run
  • with --view-id vew_x => request includes view_id=vew_x

Closes #255

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 3, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added domain/base PR touches the base domain size/M Single-domain feat or fix with limited business impact labels Apr 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

📝 Walkthrough

Walkthrough

Added view-name-to-ID resolution for record-list: inputs to --view-id can be a view name or canonical ID. executeRecordList now resolves names via the views list before calling the records API. New unit tests cover resolution, pagination of views, and missing canonical ID errors.

Changes

Cohort / File(s) Summary
Record list view resolution
shortcuts/base/record_ops.go
Added isViewIDRef and resolveRecordListViewID plus recordListViewResolvePageLimit. executeRecordList now resolves view-id to a canonical view ID before calling the records API. dryRunRecordList updated to indicate placeholder when a name is supplied.
Execute tests (view resolution)
shortcuts/base/base_execute_test.go
Added three tests: resolves single-page view name to ID; resolves view name across paginated views; asserts error when a view lacks a canonical id. Stubs views and records endpoints to validate behavior.
Dry-run test
shortcuts/base/base_dryrun_ops_test.go
Added TestDryRunRecordListWithViewName asserting dryRunRecordList emits a placeholder-encoded view_id query when given a view name (no canonical ID present in path).

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI/Shortcut
    participant Runtime as Runtime
    participant ViewsAPI as Views Service
    participant RecordsAPI as Records Service

    CLI->>Runtime: run record-list with --view-id="Main"
    Runtime->>ViewsAPI: list views (paged) / resolve view name -> view_id="vew_x"
    ViewsAPI-->>Runtime: return view_id="vew_x"
    Runtime->>RecordsAPI: list records with view_id="vew_x", offset/limit
    RecordsAPI-->>Runtime: return records (rec_1,...)
    Runtime-->>CLI: render records output
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hopped through views both near and far,
Found "Main" and named it like a star.
Resolved a name to vew_x with glee,
Lists now honor filters properly—
Hooray, records dance for me! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 directly and accurately describes the main change: resolving record-list --view-id by view name instead of treating view names as raw IDs.
Linked Issues check ✅ Passed The PR directly addresses issue #255 by implementing view name resolution to canonical IDs, enabling +record-list --view-id to properly apply filters set by +view-set-filter.
Out of Scope Changes check ✅ Passed All changes are directly related to resolving view references by name: new test cases in base_execute_test.go and base_dryrun_ops_test.go, and view resolution logic in record_ops.go.
Description check ✅ Passed The pull request description comprehensively covers all required template sections with clear motivation, detailed changes, verification steps, and related issue closure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 3, 2026

Greptile Summary

This PR fixes +record-list --view-id to accept view names (e.g. --view-id "Main") in addition to raw vew_/viw_ prefixed IDs, resolving issue #255 where filters set via +view-set-filter appeared to be ignored because users were passing view names that were forwarded verbatim as the view_id query parameter.

Key changes:

  • record_ops.go: Introduces isViewIDRef (handles both vew_ and viw_ prefixes), and resolveRecordListViewID which paginates through all views until the named view is found or exhausted. The dry-run path emits a descriptive placeholder instead of making a live API call.
  • base_execute_test.go: Three new tests covering the happy path (name → ID), the multi-page pagination path (empty first page with total > len), and the error path (view with no view_id field).
  • base_dryrun_ops_test.go: One new dry-run test verifying the placeholder is correctly URL-encoded in the output.

Both prior review comments (silent failure for 200+ views, and strings.HasPrefix style) have been addressed.

Confidence Score: 5/5

Safe to merge — both prior review concerns are addressed, new logic is well-tested, and no P0/P1 issues remain.

The pagination loop correctly handles all cases (view on first page, view on later page, empty pages with reliable total, missing view, and view with no canonical ID). The two previously raised concerns — silent failure for 200+ views and the strings.HasPrefix idiom — are both fully resolved. Three new execute tests and one dry-run test provide solid coverage. No new correctness or security issues were introduced.

No files require special attention.

Important Files Changed

Filename Overview
shortcuts/base/record_ops.go Adds isViewIDRef, resolveRecordListViewID with correct pagination loop, and wires both dryRunRecordList and executeRecordList to use them; logic is sound and prior review concerns addressed.
shortcuts/base/base_execute_test.go Adds three focused integration tests: basic name resolution, multi-page (empty-first-page) resolution, and missing canonical ID error path — good coverage of new logic.
shortcuts/base/base_dryrun_ops_test.go Adds a dry-run test verifying the placeholder string is set (and URL-encoded) correctly when a view name rather than a raw ID is provided.

Reviews (3): Last reviewed commit: "fix(base): guard missing canonical id in..." | Re-trigger Greptile

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@shortcuts/base/record_ops.go`:
- Line 36: The call to listAllViews(runtime, runtime.Str("base-token"),
baseTableID(runtime), 0, 200) only fetches the first page (limit 200), so views
beyond that are omitted; update the code around that call to implement
pagination: repeatedly call listAllViews using an increasing offset (e.g.,
offset += limit) and collect/append returned views until the returned slice
length is less than the limit (or no more items), then use the aggregated views
for name resolution; alternatively, if the API supports it, replace the
hardcoded limit with a sufficiently large value, but prefer the looped
pagination approach to ensure correctness when using listAllViews,
runtime.Str("base-token"), and baseTableID(runtime).
- Around line 40-44: resolveViewRef may return a view without a canonical ID so
change the success path after resolveViewRef(viewRef) to call viewID(view) and
if it returns empty, fail fast by returning an error (e.g., fmt.Errorf("view %q
has no canonical id", viewRef or view.Name)) instead of returning an empty
string; update the function that currently returns viewID(view) to validate
non-empty, import the fmt package, and ensure callers such as executeRecordList
receive an error rather than an empty view_id.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b080c0f7-526c-4989-ab45-9f751390f9e2

📥 Commits

Reviewing files that changed from the base of the PR and between 0c77c95 and 936e30c.

📒 Files selected for processing (2)
  • shortcuts/base/base_execute_test.go
  • shortcuts/base/record_ops.go

@wwenrr
Copy link
Copy Markdown
Author

wwenrr commented Apr 3, 2026

Addressed review feedback ✅

Thanks for the detailed comments. I updated the PR with the following fixes:

  1. Dry-run consistency

    • dryRunRecordList now mirrors execution semantics better:
      • if --view-id is already an id-like ref (vew_/viw_), dry-run emits it directly
      • if --view-id looks like a view name, dry-run now shows an explicit placeholder:
        • view_id=<resolved from view name: ...>
    • this avoids falsely suggesting we send raw view names as view_id.
  2. Pagination for view-name resolution

    • resolveRecordListViewID now paginates through views instead of single-page fetch
    • continues until total is exhausted (including sparse-page edge handling), then returns not found only after full scan
  3. Style/maintainability

    • replaced manual prefix slicing with strings.HasPrefix
    • extracted helper isViewIDRef and constant recordListViewResolvePageLimit

Tests added/updated

  • TestDryRunRecordListWithViewName
  • TestBaseRecordResolveViewIDAcrossPages
  • existing name->id execution test remains: TestBaseRecordExecuteListWithViewNameResolvesToViewID

Verification

docker run --rm -v /tmp/larksuite-cli:/src -w /src golang:1.24 bash -lc "export PATH=/usr/local/go/bin:$PATH; gofmt -w shortcuts/base/record_ops.go shortcuts/base/base_dryrun_ops_test.go shortcuts/base/base_execute_test.go && go test ./shortcuts/base -run 'TestBaseRecordExecuteListWithViewNameResolvesToViewID|TestBaseRecordResolveViewIDAcrossPages|TestDryRunRecordListWithViewName'"

Result: pass (ok github.com/larksuite/cli/shortcuts/base)

@wwenrr
Copy link
Copy Markdown
Author

wwenrr commented Apr 3, 2026

Addressed CodeRabbit feedback ✅

I verified and handled both actionable points:

  1. Pagination for view resolution
  • already fixed in previous commit by paging through listAllViews until total is exhausted (with sparse-page handling), instead of single-page lookup.
  1. Canonical ID guard
  • added an explicit check after resolveViewRef:
    • if viewID(view) is empty, return fmt.Errorf("view %q has no canonical id", viewRef)
    • this prevents silently sending empty view_id.

Also kept the prior dry-run consistency + prefix cleanup improvements.

Added/updated tests

  • TestBaseRecordResolveViewIDAcrossPages
  • TestDryRunRecordListWithViewName
  • TestBaseRecordResolveViewIDMissingCanonicalID (new)
  • existing TestBaseRecordExecuteListWithViewNameResolvesToViewID

Verification

docker run --rm -v /tmp/larksuite-cli:/src -w /src golang:1.24 bash -lc "export PATH=/usr/local/go/bin:$PATH; gofmt -w shortcuts/base/record_ops.go shortcuts/base/base_execute_test.go && go test ./shortcuts/base -run 'TestBaseRecordExecuteListWithViewNameResolvesToViewID|TestBaseRecordResolveViewIDAcrossPages|TestDryRunRecordListWithViewName|TestBaseRecordResolveViewIDMissingCanonicalID'"

Result: pass (ok github.com/larksuite/cli/shortcuts/base)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/base PR touches the base 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.

[BUG] +view-set-filter成功后list 查询仍然返回全量数据

2 participants