mirror of
https://github.com/affaan-m/ECC.git
synced 2026-10-28 03:15:15 +00:00
fix: exclude option values from session inspection targets
This commit is contained in:
1 parent
b92f181b3b
commit
93fc92da7d
2 files changed
+25
-9
No files matched your search
@@ -39,7 +39,8 @@ function usage() {
|
||||
|
||||
function parseArgs(argv) {
|
||||
const args = argv.slice(2);
|
||||
const target = args.find(argument => !argument.startsWith('--'));
|
||||
const valueOptions = ['--adapter', '--target-type', '--skill', '--amendment-id', '--observations', '--write'];
|
||||
const target = args.find((argument, index) => !argument.startsWith('--') && !valueOptions.includes(args[index - 1]));
|
||||
const listAdapters = args.includes('--list-adapters');
|
||||
|
||||
const adapterIndex = args.indexOf('--adapter');
|
||||
|
||||
@@ -9,6 +9,7 @@ const path = require('path');
|
||||
const { execFileSync } = require('child_process');
|
||||
|
||||
const { getFallbackSessionRecordingPath } = require('../../scripts/lib/session-adapters/canonical-session');
|
||||
const { parseArgs } = require('../../scripts/session-inspect');
|
||||
|
||||
const SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'session-inspect.js');
|
||||
|
||||
@@ -64,6 +65,15 @@ function runTests() {
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
|
||||
if (test('does not mistake option values for the positional target', () => {
|
||||
for (const flag of ['--adapter', '--target-type', '--skill', '--amendment-id', '--observations', '--write']) {
|
||||
for (const args of [[flag, 'value', 'claude:latest'], ['claude:latest', flag, 'value']]) {
|
||||
assert.strictEqual(parseArgs(['node', SCRIPT, ...args]).target, 'claude:latest');
|
||||
}
|
||||
}
|
||||
assert.strictEqual(parseArgs(['node', SCRIPT, '--adapter', 'claude-history']).target, undefined);
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('shows usage when no target is provided', () => {
|
||||
const result = run();
|
||||
assert.strictEqual(result.code, 1);
|
||||
@@ -152,14 +162,19 @@ function runTests() {
|
||||
'# Inspect Session\n\n**Branch:** feat/session-inspect\n'
|
||||
);
|
||||
|
||||
const result = run(['claude:latest', '--write', outputPath], {
|
||||
env: { HOME: homeDir }
|
||||
});
|
||||
|
||||
assert.strictEqual(result.code, 0, result.stderr);
|
||||
assert.ok(fs.existsSync(outputPath));
|
||||
const written = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
|
||||
assert.strictEqual(written.adapterId, 'claude-history');
|
||||
for (const args of [
|
||||
['claude:latest', '--adapter', 'claude-history', '--write', outputPath],
|
||||
['--adapter', 'claude-history', '--write', outputPath, 'claude:latest'],
|
||||
['--write', outputPath, 'claude:latest', '--adapter', 'claude-history'],
|
||||
]) {
|
||||
const result = run(args, {
|
||||
env: { HOME: homeDir, ECC_SESSION_RECORDING_DIR: outputDir }
|
||||
});
|
||||
assert.strictEqual(result.code, 0, result.stderr);
|
||||
assert.ok(fs.existsSync(outputPath));
|
||||
const written = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
|
||||
assert.strictEqual(written.adapterId, 'claude-history');
|
||||
}
|
||||
} finally {
|
||||
fs.rmSync(homeDir, { recursive: true, force: true });
|
||||
fs.rmSync(outputDir, { recursive: true, force: true });
|
||||
|
||||
Reference in new issue
Block a user