From c5fbd3b50a8ad156eeeb39c04822ef18e217ddd8 Mon Sep 17 00:00:00 2001 From: MistyStar <144589976+Misty-Star@users.noreply.github.com> Date: Fri, 4 Sep 2026 18:53:25 +0800 Subject: [PATCH] fix: validate explicit Grok install targets --- scripts/grok-install.js | 11 +++++++---- tests/lib/grok-canonical-install.test.js | 4 ++-- tests/scripts/install-apply.test.js | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/scripts/grok-install.js b/scripts/grok-install.js index c6fe3904c..64558f4d4 100644 --- a/scripts/grok-install.js +++ b/scripts/grok-install.js @@ -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]; } diff --git a/tests/lib/grok-canonical-install.test.js b/tests/lib/grok-canonical-install.test.js index ee85f2028..f55bdb18d 100644 --- a/tests/lib/grok-canonical-install.test.js +++ b/tests/lib/grok-canonical-install.test.js @@ -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]); diff --git a/tests/scripts/install-apply.test.js b/tests/scripts/install-apply.test.js index 2d0a3264e..ccddd5c02 100644 --- a/tests/scripts/install-apply.test.js +++ b/tests/scripts/install-apply.test.js @@ -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', () => {