* test(#443): RED unified effort + fast_mode + resolve-execution All 68 tests failing as expected — no implementation yet. Covers: effort cascade (tier defaults, overrides, invalid fallthrough), fast_mode cascade (boolean-only, tier defaults), resolveEffortForTier escalation, renderEffortForRuntime clamping, resolve-execution CLI, config schema new keys, QA hostile-input matrix. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(#443): unified cross-provider effort + fast_mode knobs and resolve-execution query Adds config-driven effort control (universal ladder: minimal<low<medium<high<xhigh<max) and fast_mode propagation knobs, with per-runtime rendering that clamps the unique tail values (max=Anthropic-only clamps to xhigh on Codex; minimal=Codex-only clamps to low on Claude). Key changes: - config-schema.manifest.json: add effort.default, fast_mode.enabled as validKeys; add 4 dynamicKeyPatterns for effort.routing_tier_defaults, effort.agent_overrides, fast_mode.routing_tier_defaults, fast_mode.agent_overrides; fix stale _comment - config-defaults.manifest.json: add effort and fast_mode blocks with tier defaults - model-catalog.cjs: add EFFORT_RENDERING map, renderEffortForRuntime(), RUNTIMES_WITH_FAST_MODE - model-profiles.cjs: re-export new catalog exports - core.cjs: add resolveEffortInternal, resolveFastModeInternal, resolveEffortForTier, VALID_EFFORTS, EFFORT_SET, nextEffort; pass effort/fast_mode through loadConfig - commands.cjs: replace reasoning_effort in cmdResolveModel with unified effort; add cmdResolveExecution (superset command with effort_rendered, effort_param, effort_propagation, fast_mode, fast_mode_supported) - gsd-tools.cjs: add resolve-execution case with --effort/--fast-mode/--attempt flags - tests/feat-443: 69 tests covering cascade, rendering, escalation, CLI, schema, QA matrix - tests/commands.test.cjs: convert 3 reasoning_effort assertions to unified effort - docs/CONFIGURATION.md: document effort + fast_mode + resolve-execution sections - settings-advanced.md: list new effort/fast_mode keys in confirmation table Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(#443): remove dead catalog effort lane; unify codex effort through renderEffortForRuntime - Remove resolveReasoningEffortInternal (catalog-driven effort function) from core.cjs and its export; remove from commands.cjs destructure import - Convert tests/issue-2517-runtime-aware-profiles.test.cjs: all 11 effort assertions now use resolveEffortInternal + renderEffortForRuntime; Claude effort is first-class (output_config.effort); unknown runtimes assert param===null - Convert tests/feat-3023-model-phase-types.test.cjs: replace the entire resolveReasoningEffortInternal describe with unified effort assertions; effort derives from AGENT_DEFAULT_TIERS routing tier, not phase-type tier Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs(#443): ADR for unified cross-provider effort + fast-mode routing Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * test(#443): architecture-level QA invariants + test-strategy doc Add 48-test integration suite (feat-443-effort-fast-mode.integration.test.cjs) covering 8 architectural invariants: cross-provider validity (never emit a value the real API would 400 on), param/channel contract stability, resolve-execution JSON contract (all 8 keys + correct types), totality across the full 33-agent registry, fast-mode honesty (claude always fast_mode_supported=false), precedence first-valid-wins matrix for both effort and fast_mode cascades, dynamic-routing composition (effort escalation independent of model tier), and config-set round-trip for all new effort/* and fast_mode/* key namespaces. Append test-strategy section with invariant rationale and E2E gap documentation to docs/TESTING-SUITES.md. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test(#443): add failing install-wiring tests for effort per-runtime injection (RED) TDD RED: 10 failing tests covering: - Claude .md gets effort: injected per tier (planner=xhigh, mapper=low, executor=high) - Gemini .md does NOT get effort: (already passing — Gemini-safe) - Codex .toml gets model_reasoning_effort via unified resolver - Config-driven: effort.agent_overrides drives both Claude .md and Codex .toml - Source purity: agents/*.md have no effort: key (already passing) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat(#443): wire effort per-runtime at install (Claude .md frontmatter + Codex .toml unified) - Import AGENT_DEFAULT_TIERS and renderEffortForRuntime from model-catalog.cjs - Add readGsdEffectiveEffortConfig(targetDir): reads merged effort config from .planning/config.json (per-project wins) + ~/.gsd/defaults.json (global fallback), same probe pattern as readGsdRuntimeProfileResolver - Add resolveInstallTimeEffort(effortCfg, agentName): pure function matching resolveEffortInternal() precedence (agent_overrides > routing_tier_defaults > default > 'high') without loadConfig side-effects (no sub-repo detection, no migration writes) - Claude agent copy loop: inject `effort: <value>` into frontmatter ONLY for runtime === 'claude'; all other .md runtimes (Gemini, Qwen, Hermes, etc.) stay effort-free (Gemini-safe source contract preserved in agents/*.md) - generateCodexAgentToml: add effortCfg param; emit model_reasoning_effort from unified resolver (replaces old catalog entry.reasoning_effort); Codex clamps max → xhigh via renderEffortForRuntime('codex', ...) - installCodexConfig: pass readGsdEffectiveEffortConfig(targetDir) to generateCodexAgentToml so per-project config wins for Codex .toml too - Update failing tests to GREEN: 12/12 pass; all 17 install tests pass; 2847/2848 unit tests pass (1 pre-existing failure: policy-shell-pinning) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor(#443): source install effort defaults from manifest (kill drift) + guard test Replace hardcoded _GSD_EFFORT_MANIFEST_TIER_DEFAULTS and the 'high' fallback in resolveInstallTimeEffort with values read from config-defaults.manifest.json at module init, using the same __dirname-relative path install.js already uses for all shared manifests. Add feat-443-effort-defaults-drift.test.cjs to assert equality between install.js's runtime constants and the manifest on every CI run. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(#443): reconcile Codex TOML tests with unified effort design The #443 unified effort resolver makes generateCodexAgentToml always emit model_reasoning_effort (driven by resolveInstallTimeEffort, not model_profile_overrides). The test 'generated TOML omits reasoning_effort when runtime has none' had an obsolete premise — model_profile_overrides.reasoning_effort:'' no longer suppresses unified effort. Convert it to assert the new invariant: Codex TOML always carries a valid model_reasoning_effort from the agent's routing tier (xhigh for gsd-planner, a heavy-tier agent), while model_profile_overrides model override is still respected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(#443): make install.js effort resolution lazy (no load-time side effects breaking launcher-parity) Replace module-load-time IIFE + hard throw (config-defaults.manifest.json read) and top-level require of model-catalog.cjs with a lazy _getGsdEffortCatalog() getter that initialises on first call from resolveInstallTimeEffort / generateCodexAgentToml / Claude .md effort injection. Requiring install.js in unrelated test contexts (e.g. runtime-launcher-parity) no longer triggers manifest IO or throws, eliminating the load-time side effect that changed subprocess exit codes / stderr on the bench. Drift-guard exports (_GSD_EFFORT_MANIFEST_TIER_DEFAULTS / _GSD_EFFORT_MANIFEST_DEFAULT) preserved as lazy getter properties on module.exports so feat-443-effort-defaults-drift still validates them without forcing eager load. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(#443): isolate install-wiring test HOME to stop \$HOME/.claude pollution breaking launcher-parity runGlobalInstall() now redirects HOME to a per-call isolated tmpdir in addition to the existing runtime-specific env-var redirects (CLAUDE_CONFIG_DIR, GEMINI_CONFIG_DIR, CODEX_HOME). This ensures install.js code that uses os.homedir() directly — including the ~/.cache/gsd update-check deletion, ~/.gsd/defaults.json reads, and any HOME-relative npm subprocess writes — never touches the real \$HOME during the test. Without the HOME isolation the install test (which is new to this branch and is now picked up by Docker's raw \`tests/*.test.cjs\` glob) could write or delete files under the real \$HOME, causing runtime-launcher-parity test (D) to fail: (D) asserts a loud non-zero exit when \$RUNTIME_DIR/gsd-tools.cjs is absent and gsd-tools is not on PATH, but the launcher's \$HOME/.claude fallback arm succeeds if \$HOME/.claude/get-shit-done/bin/gsd-tools.cjs exists. Also sets GSD_SKIP_STALE_SDK_CHECK=1 to suppress the \`npm ls -g\` subprocess that the global installer spawns — irrelevant to effort-wiring assertions, slow, and potentially writes to ~/.npm cache. All 12 feat-443 install-wiring assertions preserved. Drift-guard 5/5. Unit suite 2848/2850 (pre-existing policy-shell-pinning.test.cjs failure on next). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * chore(#443): add changeset fragment for effort + fast-mode routing Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(#443): set GSD_TEST_MODE before requiring install.js in drift-guard test to prevent HOME leak Without GSD_TEST_MODE=1, require('bin/install.js') runs the module's main install block (guarded by !GSD_TEST_MODE), performing a real global Claude install into $HOME/.claude/. On CI ubuntu where node is on standard PATH, the launcher's $HOME/.claude fallback arm then finds gsd-tools.cjs, causing runtime-launcher-parity test (D) to exit zero when it must exit non-zero. Root cause: feat-443-effort-defaults-drift.test.cjs (unit suite) runs alphabetically before runtime-launcher-parity.test.cjs in the same node --test invocation. Each runs in a separate worker process but shares the same HOME. The drift test's install leaks gsd-tools.cjs into that HOME, then the launcher test's bash subprocess finds it via the $HOME/.claude arm. Fix: add process.env.GSD_TEST_MODE = '1' at the top of the drift-guard test, before the require(installPath) call. This matches the pattern used by feat-443-effort-fast-mode.test.cjs and feat-443-effort-install-wiring .install.test.cjs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(#443): deterministic resolve-execution arg parsing + validate install-time effort (Codex adversarial findings) Finding 1: resolve-execution --effort low gsd-planner misrouted 'low' as the agent. Replace find(non-dash) with a proper flag-consuming loop that collects a single positional; validate missing/extra positionals and malformed --attempt values. Finding 2: resolveInstallTimeEffort returned unvalidated effort strings (e.g. "ultra") verbatim. Each precedence layer now checks GSD_EFFORT_SET (imported once from core.cjs) before accepting a value, mirroring resolveEffortInternal exactly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(#443): newline-agnostic effort frontmatter injection (Windows CRLF) + CRLF-safe assertions Extracts injectEffortFrontmatter(content, effortValue) pure helper that detects EOL (LF vs CRLF) from the opening '---' line and inserts 'effort: <value>' before the closing '---' delimiter using the same EOL as the surrounding frontmatter. Regex now uses /^---\r?\n([\s\S]*?)^---\r?$/m instead of the LF-only /^(---\n[\s\S]*?)(---)(\n|$)/ that silently skipped CRLF files on Windows (git core.autocrlf=true checkout). Also adds 7 unit tests covering LF, CRLF, idempotency, no-frontmatter, and complex frontmatter cases. Exports injectEffortFrontmatter from module.exports. Fixes 6 CI failures in tests/feat-443-effort-install-wiring.install.test.cjs on windows-latest runners (lines 138, 145, 152, 261, 345, 356). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: CI Rebase Check <ci@gsd-redux> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
863 lines
36 KiB
JavaScript
863 lines
36 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Feature test for issue #443 — unified cross-provider effort + fast_mode knobs.
|
|
*
|
|
* Adds config-driven effort (universal ladder: minimal<low<medium<high<xhigh<max)
|
|
* and fast_mode knobs. Per-runtime rendering clamps the unique tails:
|
|
* - Anthropic/Claude: supports {low,medium,high,xhigh,max}, param=output_config.effort
|
|
* - Codex: supports {minimal,low,medium,high,xhigh}, param=model_reasoning_effort
|
|
*
|
|
* Also adds resolve-execution query which is the superset command including
|
|
* effort rendering and fast_mode propagation metadata.
|
|
*/
|
|
|
|
process.env.GSD_TEST_MODE = '1';
|
|
|
|
const { describe, test, beforeEach, afterEach } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const { createTempProject, createTempDir, cleanup, runGsdTools } = require('./helpers.cjs');
|
|
|
|
const {
|
|
resolveEffortInternal,
|
|
resolveFastModeInternal,
|
|
resolveEffortForTier,
|
|
} = require('../get-shit-done/bin/lib/core.cjs');
|
|
|
|
const {
|
|
renderEffortForRuntime,
|
|
RUNTIMES_WITH_FAST_MODE,
|
|
} = require('../get-shit-done/bin/lib/model-catalog.cjs');
|
|
|
|
const {
|
|
injectEffortFrontmatter,
|
|
} = require('../bin/install.js');
|
|
|
|
function writeConfig(dir, config) {
|
|
const planningDir = path.join(dir, '.planning');
|
|
fs.mkdirSync(planningDir, { recursive: true });
|
|
fs.writeFileSync(path.join(planningDir, 'config.json'), JSON.stringify(config, null, 2));
|
|
}
|
|
|
|
// ─── Effort cascade ───────────────────────────────────────────────────────────
|
|
|
|
describe('#443 effort cascade', () => {
|
|
let tmpDir;
|
|
beforeEach(() => { tmpDir = createTempProject(); });
|
|
afterEach(() => { cleanup(tmpDir); });
|
|
|
|
test('no config -> gsd-planner (heavy) defaults to "xhigh" via tier default', () => {
|
|
// gsd-planner is heavy tier; manifest default for heavy is xhigh
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'xhigh');
|
|
});
|
|
|
|
test('routing_tier_defaults: light (gsd-codebase-mapper) -> "low"', () => {
|
|
// gsd-codebase-mapper routingTier=light, default for light is "low"
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-codebase-mapper'), 'low');
|
|
});
|
|
|
|
test('routing_tier_defaults: standard (gsd-executor) -> "high"', () => {
|
|
// gsd-executor routingTier=standard, default for standard is "high"
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-executor'), 'high');
|
|
});
|
|
|
|
test('routing_tier_defaults: heavy (gsd-planner) -> "xhigh"', () => {
|
|
// gsd-planner routingTier=heavy, default for heavy is "xhigh"
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'xhigh');
|
|
});
|
|
|
|
test('effort.routing_tier_defaults override beats tier default', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: { routing_tier_defaults: { heavy: 'medium' } },
|
|
});
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'medium');
|
|
});
|
|
|
|
test('effort.agent_overrides beats routing_tier_defaults', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: {
|
|
routing_tier_defaults: { heavy: 'medium' },
|
|
agent_overrides: { 'gsd-planner': 'low' },
|
|
},
|
|
});
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'low');
|
|
});
|
|
|
|
test('opts.override beats agent_overrides', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: { agent_overrides: { 'gsd-planner': 'low' } },
|
|
});
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner', { override: 'minimal' }), 'minimal');
|
|
});
|
|
|
|
test('invalid override falls through to agent_overrides', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: { agent_overrides: { 'gsd-planner': 'low' } },
|
|
});
|
|
// 'turbo' is not a valid effort — should fall through to agent_overrides
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner', { override: 'turbo' }), 'low');
|
|
});
|
|
|
|
test('invalid agent_overrides value falls through to routing_tier_defaults', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: {
|
|
agent_overrides: { 'gsd-planner': 123 },
|
|
routing_tier_defaults: { heavy: 'medium' },
|
|
},
|
|
});
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'medium');
|
|
});
|
|
|
|
test('invalid routing_tier_defaults value falls through to effort.default', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: {
|
|
routing_tier_defaults: { heavy: 'turbo' },
|
|
default: 'low',
|
|
},
|
|
});
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'low');
|
|
});
|
|
|
|
test('invalid effort.default falls through to hardcoded "high" (no routing_tier_defaults set)', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: { default: 'turbo' },
|
|
});
|
|
// effortCfg set but no routing_tier_defaults; turbo is invalid; fallback = hardcoded 'high'
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'high');
|
|
});
|
|
|
|
test('unknown agent -> uses effort.default', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: { default: 'medium' },
|
|
});
|
|
// unknown-agent has no routingTier, so step 3 skipped
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'unknown-agent-xyz'), 'medium');
|
|
});
|
|
|
|
test('effort.default numeric value (123) ignored, hardcoded "high" fallback', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: { default: 123 },
|
|
});
|
|
// effortCfg set, no routing_tier_defaults -> no tier default; numeric ignored -> 'high'
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'high');
|
|
});
|
|
|
|
test('effort block missing entirely -> uses tier default', () => {
|
|
// No effort key in config at all
|
|
writeConfig(tmpDir, { model_profile: 'balanced' });
|
|
// heavy agent: tier default xhigh
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'xhigh');
|
|
});
|
|
|
|
test('effort block is non-object (string) -> effortCfg=null -> uses manifest tier default xhigh', () => {
|
|
writeConfig(tmpDir, { effort: 'bad' });
|
|
// Non-object effort => effortCfg=null; gsd-planner heavy tier manifest default = xhigh
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'xhigh');
|
|
});
|
|
|
|
test('effort.routing_tier_defaults empty object -> effort.default', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: { routing_tier_defaults: {}, default: 'low' },
|
|
});
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'low');
|
|
});
|
|
});
|
|
|
|
// ─── Fast mode cascade ────────────────────────────────────────────────────────
|
|
|
|
describe('#443 fast_mode cascade', () => {
|
|
let tmpDir;
|
|
beforeEach(() => { tmpDir = createTempProject(); });
|
|
afterEach(() => { cleanup(tmpDir); });
|
|
|
|
test('no config -> defaults to false', () => {
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'gsd-planner'), false);
|
|
});
|
|
|
|
test('fast_mode.enabled=true -> true when no tier/agent overrides', () => {
|
|
writeConfig(tmpDir, { fast_mode: { enabled: true } });
|
|
// heavy agent: tier default is false, but enabled=true is layer 4
|
|
// tier default for heavy is false (below enabled), so gets enabled=true
|
|
// Wait — the cascade is: 1.override 2.agent_overrides 3.tier_defaults 4.enabled 5.false
|
|
// For gsd-planner (heavy), tier default is false — falls through to enabled=true
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'gsd-planner'), true);
|
|
});
|
|
|
|
test('fast_mode.routing_tier_defaults.light=true -> light agent gets true', () => {
|
|
writeConfig(tmpDir, {
|
|
fast_mode: { routing_tier_defaults: { light: true } },
|
|
});
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'gsd-codebase-mapper'), true);
|
|
});
|
|
|
|
test('fast_mode.routing_tier_defaults.heavy=false -> heavy agent stays false', () => {
|
|
writeConfig(tmpDir, {
|
|
fast_mode: { enabled: true, routing_tier_defaults: { heavy: false } },
|
|
});
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'gsd-planner'), false);
|
|
});
|
|
|
|
test('fast_mode.agent_overrides beats routing_tier_defaults', () => {
|
|
writeConfig(tmpDir, {
|
|
fast_mode: {
|
|
routing_tier_defaults: { light: false },
|
|
agent_overrides: { 'gsd-codebase-mapper': true },
|
|
},
|
|
});
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'gsd-codebase-mapper'), true);
|
|
});
|
|
|
|
test('opts.override beats agent_overrides', () => {
|
|
writeConfig(tmpDir, {
|
|
fast_mode: { agent_overrides: { 'gsd-planner': true } },
|
|
});
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'gsd-planner', { override: false }), false);
|
|
});
|
|
|
|
test('string "true" NOT accepted as fast_mode override', () => {
|
|
writeConfig(tmpDir, {
|
|
fast_mode: { agent_overrides: { 'gsd-planner': 'true' } },
|
|
});
|
|
// string "true" is not boolean -> fall through to tier default or enabled
|
|
const result = resolveFastModeInternal(tmpDir, 'gsd-planner');
|
|
assert.strictEqual(typeof result, 'boolean');
|
|
});
|
|
|
|
test('string "true" in opts.override NOT accepted', () => {
|
|
// opts.override must be strict boolean — string falls through
|
|
const result = resolveFastModeInternal(tmpDir, 'gsd-planner', { override: 'true' });
|
|
assert.strictEqual(result, false);
|
|
});
|
|
|
|
test('fast_mode block missing entirely -> defaults to false', () => {
|
|
writeConfig(tmpDir, { model_profile: 'balanced' });
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'gsd-planner'), false);
|
|
});
|
|
|
|
test('fast_mode.enabled="yes" (non-boolean) ignored -> false', () => {
|
|
writeConfig(tmpDir, { fast_mode: { enabled: 'yes' } });
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'gsd-planner'), false);
|
|
});
|
|
|
|
test('unknown agent fast_mode -> uses enabled flag', () => {
|
|
writeConfig(tmpDir, { fast_mode: { enabled: true } });
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'unknown-agent-xyz'), true);
|
|
});
|
|
});
|
|
|
|
// ─── Effort escalation (resolveEffortForTier) ─────────────────────────────────
|
|
|
|
describe('#443 resolveEffortForTier escalation', () => {
|
|
let tmpDir;
|
|
beforeEach(() => { tmpDir = createTempProject(); });
|
|
afterEach(() => { cleanup(tmpDir); });
|
|
|
|
test('dynamic_routing disabled -> attempt ignored, returns base effort', () => {
|
|
// gsd-planner heavy -> xhigh baseline
|
|
const base = resolveEffortForTier(tmpDir, 'gsd-planner', 0);
|
|
const attempt1 = resolveEffortForTier(tmpDir, 'gsd-planner', 1);
|
|
assert.strictEqual(base, 'xhigh');
|
|
assert.strictEqual(attempt1, 'xhigh'); // no dynamic_routing -> attempt ignored
|
|
});
|
|
|
|
test('dynamic_routing enabled, escalate_on_failure=false -> attempt ignored', () => {
|
|
writeConfig(tmpDir, {
|
|
dynamic_routing: {
|
|
enabled: true,
|
|
tier_models: { light: 'haiku', standard: 'sonnet', heavy: 'opus' },
|
|
escalate_on_failure: false,
|
|
max_escalations: 2,
|
|
},
|
|
});
|
|
const base = resolveEffortForTier(tmpDir, 'gsd-codebase-mapper', 0);
|
|
const attempt1 = resolveEffortForTier(tmpDir, 'gsd-codebase-mapper', 1);
|
|
assert.strictEqual(base, attempt1);
|
|
});
|
|
|
|
test('dynamic_routing enabled, attempt=1 -> one step up from base', () => {
|
|
writeConfig(tmpDir, {
|
|
dynamic_routing: {
|
|
enabled: true,
|
|
tier_models: { light: 'haiku', standard: 'sonnet', heavy: 'opus' },
|
|
escalate_on_failure: true,
|
|
max_escalations: 2,
|
|
},
|
|
effort: { routing_tier_defaults: { light: 'low' } },
|
|
});
|
|
// gsd-codebase-mapper: light -> effort 'low'; attempt=1 -> 'medium'
|
|
assert.strictEqual(resolveEffortForTier(tmpDir, 'gsd-codebase-mapper', 0), 'low');
|
|
assert.strictEqual(resolveEffortForTier(tmpDir, 'gsd-codebase-mapper', 1), 'medium');
|
|
});
|
|
|
|
test('escalation clamps at "max"', () => {
|
|
writeConfig(tmpDir, {
|
|
dynamic_routing: {
|
|
enabled: true,
|
|
tier_models: { light: 'haiku', standard: 'sonnet', heavy: 'opus' },
|
|
escalate_on_failure: true,
|
|
max_escalations: 99,
|
|
},
|
|
effort: { default: 'xhigh' },
|
|
});
|
|
// xhigh -> max -> max (clamp)
|
|
const result = resolveEffortForTier(tmpDir, 'gsd-planner', 99);
|
|
assert.strictEqual(result, 'max');
|
|
});
|
|
|
|
test('respects max_escalations cap', () => {
|
|
writeConfig(tmpDir, {
|
|
dynamic_routing: {
|
|
enabled: true,
|
|
tier_models: { light: 'haiku', standard: 'sonnet', heavy: 'opus' },
|
|
escalate_on_failure: true,
|
|
max_escalations: 1,
|
|
},
|
|
effort: { routing_tier_defaults: { light: 'low' } },
|
|
});
|
|
// light: low -> attempt=1 -> medium (but max=1 so can only escalate once)
|
|
const at1 = resolveEffortForTier(tmpDir, 'gsd-codebase-mapper', 1);
|
|
const at2 = resolveEffortForTier(tmpDir, 'gsd-codebase-mapper', 2);
|
|
// at2 is capped at 1 escalation, same as at1
|
|
assert.strictEqual(at1, at2);
|
|
assert.strictEqual(at1, 'medium');
|
|
});
|
|
});
|
|
|
|
// ─── Rendering / clamping ──────────────────────────────────────────────────────
|
|
|
|
describe('#443 renderEffortForRuntime', () => {
|
|
test('codex: "max" clamps to "xhigh"', () => {
|
|
const r = renderEffortForRuntime('codex', 'max');
|
|
assert.strictEqual(r.value, 'xhigh');
|
|
assert.strictEqual(r.param, 'model_reasoning_effort');
|
|
});
|
|
|
|
test('codex: common levels passthrough', () => {
|
|
assert.strictEqual(renderEffortForRuntime('codex', 'low').value, 'low');
|
|
assert.strictEqual(renderEffortForRuntime('codex', 'medium').value, 'medium');
|
|
assert.strictEqual(renderEffortForRuntime('codex', 'high').value, 'high');
|
|
assert.strictEqual(renderEffortForRuntime('codex', 'xhigh').value, 'xhigh');
|
|
});
|
|
|
|
test('codex: "minimal" passthrough', () => {
|
|
assert.strictEqual(renderEffortForRuntime('codex', 'minimal').value, 'minimal');
|
|
});
|
|
|
|
test('claude: "minimal" clamps to "low"', () => {
|
|
const r = renderEffortForRuntime('claude', 'minimal');
|
|
assert.strictEqual(r.value, 'low');
|
|
assert.strictEqual(r.param, 'output_config.effort');
|
|
});
|
|
|
|
test('claude: "max" passthrough (Anthropic-only)', () => {
|
|
const r = renderEffortForRuntime('claude', 'max');
|
|
assert.strictEqual(r.value, 'max');
|
|
assert.strictEqual(r.param, 'output_config.effort');
|
|
});
|
|
|
|
test('claude: common levels passthrough', () => {
|
|
assert.strictEqual(renderEffortForRuntime('claude', 'low').value, 'low');
|
|
assert.strictEqual(renderEffortForRuntime('claude', 'medium').value, 'medium');
|
|
assert.strictEqual(renderEffortForRuntime('claude', 'high').value, 'high');
|
|
assert.strictEqual(renderEffortForRuntime('claude', 'xhigh').value, 'xhigh');
|
|
});
|
|
|
|
test('unknown runtime: param is null, value passthrough', () => {
|
|
const r = renderEffortForRuntime('unknown-runtime', 'high');
|
|
assert.strictEqual(r.param, null);
|
|
assert.strictEqual(r.value, 'high');
|
|
});
|
|
|
|
test('RUNTIMES_WITH_FAST_MODE does NOT include "claude"', () => {
|
|
// Claude Code has no per-subagent fast-mode mechanism — session-level only
|
|
assert.ok(!RUNTIMES_WITH_FAST_MODE.has('claude'),
|
|
'claude must NOT be in RUNTIMES_WITH_FAST_MODE — emitting fast_mode frontmatter is a silent no-op');
|
|
});
|
|
});
|
|
|
|
// ─── resolve-execution end-to-end ─────────────────────────────────────────────
|
|
|
|
describe('#443 resolve-execution CLI command', () => {
|
|
let tmpDir;
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
// HOME isolation to prevent ~/.gsd/defaults.json bleed
|
|
process.env._GSD_TEST_HOME_OVERRIDE = tmpDir;
|
|
});
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
delete process.env._GSD_TEST_HOME_OVERRIDE;
|
|
});
|
|
|
|
test('default (claude) runtime -> effort present, effort_param=output_config.effort, fast_mode_supported=false', () => {
|
|
const result = runGsdTools(['resolve-execution', 'gsd-planner'], tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
assert.ok(output.effort, 'should have effort field');
|
|
assert.strictEqual(output.effort_param, 'output_config.effort');
|
|
assert.strictEqual(output.fast_mode_supported, false);
|
|
assert.ok('fast_mode' in output, 'should have fast_mode field');
|
|
assert.ok('model' in output, 'should have model field');
|
|
assert.ok('profile' in output, 'should have profile field');
|
|
});
|
|
|
|
test('codex runtime -> effort_param=model_reasoning_effort, max clamps to xhigh, fast_mode_supported=false', () => {
|
|
writeConfig(tmpDir, {
|
|
runtime: 'codex',
|
|
effort: { default: 'max' },
|
|
});
|
|
const result = runGsdTools(['resolve-execution', 'gsd-planner'], tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
assert.strictEqual(output.effort_param, 'model_reasoning_effort');
|
|
assert.strictEqual(output.effort_rendered, 'xhigh');
|
|
// fast_mode_supported: codex does not support fast mode via subagent
|
|
assert.strictEqual(output.fast_mode_supported, false);
|
|
});
|
|
|
|
test('--effort flag overrides config effort', () => {
|
|
const result = runGsdTools(
|
|
['resolve-execution', 'gsd-planner', '--effort', 'low'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
assert.strictEqual(output.effort, 'low');
|
|
});
|
|
|
|
test('--fast-mode flag honored', () => {
|
|
const result = runGsdTools(
|
|
['resolve-execution', 'gsd-planner', '--fast-mode', 'true'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
assert.strictEqual(output.fast_mode, true);
|
|
});
|
|
|
|
test('--attempt flag triggers escalation', () => {
|
|
writeConfig(tmpDir, {
|
|
dynamic_routing: {
|
|
enabled: true,
|
|
tier_models: { light: 'haiku', standard: 'sonnet', heavy: 'opus' },
|
|
escalate_on_failure: true,
|
|
max_escalations: 2,
|
|
},
|
|
effort: { routing_tier_defaults: { light: 'low' } },
|
|
});
|
|
const result0 = runGsdTools(
|
|
['resolve-execution', 'gsd-codebase-mapper', '--attempt', '0'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
const result1 = runGsdTools(
|
|
['resolve-execution', 'gsd-codebase-mapper', '--attempt', '1'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result0.success && result1.success);
|
|
const out0 = JSON.parse(result0.output);
|
|
const out1 = JSON.parse(result1.output);
|
|
assert.strictEqual(out0.effort, 'low');
|
|
assert.strictEqual(out1.effort, 'medium');
|
|
});
|
|
|
|
test('--raw prints effort string', () => {
|
|
const result = runGsdTools(
|
|
['resolve-execution', 'gsd-planner', '--raw'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
// Raw output should be the effort string
|
|
const VALID_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
assert.ok(VALID_EFFORTS.includes(result.output.trim()),
|
|
`Expected effort string, got: ${result.output}`);
|
|
});
|
|
|
|
test('fails when no agent-type provided', () => {
|
|
const result = runGsdTools(['resolve-execution'], tmpDir, { HOME: tmpDir });
|
|
assert.ok(!result.success, 'should fail without agent-type');
|
|
assert.ok(result.error.includes('agent-type required'), `error: ${result.error}`);
|
|
});
|
|
|
|
test('unknown agent -> unknown_agent=true still emits effort', () => {
|
|
const result = runGsdTools(['resolve-execution', 'unknown-agent-xyz'], tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
assert.strictEqual(output.unknown_agent, true);
|
|
assert.ok(output.effort, 'should have effort even for unknown agent');
|
|
});
|
|
|
|
test('emits effort_propagation (channel) field', () => {
|
|
const result = runGsdTools(['resolve-execution', 'gsd-planner'], tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
assert.ok('effort_propagation' in output, 'should have effort_propagation field');
|
|
});
|
|
});
|
|
|
|
// ─── resolve-model now emits effort (replaces reasoning_effort) ───────────────
|
|
|
|
describe('#443 resolve-model emits effort (unified)', () => {
|
|
let tmpDir;
|
|
beforeEach(() => { tmpDir = createTempProject(); });
|
|
afterEach(() => { cleanup(tmpDir); });
|
|
|
|
test('resolve-model on claude runtime emits effort (not null)', () => {
|
|
const result = runGsdTools(['resolve-model', 'gsd-planner'], tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
// effort must be present and valid
|
|
const VALID_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
assert.ok(VALID_EFFORTS.includes(output.effort),
|
|
`Expected valid effort, got: ${output.effort}`);
|
|
// reasoning_effort must NOT be present (removed)
|
|
assert.ok(!Object.prototype.hasOwnProperty.call(output, 'reasoning_effort'),
|
|
'resolve-model must not emit reasoning_effort (replaced by effort)');
|
|
});
|
|
|
|
test('resolve-model on codex runtime emits unified effort (not reasoning_effort)', () => {
|
|
fs.writeFileSync(
|
|
path.join(tmpDir, '.planning', 'config.json'),
|
|
JSON.stringify({ runtime: 'codex', model_profile: 'balanced' })
|
|
);
|
|
const result = runGsdTools(['resolve-model', 'gsd-planner'], tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
const VALID_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
assert.ok(VALID_EFFORTS.includes(output.effort),
|
|
`Expected valid effort, got: ${output.effort}`);
|
|
assert.ok(!Object.prototype.hasOwnProperty.call(output, 'reasoning_effort'),
|
|
'resolve-model must not emit reasoning_effort');
|
|
});
|
|
});
|
|
|
|
// ─── QA Matrix — hostile/malformed configs ───────────────────────────────────
|
|
|
|
describe('#443 QA matrix — malformed effort/fast_mode configs', () => {
|
|
let tmpDir;
|
|
beforeEach(() => { tmpDir = createTempProject(); });
|
|
afterEach(() => { cleanup(tmpDir); });
|
|
|
|
test('effort.default=123 (numeric) -> gracefully falls through', () => {
|
|
writeConfig(tmpDir, { effort: { default: 123 } });
|
|
// gsd-planner is heavy, tier default xhigh is used instead
|
|
const result = resolveEffortInternal(tmpDir, 'gsd-planner');
|
|
assert.ok(typeof result === 'string');
|
|
const VALID_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
assert.ok(VALID_EFFORTS.includes(result));
|
|
});
|
|
|
|
test('fast_mode.enabled="yes" (string) -> ignored, returns false', () => {
|
|
writeConfig(tmpDir, { fast_mode: { enabled: 'yes' } });
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'gsd-planner'), false);
|
|
});
|
|
|
|
test('effort:{} empty block -> uses tier default or hardcoded high', () => {
|
|
writeConfig(tmpDir, { effort: {} });
|
|
const result = resolveEffortInternal(tmpDir, 'gsd-planner');
|
|
const VALID_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
assert.ok(VALID_EFFORTS.includes(result));
|
|
});
|
|
|
|
test('fast_mode:{} empty block -> false', () => {
|
|
writeConfig(tmpDir, { fast_mode: {} });
|
|
assert.strictEqual(resolveFastModeInternal(tmpDir, 'gsd-planner'), false);
|
|
});
|
|
|
|
test('effort config is completely absent -> still resolves valid effort', () => {
|
|
writeConfig(tmpDir, { model_profile: 'quality' });
|
|
const result = resolveEffortInternal(tmpDir, 'gsd-planner');
|
|
const VALID_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
assert.ok(VALID_EFFORTS.includes(result));
|
|
});
|
|
|
|
test('effort.routing_tier_defaults has boolean value -> falls through', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: {
|
|
routing_tier_defaults: { heavy: true },
|
|
default: 'medium',
|
|
},
|
|
});
|
|
// boolean true is not a valid effort -> falls through to default 'medium'
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'gsd-planner'), 'medium');
|
|
});
|
|
|
|
test('effort.agent_overrides is non-object -> falls through gracefully', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: {
|
|
agent_overrides: 'not-an-object',
|
|
default: 'low',
|
|
},
|
|
});
|
|
// non-object agent_overrides -> skip step 2, use tier default (heavy=xhigh)
|
|
// actually heavy tier default kicks in first if no routing_tier_defaults
|
|
const result = resolveEffortInternal(tmpDir, 'gsd-planner');
|
|
const VALID_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
assert.ok(VALID_EFFORTS.includes(result));
|
|
});
|
|
|
|
test('config.json has unknown agent with effort.default set -> uses effort.default', () => {
|
|
writeConfig(tmpDir, { effort: { default: 'minimal' } });
|
|
assert.strictEqual(resolveEffortInternal(tmpDir, 'completely-unknown-agent-98765'), 'minimal');
|
|
});
|
|
|
|
test('resolve-execution with malformed config does not crash', () => {
|
|
writeConfig(tmpDir, {
|
|
effort: { default: null, routing_tier_defaults: null },
|
|
fast_mode: { enabled: null, agent_overrides: null },
|
|
});
|
|
const result = runGsdTools(['resolve-execution', 'gsd-planner'], tmpDir, { HOME: tmpDir });
|
|
assert.ok(result.success, `Should not crash with null config values: ${result.error}`);
|
|
});
|
|
});
|
|
|
|
// ─── Config schema: new keys are valid ───────────────────────────────────────
|
|
|
|
describe('#443 config schema: new effort/fast_mode keys valid', () => {
|
|
const { isValidConfigKey } = require('../get-shit-done/bin/lib/config-schema.cjs');
|
|
|
|
test('effort.default is a valid config key', () => {
|
|
assert.ok(isValidConfigKey('effort.default'), 'effort.default must be valid');
|
|
});
|
|
|
|
test('fast_mode.enabled is a valid config key', () => {
|
|
assert.ok(isValidConfigKey('fast_mode.enabled'), 'fast_mode.enabled must be valid');
|
|
});
|
|
|
|
test('effort.routing_tier_defaults.light is valid (dynamic pattern)', () => {
|
|
assert.ok(isValidConfigKey('effort.routing_tier_defaults.light'));
|
|
});
|
|
|
|
test('effort.routing_tier_defaults.standard is valid', () => {
|
|
assert.ok(isValidConfigKey('effort.routing_tier_defaults.standard'));
|
|
});
|
|
|
|
test('effort.routing_tier_defaults.heavy is valid', () => {
|
|
assert.ok(isValidConfigKey('effort.routing_tier_defaults.heavy'));
|
|
});
|
|
|
|
test('effort.agent_overrides.<agent-id> is valid (dynamic pattern)', () => {
|
|
assert.ok(isValidConfigKey('effort.agent_overrides.gsd-planner'));
|
|
assert.ok(isValidConfigKey('effort.agent_overrides.my-custom-agent'));
|
|
});
|
|
|
|
test('fast_mode.routing_tier_defaults.light is valid', () => {
|
|
assert.ok(isValidConfigKey('fast_mode.routing_tier_defaults.light'));
|
|
});
|
|
|
|
test('fast_mode.agent_overrides.<agent-id> is valid', () => {
|
|
assert.ok(isValidConfigKey('fast_mode.agent_overrides.gsd-planner'));
|
|
});
|
|
|
|
test('effort.routing_tier_defaults.invalid-tier is NOT valid', () => {
|
|
assert.ok(!isValidConfigKey('effort.routing_tier_defaults.super'));
|
|
});
|
|
});
|
|
|
|
// ─── resolve-execution arg parsing matrix (Codex adversarial finding #1) ──────
|
|
//
|
|
// These tests FAIL before the fix: flags-first ordering misroutes the agent.
|
|
|
|
describe('#443 resolve-execution: deterministic arg parsing (flags-first ordering)', () => {
|
|
let tmpDir;
|
|
beforeEach(() => {
|
|
tmpDir = createTempProject();
|
|
process.env._GSD_TEST_HOME_OVERRIDE = tmpDir;
|
|
});
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
delete process.env._GSD_TEST_HOME_OVERRIDE;
|
|
});
|
|
|
|
test('flags-first: --effort low gsd-planner resolves gsd-planner (NOT "low" as agent)', () => {
|
|
// BUG: before fix, agentTypeArg = 'low' (first non-dash token) -> unknown_agent:true
|
|
const result = runGsdTools(
|
|
['resolve-execution', '--effort', 'low', 'gsd-planner'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
assert.ok(!output.unknown_agent, `agent must be resolved (not unknown_agent), got: ${JSON.stringify(output)}`);
|
|
assert.strictEqual(output.effort, 'low', `effort should be low, got: ${output.effort}`);
|
|
});
|
|
|
|
test('flags-first: --attempt 1 gsd-codebase-mapper resolves gsd-codebase-mapper (NOT "1" as agent)', () => {
|
|
// BUG: before fix, agentTypeArg = '1' -> unknown_agent:true
|
|
const result = runGsdTools(
|
|
['resolve-execution', '--attempt', '1', 'gsd-codebase-mapper'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result.success, `Command failed: ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
assert.ok(!output.unknown_agent, `gsd-codebase-mapper must be resolved, got: ${JSON.stringify(output)}`);
|
|
});
|
|
|
|
test('agent-first parity: gsd-planner --effort low produces same effort as flags-first', () => {
|
|
const flagsFirst = runGsdTools(
|
|
['resolve-execution', '--effort', 'low', 'gsd-planner'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
const agentFirst = runGsdTools(
|
|
['resolve-execution', 'gsd-planner', '--effort', 'low'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(flagsFirst.success && agentFirst.success,
|
|
`Both orderings must succeed. flags-first err: ${flagsFirst.error} agent-first err: ${agentFirst.error}`);
|
|
const outFF = JSON.parse(flagsFirst.output);
|
|
const outAF = JSON.parse(agentFirst.output);
|
|
assert.strictEqual(outFF.effort, outAF.effort, 'effort must be identical for both orderings');
|
|
assert.strictEqual(outFF.model, outAF.model, 'model must be identical for both orderings');
|
|
});
|
|
|
|
test('error: missing agent (--effort low with no positional) -> non-zero exit, no stack trace', () => {
|
|
const result = runGsdTools(
|
|
['resolve-execution', '--effort', 'low'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(!result.success, 'must exit non-zero when agent is missing');
|
|
assert.ok(!result.error.includes('at '), `error must not contain stack trace, got: ${result.error}`);
|
|
assert.ok(result.error.length > 0, 'must emit an error message');
|
|
});
|
|
|
|
test('error: two positional agents -> non-zero exit', () => {
|
|
const result = runGsdTools(
|
|
['resolve-execution', 'gsd-planner', 'gsd-executor'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(!result.success, 'must exit non-zero when two agents are given');
|
|
});
|
|
|
|
test('error: --attempt notanumber -> non-zero exit, clear error', () => {
|
|
const result = runGsdTools(
|
|
['resolve-execution', '--attempt', 'notanumber', 'gsd-planner'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(!result.success, 'must exit non-zero for non-integer --attempt');
|
|
assert.ok(result.error.length > 0, 'must emit an error message');
|
|
});
|
|
|
|
test('error: trailing --effort (no value) -> non-zero exit', () => {
|
|
const result = runGsdTools(
|
|
['resolve-execution', 'gsd-planner', '--effort'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(!result.success, 'must exit non-zero for trailing --effort with no value');
|
|
assert.ok(result.error.length > 0, 'must emit an error message');
|
|
});
|
|
|
|
test('unknown agent positional -> unknown_agent:true (preserved behavior)', () => {
|
|
const result = runGsdTools(
|
|
['resolve-execution', 'totally-not-an-agent'],
|
|
tmpDir,
|
|
{ HOME: tmpDir }
|
|
);
|
|
assert.ok(result.success, `Should succeed (unknown agent is valid input): ${result.error}`);
|
|
const output = JSON.parse(result.output);
|
|
assert.strictEqual(output.unknown_agent, true, 'unknown agent must emit unknown_agent:true');
|
|
});
|
|
});
|
|
|
|
// ─── injectEffortFrontmatter: newline-agnostic injection (#443 Windows fix) ──
|
|
|
|
describe('#443 injectEffortFrontmatter: newline-agnostic YAML frontmatter injection', () => {
|
|
// LF source (macOS / Linux git checkout) — baseline
|
|
test('LF frontmatter: injects effort: before closing ---', () => {
|
|
const content = '---\nname: gsd-planner\ndescription: Creates plans\ncolor: blue\n---\nBody here\n';
|
|
const result = injectEffortFrontmatter(content, 'xhigh');
|
|
assert.notStrictEqual(result, content, 'content should be modified');
|
|
assert.match(result, /^effort:\s*xhigh$/m, 'effort: xhigh must be present');
|
|
assert.ok(result.includes('\neffort: xhigh\n---\n'), 'effort: must appear before closing --- with LF');
|
|
// Closing --- must still be present and intact
|
|
assert.ok(result.includes('\n---\n'), 'closing --- must remain with LF');
|
|
});
|
|
|
|
// CRLF source (Windows git checkout with core.autocrlf=true) — the actual bug
|
|
test('CRLF frontmatter: injects effort: with CRLF preserved (Windows fix)', () => {
|
|
const content = '---\r\nname: gsd-planner\r\ndescription: Creates plans\r\ncolor: blue\r\n---\r\nBody here\r\n';
|
|
const result = injectEffortFrontmatter(content, 'xhigh');
|
|
assert.notStrictEqual(result, content, 'content should be modified (CRLF source was silently skipped before fix)');
|
|
// effort: line must use CRLF, not LF (EOL consistency)
|
|
assert.ok(result.includes('effort: xhigh\r\n'), 'effort: line must use CRLF to match surrounding frontmatter');
|
|
// Closing --- must use CRLF and remain intact
|
|
assert.ok(result.includes('\r\neffort: xhigh\r\n---\r\n'), 'effort: must appear before closing ---\\r\\n with CRLF');
|
|
// The effort value must be readable via multiline regex (as the install-wiring assertions do)
|
|
assert.match(result, /^effort:\s*xhigh$/m, '/^effort:\\s*xhigh$/m must match in CRLF output');
|
|
});
|
|
|
|
// Idempotency: don't double-insert if effort: already exists
|
|
test('idempotent: does NOT insert a second effort: line when already present (LF)', () => {
|
|
const content = '---\nname: gsd-planner\neffort: high\n---\nBody\n';
|
|
const result = injectEffortFrontmatter(content, 'xhigh');
|
|
assert.strictEqual(result, content, 'content must be unchanged when effort: already present');
|
|
// Confirm no duplicate
|
|
const matches = [...result.matchAll(/^effort:/mg)];
|
|
assert.strictEqual(matches.length, 1, 'exactly one effort: key must exist');
|
|
});
|
|
|
|
test('idempotent: does NOT insert a second effort: line when already present (CRLF)', () => {
|
|
const content = '---\r\nname: gsd-planner\r\neffort: high\r\n---\r\nBody\r\n';
|
|
const result = injectEffortFrontmatter(content, 'xhigh');
|
|
assert.strictEqual(result, content, 'content must be unchanged when effort: already present (CRLF)');
|
|
});
|
|
|
|
// No frontmatter — leave unchanged
|
|
test('no YAML frontmatter: returns content unchanged', () => {
|
|
const content = 'Just a body\nNo frontmatter here\n';
|
|
const result = injectEffortFrontmatter(content, 'xhigh');
|
|
assert.strictEqual(result, content, 'content without frontmatter must be returned unchanged');
|
|
});
|
|
|
|
// Complex frontmatter with comment lines and color: key (mirrors real agent .md files)
|
|
test('complex LF frontmatter (# comment + color:) still injects effort: before ---', () => {
|
|
const content = [
|
|
'---',
|
|
'name: gsd-executor',
|
|
'# hooks: see .claude/settings.json',
|
|
'description: Executes tasks',
|
|
'color: green',
|
|
'---',
|
|
'Body content here',
|
|
'',
|
|
].join('\n');
|
|
const result = injectEffortFrontmatter(content, 'high');
|
|
assert.match(result, /^effort:\s*high$/m, 'effort: high must be present');
|
|
assert.ok(result.includes('\neffort: high\n---\n'), 'effort: must appear immediately before closing ---');
|
|
// Other frontmatter fields must be untouched
|
|
assert.ok(result.includes('color: green'), 'color: must be preserved');
|
|
assert.ok(result.includes('# hooks:'), '# comment must be preserved');
|
|
});
|
|
|
|
test('complex CRLF frontmatter (# comment + color:) still injects effort: with CRLF before ---', () => {
|
|
const lines = [
|
|
'---',
|
|
'name: gsd-executor',
|
|
'# hooks: see .claude/settings.json',
|
|
'description: Executes tasks',
|
|
'color: green',
|
|
'---',
|
|
'Body content here',
|
|
'',
|
|
];
|
|
const content = lines.join('\r\n');
|
|
const result = injectEffortFrontmatter(content, 'high');
|
|
assert.ok(result.includes('effort: high\r\n'), 'effort: must use CRLF in CRLF file');
|
|
assert.ok(result.includes('\r\neffort: high\r\n---\r\n'), 'effort: must appear before closing ---\\r\\n');
|
|
assert.ok(result.includes('color: green\r\n'), 'color: must be preserved with CRLF');
|
|
});
|
|
});
|