Skip to content

Commit b990cd0

Browse files
committed
test: route integration tests through centralized default-model helper
Adds js/tests/integration/_defaults.js which re-exports the runtime defaults (DEFAULT_MODEL, DEFAULT_COMPACTION_MODEL, etc.) and exposes a testDefaultModel() helper that honors LINK_ASSISTANT_AGENT_DEFAULT_MODEL. Each integration test now imports the model string from this helper instead of hard-coding "opencode/minimax-m2.5-free", so a single change in js/src/config/defaults.ts (or a single env-var override at run time) flows through every test. Refs: #267 (comment)
1 parent e2ff5f1 commit b990cd0

19 files changed

Lines changed: 123 additions & 32 deletions

js/tests/integration/_defaults.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Centralized default-model accessor for integration tests.
3+
*
4+
* Re-exports the runtime defaults (`js/src/config/defaults.ts`) so test
5+
* files import a single source of truth for the model string used by
6+
* the agent and by sibling tools like `opencode`. Override at test time
7+
* via `LINK_ASSISTANT_AGENT_DEFAULT_MODEL` (matches the runtime env var).
8+
*
9+
* Tests should never hard-code provider/model strings; pull them from
10+
* here so a single change to `js/src/config/defaults.ts` (or a single
11+
* env-var override at run time) flows through every test in the tree.
12+
*/
13+
export {
14+
DEFAULT_MODEL,
15+
DEFAULT_MODEL_ENV,
16+
DEFAULT_COMPACTION_MODEL,
17+
DEFAULT_COMPACTION_MODEL_ENV,
18+
DEFAULT_COMPACTION_MODELS,
19+
DEFAULT_COMPACTION_MODELS_ENV,
20+
DEFAULT_COMPACTION_SAFETY_MARGIN_PERCENT,
21+
DEFAULT_COMPACTION_SAFETY_MARGIN_PERCENT_ENV,
22+
getDefaultModel,
23+
getDefaultCompactionModel,
24+
getDefaultCompactionModels,
25+
getDefaultCompactionSafetyMarginPercent,
26+
} from '../../src/config/defaults.ts';
27+
28+
import { getDefaultModel } from '../../src/config/defaults.ts';
29+
30+
/**
31+
* Resolve the default model string for tests, honoring the runtime env
32+
* override. Use this in shell templates so the same value flows to the
33+
* agent and to sibling tools like `opencode`.
34+
*/
35+
export function testDefaultModel() {
36+
return getDefaultModel();
37+
}

js/tests/integration/bash.tools.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { test, expect } from 'bun:test';
22
import { $ } from 'bun';
3+
import { testDefaultModel } from './_defaults.js';
4+
5+
const MODEL = testDefaultModel();
36

47
// Shared assertion function to validate OpenCode-compatible JSON structure
58
function validateBashToolOutput(toolEvent, label) {
@@ -59,7 +62,7 @@ test('Reference test: OpenCode tool produces expected JSON format', async () =>
5962

6063
// Test original OpenCode bash tool
6164
const originalResult =
62-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
65+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
6366
.quiet()
6467
.nothrow();
6568
const originalLines = originalResult.stdout
@@ -88,7 +91,7 @@ test('Agent-cli bash tool produces 100% compatible JSON output with OpenCode', a
8891

8992
// Get OpenCode output
9093
const originalResult =
91-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
94+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
9295
.quiet()
9396
.nothrow();
9497
const originalLines = originalResult.stdout

js/tests/integration/basic.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { test, expect, setDefaultTimeout } from 'bun:test';
22
// @ts-ignore
33
import { sh } from 'command-stream';
44
import { $ } from 'bun';
5+
import { testDefaultModel } from './_defaults.js';
6+
7+
const MODEL = testDefaultModel();
58

69
// Increase default timeout to 60 seconds for these tests
710
setDefaultTimeout(60000);
@@ -87,7 +90,7 @@ function validateBasicMessageOutput(events, label) {
8790
test('OpenCode reference: processes JSON input "hi" and produces JSON output', async () => {
8891
const input = '{"message":"hi"}';
8992
const opencodeResult =
90-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
93+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
9194
.quiet()
9295
.nothrow();
9396
const opencodeLines = opencodeResult.stdout
@@ -116,7 +119,7 @@ test('Agent-cli produces 100% compatible JSON output with OpenCode', async () =>
116119

117120
// Get OpenCode output
118121
const opencodeResult =
119-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
122+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
120123
.quiet()
121124
.nothrow();
122125
const opencodeLines = opencodeResult.stdout
@@ -158,7 +161,7 @@ test('Agent-cli produces 100% compatible JSON output with OpenCode', async () =>
158161
test('OpenCode reference: processes plain text "2+2?" and produces JSON output', async () => {
159162
const input = '2+2?';
160163
const opencodeResult =
161-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
164+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
162165
.quiet()
163166
.nothrow();
164167
const opencodeLines = opencodeResult.stdout

js/tests/integration/batch.tools.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { test, expect, setDefaultTimeout } from 'bun:test';
22
import { $ } from 'bun';
33
import { spawn } from 'child_process';
44
import { join } from 'path';
5+
import { testDefaultModel } from './_defaults.js';
6+
7+
const MODEL = testDefaultModel();
58

69
// Disable timeouts for these tests
710
setDefaultTimeout(0);
@@ -11,7 +14,7 @@ async function runOpenCode(input, tmpDir) {
1114
return new Promise((resolve, reject) => {
1215
const proc = spawn(
1316
'opencode',
14-
['run', '--format', 'json', '--model', 'opencode/minimax-m2.5-free'],
17+
['run', '--format', 'json', '--model', MODEL],
1518
{
1619
stdio: ['pipe', 'pipe', 'pipe'],
1720
cwd: tmpDir,

js/tests/integration/codesearch.tools.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { test, expect, setDefaultTimeout } from 'bun:test';
22
// $ imported for consistency with other tests
33
import { spawn } from 'child_process';
44
import { join } from 'path';
5+
import { testDefaultModel } from './_defaults.js';
6+
7+
const MODEL = testDefaultModel();
58

69
// Disable timeouts for these tests
710
setDefaultTimeout(0);
@@ -11,7 +14,7 @@ async function runOpenCode(input) {
1114
return new Promise((resolve, reject) => {
1215
const proc = spawn(
1316
'opencode',
14-
['run', '--format', 'json', '--model', 'opencode/minimax-m2.5-free'],
17+
['run', '--format', 'json', '--model', MODEL],
1518
{
1619
stdio: ['pipe', 'pipe', 'pipe'],
1720
env: { ...process.env, LINK_ASSISTANT_AGENT_EXPERIMENTAL_EXA: 'true' },

js/tests/integration/dry-run.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { test, expect, describe, setDefaultTimeout } from 'bun:test';
22
// @ts-ignore
33
import { sh } from 'command-stream';
4+
import { testDefaultModel } from './_defaults.js';
5+
6+
const MODEL = testDefaultModel();
47

58
// Increase default timeout
69
setDefaultTimeout(60000);
@@ -458,7 +461,7 @@ describe('Cache provider (unit tests)', () => {
458461

459462
expect(model.specificationVersion).toBe('v2');
460463
expect(model.provider).toBe('link-assistant');
461-
expect(model.modelId).toBe('opencode/minimax-m2.5-free');
464+
expect(model.modelId).toBe(MODEL);
462465
expect(typeof model.doGenerate).toBe('function');
463466
expect(typeof model.doStream).toBe('function');
464467

js/tests/integration/edit.tools.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99
existsSync,
1010
} from 'fs';
1111
import { join } from 'path';
12+
import { testDefaultModel } from './_defaults.js';
13+
14+
const MODEL = testDefaultModel();
1215

1316
// Increase default timeout to 60 seconds for these tests
1417
setDefaultTimeout(60000);
@@ -135,7 +138,7 @@ test('Reference test: OpenCode edit tool produces expected JSON format', async (
135138
// Test original OpenCode edit tool
136139
const input = `{"message":"edit file","tools":[{"name":"edit","params":{"filePath":"${testFileName}","oldString":"Hello","newString":"Hi"}}]}`;
137140
const originalResult =
138-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
141+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
139142
.quiet()
140143
.nothrow();
141144
const originalLines = originalResult.stdout
@@ -188,7 +191,7 @@ test('Agent-cli edit tool produces 100% compatible JSON output with OpenCode', a
188191
// Get OpenCode output
189192
const openCodeInput = `{"message":"edit file","tools":[{"name":"edit","params":{"filePath":"${openCodeFileName}","oldString":"Hello","newString":"Hi"}}]}`;
190193
const originalResult =
191-
await $`echo ${openCodeInput} | opencode run --format json --model opencode/minimax-m2.5-free`
194+
await $`echo ${openCodeInput} | opencode run --format json --model ${MODEL}`
192195
.quiet()
193196
.nothrow();
194197
const originalLines = originalResult.stdout

js/tests/integration/glob.tools.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { $ } from 'bun';
33
import { spawn } from 'child_process';
44
import { writeFileSync, unlinkSync, mkdirSync, existsSync } from 'fs';
55
import { join } from 'path';
6+
import { testDefaultModel } from './_defaults.js';
7+
8+
const MODEL = testDefaultModel();
69

710
// Increase default timeout to 60 seconds for these tests
811
setDefaultTimeout(60000);
@@ -128,7 +131,7 @@ test('Reference test: OpenCode tool produces expected JSON format', async () =>
128131
// Test original OpenCode glob tool
129132
const input = `{"message":"find txt files","tools":[{"name":"glob","params":{"pattern":"tmp/test*-${timestamp}-${randomId}.txt"}}]}`;
130133
const originalResult =
131-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
134+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
132135
.quiet()
133136
.nothrow();
134137
const originalLines = originalResult.stdout
@@ -187,7 +190,7 @@ test('Agent-cli glob tool produces 100% compatible JSON output with OpenCode', a
187190

188191
// Get OpenCode output
189192
const originalResult =
190-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
193+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
191194
.quiet()
192195
.nothrow();
193196
const originalLines = originalResult.stdout

js/tests/integration/grep.tools.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { $ } from 'bun';
33
import { spawn } from 'child_process';
44
import { writeFileSync, unlinkSync, mkdirSync, existsSync } from 'fs';
55
import { join } from 'path';
6+
import { testDefaultModel } from './_defaults.js';
7+
8+
const MODEL = testDefaultModel();
69

710
// Increase default timeout to 60 seconds for these tests
811
setDefaultTimeout(60000);
@@ -154,7 +157,7 @@ test('Reference test: OpenCode tool produces expected JSON format', async () =>
154157
// Test original OpenCode grep tool - use basename pattern since files are in tmp
155158
const input = `{"message":"search for text","tools":[{"name":"grep","params":{"pattern":"search","include":"grep*-${timestamp}-${randomId}.txt","path":"${TMP_DIR}"}}]}`;
156159
const originalResult =
157-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
160+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
158161
.quiet()
159162
.nothrow();
160163
const originalLines = originalResult.stdout
@@ -213,7 +216,7 @@ test('Agent-cli grep tool produces 100% compatible JSON output with OpenCode', a
213216

214217
// Get OpenCode output
215218
const originalResult =
216-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
219+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
217220
.quiet()
218221
.nothrow();
219222
const originalLines = originalResult.stdout

js/tests/integration/list.tools.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { $ } from 'bun';
33
import { spawn } from 'child_process';
44
import { writeFileSync, unlinkSync, mkdirSync, existsSync } from 'fs';
55
import { join } from 'path';
6+
import { testDefaultModel } from './_defaults.js';
7+
8+
const MODEL = testDefaultModel();
69

710
// Ensure tmp directory exists
811
const TMP_DIR = join(process.cwd(), 'tmp');
@@ -146,7 +149,7 @@ test('Reference test: OpenCode tool produces expected JSON format', async () =>
146149
// Test original OpenCode list tool
147150
const input = `{"message":"list files","tools":[{"name":"list","params":{"path":"tmp"}}]}`;
148151
const originalResult =
149-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
152+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
150153
.quiet()
151154
.nothrow();
152155
const originalLines = originalResult.stdout
@@ -202,7 +205,7 @@ test('Agent-cli list tool produces 100% compatible JSON output with OpenCode', a
202205

203206
// Get OpenCode output
204207
const originalResult =
205-
await $`echo ${input} | opencode run --format json --model opencode/minimax-m2.5-free`
208+
await $`echo ${input} | opencode run --format json --model ${MODEL}`
206209
.quiet()
207210
.nothrow();
208211
const originalLines = originalResult.stdout

0 commit comments

Comments
 (0)