Files
msd-core/tests/feat-443-effort-fast-mode.test.cjs
Tom Boucher 463cffd894 chore(#604): rename get-shit-done/ runtime directory to gsd-core/ (#615)
* chore(#604): rename get-shit-done/ runtime directory to gsd-core/

Renames the installed runtime directory `get-shit-done/` to `gsd-core/` so the
on-disk name matches the package (`@opengsd/gsd-core`), repo, and binary
(`gsd-tools`). The npm package name and binary are unchanged; npx/npm consumers
are unaffected.

Mechanical (bulk, ~90% of the diff):
- `git mv get-shit-done gsd-core`
- Swept path/identifier references across the repo via
  `perl -pe 's/get-shit-done(?!-\w)/gsd-core/g'`. The negative lookahead
  preserves the five legitimate slug variants that are NOT the directory:
  get-shit-done-{OLD,cc,classic,cli,redux} (old package/repo names).
- Build/manifest wiring: package.json (bin, files, coverage globs),
  tsconfig.build.json (outDir), ~86 .gitignore build-output entries,
  stryker.config.mjs, scan-ignore files, install.js path strings.
- Frozen (not rewritten): CHANGELOG.md history; translated docs
  (README.<locale>.md and docs/{ja-JP,ko-KR,pt-BR,zh-CN}/).

New logic (review here):
- src/installer-migrations/003-rename-get-shit-done-to-gsd-core.cts: a proper
  ADR-0008 installer migration. On upgrade it walks the legacy
  `~/.claude/get-shit-done/` tree, classifies each file via the prior install
  manifest, and emits remove-managed / backup-and-remove for managed files
  while PRESERVING unknown user-added files. Symlink-safe (skips a symlinked
  root and symlinked entries; bounds-checks every path under configDir). The
  framework rolls back on install failure. Emptied dirs may remain (framework
  has no recursive dir-removal primitive) — documented.
- scripts/lint-legacy-dir-name.cjs: CI regression guard forbidding the bare
  `get-shit-done` directory token (split token to avoid self-match; case-
  insensitive; `(?!-\w)` lookahead allows the slug variants; allowlists
  CHANGELOG, translated docs, and `gsd-allow-legacy-name` marker lines).
  Wired into the lint-tests CI job.
- Restored scripts/lint-package-identity-drift.cjs detection regexes (the
  mechanical sweep had wrongly rewritten the old-name patterns it exists to
  detect) and marked them as intentional legacy references.
- TDD tests for the migration and the guard; do.md slash-command guard regex
  tightened so a `/gsd-core/bin` path segment is not mistaken for a command;
  changeset + docs/installer-migrations.md row added.

Breaking: the installed runtime path moves `~/.claude/get-shit-done/` ->
`~/.claude/gsd-core/`. Migration 003 removes the stale legacy dir's managed
files (preserving user files) on upgrade. Users with custom hooks/configs
hardcoding the old path must update them.

Closes #604

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(#604): unsweep pending changesets + allowlist injection-example docs

CI fixes for the rename PR:
- Do not sweep pending .changeset/*.md (ephemeral release-note fragments,
  like CHANGELOG); reverted those body edits so 5 pre-existing malformed
  fragments (missing type/pr) no longer enter the PR diff and trip docs-lint.
  Allowlisted .changeset/ in the legacy-name guard accordingly.
- Allowlisted TEST-EXAMPLES.md and docs/explanation/security-model.md in
  prompt-injection-scan.sh: they contain intentional injection examples /
  security-model prose; the path-reference rewrites are kept.

CodeQL alerts on this PR are pre-existing (alert lines unchanged by this PR;
none in the new migration/guard) and are out of scope for the rename.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(#604): resolve CodeQL alerts surfaced on this PR

The rename diff touched files carrying pre-existing CodeQL findings; per the
no-pre-existing-dismissal rule, fixing every surfaced alert rather than waving
them off. All behavior-preserving:

- scripts/ci-test-scope.cjs: build the config-path match from string
  .includes() instead of a RegExp over an arg-derived value (js/regex-injection).
- src/profile-output.cts: escape backslashes before pipe-escaping desc/safeName
  so the table-cell escape is complete (js/incomplete-sanitization).
- tests/{bug-2643,bug-2808,docs-parity-live-registry}: two-pass HTML-comment
  strip so a bare/unclosed `<!--` cannot survive (js/incomplete-multi-character-sanitization).
- tests/inline-plan-threshold: drop the no-op `\s`->`\s` identity replace,
  keep the meaningful POSIX-class conversion (js/identity-replacement).

Verified: build:lib green; the touched test files + ci-test-scope + profile-output
suites pass; lint:legacy-name clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(#604): correctly resolve remaining CodeQL alerts (regex-injection + sanitization)

The prior commit's fixes for two alerts were ineffective:
- ci-test-scope.cjs js/regex-injection: the alert is the CLI-arg-derived `file`
  reaching static regex `.test(file)` calls (not the config rule). Removed ALL
  regex over file/t — startsWith/includes/=== string checks + an isWindowsHint
  helper — so there is no regex sink for the tainted value.
- js/incomplete-multi-character-sanitization (3 test files): a single
  `.replace(/<!--...-->/g,'')` can let `<!--` re-form. Replaced with a fixpoint
  loop (replace until stable) plus a final bare-opener strip.

Verified: no regex over file/t remains; ci-test-scope + the 3 test suites pass;
lint:legacy-name clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(#604): make ci-test-scope + comment-strippers regex-free to clear CodeQL

CodeQL flags the regex PATTERNS syntactically (regex-injection on the
--files arg split; incomplete-multi-character-sanitization on the <!--...-->
replace), so loop fixes do not satisfy it. Made these paths regex-free:
- ci-test-scope.cjs splitFiles: char-by-char separator tokenizer (no /[,\\s]+/).
- 3 test files: indexOf/slice HTML-comment stripper (no .replace(/<!--/)).
Behavior preserved; ci-test-scope + the 3 suites pass; guard clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(#604): unblock security base64 scan on the large rename diff

The security job hit its 10m timeout: base64-scan.sh choked on the binary
test fixture tests/feat-3594-parser-property-style.test.cjs (embedded NUL/
non-UTF8 bytes -> thousands of bogus blobs + "ignored null byte" warnings),
and the ~800-file rename diff is slow to scan regardless.

- scripts/base64-scan.sh: skip binary-by-content files (grep -Iq .) — they
  can't carry base64-obfuscated *text* and feeding NUL bytes through the
  per-line scanner is pathologically slow. collect_files already filtered
  binary *extensions*; this catches binary *content* in text extensions.
- .github/workflows/security-scan.yml: raise the security job timeout 10m->30m
  to accommodate very large diffs (the scan itself is unchanged).

Verified locally: scan skips the fixture, 0 "ignored null byte" warnings,
0 findings, exit 0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(#604): sweep get-shit-done refs introduced by merging next

The branch was updated with next (#614/#384/#618 etc.), which reference the
get-shit-done/ dir (still named that on next). Swept the stale references in
the merged files to gsd-core so the rename stays consistent and lint:legacy-name
passes:
- commands/gsd/discuss-phase.md (runtime-launcher shim paths)
- src/core.cts (getAgentsDir layout comments)
- tests/bug-384-agents-runtime-aware.test.cjs (require path to runtime lib)

Verified: guard 0 violations; build green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(#604): exclude gsd-core/ path segments from bug-3683 command cross-ref invariant

The #614 runtime-launcher shim added to discuss-phase.md references
`${_GSD_RUNTIME_ROOT}/gsd-core/bin/...`. bug-3683's REF_PATTERN excluded path-y
refs only via lookbehind, but `}` precedes `/gsd-core/` in the shim, so it
mis-read the directory path as a dangling `/gsd-core` command ref (same class as
the #604 bug-2954 fix). Added a trailing `(?![\w-]*\/)` so `/gsd-<x>/...` path
segments are not treated as slash-command references.

Verified locally on BOTH platforms before pushing:
- mac (node 26) full suite: 0 failures
- gsd-test-runner (linux, node22 image) full suite: 0 failures
- bug-3683 + bug-2954 pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(#604): lazily resolve findProjectRoot in gsd-tools (harden flaky CI)

CI intermittently failed state.test's gsd-tools subprocess with
"findProjectRoot is not a function" (flip-flopping across legs; not reproducible
on mac full suite, gsd-test linux full suite, test:unit, or state.test x8).
findProjectRoot is a re-export from core.cjs (sourced from project-root.cjs);
binding it via destructure at module-load can be undefined under a load-ordering
edge. Resolve it lazily at call time via a small wrapper so the lookup happens
after core.cjs is fully initialized.

Verified green on BOTH platforms before pushing:
- mac (node 26) full suite: 0 failures
- gsd-test-runner (linux, node22) full suite: 0 failures
- state.test.cjs: 106/106; gsd-tools loads cleanly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(#604): allowlist verification-patterns.md placeholder examples in secret scan

The rename git-mv'd references/verification-patterns.md into gsd-core/, pulling
it into the secret-scan diff. It documents stub/placeholder RED-FLAG env-var
examples (illustrative Stripe test-key / database-URL / API-key placeholders) —
not real credentials. Added it to .secretscanignore with the strict annotation,
mirroring the existing gsd-core/workflows/plan-phase.md exception.

Verified locally: secret-scan-lint --strict OK; secret-scan --diff origin/next
exits 0 with 0 findings.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-02 18:35:29 -04:00

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('../gsd-core/bin/lib/core.cjs');
const {
renderEffortForRuntime,
RUNTIMES_WITH_FAST_MODE,
} = require('../gsd-core/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('../gsd-core/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');
});
});