mirror of
https://github.com/larksuite/cli.git
synced 2026-09-14 18:42:53 +08:00
37d490a198
* 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>
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package output
|
|
|
|
import "io"
|
|
|
|
// SuccessEnvelopeOptions configures the shortcut-compatible success envelope.
|
|
type SuccessEnvelopeOptions struct {
|
|
CommandPath string
|
|
Identity string
|
|
DryRun bool
|
|
JqExpr string
|
|
Out io.Writer
|
|
ErrOut io.Writer
|
|
}
|
|
|
|
// SuccessEnvelopeData extracts the business payload for the standard success
|
|
// envelope from a Lark API response. Outer code/msg fields are transport
|
|
// protocol details and are intentionally not exposed as business data.
|
|
func SuccessEnvelopeData(result interface{}) interface{} {
|
|
m, ok := result.(map[string]interface{})
|
|
if !ok {
|
|
return map[string]interface{}{}
|
|
}
|
|
data, ok := m["data"]
|
|
if !ok || data == nil {
|
|
return map[string]interface{}{}
|
|
}
|
|
return data
|
|
}
|
|
|
|
// WriteSuccessEnvelope emits the standard success envelope used by shortcuts.
|
|
// JSON output carries content-safety alerts inside the envelope. When jq is
|
|
// applied, the alert may be filtered away, so warn mode also writes stderr.
|
|
func WriteSuccessEnvelope(data interface{}, opts SuccessEnvelopeOptions) error {
|
|
scanResult := ScanForSafety(opts.CommandPath, data, opts.ErrOut)
|
|
if scanResult.Blocked {
|
|
return scanResult.BlockErr
|
|
}
|
|
|
|
env := Envelope{
|
|
OK: true,
|
|
Identity: opts.Identity,
|
|
DryRun: opts.DryRun,
|
|
Data: data,
|
|
Notice: GetNotice(),
|
|
}
|
|
if scanResult.Alert != nil {
|
|
env.ContentSafetyAlert = scanResult.Alert
|
|
}
|
|
if opts.JqExpr != "" {
|
|
if scanResult.Alert != nil && opts.ErrOut != nil {
|
|
WriteAlertWarning(opts.ErrOut, scanResult.Alert)
|
|
}
|
|
return JqFilter(opts.Out, env, opts.JqExpr)
|
|
}
|
|
PrintJson(opts.Out, env)
|
|
return nil
|
|
}
|