mirror of
https://github.com/larksuite/cli.git
synced 2026-09-14 18:42:53 +08:00
a6f3e635d4
* feat(docs): add local authoring and resource workflows Add docs +script workflows for isolated draft initialization and tolerant XML/Markdown profiling. Support local and remote document resources across create and update flows with safe, bounded-concurrency uploads, binding verification, and cleanup. Synchronize shared credential-source selection during concurrent uploads, refresh lark-doc guidance, and expand unit, dry-run, and live E2E coverage. * docs(lark-doc): clarify genre reference paths * fix(docs): address PR validation feedback * docs(lark-doc): clarify remote image handling * feat: streamline docs draft workflow * fix(docs): clarify script input and resource cleanup * fix(docs): align script dry-run test with auth flow * fix(docs): authenticate local script e2e test * fix(docs): refine script diagnostics and image preflight * fix(docs): align draft workspace cleanup with VFS * fix(docs): route workspace cleanup through FileIO * docs(lark-doc): simplify profile check guidance
71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package doc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/larksuite/cli/internal/cmdutil"
|
|
"github.com/larksuite/cli/internal/output"
|
|
)
|
|
|
|
func TestDocsWritePreservesServiceFailureDetails(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
method string
|
|
path string
|
|
args []string
|
|
}{
|
|
{
|
|
name: "create",
|
|
method: "POST",
|
|
path: "/open-apis/docs_ai/v1/documents",
|
|
args: []string{"+create", "--content", "<p>content</p>", "--as", "user"},
|
|
},
|
|
{
|
|
name: "update",
|
|
method: "PUT",
|
|
path: "/open-apis/docs_ai/v1/documents/doxcn_failed",
|
|
args: []string{"+update", "--doc", "doxcn_failed", "--command", "append", "--content", "<p>content</p>", "--as", "user"},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
f, stdout, _, reg := cmdutil.TestFactory(t, docsTestConfigWithAppID("docs-result-"+tt.name))
|
|
registerDocsAIStub(reg, tt.method, tt.path, map[string]interface{}{
|
|
"result": "failed",
|
|
"warnings": []interface{}{"the target block is not replaceable"},
|
|
})
|
|
|
|
shortcut := DocsCreate
|
|
if tt.name == "update" {
|
|
shortcut = DocsUpdate
|
|
}
|
|
err := mountAndRunDocs(t, shortcut, tt.args, f, stdout)
|
|
var partial *output.PartialFailureError
|
|
if !errors.As(err, &partial) {
|
|
t.Fatalf("error = %T %v, want *output.PartialFailureError", err, err)
|
|
}
|
|
|
|
var envelope struct {
|
|
OK bool `json:"ok"`
|
|
Data struct {
|
|
Result string `json:"result"`
|
|
Warnings []string `json:"warnings"`
|
|
} `json:"data"`
|
|
}
|
|
if decodeErr := json.Unmarshal(stdout.Bytes(), &envelope); decodeErr != nil {
|
|
t.Fatalf("decode stdout: %v\n%s", decodeErr, stdout.String())
|
|
}
|
|
if envelope.OK || envelope.Data.Result != "failed" || len(envelope.Data.Warnings) != 1 ||
|
|
envelope.Data.Warnings[0] != "the target block is not replaceable" {
|
|
t.Fatalf("envelope = %+v", envelope)
|
|
}
|
|
})
|
|
}
|
|
}
|