Skip to content

fix: support field create json array input - #1661

Merged
zgz2048 merged 1 commit into
larksuite:mainfrom
zgz2048:codex/base-field-create-json-array
Jul 1, 2026
Merged

fix: support field create json array input#1661
zgz2048 merged 1 commit into
larksuite:mainfrom
zgz2048:codex/base-field-create-json-array

Conversation

@zgz2048

@zgz2048 zgz2048 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Allow base +field-create --json to accept an internal compatibility array of field JSON objects while preserving the existing single-object path and output shape.
  • Execute array entries sequentially with a 1s delay between field-create API calls, and stop on the first typed API error without rollback.
  • Clarify datetime field JSON docs that style.format controls frontend display while stored time values can retain seconds precision.

Validation

  • make build
  • go test ./shortcuts/base -run 'TestBaseFieldValidate|TestDryRunFieldOps|TestBaseObjectJSONShortcutsRejectArrayInDryRun|TestBaseFieldExecuteCRUD'\n- go test ./tests/cli_e2e/base -run TestBaseFieldCreateDryRunArrayCompat

Summary by CodeRabbit

  • New Features

    • Field creation now supports submitting multiple fields at once from a JSON array, including in dry-run mode.
    • Successful creation responses now summarize multiple created fields when applicable.
  • Bug Fixes

    • Improved validation for array-based input, including clearer errors when an array item is not a valid object.
    • Formula field creation checks now apply consistently across all items in a batch.
  • Documentation

    • Clarified datetime field formatting behavior and display precision guidance.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

BaseFieldCreate now accepts a --json array of field definitions. field_ops.go adds parseFieldCreateBodies, refactors validateFieldCreate and dryRunFieldCreate to iterate over multiple bodies, and rewrites executeFieldCreate to POST each field sequentially with a configurable fieldCreateBatchDelay. Unit, integration, and e2e tests are updated accordingly.

Changes

Field Create Array Batch Support

Layer / File(s) Summary
Array parsing, validation, and batched execution
shortcuts/base/field_ops.go
Adds parseFieldCreateBodies helper; refactors validateFieldCreate and dryRunFieldCreate to iterate over parsed bodies; rewrites executeFieldCreate to POST sequentially with optional delay, returning field for n=1 or fields+total for n>1.
Unit and integration tests
shortcuts/base/base_dryrun_ops_test.go, shortcuts/base/base_execute_test.go, shortcuts/base/base_shortcuts_test.go
Adds dry-run array assertions; removes now-invalid array-rejection test case; adds Validate cases for array-form --json; adds create array sequentially subtest covering stubbed dual-POST execution.
E2e test, coverage tracking, and doc clarification
tests/cli_e2e/base/base_field_dryrun_test.go, tests/cli_e2e/base/coverage.md, skills/lark-base/references/lark-base-field-json.md
Adds TestBaseFieldCreateDryRunArrayCompat e2e test verifying two API call entries; updates coverage metrics and command table; adds datetime style.format minute-precision clarification.

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant parseFieldCreateBodies
  participant executeFieldCreate
  participant LarkBaseAPI

  CLI->>parseFieldCreateBodies: --json array
  parseFieldCreateBodies-->>executeFieldCreate: []fieldBody
  loop for each fieldBody
    executeFieldCreate->>LarkBaseAPI: POST /fields (body)
    LarkBaseAPI-->>executeFieldCreate: created field
    executeFieldCreate->>executeFieldCreate: sleep(fieldCreateBatchDelay)
  end
  executeFieldCreate-->>CLI: field (n=1) or fields+total (n>1)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • larksuite/cli#458: Previously tightened base shortcut JSON validation to reject arrays for field create dry-run/validation — directly superseded by this PR's array acceptance logic.

Suggested reviewers

  • kongenpei

🐇 A field named A, a field named B,
Into the base they hop, one-two-three!
With a loop and a sleep between each POST,
Arrays now welcome from coast to coast.
No more rejection — arrays may stay,
The rabbit has patched the CLI today! 🌟

🚥 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 clearly matches the main change: adding support for field-create JSON array input.
Description check ✅ Passed The description covers the core summary and validation, but it omits the template's explicit Changes, Test Plan, and Related Issues sections.
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 unit tests (beta)
  • Create PR with unit tests

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.

@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 Jun 30, 2026
@zgz2048
zgz2048 marked this pull request as ready for review June 30, 2026 03:33

@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.

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@shortcuts/base/base_execute_test.go`:
- Around line 1100-1146: Add a new fail-fast batch error subtest in the existing
BaseFieldCreate test suite, alongside the current “create array sequentially”
case, to cover the changed command contract. Use the same helpers and symbols
like runShortcut, BaseFieldCreate, newExecuteFactory, and the
/open-apis/base/v3/bases/app_x/tables/tbl_x/fields stubs, but make the second
POST /fields return a typed API error and assert the command stops immediately,
does not continue to any later requests, and does not roll back earlier
successes.

In `@shortcuts/base/base_shortcuts_test.go`:
- Around line 1066-1070: The new negative assertions in BaseFieldCreate.Validate
only check err.Error() text, so switch them to typed error checks instead. Use
errs.ProblemOf on the validation failures from BaseFieldCreate.Validate to
assert the problem category/subtype, and add errors.As against
*errs.ValidationError when you need to verify Param for the --json case. Keep
the existing scenarios, but stop relying on message substrings alone and ensure
the test covers the structured error metadata and cause preservation.

In `@tests/cli_e2e/base/base_field_dryrun_test.go`:
- Around line 35-44: The dry-run assertions in base_field_dryrun_test.go only
validate api.0 and api.1, so extra emitted requests could still slip through;
update the test around the result.Stdout checks to first assert the API call
array length is exactly two, then keep the existing validations for the entries
using gjson.Get on api.0 and api.1. Use the same result.Stdout and gjson-based
assertions in the test to locate the spot and make the expectation explicit.
🪄 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: d0287631-d75f-49b0-b92c-7fb0c7fb71d9

📥 Commits

Reviewing files that changed from the base of the PR and between 1dd0758 and 1339162.

📒 Files selected for processing (7)
  • shortcuts/base/base_dryrun_ops_test.go
  • shortcuts/base/base_execute_test.go
  • shortcuts/base/base_shortcuts_test.go
  • shortcuts/base/field_ops.go
  • skills/lark-base/references/lark-base-field-json.md
  • tests/cli_e2e/base/base_field_dryrun_test.go
  • tests/cli_e2e/base/coverage.md

Comment thread shortcuts/base/base_execute_test.go
Comment thread shortcuts/base/base_shortcuts_test.go
Comment thread tests/cli_e2e/base/base_field_dryrun_test.go
@github-actions

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add zgz2048/cli#codex/base-field-create-json-array -y -g

@zgz2048
zgz2048 merged commit 3bda9e1 into larksuite:main Jul 1, 2026
40 checks passed
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.

2 participants