feat(ai-code-review): 支援 Antigravity CLI
CI / Release Tag Version (pull_request) Successful in 4s
CI / AI Code Review (pull_request) Failing after 17s

This commit is contained in:
2026-06-27 13:47:44 +00:00
parent 5457e68065
commit 6f997083ef
8 changed files with 60 additions and 12 deletions
+12 -1
View File
@@ -1,6 +1,6 @@
import { describe, it, beforeEach, afterEach } from 'node:test';
import assert from 'node:assert/strict';
import { getLLMConfig, getOpenCodeHttpsAgent } from '../config.js';
import { getLLMCLICommands, getLLMConfig, getOpenCodeHttpsAgent } from '../config.js';
const ENV_KEYS = [
'AI_ASSISTANT_CLI', 'MODEL', 'OPENCODE_MODEL',
@@ -19,6 +19,10 @@ afterEach(() => {
});
describe('getLLMConfig', () => {
it('exports the supported assistant CLI commands', () => {
assert.deepEqual(getLLMCLICommands(), ['codex', 'claude', 'agy', 'antigravity', 'opencode']);
});
it('returns null provider when no env vars set', () => {
const cfg = getLLMConfig({ commandExistsFn: () => false });
assert.equal(cfg.provider, null);
@@ -43,6 +47,13 @@ describe('getLLMConfig', () => {
assert.equal(cfg.model, 'gpt-5-mini');
});
it('detects Antigravity through the agy command', () => {
const cfg = getLLMConfig({ commandExistsFn: command => command === 'agy' });
assert.equal(cfg.provider, 'antigravity');
assert.equal(cfg.command, 'agy');
assert.equal(cfg.model, 'gemini-2.5-flash');
});
it('can force a CLI with AI_ASSISTANT_CLI', () => {
process.env.AI_ASSISTANT_CLI = 'opencode';
process.env.OPENCODE_MODEL = 'google/gemini-2.5-pro';
+19 -2
View File
@@ -31,13 +31,13 @@ async function installFakeCLI(command = 'codex') {
const script = join(tempDir, command);
await writeFile(script, `#!/bin/sh
if [ -n "$FAKE_AI_ARGS_PATH" ]; then printf '%s\\n' "$*" > "$FAKE_AI_ARGS_PATH"; fi
if [ -n "$FAKE_AI_STDIN_PATH" ]; then cat > "$FAKE_AI_STDIN_PATH"; else cat >/dev/null; fi
if [ -n "$FAKE_AI_STDIN_PATH" ]; then /bin/cat > "$FAKE_AI_STDIN_PATH"; else /bin/cat >/dev/null; fi
if [ -n "$FAKE_AI_STDERR" ]; then printf '%s' "$FAKE_AI_STDERR" >&2; fi
if [ -n "$FAKE_AI_STDOUT" ]; then printf '%s' "$FAKE_AI_STDOUT"; fi
exit "\${FAKE_AI_EXIT:-0}"
`);
await chmod(script, 0o755);
process.env.PATH = `${tempDir}:${saved.PATH || ''}`;
process.env.PATH = tempDir;
return { stdinPath: join(tempDir, 'stdin.txt'), argsPath: join(tempDir, 'args.txt') };
}
@@ -73,6 +73,23 @@ describe('chat - assistant CLI', async () => {
assert.match(await readFile(argsPath, 'utf8'), /run --model google\/gemini-2.5-pro/);
});
it('runs Antigravity through agy with MODEL and prompt argument', async () => {
const { stdinPath, argsPath } = await installFakeCLI('agy');
process.env.AI_ASSISTANT_CLI = 'agy';
process.env.MODEL = 'gemini-2.5-pro';
process.env.FAKE_AI_STDOUT = 'antigravity response';
process.env.FAKE_AI_STDIN_PATH = stdinPath;
process.env.FAKE_AI_ARGS_PATH = argsPath;
const result = await chat('sys', 'user');
assert.equal(result, 'antigravity response');
const args = await readFile(argsPath, 'utf8');
assert.match(args, /-p .*--model gemini-2.5-pro/s);
assert.match(args, /<system>\nsys\n<\/system>/);
assert.equal(await readFile(stdinPath, 'utf8'), '');
});
it('throws an error when the CLI fails instead of exiting the process', async () => {
await installFakeCLI('codex');
process.env.FAKE_AI_EXIT = '2';
+1
View File
@@ -120,6 +120,7 @@ describe('fetchAccountQuota', () => {
it('reports 不適用 for local platforms', async () => {
assert.equal((await fetchAccountQuota('ollama', {})).available, false);
assert.equal((await fetchAccountQuota('opencode', {})).available, false);
assert.equal((await fetchAccountQuota('antigravity', {})).available, false);
});
it('degrades gracefully when the quota call throws', async () => {