mirror of
https://github.com/larksuite/cli.git
synced 2026-08-03 08:32:46 +08:00
* fix: unify dry-run output contract
* fix: address dry-run review feedback
* fix(dryrun): tighten preview contract and unify data shape
- transcribe HTTP method verbatim in previews (HEAD/OPTIONS were
reported as GET); reject an empty method in api with a typed error
- unify the dry-run data payload across api/service/shortcut paths:
{api, context?: {app_id, user_open_id}}; drop data.as — the envelope
top-level identity is the single identity source
- mark pretty dry-run stdout with '# dry-run: request not sent' so logs
that drop stderr still show it was a preview
- extract the shared preview builder, collapse PrintDryRunWithFile's
loose params into FileUploadMeta, and fail loudly on nil previews
- revert description-marker identity parsing: stale prose must not
override corrected accessTokens (blocks legal user calls on
images.create); identity gating keys off accessTokens only
- pin the new contracts with tests: verbatim method, three-way context
parity, nil-preview error, empty-context omission, marker line
* docs(agents): add typed-data, faithful-transcription, and contract-test conventions
- typed struct at the boundary over map[string]interface{} threading;
distinct types where values could swap silently (internal/meta.Token)
- transcribe input verbatim in previews/transformations; reject
unhonorable flag combinations with typed errors instead of silently
substituting behavior
- contract tests must fail when the implementation is reverted
* test: migrate dry-run tests grown on main to the envelope format
main gained raw-format dry-run readers while the PR was in flight
(wiki drive export #1802, drive list comments #1845, slash commands,
sheets history, docs fetch, mail draft-send/triage, vc meeting events).
Migrate them to the envelope accessors (clie2e.DryRunGet / data-wrapped
decoders) and drop the now-redundant DryRunData extractions in files
unified on DryRunGet.
---------
Co-authored-by: guokexin.02 <264159873+Tantanz20020918@users.noreply.github.com>
97 lines
3.0 KiB
Go
97 lines
3.0 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package note
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
clie2e "github.com/larksuite/cli/tests/cli_e2e"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestNoteDetailDryRun(t *testing.T) {
|
|
setNoteDryRunEnv(t)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
t.Cleanup(cancel)
|
|
|
|
result, err := clie2e.RunCmd(ctx, clie2e.Request{
|
|
Args: []string{
|
|
"note", "+detail",
|
|
"--note-id", "note_dryrun",
|
|
"--dry-run",
|
|
},
|
|
DefaultAs: "user",
|
|
})
|
|
require.NoError(t, err)
|
|
result.AssertExitCode(t, 0)
|
|
|
|
out := result.Stdout
|
|
if got := clie2e.DryRunGet(out, "api.0.method").String(); got != "GET" {
|
|
t.Fatalf("method=%q, want GET\nstdout:\n%s", got, out)
|
|
}
|
|
if got := clie2e.DryRunGet(out, "api.0.url").String(); got != "/open-apis/vc/v1/notes/note_dryrun" {
|
|
t.Fatalf("url=%q, want note detail endpoint\nstdout:\n%s", got, out)
|
|
}
|
|
}
|
|
|
|
func TestNoteTranscriptDryRun(t *testing.T) {
|
|
setNoteDryRunEnv(t)
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
t.Cleanup(cancel)
|
|
|
|
result, err := clie2e.RunCmd(ctx, clie2e.Request{
|
|
Args: []string{
|
|
"note", "+transcript",
|
|
"--note-id", "note_dryrun",
|
|
"--transcript-format", "plain_text",
|
|
"--dry-run",
|
|
},
|
|
DefaultAs: "user",
|
|
Format: "json",
|
|
})
|
|
require.NoError(t, err)
|
|
result.AssertExitCode(t, 0)
|
|
|
|
out := result.Stdout
|
|
if got := clie2e.DryRunGet(out, "api.#").Int(); got != 2 {
|
|
t.Fatalf("api count=%d, want 2\nstdout:\n%s", got, out)
|
|
}
|
|
if got := clie2e.DryRunGet(out, "api.0.method").String(); got != "GET" {
|
|
t.Fatalf("detail method=%q, want GET\nstdout:\n%s", got, out)
|
|
}
|
|
if got := clie2e.DryRunGet(out, "api.0.url").String(); got != "/open-apis/vc/v1/notes/note_dryrun" {
|
|
t.Fatalf("detail url=%q, want note detail endpoint\nstdout:\n%s", got, out)
|
|
}
|
|
if got := clie2e.DryRunGet(out, "api.1.method").String(); got != "GET" {
|
|
t.Fatalf("transcript method=%q, want GET\nstdout:\n%s", got, out)
|
|
}
|
|
if got := clie2e.DryRunGet(out, "api.1.url").String(); got != "/open-apis/vc/v1/notes/note_dryrun/unified_note_transcript" {
|
|
t.Fatalf("transcript url=%q, want unified transcript endpoint\nstdout:\n%s", got, out)
|
|
}
|
|
if got := clie2e.DryRunGet(out, "api.1.params.format").String(); got != "plain_text" {
|
|
t.Fatalf("transcript API format=%q, want plain_text\nstdout:\n%s", got, out)
|
|
}
|
|
if got := clie2e.DryRunGet(out, "api.1.params.page_size").Int(); got != 200 {
|
|
t.Fatalf("page_size=%d, want 200\nstdout:\n%s", got, out)
|
|
}
|
|
if got := clie2e.DryRunGet(out, "api.1.params.locale").String(); got != "zh_cn" {
|
|
t.Fatalf("locale=%q, want zh_cn\nstdout:\n%s", got, out)
|
|
}
|
|
if got := clie2e.DryRunGet(out, "transcript_format").String(); got != "plain_text" {
|
|
t.Fatalf("transcript_format=%q, want plain_text\nstdout:\n%s", got, out)
|
|
}
|
|
}
|
|
|
|
func setNoteDryRunEnv(t *testing.T) {
|
|
t.Helper()
|
|
t.Setenv("LARKSUITE_CLI_CONFIG_DIR", t.TempDir())
|
|
t.Setenv("LARKSUITE_CLI_APP_ID", "note_dryrun_test")
|
|
t.Setenv("LARKSUITE_CLI_APP_SECRET", "note_dryrun_secret")
|
|
t.Setenv("LARKSUITE_CLI_BRAND", "feishu")
|
|
}
|