mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-26 09:54:19 +01:00
test: run the fake claude through bun so the gateway provider test passes on Windows
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
3340d95ea2
commit
990ba7bee8
1 file changed
+15
-9
@@ -9,23 +9,29 @@ import { estimateCostUsd, hasPricing } from '../lib/pricing';
|
||||
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gateway-provider-'));
|
||||
const savedBin = process.env.GSTACK_CLAUDE_BIN;
|
||||
const savedArgs = process.env.GSTACK_CLAUDE_BIN_ARGS;
|
||||
afterEach(() => {
|
||||
if (savedBin === undefined) delete process.env.GSTACK_CLAUDE_BIN;
|
||||
else process.env.GSTACK_CLAUDE_BIN = savedBin;
|
||||
if (savedArgs === undefined) delete process.env.GSTACK_CLAUDE_BIN_ARGS;
|
||||
else process.env.GSTACK_CLAUDE_BIN_ARGS = savedArgs;
|
||||
});
|
||||
|
||||
/** A stand-in claude CLI: records its env and prints a result envelope billing FAKE_MODELS. */
|
||||
/** A stand-in claude CLI run by bun (so it works on Windows): records its env and prints a result envelope billing FAKE_MODELS. */
|
||||
function fakeClaude(): string {
|
||||
const bin = path.join(tmp, 'claude');
|
||||
fs.writeFileSync(bin, [
|
||||
'#!/bin/sh',
|
||||
'cat > /dev/null',
|
||||
'env > "$FAKE_ENV_OUT"',
|
||||
'printf \'{"type":"result","subtype":"success","is_error":false,"result":"ok","num_turns":2,"usage":{"input_tokens":1000,"output_tokens":10,"cache_read_input_tokens":50,"cache_creation_input_tokens":7},"modelUsage":{%s}}\' "$FAKE_MODELS"',
|
||||
].join('\n') + '\n', { mode: 0o755 });
|
||||
return bin;
|
||||
const script = path.join(tmp, 'fake-claude.js');
|
||||
fs.writeFileSync(script, [
|
||||
"const fs = require('fs');",
|
||||
"fs.writeFileSync(process.env.FAKE_ENV_OUT, Object.entries(process.env).map(([k, v]) => k + '=' + v).join('\\n') + '\\n');",
|
||||
"const modelUsage = JSON.parse('{' + (process.env.FAKE_MODELS || '') + '}');",
|
||||
"process.stdout.write(JSON.stringify({ type: 'result', subtype: 'success', is_error: false, result: 'ok', num_turns: 2, usage: { input_tokens: 1000, output_tokens: 10, cache_read_input_tokens: 50, cache_creation_input_tokens: 7 }, modelUsage }));",
|
||||
].join('\n') + '\n');
|
||||
process.env.GSTACK_CLAUDE_BIN_ARGS = JSON.stringify([script]);
|
||||
return process.execPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
describe('gateway provider', () => {
|
||||
test('the child env drops every Anthropic credential and pins all aliases to the arm model', () => {
|
||||
const env = gatewayEnvironment('particle-ai/particle-1', { PATH: '/bin', OPENROUTER_API_KEY: 'sk-or', ANTHROPIC_API_KEY: 'sk-ant', GSTACK_ANTHROPIC_API_KEY: 'sk-ant-2', CLAUDE_CODE_OAUTH_TOKEN: 'oauth' });
|
||||
|
||||
Reference in new issue
Block a user