mirror of
https://github.com/wu736139669/hapi.git
synced 2026-10-15 20:29:55 +00:00
This refactoring introduces CLI argument overrides for sandbox and approval policy settings in remote mode, allowing users to specify security constraints via `--sandbox` and `--ask-for-approval` flags. Changes: - Add `CodexCliOverrides` type and `parseCodexCliOverrides()` utility to parse CLI flags like `--sandbox`, `-s`, `--ask-for-approval`, `-a`, along with convenience flags (`--full-auto`, `--dangerously-bypass-approvals-and-sandbox`) - Extract complex start config building logic into `buildCodexStartConfig()` function with proper approval policy and sandbox resolution based on permission mode - Thread `codexCliOverrides` through the session/loop/launcher chain and apply overrides only when permission mode is 'default' - Update `codexRemoteLauncher` to use the new config builder and display appropriate warnings based on whether overrides are present - Add comprehensive tests for both parsing and config building functions
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { buildCodexStartConfig } from './codexStartConfig';
|
|
|
|
describe('buildCodexStartConfig', () => {
|
|
const mcpServers = { hapi: { command: 'node', args: ['mcp'] } };
|
|
|
|
it('applies CLI overrides when permission mode is default', () => {
|
|
const config = buildCodexStartConfig({
|
|
message: 'hello',
|
|
mode: { permissionMode: 'default' },
|
|
first: true,
|
|
mcpServers,
|
|
cliOverrides: { sandbox: 'danger-full-access', approvalPolicy: 'never' }
|
|
});
|
|
|
|
expect(config.sandbox).toBe('danger-full-access');
|
|
expect(config['approval-policy']).toBe('never');
|
|
expect(config.config).toEqual({ mcp_servers: mcpServers });
|
|
});
|
|
|
|
it('ignores CLI overrides when permission mode is not default', () => {
|
|
const config = buildCodexStartConfig({
|
|
message: 'hello',
|
|
mode: { permissionMode: 'yolo' },
|
|
first: false,
|
|
mcpServers,
|
|
cliOverrides: { sandbox: 'read-only', approvalPolicy: 'never' }
|
|
});
|
|
|
|
expect(config.sandbox).toBe('danger-full-access');
|
|
expect(config['approval-policy']).toBe('on-failure');
|
|
});
|
|
|
|
it('passes model when provided', () => {
|
|
const config = buildCodexStartConfig({
|
|
message: 'hello',
|
|
mode: { permissionMode: 'default', model: 'o3' },
|
|
first: false,
|
|
mcpServers
|
|
});
|
|
|
|
expect(config.model).toBe('o3');
|
|
});
|
|
});
|