Skip to content

feat(base): require --fields on +table-create - #2221

Open
CarolSum wants to merge 1 commit into
larksuite:mainfrom
CarolSum:feat/base-table-create-require-fields
Open

feat(base): require --fields on +table-create#2221
CarolSum wants to merge 1 commit into
larksuite:mainfrom
CarolSum:feat/base-table-create-require-fields

Conversation

@CarolSum

@CarolSum CarolSum commented Aug 6, 2026

Copy link
Copy Markdown

Summary

+table-create without --fields creates a table with the platform default schema. Those default fields then coexist with every field the caller adds afterwards, and no field command removes them all — the only clean recovery is to delete the table and start over. This makes --fields required, so the schema is declared up front, matching what +base-create already recommends via --table-name + --fields.

Concretely, the failure this prevents: an agent runs +table-create --name X, gets a table carrying the default schema, adds its own N fields, and ends up with a table of N + default-schema fields — while reporting N to the user, because the extra columns were never part of its plan.

Changes

  • Mark --fields Required on +table-create, so --help and the machine-readable schema both advertise it.
  • Reject blank / non-array / empty-array --fields in Validate. Cobra's MarkFlagRequired only checks that the flag was set, so --fields "" and --fields "[]" would still reach the API with no fields body and silently fall back to the default schema. Both now return a typed *errs.ValidationError with param: --fields and a hint. This mirrors the two-layer pattern already used by sheets/+history-revert.
  • Validate runs ahead of the dry-run branch, so --dry-run can no longer preview an invocation the real call would reject.
  • Sharpen the flag description and add a worked example + a tip explaining why the flag is required.
  • Update skills/lark-base/SKILL.md, tests/cli_e2e/base/coverage.md, and the live e2e helper (all three existing live-e2e callers already pass a schema, so no live coverage is lost).

Test Plan

  • Unit tests pass — make unit-test clean; new contract tests in shortcuts/base/table_create_test.go cover the Required declaration, missing / blank / empty-array / non-object-item rejection, the dry-run gate, and the valid path. Each fails if the corresponding code change is reverted.
  • Manual local verification confirms the lark-cli base +table-create flow works as expected:
    • missing --fields{"type":"validation","subtype":"invalid_argument","message":"required flag(s) \"fields\" not set"}
    • --fields '[]'{"type":"validation","subtype":"invalid_argument","message":"--fields must define at least one field","param":"--fields","hint":"An empty array is not a schema: ..."}
    • --fields '[{"name":"Title","type":"text"}]'POST /open-apis/base/v3/bases/:base_token/tables with the schema inline, unchanged from before
  • go vet ./..., gofmt -l ., go mod tidy (no change), golangci-lint run --new-from-rev=origin/main (0 issues)

Notes for reviewers

This is a breaking change: +table-create --base-token <t> --name <n> without --fields now fails instead of creating a default-schema table. Callers that relied on create-empty-then-add-fields must pass the schema to --fields. If you would rather stage it, the same validation could first ship as a deprecation warning on the fieldless path — happy to rework it that way.

One thing I deliberately left alone: the missing-flag case still surfaces cobra's terse required flag(s) "fields" not set, without param or hint, because enriching that path touches the shared dispatcher in cmd/root.go and belongs in its own PR. The flag description and tips carry the guidance in --help meanwhile.

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Table creation now requires a complete field schema provided through --fields.
    • Added clearer guidance on defining fields and platform default-field behavior.
  • Bug Fixes

    • Invalid, blank, empty, or malformed field definitions are rejected with descriptive validation messages.
    • Dry-run validation now consistently enforces required field schemas.
  • Tests

    • Expanded coverage for required fields, invalid schemas, dry runs, and valid table creation.

A table created without --fields gets the platform default schema. Those
default fields then sit in the table alongside every field the caller adds
afterwards, and no field command removes them all, so the only clean recovery
is to drop the table and start over.

Make --fields required so the schema is declared up front, the way
+base-create already recommends via --table-name + --fields.

- Mark --fields Required on +table-create, and reject blank / non-array /
  empty-array values in Validate: cobra's MarkFlagRequired only checks that the
  flag was set, so --fields "" and --fields "[]" would still reach the API with
  no fields body and fall back to the default schema.
- Validate runs ahead of the dry-run branch, so --dry-run can no longer preview
  an invocation the real call would reject.
- Update the lark-base skill, e2e coverage notes and the live e2e helper.

BREAKING CHANGE: `lark-cli base +table-create --base-token <t> --name <n>`
without --fields now fails with a validation error instead of creating a
default-schema table. Callers that relied on create-empty-then-add-fields must
pass the schema to --fields.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@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 Aug 6, 2026
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


lijiehong seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The +table-create command now requires a non-empty JSON field schema. Validation rejects invalid schemas before request execution. Tests, CLI coverage, helper functions, and Lark Base guidance now reflect this requirement.

Changes

Explicit table schema creation

Layer / File(s) Summary
Table-create CLI contract
shortcuts/base/table_create.go, shortcuts/base/base_shortcuts_test.go, shortcuts/base/base_dryrun_ops_test.go
--fields is required. Help text, examples, and dry-run coverage describe explicit non-empty schemas.
Field schema validation
shortcuts/base/table_ops.go, shortcuts/base/table_create_test.go, shortcuts/base/base_shortcuts_test.go
Validation rejects blank, malformed, empty, and non-object field schemas. Valid schemas pass validation.
Workflow and documentation alignment
tests/cli_e2e/base/helpers_test.go, tests/cli_e2e/base/coverage.md, skills/lark-base/SKILL.md
Helpers always pass --fields, and documentation describes the required schema and platform default-field behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • larksuite/cli#2153: Both changes strengthen validateTableCreate field-schema validation.

Suggested reviewers: liangshuo-1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: requiring --fields for +table-create.
Description check ✅ Passed The description includes the required Summary, Changes, Test Plan, and Related Issues sections with detailed motivation, scope, verification, and breaking-change notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

@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: 2

🤖 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_shortcuts_test.go`:
- Around line 1224-1226: Strengthen the invalid-fields rejection test in
shortcuts/base/base_shortcuts_test.go:1224-1226 by using errs.ProblemOf to
assert the validation category and subtype, errors.As to inspect
*errs.ValidationError and verify its Param, and an errors.Is or equivalent
assertion for the JSON parse cause. Apply the same typed-error assertions in
shortcuts/base/table_create_test.go:35-41, including Param == "--fields" and
preservation of the wrapped Cobra required-flag cause.

In `@shortcuts/base/table_create.go`:
- Line 34: Update the fieldless-create guidance in
shortcuts/base/table_create.go lines 34-34 and skills/lark-base/SKILL.md lines
84-84 to state that omitted, blank, or empty schemas are rejected before table
creation, rather than creating platform-default fields; keep both descriptions
consistent with the current validation behavior.
🪄 Autofix

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 Plus

Run ID: 0d1d98bd-f502-4032-8af9-7371cc8f301e

📥 Commits

Reviewing files that changed from the base of the PR and between f7d0326 and 2f4576b.

📒 Files selected for processing (8)
  • shortcuts/base/base_dryrun_ops_test.go
  • shortcuts/base/base_shortcuts_test.go
  • shortcuts/base/table_create.go
  • shortcuts/base/table_create_test.go
  • shortcuts/base/table_ops.go
  • skills/lark-base/SKILL.md
  • tests/cli_e2e/base/coverage.md
  • tests/cli_e2e/base/helpers_test.go

Comment on lines +1224 to 1226
if err := BaseTableCreate.Validate(ctx, newBaseTestRuntime(map[string]string{"base-token": "b", "name": "Orders", "fields": "{"}, nil, nil)); err == nil {
t.Fatal("invalid fields json should fail CLI validate")
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Protect typed validation errors in both new rejection tests.

Both tests currently accept any error with matching presence or text. This does not protect the machine-readable validation contract.

  • shortcuts/base/base_shortcuts_test.go#L1224-L1226: assert category and subtype with errs.ProblemOf, assert Param through errors.As on *errs.ValidationError, and verify the JSON parse cause.
  • shortcuts/base/table_create_test.go#L35-L41: assert category and subtype with errs.ProblemOf, assert Param == "--fields" through errors.As, and verify the wrapped Cobra required-flag cause.

As per coding guidelines, error-path tests must assert typed metadata and preserve the cause. Based on learnings, errs.ProblemOf does not expose Param; read it from *errs.ValidationError through errors.As.

📍 Affects 2 files
  • shortcuts/base/base_shortcuts_test.go#L1224-L1226 (this comment)
  • shortcuts/base/table_create_test.go#L35-L41
🤖 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/base/base_shortcuts_test.go` around lines 1224 - 1226, Strengthen
the invalid-fields rejection test in
shortcuts/base/base_shortcuts_test.go:1224-1226 by using errs.ProblemOf to
assert the validation category and subtype, errors.As to inspect
*errs.ValidationError and verify its Param, and an errors.Is or equivalent
assertion for the JSON parse cause. Apply the same typed-error assertions in
shortcuts/base/table_create_test.go:35-41, including Param == "--fields" and
preservation of the wrapped Cobra required-flag cause.

Sources: Coding guidelines, Learnings

},
Tips: []string{
`Example: lark-cli base +table-create --base-token <base_token> --name "Tasks" --fields '[{"name":"Title","type":"text"},{"name":"Status","type":"select","options":[{"name":"Todo"},{"name":"Done"}]}]'`,
"--fields is required: a table created without it gets the platform default schema, and those default fields stay in the table alongside the ones you add.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Update the stale fieldless-create guidance.

The command now rejects missing --fields before it creates a table. Both locations describe the prior platform behavior as if it remains reachable through +table-create.

  • shortcuts/base/table_create.go#L34-L34: state that the command rejects omitted, blank, and empty schemas before platform-default fields can be created.
  • skills/lark-base/SKILL.md#L84-L84: replace the claim that omission creates a table with the current validation behavior.
📍 Affects 2 files
  • shortcuts/base/table_create.go#L34-L34 (this comment)
  • skills/lark-base/SKILL.md#L84-L84
🤖 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/base/table_create.go` at line 34, Update the fieldless-create
guidance in shortcuts/base/table_create.go lines 34-34 and
skills/lark-base/SKILL.md lines 84-84 to state that omitted, blank, or empty
schemas are rejected before table creation, rather than creating
platform-default fields; keep both descriptions consistent with the current
validation behavior.

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