11// Opencode Go tests cover index plugin behavior.
2+ import { clampThinkingLevel } from "openclaw/plugin-sdk/llm" ;
23import type { ProviderRuntimeModel } from "openclaw/plugin-sdk/plugin-entry" ;
34import {
45 registerProviderPlugin ,
@@ -42,6 +43,36 @@ function requireCatalogEntry(entries: readonly unknown[] | null | undefined, id:
4243 return requireRecord ( entry , `supplemental catalog entry ${ id } ` ) ;
4344}
4445
46+ const deepSeekV4ThinkingProfileLevelIds = [
47+ "off" ,
48+ "minimal" ,
49+ "low" ,
50+ "medium" ,
51+ "high" ,
52+ "xhigh" ,
53+ "max" ,
54+ ] as const ;
55+ const deepSeekV4ThinkingProfile = {
56+ levels : deepSeekV4ThinkingProfileLevelIds . map ( ( id ) => ( { id } ) ) ,
57+ defaultLevel : "high" ,
58+ } ;
59+ const deepSeekV4ThinkingLevelMap = {
60+ minimal : "high" ,
61+ low : "high" ,
62+ medium : "high" ,
63+ high : "high" ,
64+ xhigh : "max" ,
65+ max : "max" ,
66+ } ;
67+
68+ function expectDeepSeekV4ThinkingLevels ( model : ProviderRuntimeModel ) {
69+ expect ( model . thinkingLevelMap ) . toEqual ( deepSeekV4ThinkingLevelMap ) ;
70+ expect ( clampThinkingLevel ( model , "off" ) ) . toBe ( "off" ) ;
71+ expect ( clampThinkingLevel ( model , "high" ) ) . toBe ( "high" ) ;
72+ expect ( clampThinkingLevel ( model , "xhigh" ) ) . toBe ( "xhigh" ) ;
73+ expect ( clampThinkingLevel ( model , "max" ) ) . toBe ( "max" ) ;
74+ }
75+
4576describe ( "opencode-go provider plugin" , ( ) => {
4677 beforeEach ( ( ) => {
4778 clearLiveCatalogCacheForTests ( ) ;
@@ -114,6 +145,17 @@ describe("opencode-go provider plugin", () => {
114145 models . set ( model . id , model ) ;
115146 }
116147 expect ( [ ...models . keys ( ) ] ) . toEqual ( expectedModelIds ) ;
148+ expectDeepSeekV4ThinkingLevels ( requireMapEntry ( models , "deepseek-v4-pro" ) ) ;
149+ expectDeepSeekV4ThinkingLevels ( requireMapEntry ( models , "deepseek-v4-flash" ) ) ;
150+ expect (
151+ provider . resolveThinkingProfile ?.( { provider : "opencode-go" , modelId : "deepseek-v4-pro" } ) ,
152+ ) . toEqual ( deepSeekV4ThinkingProfile ) ;
153+ expect (
154+ provider . resolveThinkingProfile ?.( { provider : "opencode-go" , modelId : "deepseek-v4-flash" } ) ,
155+ ) . toEqual ( deepSeekV4ThinkingProfile ) ;
156+ expect (
157+ provider . resolveThinkingProfile ?.( { provider : "opencode-go" , modelId : "glm-5" } ) ,
158+ ) . toBeUndefined ( ) ;
117159 const supplemental = await provider . augmentModelCatalog ?.( {
118160 entries : [ ...models . values ( ) ] . map ( ( model ) => ( {
119161 provider : model . provider ,
@@ -242,6 +284,19 @@ describe("opencode-go provider plugin", () => {
242284 it ( "loads OpenCode Go model discovery through the provider runtime" , ( ) => {
243285 expect ( manifest . providerCatalogEntry ) . toBe ( "./provider-discovery.ts" ) ;
244286 expect ( manifest . modelCatalog . discovery [ "opencode-go" ] ) . toBe ( "runtime" ) ;
287+ const manifestProvider = requireRecord (
288+ manifest . modelCatalog . providers [ "opencode-go" ] ,
289+ "manifest provider" ,
290+ ) ;
291+ if ( ! Array . isArray ( manifestProvider . models ) ) {
292+ throw new Error ( "expected manifest models" ) ;
293+ }
294+ expect (
295+ requireCatalogEntry ( manifestProvider . models , "deepseek-v4-pro" ) . thinkingLevelMap ,
296+ ) . toEqual ( deepSeekV4ThinkingLevelMap ) ;
297+ expect (
298+ requireCatalogEntry ( manifestProvider . models , "deepseek-v4-flash" ) . thinkingLevelMap ,
299+ ) . toEqual ( deepSeekV4ThinkingLevelMap ) ;
245300 } ) ;
246301
247302 it ( "exposes the complete offline catalog through provider discovery" , async ( ) => {
@@ -250,13 +305,21 @@ describe("opencode-go provider plugin", () => {
250305 throw new Error ( "expected OpenCode Go static provider" ) ;
251306 }
252307 const deepSeekPro = result . provider . models . find ( ( model ) => model . id === "deepseek-v4-pro" ) ;
308+ const deepSeekFlash = result . provider . models . find ( ( model ) => model . id === "deepseek-v4-flash" ) ;
253309 const glm52 = result . provider . models . find ( ( model ) => model . id === "glm-5.2" ) ;
254310
255311 expect ( result . provider . models ) . toHaveLength ( 18 ) ;
256312 expect ( deepSeekPro ) . toMatchObject ( {
257313 provider : "opencode-go" ,
258314 contextWindow : 1_000_000 ,
259315 maxTokens : 384_000 ,
316+ thinkingLevelMap : deepSeekV4ThinkingLevelMap ,
317+ } ) ;
318+ expect ( deepSeekFlash ) . toMatchObject ( {
319+ provider : "opencode-go" ,
320+ contextWindow : 1_000_000 ,
321+ maxTokens : 384_000 ,
322+ thinkingLevelMap : deepSeekV4ThinkingLevelMap ,
260323 } ) ;
261324 expect ( glm52 ) . toMatchObject ( {
262325 provider : "opencode-go" ,
@@ -386,15 +449,93 @@ describe("opencode-go provider plugin", () => {
386449 expect ( fallback . models . map ( ( model ) => model . id ) ) . toContain ( "minimax-m3" ) ;
387450 } ) ;
388451
389- it ( "disables invalid DeepSeek V4 reasoning_effort off payloads on OpenCode Go" , async ( ) => {
452+ it . each ( [ "deepseek-v4-pro" , "deepseek-v4-flash" ] as const ) (
453+ "disables invalid DeepSeek V4 reasoning_effort off payloads on OpenCode Go for %s" ,
454+ async ( modelId ) => {
455+ const provider = await registerSingleProviderPlugin ( plugin ) ;
456+ const capturedPayloads : Record < string , unknown > [ ] = [ ] ;
457+ const baseStreamFn = ( _model : unknown , _context : unknown , options : unknown ) => {
458+ const payload = {
459+ model : modelId ,
460+ reasoning_effort : "off" ,
461+ reasoning : "off" ,
462+ } ;
463+ ( options as { onPayload ?: ( payload : Record < string , unknown > ) => void } ) ?. onPayload ?.(
464+ payload ,
465+ ) ;
466+ capturedPayloads . push ( payload ) ;
467+ return { } as never ;
468+ } ;
469+
470+ const streamFn = provider . wrapStreamFn ?.( {
471+ streamFn : baseStreamFn as never ,
472+ providerId : "opencode-go" ,
473+ modelId,
474+ thinkingLevel : "off" ,
475+ } as never ) ;
476+
477+ expect ( streamFn ) . toBeTypeOf ( "function" ) ;
478+ await streamFn ?.( { provider : "opencode-go" , id : modelId } as never , { } as never , { } ) ;
479+
480+ expect ( capturedPayloads ) . toEqual ( [
481+ {
482+ model : modelId ,
483+ thinking : { type : "disabled" } ,
484+ } ,
485+ ] ) ;
486+ } ,
487+ ) ;
488+
489+ it . each ( [
490+ [ "minimal" , "high" ] ,
491+ [ "low" , "high" ] ,
492+ [ "medium" , "high" ] ,
493+ [ "high" , "high" ] ,
494+ [ "xhigh" , "max" ] ,
495+ [ "max" , "max" ] ,
496+ ] as const ) (
497+ "maps OpenCode Go DeepSeek V4 %s thinking to %s reasoning effort" ,
498+ async ( thinkingLevel , reasoningEffort ) => {
499+ const provider = await registerSingleProviderPlugin ( plugin ) ;
500+ const capturedPayloads : Record < string , unknown > [ ] = [ ] ;
501+ const baseStreamFn = ( _model : unknown , _context : unknown , options : unknown ) => {
502+ const payload = { model : "deepseek-v4-flash" } ;
503+ ( options as { onPayload ?: ( payload : Record < string , unknown > ) => void } ) ?. onPayload ?.(
504+ payload ,
505+ ) ;
506+ capturedPayloads . push ( payload ) ;
507+ return { } as never ;
508+ } ;
509+
510+ const streamFn = provider . wrapStreamFn ?.( {
511+ streamFn : baseStreamFn as never ,
512+ providerId : "opencode-go" ,
513+ modelId : "deepseek-v4-flash" ,
514+ thinkingLevel,
515+ } as never ) ;
516+
517+ expect ( streamFn ) . toBeTypeOf ( "function" ) ;
518+ await streamFn ?.(
519+ { provider : "opencode-go" , id : "deepseek-v4-flash" } as never ,
520+ { } as never ,
521+ { } ,
522+ ) ;
523+
524+ expect ( capturedPayloads ) . toEqual ( [
525+ {
526+ model : "deepseek-v4-flash" ,
527+ thinking : { type : "enabled" } ,
528+ reasoning_effort : reasoningEffort ,
529+ } ,
530+ ] ) ;
531+ } ,
532+ ) ;
533+
534+ it ( "does not apply DeepSeek V4 thinking payloads to unrelated OpenCode Go models" , async ( ) => {
390535 const provider = await registerSingleProviderPlugin ( plugin ) ;
391536 const capturedPayloads : Record < string , unknown > [ ] = [ ] ;
392537 const baseStreamFn = ( _model : unknown , _context : unknown , options : unknown ) => {
393- const payload = {
394- model : "deepseek-v4-flash" ,
395- reasoning_effort : "off" ,
396- reasoning : "off" ,
397- } ;
538+ const payload = { model : "glm-5" , reasoning_effort : "max" } ;
398539 ( options as { onPayload ?: ( payload : Record < string , unknown > ) => void } ) ?. onPayload ?.( payload ) ;
399540 capturedPayloads . push ( payload ) ;
400541 return { } as never ;
@@ -403,23 +544,14 @@ describe("opencode-go provider plugin", () => {
403544 const streamFn = provider . wrapStreamFn ?.( {
404545 streamFn : baseStreamFn as never ,
405546 providerId : "opencode-go" ,
406- modelId : "deepseek-v4-flash " ,
407- thinkingLevel : "off " ,
547+ modelId : "glm-5 " ,
548+ thinkingLevel : "max " ,
408549 } as never ) ;
409550
410551 expect ( streamFn ) . toBeTypeOf ( "function" ) ;
411- await streamFn ?.(
412- { provider : "opencode-go" , id : "deepseek-v4-flash" } as never ,
413- { } as never ,
414- { } ,
415- ) ;
552+ await streamFn ?.( { provider : "opencode-go" , id : "glm-5" } as never , { } as never , { } ) ;
416553
417- expect ( capturedPayloads ) . toEqual ( [
418- {
419- model : "deepseek-v4-flash" ,
420- thinking : { type : "disabled" } ,
421- } ,
422- ] ) ;
554+ expect ( capturedPayloads ) . toEqual ( [ { model : "glm-5" , reasoning_effort : "max" } ] ) ;
423555 } ) ;
424556
425557 it ( "strips unsupported Kimi reasoning payloads on OpenCode Go" , async ( ) => {
0 commit comments