mirror of
https://github.com/affaan-m/ECC.git
synced 2026-10-26 18:35:05 +00:00
fix: reject missing session inspection option values
This commit is contained in:
1 parent
93fc92da7d
commit
a6619f5efd
2 files changed
+19
No files matched your search
@@ -40,6 +40,11 @@ function usage() {
|
||||
function parseArgs(argv) {
|
||||
const args = argv.slice(2);
|
||||
const valueOptions = ['--adapter', '--target-type', '--skill', '--amendment-id', '--observations', '--write'];
|
||||
for (const [index, argument] of args.entries()) {
|
||||
if (valueOptions.includes(argument) && (!args[index + 1] || args[index + 1].startsWith('--'))) {
|
||||
throw new Error(`Missing value for ${argument}`);
|
||||
}
|
||||
}
|
||||
const target = args.find((argument, index) => !argument.startsWith('--') && !valueOptions.includes(args[index - 1]));
|
||||
const listAdapters = args.includes('--list-adapters');
|
||||
|
||||
|
||||
@@ -80,6 +80,14 @@ function runTests() {
|
||||
assert.ok(result.stdout.includes('Usage:'));
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('rejects missing values for every value-taking option', () => {
|
||||
for (const flag of ['--adapter', '--target-type', '--skill', '--amendment-id', '--observations', '--write']) {
|
||||
for (const args of [[flag], [flag, '--write', 'out.json', 'claude:latest'], [flag, 'value', flag]]) {
|
||||
assert.throws(() => parseArgs(['node', SCRIPT, ...args]), { message: `Missing value for ${flag}` });
|
||||
}
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('lists registered adapters', () => {
|
||||
const result = run(['--list-adapters']);
|
||||
assert.strictEqual(result.code, 0, result.stderr);
|
||||
@@ -167,6 +175,7 @@ function runTests() {
|
||||
['--adapter', 'claude-history', '--write', outputPath, 'claude:latest'],
|
||||
['--write', outputPath, 'claude:latest', '--adapter', 'claude-history'],
|
||||
]) {
|
||||
fs.rmSync(outputPath, { force: true });
|
||||
const result = run(args, {
|
||||
env: { HOME: homeDir, ECC_SESSION_RECORDING_DIR: outputDir }
|
||||
});
|
||||
@@ -175,6 +184,11 @@ function runTests() {
|
||||
const written = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
|
||||
assert.strictEqual(written.adapterId, 'claude-history');
|
||||
}
|
||||
fs.rmSync(outputPath, { force: true });
|
||||
const invalid = run(['--adapter', '--write', outputPath, 'claude:latest'], { env: { HOME: homeDir } });
|
||||
assert.strictEqual(invalid.code, 1);
|
||||
assert.match(invalid.stderr, /Missing value for --adapter/);
|
||||
assert.ok(!fs.existsSync(outputPath));
|
||||
} finally {
|
||||
fs.rmSync(homeDir, { recursive: true, force: true });
|
||||
fs.rmSync(outputDir, { recursive: true, force: true });
|
||||
|
||||
Reference in new issue
Block a user