From 909f78ed581b63f55752c79c108a084e8eccf8da Mon Sep 17 00:00:00 2001 From: wenzhuozhen Date: Tue, 30 Jun 2026 12:55:43 +0800 Subject: [PATCH] fix(sheets): make +history-revert-status --transaction-id cobra-required (match +history-revert) Companion to commit 6ca35b06: same gating model now applies to both history receipts. - shortcuts/sheets/lark_sheet_history_revert.go: transactionIDFlag.Required=true. Validate keeps a trim/empty-string guard for '--transaction-id ""'. - shortcuts/sheets/data/flag-defs.json: +history-revert-status --transaction-id required: optional -> required (synced from sheet-skill-spec @9ca814d). - shortcuts/sheets/flag_defs_gen.go: regenerated. - shortcuts/sheets/lark_sheet_history_test.go: TestHistoryRevert_MissingRequiredFlag/+history-revert-status moved to the cobra "required flag(s)" text contract (the test rig invokes the shortcut via cmd.Execute, which sees the raw cobra error directly without the dispatcher's typed wrap). Drop now-unused `errors` and `errs` imports. Validation: - go test ./shortcuts/sheets/... PASS (sheets + backward) - TestFlagsFor_EveryRegisteredCommandHasDefs: PASS - TestFlagDefsGen_MatchesJSON: PASS - TestHistoryRevert_MissingRequiredFlag (both subtests): PASS --- shortcuts/sheets/data/flag-defs.json | 2 +- shortcuts/sheets/flag_defs_gen.go | 2 +- shortcuts/sheets/lark_sheet_history_revert.go | 10 +++++++--- shortcuts/sheets/lark_sheet_history_test.go | 13 ++++--------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/shortcuts/sheets/data/flag-defs.json b/shortcuts/sheets/data/flag-defs.json index 94799aac6..d003282d1 100644 --- a/shortcuts/sheets/data/flag-defs.json +++ b/shortcuts/sheets/data/flag-defs.json @@ -4912,7 +4912,7 @@ "name": "transaction-id", "kind": "own", "type": "string", - "required": "optional", + "required": "required", "desc": "Async revert transaction id (from +history-revert)." }, { diff --git a/shortcuts/sheets/flag_defs_gen.go b/shortcuts/sheets/flag_defs_gen.go index aa1401f06..1228d0c44 100644 --- a/shortcuts/sheets/flag_defs_gen.go +++ b/shortcuts/sheets/flag_defs_gen.go @@ -669,7 +669,7 @@ var flagDefs = map[string]commandDef{ Flags: []flagDef{ {Name: "url", Kind: "public", Type: "string", Required: "xor", Desc: "Spreadsheet locator"}, {Name: "spreadsheet-token", Kind: "public", Type: "string", Required: "xor", Desc: "Spreadsheet locator"}, - {Name: "transaction-id", Kind: "own", Type: "string", Required: "optional", Desc: "Async revert transaction id (from +history-revert)."}, + {Name: "transaction-id", Kind: "own", Type: "string", Required: "required", Desc: "Async revert transaction id (from +history-revert)."}, {Name: "dry-run", Kind: "system", Type: "bool", Required: "optional"}, }, }, diff --git a/shortcuts/sheets/lark_sheet_history_revert.go b/shortcuts/sheets/lark_sheet_history_revert.go index 8dda70b7d..249b3e8c4 100644 --- a/shortcuts/sheets/lark_sheet_history_revert.go +++ b/shortcuts/sheets/lark_sheet_history_revert.go @@ -71,11 +71,15 @@ func historyRevertInput(token, versionID string) map[string]interface{} { // transactionIDFlag is the async-revert receipt selector used by // +history-revert-status: the transaction_id returned by +history-revert (NOT a // history version id — the facade-agg status tool keys on transaction_id). +// Required at the cli surface (cobra MarkFlagRequired) — same gating model as +// historyVersionIDFlag. Validate still trims + rejects empty/control-char +// values to catch the "--transaction-id ''" cobra-accepts-but-empty case. func transactionIDFlag() common.Flag { return common.Flag{ - Name: "transaction-id", - Type: "string", - Desc: "Async revert transaction id (from +history-revert). Required.", + Name: "transaction-id", + Type: "string", + Required: true, + Desc: "Async revert transaction id (from +history-revert).", } } diff --git a/shortcuts/sheets/lark_sheet_history_test.go b/shortcuts/sheets/lark_sheet_history_test.go index 5864aff73..2e83b2fd4 100644 --- a/shortcuts/sheets/lark_sheet_history_test.go +++ b/shortcuts/sheets/lark_sheet_history_test.go @@ -4,11 +4,9 @@ package sheets import ( - "errors" "strings" "testing" - "github.com/larksuite/cli/errs" "github.com/larksuite/cli/shortcuts/common" ) @@ -132,14 +130,11 @@ func TestHistoryRevert_MissingRequiredFlag(t *testing.T) { t.Parallel() _, _, err := runShortcutCapturingErr(t, HistoryRevertStatus, []string{"--url", testURL}) if err == nil { - t.Fatalf("%s: expected validation error for missing --transaction-id", HistoryRevertStatus.Command) + t.Fatalf("%s: expected error for missing --transaction-id", HistoryRevertStatus.Command) } - var validationErr *errs.ValidationError - if !errors.As(err, &validationErr) { - t.Fatalf("%s: error = %T %v, want *errs.ValidationError", HistoryRevertStatus.Command, err, err) - } - if validationErr.Param != "--transaction-id" { - t.Fatalf("%s: param = %q, want --transaction-id", HistoryRevertStatus.Command, validationErr.Param) + msg := err.Error() + if !strings.Contains(msg, "required flag(s)") || !strings.Contains(msg, "transaction-id") { + t.Fatalf("%s: cobra error = %q, want substrings 'required flag(s)' and 'transaction-id'", HistoryRevertStatus.Command, msg) } }) }