From 990ba7bee8f88c538e7b1b6701ab50fea1ac6aa6 Mon Sep 17 00:00:00 2001 From: garrytan Date: Fri, 30 Oct 2026 01:40:31 +0000 Subject: [PATCH] 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> --- test/gateway-provider.test.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/test/gateway-provider.test.ts b/test/gateway-provider.test.ts index 29a21fd401..2b813e3dfa 100644 --- a/test/gateway-provider.test.ts +++ b/test/gateway-provider.test.ts @@ -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' });