Skip to content

Commit 73d0184

Browse files
author
zh
committed
Validate docs create v2 legacy flags
1 parent e98471c commit 73d0184

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

shortcuts/doc/docs_create_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,85 @@ func TestDocsCreateV2PreservesBackendURL(t *testing.T) {
249249
}
250250
}
251251

252+
func TestDocsCreateV2RejectsV1OnlyFlags(t *testing.T) {
253+
t.Parallel()
254+
255+
tests := []struct {
256+
name string
257+
args []string
258+
wantErr string
259+
}{
260+
{
261+
name: "markdown",
262+
args: []string{
263+
"+create",
264+
"--api-version", "v2",
265+
"--markdown", "## legacy",
266+
},
267+
wantErr: "use --content with --doc-format markdown",
268+
},
269+
{
270+
name: "wiki node",
271+
args: []string{
272+
"+create",
273+
"--api-version", "v2",
274+
"--content", "<title>内容</title><p>正文</p>",
275+
"--wiki-node", "wikcn_legacy_node",
276+
},
277+
wantErr: "use --parent-token",
278+
},
279+
{
280+
name: "title",
281+
args: []string{
282+
"+create",
283+
"--api-version", "v2",
284+
"--content", "<p>正文</p>",
285+
"--title", "Legacy title",
286+
},
287+
wantErr: "include the document title in --content",
288+
},
289+
{
290+
name: "folder token",
291+
args: []string{
292+
"+create",
293+
"--api-version", "v2",
294+
"--content", "<title>内容</title><p>正文</p>",
295+
"--folder-token", "fldcn_legacy_folder",
296+
},
297+
wantErr: "use --parent-token",
298+
},
299+
{
300+
name: "wiki space",
301+
args: []string{
302+
"+create",
303+
"--api-version", "v2",
304+
"--content", "<title>内容</title><p>正文</p>",
305+
"--wiki-space", "my_library",
306+
},
307+
wantErr: "use --parent-position or --parent-token",
308+
},
309+
}
310+
311+
for _, tt := range tests {
312+
tt := tt
313+
t.Run(tt.name, func(t *testing.T) {
314+
t.Parallel()
315+
316+
f, stdout, _, _ := cmdutil.TestFactory(t, docsCreateTestConfig(t, ""))
317+
err := runDocsCreateShortcut(t, f, stdout, tt.args)
318+
if err == nil {
319+
t.Fatal("expected validation error, got nil")
320+
}
321+
if !strings.Contains(err.Error(), tt.wantErr) {
322+
t.Fatalf("error = %v, want to contain %q", err, tt.wantErr)
323+
}
324+
if !strings.Contains(err.Error(), "--api-version v2") {
325+
t.Fatalf("error = %v, want v2 guidance", err)
326+
}
327+
})
328+
}
329+
}
330+
252331
// ── V1 (MCP) tests ──
253332

254333
func TestDocsCreateV1BotAutoGrantSuccess(t *testing.T) {

shortcuts/doc/docs_create_v2.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ func v2CreateFlags() []common.Flag {
2121
}
2222

2323
func validateCreateV2(_ context.Context, runtime *common.RuntimeContext) error {
24+
if err := rejectV1CreateFlagsForV2(runtime); err != nil {
25+
return err
26+
}
2427
if runtime.Str("content") == "" {
2528
return common.FlagErrorf("--content is required")
2629
}
@@ -30,6 +33,25 @@ func validateCreateV2(_ context.Context, runtime *common.RuntimeContext) error {
3033
return nil
3134
}
3235

36+
func rejectV1CreateFlagsForV2(runtime *common.RuntimeContext) error {
37+
v1Flags := []struct {
38+
name string
39+
hint string
40+
}{
41+
{name: "markdown", hint: "use --content with --doc-format markdown"},
42+
{name: "title", hint: "include the document title in --content"},
43+
{name: "folder-token", hint: "use --parent-token"},
44+
{name: "wiki-node", hint: "use --parent-token"},
45+
{name: "wiki-space", hint: "use --parent-position or --parent-token"},
46+
}
47+
for _, flag := range v1Flags {
48+
if runtime.Str(flag.name) != "" {
49+
return common.FlagErrorf("--%s is only supported by docs +create v1; for --api-version v2, %s", flag.name, flag.hint)
50+
}
51+
}
52+
return nil
53+
}
54+
3355
func dryRunCreateV2(_ context.Context, runtime *common.RuntimeContext) *common.DryRunAPI {
3456
body := buildCreateBody(runtime)
3557
desc := "OpenAPI: create document"

0 commit comments

Comments
 (0)