fix: validate explicit Grok install targets

This commit is contained in:
MistyStar committed 2026-10-20 10:35:37 +08:00
1 parent caf1b4a6d3
commit c5fbd3b50a
3 files changed
+10 -6

No files matched your search

+7 -4
View File
@@ -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];
}
+2 -2
View File
@@ -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]);
+1
View File
@@ -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', () => {