mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-26 01:43:56 +01:00
fix: gateway benchmark runs load no Claude Code settings
A settings.json env block's ANTHROPIC_API_KEY was sent to the OpenRouter base URL as x-api-key; --setting-sources '' loads no settings source. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
1a8a62cb10
commit
056e67b736
4 files changed
+14
-3
No files matched your search
@@ -23,6 +23,7 @@ function fakeClaude(): string {
|
||||
const script = path.join(tmp, 'fake-claude.js');
|
||||
fs.writeFileSync(script, [
|
||||
"const fs = require('fs');",
|
||||
"if (process.env.FAKE_ARGS_OUT) fs.writeFileSync(process.env.FAKE_ARGS_OUT, JSON.stringify(process.argv.slice(2)));",
|
||||
"fs.writeFileSync(process.env.FAKE_ENV_OUT, Object.entries(process.env).map(([k, v]) => k + '=' + v).join('\\n') + '\\n');",
|
||||
"if (process.env.FAKE_ERROR) { process.stdout.write(JSON.stringify({ type: 'result', subtype: 'error_during_execution', is_error: true, result: '' })); process.exit(0); }",
|
||||
"const modelUsage = JSON.parse('{' + (process.env.FAKE_MODELS || '') + '}');",
|
||||
@@ -71,6 +72,16 @@ describe('gateway provider', () => {
|
||||
expect(foreignModels('particle-ai/particle-1', ['particle-1', 'PARTICLE-AI/particle-1'])).toEqual([]);
|
||||
});
|
||||
|
||||
test('gateway runs load no Claude Code settings, so a settings.json key never reaches the gateway', async () => {
|
||||
process.env.GSTACK_CLAUDE_BIN = fakeClaude();
|
||||
const argsOut = path.join(tmp, 'args.json');
|
||||
await new GatewayAdapter('particle', { PATH: process.env.PATH, HOME: tmp, OPENROUTER_API_KEY: 'sk-or', FAKE_ENV_OUT: path.join(tmp, 'env-args.txt'), FAKE_ARGS_OUT: argsOut, FAKE_MODELS: '"particle-ai/particle-1":{}' }).run({ prompt: 'hi', workdir: tmp, timeoutMs: 10_000 });
|
||||
const argv: string[] = JSON.parse(fs.readFileSync(argsOut, 'utf-8'));
|
||||
const at = argv.indexOf('--setting-sources');
|
||||
expect(at).toBeGreaterThan(-1);
|
||||
expect(argv[at + 1]).toBe('');
|
||||
});
|
||||
|
||||
test('an error envelope from the gateway is an error, not a benchmark result', async () => {
|
||||
process.env.GSTACK_CLAUDE_BIN = fakeClaude();
|
||||
const adapter = new GatewayAdapter('particle', { PATH: process.env.PATH, HOME: tmp, OPENROUTER_API_KEY: 'sk-or', FAKE_ENV_OUT: path.join(tmp, 'env-err.txt'), FAKE_ERROR: '1' });
|
||||
|
||||
@@ -85,7 +85,7 @@ export class GatewayAdapter implements ProviderAdapter {
|
||||
if (opts.csoProducer) {
|
||||
return { output: '', tokens: { input: 0, output: 0 }, durationMs: 0, toolCalls: 0, modelUsed: this.model, error: { code: 'unknown', reason: 'gateway providers do not run CSO producers' } };
|
||||
}
|
||||
const result = await this.harness.run({ ...opts, model: this.model });
|
||||
const result = await this.harness.run({ ...opts, model: this.model, extraArgs: [...(opts.extraArgs ?? []), '--setting-sources', ''] });
|
||||
const foreign = foreignModels(this.model, result.modelsBilled);
|
||||
if (!result.error && foreign.length) {
|
||||
return { ...result, error: { code: 'unknown', reason: `MODEL_MIX: the run also billed ${foreign.join(', ')}` } };
|
||||
|
||||
Reference in new issue
Block a user