mirror of
https://github.com/affaan-m/ECC.git
synced 2026-12-04 14:12:11 +09:00
fix: validate explicit Grok install targets
This commit is contained in:
1 parent
caf1b4a6d3
commit
c5fbd3b50a
3 files changed
+10
-6
No files matched your search
@@ -14,7 +14,7 @@ const VALUE_FLAGS = new Set([
|
||||
]);
|
||||
|
||||
function canonicalArgs(argv = process.argv.slice(2)) {
|
||||
const args = [];
|
||||
let args = [];
|
||||
let hasSelection = false;
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const argument = argv[index];
|
||||
@@ -23,24 +23,27 @@ function canonicalArgs(argv = process.argv.slice(2)) {
|
||||
if (!value || value.startsWith('-')) {
|
||||
throw new Error('Missing value for --target');
|
||||
}
|
||||
if (value !== 'grok') {
|
||||
throw new Error(`Invalid value for --target: ${value}; expected grok`);
|
||||
}
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
args.push(argument);
|
||||
args = [...args, argument];
|
||||
if (SELECTION_FLAGS.has(argument)) hasSelection = true;
|
||||
if (VALUE_FLAGS.has(argument)) {
|
||||
const value = argv[index + 1];
|
||||
if (!value || value.startsWith('-')) {
|
||||
throw new Error(`Missing value for ${argument}`);
|
||||
}
|
||||
args.push(value);
|
||||
args = [...args, value];
|
||||
index += 1;
|
||||
} else if (!argument.startsWith('-')) {
|
||||
hasSelection = true;
|
||||
}
|
||||
}
|
||||
if (!hasSelection && !args.includes('--help') && !args.includes('-h')) {
|
||||
args.unshift('--profile', 'full');
|
||||
args = ['--profile', 'full', ...args];
|
||||
}
|
||||
return ['--target', 'grok', ...args];
|
||||
}
|
||||
|
||||
@@ -245,11 +245,11 @@ function runTests() {
|
||||
if (test('canonical source extraction forces tar to read the piped archive', () => {
|
||||
const parent = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-grok-tar-'));
|
||||
const destination = path.join(parent, 'snapshot');
|
||||
const calls = [];
|
||||
let calls = [];
|
||||
try {
|
||||
const archive = Buffer.from('archive');
|
||||
copyGitArchive('/source', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', destination, (...args) => {
|
||||
calls.push(args);
|
||||
calls = [...calls, args];
|
||||
return archive;
|
||||
});
|
||||
assert.deepStrictEqual(calls[1][1], ['-x', '-f', '-', '-C', destination]);
|
||||
|
||||
@@ -168,6 +168,7 @@ function runTests() {
|
||||
if (test('Grok alias rejects option-prefixed values for value flags', () => {
|
||||
assert.throws(() => canonicalArgs(['--target', '--dry-run']), /Missing value for --target/);
|
||||
assert.throws(() => canonicalArgs(['--consent-mcp', '--dry-run']), /Missing value for --consent-mcp/);
|
||||
assert.throws(() => canonicalArgs(['--target', 'claude']), /Invalid value for --target: claude/);
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('plans Grok through the canonical request with a local pinned fixture', () => {
|
||||
|
||||
Reference in new issue
Block a user