1- import { tmpdir } from "os" ;
21import { describe , expect , test } from "vite-plus/test" ;
32import { parseStdoutJson , runCli } from "./helpers.ts" ;
43
@@ -33,64 +32,60 @@ describe("e2e: knowledge chat", () => {
3332 } ) ;
3433
3534 test ( "缺少 --message 时打印帮助并退出 (0)" , async ( ) => {
36- const { stderr, exitCode } = await runCli (
37- [ "knowledge" , "chat" , "--agent-id" , "aid_test" , "--non-interactive" ] ,
38- { DASHSCOPE_API_KEY : "sk-fake" , BAILIAN_CONFIG_DIR : tmpdir ( ) } ,
39- ) ;
35+ const { stderr, exitCode } = await runCli ( [
36+ "knowledge" ,
37+ "chat" ,
38+ "--agent-id" ,
39+ "aid_test" ,
40+ "--non-interactive" ,
41+ ] ) ;
4042 expect ( exitCode ) . toBe ( 0 ) ;
4143 expect ( stderr ) . toMatch ( / - - m e s s a g e | U s a g e : / i) ;
4244 } ) ;
4345
4446 test ( "缺少 --agent-id 时打印帮助并退出 (0)" , async ( ) => {
45- const { stderr, exitCode } = await runCli (
46- [ "knowledge" , "chat" , "--message" , "Hello" , "--non-interactive" ] ,
47- { DASHSCOPE_API_KEY : "sk-fake" , BAILIAN_CONFIG_DIR : tmpdir ( ) } ,
48- ) ;
47+ const { stderr, exitCode } = await runCli ( [
48+ "knowledge" ,
49+ "chat" ,
50+ "--message" ,
51+ "Hello" ,
52+ "--non-interactive" ,
53+ ] ) ;
4954 expect ( exitCode ) . toBe ( 0 ) ;
5055 expect ( stderr ) . toMatch ( / - - a g e n t - i d | U s a g e : / i) ;
5156 } ) ;
5257
5358 test ( "缺少 --workspace-id 时非零退出并提示" , async ( ) => {
54- const { stderr, exitCode } = await runCli (
55- [
56- "knowledge" ,
57- "chat" ,
58- "--message" ,
59- "Hello" ,
60- "--agent-id" ,
61- "aid_test" ,
62- "--non-interactive" ,
63- "--output" ,
64- "json" ,
65- ] ,
66- {
67- DASHSCOPE_API_KEY : "sk-fake" ,
68- BAILIAN_WORKSPACE_ID : undefined ,
69- BAILIAN_CONFIG_DIR : tmpdir ( ) ,
70- } ,
71- ) ;
59+ const { stderr, exitCode } = await runCli ( [
60+ "knowledge" ,
61+ "chat" ,
62+ "--message" ,
63+ "Hello" ,
64+ "--agent-id" ,
65+ "aid_test" ,
66+ "--non-interactive" ,
67+ "--output" ,
68+ "json" ,
69+ ] ) ;
7270 expect ( exitCode ) . not . toBe ( 0 ) ;
7371 expect ( stderr ) . toMatch ( / w o r k s p a c e .* r e q u i r e d / i) ;
7472 } ) ;
7573
7674 test ( "--dry-run 输出 endpoint 和 request body" , async ( ) => {
77- const { stdout, stderr, exitCode } = await runCli (
78- [
79- "knowledge" ,
80- "chat" ,
81- "--dry-run" ,
82- "--message" ,
83- "什么是RAG" ,
84- "--agent-id" ,
85- "aid_test" ,
86- "--workspace-id" ,
87- "ws_test" ,
88- "--non-interactive" ,
89- "--output" ,
90- "json" ,
91- ] ,
92- { DASHSCOPE_API_KEY : "sk-fake-for-dryrun" } ,
93- ) ;
75+ const { stdout, stderr, exitCode } = await runCli ( [
76+ "knowledge" ,
77+ "chat" ,
78+ "--dry-run" ,
79+ "--message" ,
80+ "什么是RAG" ,
81+ "--agent-id" ,
82+ "aid_test" ,
83+ "--workspace-id" ,
84+ "ws_test" ,
85+ "--non-interactive" ,
86+ "--output" ,
87+ "json" ,
88+ ] ) ;
9489 expect ( exitCode , stderr ) . toBe ( 0 ) ;
9590 const data = parseStdoutJson < DryRunBody > ( stdout ) ;
9691 expect ( data . endpoint ) . toMatch ( / w s _ t e s t \. c n - b e i j i n g \. m a a s \. a l i y u n c s \. c o m / ) ;
@@ -101,27 +96,24 @@ describe("e2e: knowledge chat", () => {
10196 } ) ;
10297
10398 test ( "--dry-run 多轮消息解析 role:content 前缀" , async ( ) => {
104- const { stdout, stderr, exitCode } = await runCli (
105- [
106- "knowledge" ,
107- "chat" ,
108- "--dry-run" ,
109- "--message" ,
110- "user:什么是RAG" ,
111- "--message" ,
112- "assistant:RAG是检索增强生成" ,
113- "--message" ,
114- "它怎么工作" ,
115- "--agent-id" ,
116- "aid_test" ,
117- "--workspace-id" ,
118- "ws_test" ,
119- "--non-interactive" ,
120- "--output" ,
121- "json" ,
122- ] ,
123- { DASHSCOPE_API_KEY : "sk-fake-for-dryrun" } ,
124- ) ;
99+ const { stdout, stderr, exitCode } = await runCli ( [
100+ "knowledge" ,
101+ "chat" ,
102+ "--dry-run" ,
103+ "--message" ,
104+ "user:什么是RAG" ,
105+ "--message" ,
106+ "assistant:RAG是检索增强生成" ,
107+ "--message" ,
108+ "它怎么工作" ,
109+ "--agent-id" ,
110+ "aid_test" ,
111+ "--workspace-id" ,
112+ "ws_test" ,
113+ "--non-interactive" ,
114+ "--output" ,
115+ "json" ,
116+ ] ) ;
125117 expect ( exitCode , stderr ) . toBe ( 0 ) ;
126118 const data = parseStdoutJson < DryRunBody > ( stdout ) ;
127119 const msgs = data . request ?. input ?. messages ?? [ ] ;
@@ -135,25 +127,22 @@ describe("e2e: knowledge chat", () => {
135127 } ) ;
136128
137129 test ( "--dry-run + --image 输出多模态 content 数组" , async ( ) => {
138- const { stdout, stderr, exitCode } = await runCli (
139- [
140- "knowledge" ,
141- "chat" ,
142- "--dry-run" ,
143- "--message" ,
144- "描述这张图" ,
145- "--agent-id" ,
146- "aid_test" ,
147- "--workspace-id" ,
148- "ws_test" ,
149- "--image" ,
150- "https://example.com/img.jpg" ,
151- "--non-interactive" ,
152- "--output" ,
153- "json" ,
154- ] ,
155- { DASHSCOPE_API_KEY : "sk-fake-for-dryrun" } ,
156- ) ;
130+ const { stdout, stderr, exitCode } = await runCli ( [
131+ "knowledge" ,
132+ "chat" ,
133+ "--dry-run" ,
134+ "--message" ,
135+ "描述这张图" ,
136+ "--agent-id" ,
137+ "aid_test" ,
138+ "--workspace-id" ,
139+ "ws_test" ,
140+ "--image" ,
141+ "https://example.com/img.jpg" ,
142+ "--non-interactive" ,
143+ "--output" ,
144+ "json" ,
145+ ] ) ;
157146 expect ( exitCode , stderr ) . toBe ( 0 ) ;
158147 const data = parseStdoutJson < DryRunBody > ( stdout ) ;
159148 const lastMsg = data . request ?. input ?. messages ?. [ 0 ] ;
@@ -168,25 +157,22 @@ describe("e2e: knowledge chat", () => {
168157 } ) ;
169158
170159 test ( "--dry-run + --image 无 --message 自动创建空 user message" , async ( ) => {
171- const { stdout, stderr, exitCode } = await runCli (
172- [
173- "knowledge" ,
174- "chat" ,
175- "--dry-run" ,
176- "--agent-id" ,
177- "aid_test" ,
178- "--workspace-id" ,
179- "ws_test" ,
180- "--image" ,
181- "https://example.com/a.png" ,
182- "--image" ,
183- "https://example.com/b.png" ,
184- "--non-interactive" ,
185- "--output" ,
186- "json" ,
187- ] ,
188- { DASHSCOPE_API_KEY : "sk-fake-for-dryrun" } ,
189- ) ;
160+ const { stdout, stderr, exitCode } = await runCli ( [
161+ "knowledge" ,
162+ "chat" ,
163+ "--dry-run" ,
164+ "--agent-id" ,
165+ "aid_test" ,
166+ "--workspace-id" ,
167+ "ws_test" ,
168+ "--image" ,
169+ "https://example.com/a.png" ,
170+ "--image" ,
171+ "https://example.com/b.png" ,
172+ "--non-interactive" ,
173+ "--output" ,
174+ "json" ,
175+ ] ) ;
190176 expect ( exitCode , stderr ) . toBe ( 0 ) ;
191177 const data = parseStdoutJson < DryRunBody > ( stdout ) ;
192178 const lastMsg = data . request ?. input ?. messages ?. [ 0 ] ;
0 commit comments