bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
81 lines
2.5 KiB
Go
81 lines
2.5 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmdutil
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/larksuite/cli/errs"
|
|
"github.com/larksuite/cli/internal/output"
|
|
)
|
|
|
|
func TestRequireConfirmation_TypedShape(t *testing.T) {
|
|
err := RequireConfirmation("drive +delete")
|
|
if err == nil {
|
|
t.Fatal("expected non-nil error")
|
|
}
|
|
|
|
var cre *errs.ConfirmationRequiredError
|
|
if !errors.As(err, &cre) {
|
|
t.Fatalf("expected *errs.ConfirmationRequiredError, got %T", err)
|
|
}
|
|
if cre.Category != errs.CategoryConfirmation {
|
|
t.Errorf("Category = %q, want %q", cre.Category, errs.CategoryConfirmation)
|
|
}
|
|
if cre.Subtype != errs.SubtypeConfirmationRequired {
|
|
t.Errorf("Subtype = %q, want %q", cre.Subtype, errs.SubtypeConfirmationRequired)
|
|
}
|
|
if got := output.ExitCodeOf(err); got != output.ExitConfirmationRequired {
|
|
t.Errorf("ExitCodeOf = %d, want %d", got, output.ExitConfirmationRequired)
|
|
}
|
|
if !strings.Contains(cre.Message, "drive +delete") || !strings.Contains(cre.Message, "requires confirmation") {
|
|
t.Errorf("Message = %q, want it to mention action and 'requires confirmation'", cre.Message)
|
|
}
|
|
if cre.Hint != "add --yes to confirm" {
|
|
t.Errorf("Hint = %q, want 'add --yes to confirm'", cre.Hint)
|
|
}
|
|
if cre.Risk != errs.RiskHighRiskWrite {
|
|
t.Errorf("Risk = %q, want %q", cre.Risk, errs.RiskHighRiskWrite)
|
|
}
|
|
if cre.Action != "drive +delete" {
|
|
t.Errorf("Action = %q, want drive +delete", cre.Action)
|
|
}
|
|
}
|
|
|
|
func TestRequireConfirmation_JSONShape(t *testing.T) {
|
|
err := RequireConfirmation("mail +send")
|
|
var cre *errs.ConfirmationRequiredError
|
|
if !errors.As(err, &cre) {
|
|
t.Fatalf("expected *errs.ConfirmationRequiredError, got %T", err)
|
|
}
|
|
raw, mErr := json.Marshal(cre)
|
|
if mErr != nil {
|
|
t.Fatalf("marshal: %v", mErr)
|
|
}
|
|
var back map[string]interface{}
|
|
if err := json.Unmarshal(raw, &back); err != nil {
|
|
t.Fatalf("unmarshal: %v", err)
|
|
}
|
|
|
|
// No fix_command field leaks into the envelope: the protocol avoids
|
|
// shell-quoting hazards by delegating retry to agent-side logic.
|
|
if _, has := back["fix_command"]; has {
|
|
t.Errorf("unexpected fix_command present in JSON: %s", raw)
|
|
}
|
|
|
|
if back["risk"] != "high-risk-write" {
|
|
t.Errorf("risk in JSON = %v", back["risk"])
|
|
}
|
|
if back["action"] != "mail +send" {
|
|
t.Errorf("action in JSON = %v", back["action"])
|
|
}
|
|
// Action-only protocol: no UpgradedBy / fix_command / upgraded_by leak.
|
|
if _, has := back["upgraded_by"]; has {
|
|
t.Errorf("unexpected upgraded_by present in JSON: %s", raw)
|
|
}
|
|
}
|