11// Alibaba tests cover video generation provider plugin behavior.
2+ import fs from "node:fs/promises" ;
3+ import os from "node:os" ;
4+ import path from "node:path" ;
5+ import {
6+ clearRuntimeAuthProfileStoreSnapshots ,
7+ saveAuthProfileStore ,
8+ } from "openclaw/plugin-sdk/agent-runtime" ;
29import {
310 getProviderHttpMocks ,
411 installProviderHttpMockCleanup ,
@@ -13,9 +20,10 @@ import {
1320 DASHSCOPE_WAN_VIDEO_MODELS ,
1421 DEFAULT_DASHSCOPE_WAN_VIDEO_MODEL ,
1522} from "openclaw/plugin-sdk/video-generation" ;
16- import { beforeAll , describe , expect , it } from "vitest" ;
23+ import { afterEach , beforeAll , describe , expect , it , vi } from "vitest" ;
1724
1825const {
26+ resolveApiKeyForProviderMock,
1927 postJsonRequestMock,
2028 fetchWithTimeoutMock,
2129 fetchWithTimeoutGuardedMock,
@@ -31,6 +39,17 @@ beforeAll(async () => {
3139
3240installProviderHttpMockCleanup ( ) ;
3341
42+ afterEach ( ( ) => {
43+ clearRuntimeAuthProfileStoreSnapshots ( ) ;
44+ vi . unstubAllEnvs ( ) ;
45+ } ) ;
46+
47+ function clearAlibabaAuthEnvironment ( ) : void {
48+ for ( const name of [ "MODELSTUDIO_API_KEY" , "DASHSCOPE_API_KEY" , "QWEN_API_KEY" ] ) {
49+ vi . stubEnv ( name , "" ) ;
50+ }
51+ }
52+
3453function requireRecord ( value : unknown , label : string ) : Record < string , unknown > {
3554 if ( value === null || typeof value !== "object" || Array . isArray ( value ) ) {
3655 throw new Error ( `expected ${ label } to be a record` ) ;
@@ -57,6 +76,188 @@ describe("alibaba video generation provider", () => {
5776 } ) ;
5877 } ) ;
5978
79+ it . each ( [ "sk-ws-alibaba-standard-key" , "sk-alibaba-legacy-standard-key" ] ) (
80+ "advertises Wan video generation with config-only Standard API key %s" ,
81+ ( apiKey ) => {
82+ clearAlibabaAuthEnvironment ( ) ;
83+
84+ expect (
85+ alibabaVideoGenerationProvider . isConfigured ?.( {
86+ cfg : {
87+ models : {
88+ providers : {
89+ alibaba : {
90+ apiKey,
91+ baseUrl : "https://dashscope-intl.aliyuncs.com" ,
92+ models : [ ] ,
93+ } ,
94+ } ,
95+ } ,
96+ } ,
97+ } ) ,
98+ ) . toBe ( true ) ;
99+ } ,
100+ ) ;
101+
102+ it ( "does not use Qwen Coding Plan credentials for Alibaba video discovery" , ( ) => {
103+ clearAlibabaAuthEnvironment ( ) ;
104+
105+ expect (
106+ alibabaVideoGenerationProvider . isConfigured ?.( {
107+ cfg : {
108+ models : {
109+ providers : {
110+ qwen : {
111+ apiKey : "qwen-coding-plan-key" ,
112+ baseUrl : "https://coding-intl.dashscope.aliyuncs.com/v1" ,
113+ models : [ ] ,
114+ } ,
115+ } ,
116+ } ,
117+ } ,
118+ } ) ,
119+ ) . toBe ( false ) ;
120+ } ) ;
121+
122+ it . each ( [ "" , "oauth:alibaba" , "custom-local" , "secretref-managed" ] ) (
123+ "does not advertise a non-secret Alibaba credential marker %j" ,
124+ ( apiKey ) => {
125+ clearAlibabaAuthEnvironment ( ) ;
126+
127+ expect (
128+ alibabaVideoGenerationProvider . isConfigured ?.( {
129+ cfg : {
130+ models : {
131+ providers : {
132+ alibaba : {
133+ apiKey,
134+ baseUrl : "https://dashscope-intl.aliyuncs.com" ,
135+ models : [ ] ,
136+ } ,
137+ } ,
138+ } ,
139+ } ,
140+ } ) ,
141+ ) . toBe ( false ) ;
142+ } ,
143+ ) ;
144+
145+ it ( "tracks whether an allowed Alibaba API-key SecretRef resolves" , ( ) => {
146+ clearAlibabaAuthEnvironment ( ) ;
147+ vi . stubEnv ( "ALIBABA_QA_CONFIG_KEY" , "resolved-alibaba-config-key" ) ;
148+
149+ const cfg = {
150+ models : {
151+ providers : {
152+ alibaba : {
153+ apiKey : {
154+ source : "env" as const ,
155+ provider : "alibaba-test-env" ,
156+ id : "ALIBABA_QA_CONFIG_KEY" ,
157+ } ,
158+ baseUrl : "https://dashscope-intl.aliyuncs.com" ,
159+ models : [ ] ,
160+ } ,
161+ } ,
162+ } ,
163+ secrets : {
164+ defaults : { env : "alibaba-test-env" } ,
165+ providers : {
166+ "alibaba-test-env" : {
167+ source : "env" as const ,
168+ allowlist : [ "ALIBABA_QA_CONFIG_KEY" ] ,
169+ } ,
170+ } ,
171+ } ,
172+ } ;
173+
174+ expect ( alibabaVideoGenerationProvider . isConfigured ?.( { cfg } ) ) . toBe ( true ) ;
175+ vi . stubEnv ( "ALIBABA_QA_CONFIG_KEY" , "" ) ;
176+ expect ( alibabaVideoGenerationProvider . isConfigured ?.( { cfg } ) ) . toBe ( false ) ;
177+ } ) ;
178+
179+ it ( "preserves Alibaba environment API-key discovery" , ( ) => {
180+ clearAlibabaAuthEnvironment ( ) ;
181+ vi . stubEnv ( "MODELSTUDIO_API_KEY" , "alibaba-environment-key" ) ;
182+
183+ expect ( alibabaVideoGenerationProvider . isConfigured ?.( { cfg : { } } ) ) . toBe ( true ) ;
184+ } ) ;
185+
186+ it ( "does not advertise an inherited Qwen Coding Plan API key" , ( ) => {
187+ clearAlibabaAuthEnvironment ( ) ;
188+ vi . stubEnv ( "QWEN_API_KEY" , "sk-sp-qwen-coding-plan-key" ) ;
189+
190+ expect ( alibabaVideoGenerationProvider . isConfigured ?.( { cfg : { } } ) ) . toBe ( false ) ;
191+ } ) ;
192+
193+ it ( "keeps explicit Standard config above an inherited Coding Plan environment key" , ( ) => {
194+ clearAlibabaAuthEnvironment ( ) ;
195+ vi . stubEnv ( "QWEN_API_KEY" , "sk-sp-qwen-coding-plan-key" ) ;
196+
197+ expect (
198+ alibabaVideoGenerationProvider . isConfigured ?.( {
199+ cfg : {
200+ models : {
201+ providers : {
202+ alibaba : {
203+ auth : "api-key" ,
204+ apiKey : "sk-ws-alibaba-standard-key" ,
205+ baseUrl : "https://dashscope-intl.aliyuncs.com" ,
206+ models : [ ] ,
207+ } ,
208+ } ,
209+ } ,
210+ } ,
211+ } ) ,
212+ ) . toBe ( true ) ;
213+ } ) ;
214+
215+ it . each ( [
216+ [ "sk-ws-alibaba-profile" , "sk-sp-qwen-environment" , true ] ,
217+ [ "sk-sp-alibaba-profile" , "sk-ws-qwen-environment" , false ] ,
218+ ] ) ( "preserves actual profile precedence for %s" , async ( profileKey , envKey , expected ) => {
219+ clearAlibabaAuthEnvironment ( ) ;
220+ vi . stubEnv ( "QWEN_API_KEY" , envKey ) ;
221+ const agentDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , "openclaw-alibaba-wan-auth-" ) ) ;
222+
223+ try {
224+ saveAuthProfileStore (
225+ {
226+ version : 1 ,
227+ profiles : {
228+ "alibaba:standard" : {
229+ type : "api_key" ,
230+ provider : "alibaba" ,
231+ key : profileKey ,
232+ } ,
233+ } ,
234+ } ,
235+ agentDir ,
236+ { filterExternalAuthProfiles : false , syncExternalCli : false } ,
237+ ) ;
238+
239+ expect ( alibabaVideoGenerationProvider . isConfigured ?.( { cfg : { } , agentDir } ) ) . toBe ( expected ) ;
240+ } finally {
241+ clearRuntimeAuthProfileStoreSnapshots ( ) ;
242+ await fs . rm ( agentDir , { force : true , recursive : true } ) ;
243+ }
244+ } ) ;
245+
246+ it ( "rejects a resolved Coding Plan API key before submitting a Wan request" , async ( ) => {
247+ resolveApiKeyForProviderMock . mockResolvedValueOnce ( { apiKey : "sk-sp-qwen-coding-plan-key" } ) ;
248+
249+ await expect (
250+ alibabaVideoGenerationProvider . generateVideo ( {
251+ provider : "alibaba" ,
252+ model : "wan2.6-t2v" ,
253+ prompt : "animate this shot" ,
254+ cfg : { } ,
255+ } ) ,
256+ ) . rejects . toThrow ( / S t a n d a r d D a s h S c o p e e n d p o i n t .* s a m e - r e g i o n S t a n d a r d A P I k e y / i) ;
257+
258+ expect ( postJsonRequestMock ) . not . toHaveBeenCalled ( ) ;
259+ } ) ;
260+
60261 it ( "submits async Wan generation, polls task status, and downloads the resulting video" , async ( ) => {
61262 mockSuccessfulDashscopeVideoTask ( { postJsonRequestMock, fetchWithTimeoutMock } ) ;
62263
0 commit comments