fix(3727): wire --fix flag dispatch in code-review workflow (#3743)

* test(3727): add failing test for --fix flag dispatch in code-review workflow

Adds bug-3727-code-review-fix-flag-dispatch.test.cjs with:
- Pure-function tests on parseCodeReviewFlags() / resolveCodeReviewWorkflow()
  from new code-review-flags.cjs typed IR module
- Structural docs-parity tests asserting dispatch_fix step exists in
  code-review.md and that initialize step references code-review-flags.cjs

Structural tests FAIL today (RED): workflow has no dispatch_fix step and
no reference to code-review-flags.cjs in initialize. IR-level tests pass
because the lib module is introduced in this commit as the typed seam.

Fixes #3727

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(3727): wire --fix/--all/--auto flags through code-review workflow

The initialize step now parses --fix, --all, and --auto from argv (via the
code-review-flags parser seam added in the previous test commit) and the
workflow dispatches gsd-code-fixer when --fix is truthy and the review
returned findings. Fixes the regression introduced when PR #2947 closed
#2946 without actually shipping the workflow dispatch.

Fixes #3727

* chore(3727): update changeset to reference PR #3743

The fix commit landed with the linked-issue number as the pr: field
placeholder. Updating to the actual PR number now that the PR is open.

* fix(3727): register code-review-flags.cjs in INVENTORY.md and manifest

Add missing row for get-shit-done/bin/lib/code-review-flags.cjs to the CLI
Modules table in docs/INVENTORY.md (count 72→73) and regenerate
docs/INVENTORY-MANIFEST.json to fix three failing CI tests:
  - cli-modules-doc-parity: every CLI module must have a row in INVENTORY.md
  - inventory-counts: headline "CLI Modules (N shipped)" must match file count
  - inventory-manifest-sync: INVENTORY-MANIFEST.json must match filesystem

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-05-20 23:09:42 -04:00
committed by GitHub
parent e690f1bc90
commit 86e067924f
6 changed files with 308 additions and 21 deletions

View File

@@ -0,0 +1,74 @@
'use strict';
/**
* Typed flag parser for the /gsd:code-review command.
*
* This is the canonical IR for code-review argument parsing. The workflow
* (code-review.md) delegates flag dispatch logic to this module so that:
* 1. Tests assert on a structured IR rather than on rendered bash text.
* 2. The dispatch decision is testable without instantiating the workflow.
*
* @typedef {Object} CodeReviewFlags
* @property {boolean} fix - true when --fix is present in argv
* @property {boolean} all - true when --all is present in argv (implies fix)
* @property {boolean} auto - true when --auto is present in argv (implies fix)
* @property {string} depth - depth override value, or '' if not supplied
* @property {string} files - files override value, or '' if not supplied
*/
/**
* Parse code-review flags from an argv array.
*
* The first positional argument (phase number) is ignored by this function —
* phase validation is handled by `gsd-sdk query init.phase-op`.
*
* @param {string[]} argv - Array of argument strings, e.g. ['2', '--fix', '--all']
* @returns {CodeReviewFlags}
*/
function parseCodeReviewFlags(argv) {
const flags = {
fix: false,
all: false,
auto: false,
depth: '',
files: '',
};
for (const arg of argv) {
if (arg === '--fix') {
flags.fix = true;
} else if (arg === '--all') {
flags.all = true;
} else if (arg === '--auto') {
flags.auto = true;
} else if (arg.startsWith('--depth=')) {
flags.depth = arg.slice('--depth='.length);
} else if (arg.startsWith('--files=')) {
flags.files = arg.slice('--files='.length);
}
}
// --all and --auto imply --fix
if (flags.all || flags.auto) {
flags.fix = true;
}
return flags;
}
/**
* Determine which workflow to dispatch based on parsed flags.
*
* Returns the workflow filename (relative to workflows/) that the orchestrator
* should load:
* - 'code-review-fix.md' when fix=true (--fix, --all, or --auto present)
* - 'code-review.md' otherwise (review-only pass)
*
* @param {CodeReviewFlags} flags
* @returns {'code-review.md' | 'code-review-fix.md'}
*/
function resolveCodeReviewWorkflow(flags) {
return flags.fix ? 'code-review-fix.md' : 'code-review.md';
}
module.exports = { parseCodeReviewFlags, resolveCodeReviewWorkflow };

View File

@@ -1,5 +1,5 @@
<purpose>
Review source files changed during a phase for bugs, security issues, and code quality problems. Computes file scope (--files override > SUMMARY.md > git diff fallback), checks config gate, spawns gsd-code-reviewer agent, commits REVIEW.md, and presents results to user.
Review source files changed during a phase for bugs, security issues, and code quality problems. Computes file scope (--files override > SUMMARY.md > git diff fallback), checks config gate, spawns gsd-code-reviewer agent, commits REVIEW.md, and presents results to user. When --fix is passed, delegates to code-review-fix.md after review to auto-apply findings via gsd-code-fixer.
</purpose>
<required_reading>
@@ -8,6 +8,7 @@ Read all files referenced by the invoking prompt's execution_context before star
<available_agent_types>
- gsd-code-reviewer: Reviews source files for bugs and quality issues
- gsd-code-fixer: Applies fixes to code review findings (used via dispatch_fix → code-review-fix.md when --fix is passed)
</available_agent_types>
<process>
@@ -40,26 +41,25 @@ Error: Phase ${PHASE_ARG} not found. Run /gsd:progress to see available phases.
This runs BEFORE config gate check so user errors are surfaced immediately regardless of config state.
Parse optional flags from $ARGUMENTS:
Parse optional flags from $ARGUMENTS using the typed flag parser:
**--depth flag:**
```bash
DEPTH_OVERRIDE=""
for arg in "$@"; do
if [[ "$arg" == --depth=* ]]; then
DEPTH_OVERRIDE="${arg#--depth=}"
fi
done
```
# Parse all code-review flags into a structured IR via code-review-flags.cjs.
# This is the canonical flag-parsing surface — do not replicate inline bash parsing
# for --fix/--all/--auto here; the module handles all flag extraction and implication
# logic (e.g., --all and --auto imply --fix).
FLAGS_JSON=$(node -e "
const { parseCodeReviewFlags } = require('./get-shit-done/bin/lib/code-review-flags.cjs');
const flags = parseCodeReviewFlags(process.argv.slice(1));
process.stdout.write(JSON.stringify(flags));
" -- "$@" 2>/dev/null)
**--files flag:**
```bash
FILES_OVERRIDE=""
for arg in "$@"; do
if [[ "$arg" == --files=* ]]; then
FILES_OVERRIDE="${arg#--files=}"
fi
done
# Extract individual flag values from the IR
FIX_FLAG=$(echo "$FLAGS_JSON" | node -e "process.stdout.write(String(JSON.parse(require('fs').readFileSync('/dev/stdin','utf-8')).fix))")
FIX_ALL=$(echo "$FLAGS_JSON" | node -e "process.stdout.write(String(JSON.parse(require('fs').readFileSync('/dev/stdin','utf-8')).all))")
FIX_AUTO=$(echo "$FLAGS_JSON" | node -e "process.stdout.write(String(JSON.parse(require('fs').readFileSync('/dev/stdin','utf-8')).auto))")
DEPTH_OVERRIDE=$(echo "$FLAGS_JSON" | node -e "process.stdout.write(JSON.parse(require('fs').readFileSync('/dev/stdin','utf-8')).depth)")
FILES_OVERRIDE=$(echo "$FLAGS_JSON" | node -e "process.stdout.write(JSON.parse(require('fs').readFileSync('/dev/stdin','utf-8')).files)")
```
If FILES_OVERRIDE is set, split by comma into array:
@@ -508,6 +508,46 @@ fi
```
</step>
<step name="dispatch_fix">
If the `--fix` flag was passed (`FIX_FLAG=true`), delegate to the `code-review-fix.md` workflow
to auto-apply findings from the REVIEW.md that was just written (or that already existed).
This step runs AFTER `commit_review` so REVIEW.md is guaranteed to be on disk before the fixer
is invoked. If REVIEW.md was not created (agent failed, scope was empty, etc.), the `code-review-fix.md`
workflow handles the missing-review error and exits cleanly.
```bash
if [ "$FIX_FLAG" = "true" ]; then
echo ""
echo "─────────────────────────────────────────────────────────────────"
echo " --fix: delegating to code-review-fix.md"
echo "─────────────────────────────────────────────────────────────────"
echo ""
# Build the fix sub-arguments: pass phase arg plus any --all/--auto flags
FIX_ARGS="${PHASE_ARG}"
if [ "$FIX_ALL" = "true" ]; then
FIX_ARGS="${FIX_ARGS} --all"
fi
if [ "$FIX_AUTO" = "true" ]; then
FIX_ARGS="${FIX_ARGS} --auto"
fi
# Load and execute the code-review-fix workflow.
# The fix workflow is the canonical implementation for all fix logic:
# gsd-code-fixer agent dispatch, --auto iteration loop, REVIEW-FIX.md commit,
# and result presentation. Do not duplicate that logic here.
Workflow(workflow="get-shit-done/workflows/code-review-fix.md", args="${FIX_ARGS}")
# Exit after fix workflow completes — present_results is for review-only output.
# The fix workflow has its own present_results step.
# Exit workflow.
fi
```
If `FIX_FLAG` is false, skip this step entirely and proceed to `present_results`.
</step>
<step name="present_results">
Read the REVIEW.md YAML frontmatter to extract finding counts.
@@ -600,6 +640,7 @@ If `--files` validation fails unexpectedly on macOS, install coreutils or use ab
<success_criteria>
- [ ] Phase validated before config gate check
- [ ] Config gate checked (workflow.code_review)
- [ ] --fix/--all/--auto flags parsed via code-review-flags.cjs typed IR (not ad-hoc bash)
- [ ] Depth resolved with validation (quick|standard|deep)
- [ ] File scope computed with 3 tiers: --files > SUMMARY.md > git diff
- [ ] Malformed/missing SUMMARY.md handled gracefully with fallback
@@ -609,5 +650,6 @@ If `--files` validation fails unexpectedly on macOS, install coreutils or use ab
- [ ] Agent spawned with explicit file list, depth, review_path, diff_base
- [ ] Agent failure handled without partial commits
- [ ] REVIEW.md committed if created
- [ ] Results presented inline with next step suggestion
- [ ] When --fix: dispatch_fix step delegates to code-review-fix.md with --all/--auto forwarded
- [ ] Results presented inline with next step suggestion (review-only path)
</success_criteria>