mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-30 20:04:15 +01:00
/cso is gone: the skill, its native helper programs, scanner images, CI jobs, docs and the rest of its tests. Upgrading removes gstack's own `/cso` entries and old helper files, and leaves a skill of your own named `cso` alone. Why: on 52 real security advisories, plainly asking the agent to audit the code caught more than /cso (13 vs 7 on particle-1; 12 vs 8 of 51 on Claude Opus 5.5, within the margin of error). To do: nothing. Optional cleanup of old scanner images and reports is in the changelog entry. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/outside-voice#1 reader=outside-voice Review-Finding: p1/outside-voice#2 reader=outside-voice Review-Finding: p1/adversarial-native#1 reader=adversarial-native Review-Finding: p1/adversarial-native#2 reader=adversarial-native
134 lines
7.0 KiB
TypeScript
134 lines
7.0 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
import { execFileSync } from 'node:child_process';
|
|
import { ClaudeAdapter, claudeExecArgs, claudeExecEnvironment, resultFromClaudeOutput } from './helpers/providers/claude';
|
|
import { codexExecArgs, GptAdapter } from './helpers/providers/gpt';
|
|
import { geminiExecArgs, geminiExecEnvironment } from './helpers/providers/gemini';
|
|
|
|
const ENV_KEYS = ['PATH', 'GSTACK_CLAUDE_BIN', 'GSTACK_CLAUDE_BIN_ARGS',
|
|
'GSTACK_CODEX_MODEL', 'EVALS_MODEL', 'GSTACK_EVAL_MODEL', 'GSTACK_EVAL_MODEL_CAPTURE'];
|
|
let saved: Record<string, string | undefined>;
|
|
let workdir: string;
|
|
|
|
describe('provider default exec policies', () => {
|
|
test('keeps exact Codex, Claude and Gemini default arguments', () => {
|
|
const work = join(tmpdir(), 'gstack-provider-work');
|
|
const common = { prompt: 'Reply OK', workdir: work, timeoutMs: 5000 };
|
|
expect(codexExecArgs(common, 'gpt-test')).toEqual([
|
|
'exec', 'Reply OK', '-C', work,
|
|
'-s', 'read-only', '--skip-git-repo-check', '--json', '-m', 'gpt-test',
|
|
]);
|
|
expect(claudeExecArgs(common, 'claude-test', ['wrapper'])).toEqual([
|
|
'wrapper', '-p', '--output-format', 'json', '--model', 'claude-test',
|
|
]);
|
|
expect(geminiExecArgs({ ...common, model: 'gemini-test' })).toEqual([
|
|
'-p', 'Reply OK', '--output-format', 'stream-json', '--yolo', '--model', 'gemini-test',
|
|
]);
|
|
});
|
|
|
|
test('preserves default provider environments', () => {
|
|
const sourceEnv = { PATH: '/bin', EVAL_FLAG: '1', UNRELATED_SECRET: 'kept-by-default', GEMINI_API_KEY: 'key' };
|
|
expect(claudeExecEnvironment(sourceEnv)).toEqual({ ...sourceEnv, GSTACK_HEADLESS: '1' });
|
|
expect(geminiExecEnvironment(sourceEnv)).toEqual({ ...sourceEnv, GOOGLE_API_KEY: 'key' });
|
|
});
|
|
|
|
test('requires Claude producer JSON with a nonblank string result',()=>{
|
|
for(const raw of ['', 'plain text', '{}', '{"result":42}', '{"result":" "}', '{"type":"result","subtype":"success","is_error":true,"result":"API Error: connection failed"}', '{"type":"result","subtype":"error_during_execution","result":"partial"}']){
|
|
expect(resultFromClaudeOutput(raw,{model:'claude-test',producer:true})).toMatchObject({output:'',error:{code:'unknown',reason:'empty or invalid output from claude CLI (exit 0)'}});
|
|
}
|
|
const valid=resultFromClaudeOutput('{"result":"OK"}',{producer:true});expect(valid.output).toBe('OK');expect(valid.error).toBeUndefined();
|
|
const legacy=resultFromClaudeOutput('plain text');expect(legacy.output).toBe('plain text');expect(legacy.error).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
// Both adapters execute these stubs, so a regression can never launch a paid CLI.
|
|
describe.skipIf(process.platform === 'win32')('provider model selection', () => {
|
|
beforeEach(() => {
|
|
saved = Object.fromEntries(ENV_KEYS.map(key => [key, process.env[key]]));
|
|
workdir = mkdtempSync(join(tmpdir(), 'gstack-model-defaults-'));
|
|
for (const key of ENV_KEYS) delete process.env[key];
|
|
process.env.PATH = `${workdir}:${saved.PATH ?? ''}`;
|
|
process.env.GSTACK_CLAUDE_BIN = join(workdir, 'claude');
|
|
for (const cli of ['claude', 'codex']) {
|
|
const response = cli === 'claude'
|
|
? '{"result":"OK","usage":{"input_tokens":1,"output_tokens":1}}'
|
|
: '{"type":"item.completed","item":{"type":"agent_message","text":"OK"}}';
|
|
writeFileSync(join(workdir, cli), `#!/bin/sh\nprintf '%s\\n' "$@" > args.txt\nprintf '%s\\n' '${response}'\n`, { mode: 0o755 });
|
|
}
|
|
});
|
|
|
|
afterEach(() => {
|
|
for (const key of ENV_KEYS) {
|
|
if (saved[key] === undefined) delete process.env[key];
|
|
else process.env[key] = saved[key];
|
|
}
|
|
rmSync(workdir, { recursive: true, force: true });
|
|
});
|
|
|
|
async function selected(adapter: ClaudeAdapter | GptAdapter, model?: string) {
|
|
// Start with PATH in the child environment; Bun can cache executable lookup
|
|
// when process.env.PATH is changed after startup.
|
|
const source = `
|
|
import { ${adapter.name === 'claude' ? 'ClaudeAdapter' : 'GptAdapter'} as Adapter }
|
|
from ${JSON.stringify(join(import.meta.dir, 'helpers/providers', `${adapter.name}.ts`))};
|
|
const result = await new Adapter().run(${JSON.stringify({ prompt: 'Reply OK', workdir, timeoutMs: 5000, model })});
|
|
console.log(JSON.stringify(result));
|
|
`;
|
|
const result = JSON.parse(execFileSync(process.execPath, ['-e', source], {
|
|
env: { ...process.env }, encoding: 'utf8', timeout: 10000,
|
|
}));
|
|
const args = readFileSync(join(workdir, 'args.txt'), 'utf8').trim().split('\n');
|
|
const flag = adapter.name === 'claude' ? '--model' : '-m';
|
|
expect(result.error).toBeUndefined();
|
|
expect(result.output).toBe('OK');
|
|
expect(args[args.indexOf(flag) + 1]).toBe(result.modelUsed);
|
|
return result.modelUsed;
|
|
}
|
|
|
|
test('Codex defaults to Astra and explicit model wins over the environment', async () => {
|
|
const adapter = new GptAdapter();
|
|
expect(await selected(adapter)).toBe('gpt-6.2-astra');
|
|
process.env.GSTACK_CODEX_MODEL = 'gpt-5.6-sol';
|
|
expect(await selected(adapter)).toBe('gpt-5.6-sol');
|
|
expect(await selected(adapter, 'custom-codex')).toBe('custom-codex');
|
|
});
|
|
|
|
test('Claude defaults to Opus 5.5 and preserves the full override chain', async () => {
|
|
const adapter = new ClaudeAdapter();
|
|
expect(await selected(adapter)).toBe('claude-opus-5-5');
|
|
process.env.GSTACK_EVAL_MODEL = 'global-model';
|
|
expect(await selected(adapter)).toBe('global-model');
|
|
process.env.GSTACK_EVAL_MODEL_CAPTURE = 'capture-model';
|
|
expect(await selected(adapter)).toBe('capture-model');
|
|
process.env.EVALS_MODEL = 'evals-model';
|
|
expect(await selected(adapter)).toBe('evals-model');
|
|
expect(await selected(adapter, 'explicit-model')).toBe('explicit-model');
|
|
});
|
|
|
|
test('Codex skill evals default to Astra and preserve model overrides', () => {
|
|
writeFileSync(join(workdir, 'SKILL.md'), '# Fixture\nReply OK.\n');
|
|
for (const [override, explicit, expected] of [
|
|
['', undefined, 'gpt-6.2-astra'],
|
|
['gpt-5.6-sol', undefined, 'gpt-5.6-sol'],
|
|
['gpt-5.6-sol', 'custom-codex', 'custom-codex'],
|
|
]) {
|
|
if (override) process.env.GSTACK_CODEX_MODEL = override;
|
|
else delete process.env.GSTACK_CODEX_MODEL;
|
|
const source = `
|
|
import { runCodexSkill } from ${JSON.stringify(join(import.meta.dir, 'helpers/codex-session-runner.ts'))};
|
|
const result = await runCodexSkill(${JSON.stringify({ skillDir: workdir, prompt: 'Reply OK', model: explicit, timeoutMs: 1000 })});
|
|
console.log(JSON.stringify(result));
|
|
process.exit(0);
|
|
`;
|
|
const result = JSON.parse(execFileSync(process.execPath, ['-e', source], {
|
|
env: { ...process.env }, encoding: 'utf8', timeout: 10000,
|
|
}));
|
|
expect(result.exitCode).toBe(0);
|
|
const args = readFileSync(join(workdir, 'args.txt'), 'utf8').trim().split('\n');
|
|
expect(args[args.indexOf('--model') + 1]).toBe(expected);
|
|
}
|
|
});
|
|
});
|