Repository navigation
fix(quorum): canonical args_template fallback — stop all slots crashing on missing field #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a248902
fix(quorum): canonical args_template fallback — stop all slots crashi…
c7c6f92
chore(secrets): refresh baseline line numbers after args_template gua…
586f9af
fix(quorum): address CodeRabbit review — no guessed templates, fail-l…
f82d77f
fix(quorum): slot-mode health_check works without health_check_args
2f6b2b3
chore(secrets): refresh baseline line numbers after slot-mode health_…
571ca65
fix(install): stop OLD_HOOK_MAP from stripping the live nf-session-st…
b8857e9
test(install): assert settings.json exists before parsing in session-…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * provider-arg-templates.cjs — canonical per-family CLI args_template map. | ||
| * | ||
| * Single source of truth for how each quorum CLI family is invoked non-interactively | ||
| * (the `{prompt}` placeholder is substituted with the actual prompt at dispatch time). | ||
| * | ||
| * WHY THIS EXISTS: providers.json entries are supposed to carry an `args_template` | ||
| * field, but the install-time auto-detection path (bin/install.js provider sync) | ||
| * historically wrote entries WITHOUT it. Every consumer then did | ||
| * `provider.args_template.map(...)` unguarded — so a missing field crashed quorum | ||
| * dispatch with an opaque "Cannot read properties of undefined (reading 'map')" | ||
| * for ALL slots (call-quorum-slot.cjs, unified-mcp-server.mjs, probe-quorum-slots, | ||
| * provider-status). This map lets both the generator emit a correct default and the | ||
| * consumers fall back / fail loud instead of crashing. | ||
| * | ||
| * The values below are the canonical templates asserted by the guided-install path | ||
| * and dispatch tests (test/install-guided-providers.test.cjs, test/shell-escape-01.test.cjs) | ||
| * — they are recovered from those invariants, not guessed. | ||
| */ | ||
|
|
||
| const FAMILY_ARGS_TEMPLATE = { | ||
| // claude CLI: print mode, skip interactive permission prompts | ||
| claude: ['-p', '{prompt}', '--dangerously-skip-permissions'], | ||
| // codex CLI: non-interactive `exec` subcommand | ||
| codex: ['exec', '{prompt}'], | ||
| // gemini CLI: print mode (default model) | ||
| gemini: ['-p', '{prompt}'], | ||
| // opencode CLI: `run` with quiet logs so stdout is just the response | ||
| opencode: ['run', '--print-logs', '--log-level', 'ERROR', '{prompt}'], | ||
| // copilot CLI: print mode, auto-approve tools, no color, suppress spinner | ||
| copilot: ['-p', '{prompt}', '--allow-all-tools', '--no-color', '-s'], | ||
| // antigravity (`agy` binary): print mode (verified against agy v1.0.8 `-p`/--print) | ||
| antigravity: ['-p', '{prompt}'], | ||
| }; | ||
|
|
||
| /** | ||
| * Return a fresh copy of the canonical args_template for a family, or null if the | ||
| * family is unknown. Callers should treat null as "cannot dispatch — fail loud". | ||
| * @param {string} mainTool - family name (e.g. 'gemini', 'codex', 'antigravity') | ||
| * @returns {string[]|null} | ||
| */ | ||
| function argsTemplateFor(mainTool) { | ||
| const t = FAMILY_ARGS_TEMPLATE[mainTool]; | ||
| return t ? t.slice() : null; | ||
| } | ||
|
|
||
| /** | ||
| * Resolve the args_template to use for a provider: its own explicit field wins, | ||
| * otherwise the canonical family default by mainTool. Returns null when neither | ||
| * is available (unknown family + no explicit template) so callers can fail loud | ||
| * with a clear message instead of crashing on `.map` of undefined. | ||
| * @param {object} provider - a providers.json entry | ||
| * @returns {string[]|null} | ||
| */ | ||
| function resolveArgsTemplate(provider) { | ||
| if (provider && Array.isArray(provider.args_template)) return provider.args_template; | ||
| if (provider && provider.mainTool) return argsTemplateFor(provider.mainTool); | ||
| return null; | ||
| } | ||
|
|
||
| module.exports = { FAMILY_ARGS_TEMPLATE, argsTemplateFor, resolveArgsTemplate }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| 'use strict'; | ||
|
|
||
| // ARGS-TEMPLATE-01 regression suite. | ||
| // | ||
| // The install-time auto-detect path wrote providers.json entries WITHOUT an | ||
| // args_template field; every consumer then did `provider.args_template.map(...)` | ||
| // unguarded, so quorum dispatch crashed for ALL slots with an opaque | ||
| // "Cannot read properties of undefined (reading 'map')". This suite locks in: | ||
| // 1. the canonical per-family template map, | ||
| // 2. the explicit-field-wins / family-default / null resolution order, | ||
| // 3. that call-quorum-slot's buildSpawnArgs falls back to the family default | ||
| // and fails LOUD (clear message) on an unknown family — never the bare crash. | ||
|
|
||
| const { describe, it } = require('node:test'); | ||
| const assert = require('node:assert/strict'); | ||
|
|
||
| const { FAMILY_ARGS_TEMPLATE, argsTemplateFor, resolveArgsTemplate } = require('./provider-arg-templates.cjs'); | ||
| const { buildSpawnArgs } = require('./call-quorum-slot.cjs'); | ||
|
|
||
| describe('provider-arg-templates: canonical map', () => { | ||
| it('has a template for every quorum CLI family incl. antigravity', () => { | ||
| for (const fam of ['claude', 'codex', 'gemini', 'opencode', 'copilot', 'antigravity']) { | ||
| assert.ok(Array.isArray(FAMILY_ARGS_TEMPLATE[fam]), `${fam} must have a template`); | ||
| assert.ok(FAMILY_ARGS_TEMPLATE[fam].includes('{prompt}'), `${fam} template must carry {prompt}`); | ||
| } | ||
| }); | ||
|
|
||
| it('codex uses exec; antigravity uses -p print mode', () => { | ||
| assert.deepEqual(argsTemplateFor('codex'), ['exec', '{prompt}']); | ||
| assert.deepEqual(argsTemplateFor('antigravity'), ['-p', '{prompt}']); | ||
| }); | ||
|
|
||
| it('argsTemplateFor returns a fresh copy (no shared mutation) and null for unknown', () => { | ||
| const a = argsTemplateFor('gemini'); | ||
| a.push('MUTATED'); | ||
| assert.ok(!argsTemplateFor('gemini').includes('MUTATED'), 'must return a defensive copy'); | ||
| assert.equal(argsTemplateFor('nope'), null); | ||
| }); | ||
|
|
||
| it('IDE runtimes (kilo/cursor/windsurf/augment/trae/cline) have NO canonical template', () => { | ||
| // install.js admits these as KNOWN_CLI_PREFIXES but they are not quorum CLIs; | ||
| // they must NOT get a guessed `-p {prompt}` template (CodeRabbit #275). | ||
| for (const ide of ['kilo', 'cursor', 'windsurf', 'augment', 'trae', 'cline']) { | ||
| assert.equal(argsTemplateFor(ide), null, `${ide} must have no canonical template`); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe('resolveArgsTemplate: resolution order', () => { | ||
| it('explicit args_template on the provider wins', () => { | ||
| const p = { mainTool: 'gemini', args_template: ['--custom', '{prompt}'] }; | ||
| assert.deepEqual(resolveArgsTemplate(p), ['--custom', '{prompt}']); | ||
| }); | ||
| it('falls back to the family default by mainTool', () => { | ||
| assert.deepEqual(resolveArgsTemplate({ mainTool: 'codex' }), ['exec', '{prompt}']); | ||
| }); | ||
| it('returns null when neither explicit nor a known family is present', () => { | ||
| assert.equal(resolveArgsTemplate({ mainTool: 'mystery' }), null); | ||
| assert.equal(resolveArgsTemplate({}), null); | ||
| }); | ||
| }); | ||
|
|
||
| describe('buildSpawnArgs: no crash on a provider missing args_template', () => { | ||
| it('a slot with no args_template falls back to the family template (the crash regression)', () => { | ||
| const { args } = buildSpawnArgs({ name: 'gemini-1', mainTool: 'gemini' }, 'HELLO'); | ||
| assert.deepEqual(args, ['-p', 'HELLO']); | ||
| }); | ||
|
|
||
| it('antigravity slot (no args_template) dispatches via -p', () => { | ||
| const { args } = buildSpawnArgs({ name: 'antigravity-1', mainTool: 'antigravity', cli: '/x/agy' }, 'HI'); | ||
| assert.deepEqual(args, ['-p', 'HI']); | ||
| }); | ||
|
|
||
| it('an explicit args_template is still honored', () => { | ||
| const { args } = buildSpawnArgs({ name: 'codex-1', mainTool: 'codex', args_template: ['exec', '{prompt}'] }, 'Q'); | ||
| assert.deepEqual(args, ['exec', 'Q']); | ||
| }); | ||
|
|
||
| it('an unknown family with no template fails LOUD, not with an opaque TypeError', () => { | ||
| assert.throws( | ||
| () => buildSpawnArgs({ name: 'weird-1', mainTool: 'weird' }, 'x'), | ||
| (e) => /no args_template/.test(e.message) && !/undefined \(reading 'map'\)/.test(e.message), | ||
| 'must throw a clear, actionable error' | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.