feat(code-review): integrate fallow structural pre-pass for /gsd-code-review (#3424)
* feat(code-review): add optional fallow structural pre-pass * fix(ci): sync lockfile for fallow optional binaries * fix(test): make fallow integration tests cross-platform * fix(review): require executable fallow binary paths * docs(review): clarify structural findings usage and size guard * fix(fallow): preserve line:0, prefer node_modules/.bin, sync SDK twin (H1, M2, N1 from #3424 review) * fix(workflow): harden fallow pre-pass — exit check, timeout, atomic write, size-guard order (B1, H2-H4, M1, M3 from #3424 review) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(deps): pin fallow floor to ^2.70.0 matching lockfile (H7 from #3424 review) * fix(config): enum-validate fallow.scope/profile + group code_quality.* contiguously (H5, N3 from #3424 review) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs(fallow): label mcp gate reserved, version-pin install, expand context schema (B3, H8, M4, M8, L1 from #3424 review) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * test(fallow): replace source-grep with behavioral tests, expand fixtures, fail-loud tmpdir (B4, H6, L2, L3, M5, M6, N2 from #3424 review) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix(workflow): escape closing structural_findings tag in JSON payload (CR #3424 inline finding) --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
5
.changeset/3210-fallow-structural-review.md
Normal file
5
.changeset/3210-fallow-structural-review.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
type: Added
|
||||
pr: 3424
|
||||
---
|
||||
**Adds optional fallow structural pre-pass support for `/gsd-code-review` via `code_quality.fallow.*` config keys** — when enabled, the workflow resolves a fallow binary (`PATH` then `node_modules/.bin`), writes `.planning/phases/<phase>/FALLOW.json`, and passes a dedicated `<structural_findings>` block into `gsd-code-reviewer` so `REVIEW.md` can separate `Structural Findings (fallow)` from narrative reviewer findings. This ships a new CLI module (`fallow-runner.cjs`) plus SDK twin normalization logic (`sdk/src/query/fallow-audit.ts`), updates config schema/docs, and keeps default behavior unchanged when fallow remains disabled.
|
||||
@@ -194,6 +194,8 @@ Key dials:
|
||||
| `workflow.research` / `plan_check` / `verifier` | Toggle the quality agents that add tokens and time |
|
||||
| `parallelization.enabled` | Run independent plans simultaneously |
|
||||
|
||||
Optional structural review: set `code_quality.fallow.enabled` to `true` to add a fallow pre-pass to `/gsd-code-review`. GSD writes `.planning/phases/<phase>/FALLOW.json` and surfaces a `Structural Findings (fallow)` section in `REVIEW.md`. Install with `npm install -D fallow@^2.70.0` (or system-wide via `cargo install fallow`; note that the Rust binary's JSON schema must match the documented v2.70+ contract — older versions may produce silent zero-finding output).
|
||||
|
||||
For the full configuration reference — all settings, git branching strategies, per-runtime model overrides, workstream config inheritance, agent skills injection — see **[docs/CONFIGURATION.md](docs/CONFIGURATION.md)**.
|
||||
|
||||
---
|
||||
|
||||
@@ -14,6 +14,8 @@ Spawned by `/gsd:code-review` workflow. You produce REVIEW.md artifact in the ph
|
||||
|
||||
**CRITICAL: Mandatory Initial Read**
|
||||
If the prompt contains a `<required_reading>` block, you MUST use the `Read` tool to load every file listed there before performing any other actions. This is your primary context.
|
||||
|
||||
If the prompt contains a `<structural_findings>` block, treat those fallow findings as **ground truth** for cross-module facts (unused exports, duplicate blocks, circular dependencies). Your narrative findings should build on that substrate instead of contradicting it.
|
||||
</role>
|
||||
|
||||
<adversarial_stance>
|
||||
@@ -134,7 +136,13 @@ If DIFF_BASE is set, run:
|
||||
git diff --name-only ${DIFF_BASE}..HEAD -- . ':!.planning/' ':!ROADMAP.md' ':!STATE.md' ':!*-SUMMARY.md' ':!*-VERIFICATION.md' ':!*-PLAN.md' ':!package-lock.json' ':!yarn.lock' ':!Gemfile.lock' ':!poetry.lock'
|
||||
```
|
||||
|
||||
**4. Load project context:** Read `./CLAUDE.md` and check for `.claude/skills/` or `.agents/skills/` (as described in `<project_context>`).
|
||||
**4. Parse structural findings when present:** If prompt includes:
|
||||
```xml
|
||||
<structural_findings>...</structural_findings>
|
||||
```
|
||||
parse JSON payload and cache it as `STRUCTURAL_FINDINGS`. When present, include these findings in the `## Structural Findings (fallow)` section of `REVIEW.md` during `write_review` (verbatim when small; concise structured summary when large). This block is optional; missing block means no structural pre-pass was provided.
|
||||
|
||||
**5. Load project context:** Read `./CLAUDE.md` and check for `.claude/skills/` or `.agents/skills/` (as described in `<project_context>`).
|
||||
</step>
|
||||
|
||||
<step name="scope_files">
|
||||
@@ -269,6 +277,12 @@ status: clean | issues_found
|
||||
---
|
||||
```
|
||||
|
||||
**3. Body sections (required order):**
|
||||
1) `## Structural Findings (fallow)` — only when structural findings were provided; list normalized items first.
|
||||
2) `## Narrative Findings (AI reviewer)` — your adversarial findings from direct code review.
|
||||
|
||||
Never merge these into one section; structural substrate must stay distinguishable from narrative findings.
|
||||
|
||||
**Label equivalence:** The canonical frontmatter key is `critical:`. The workflow also accepts `blocker:` as a tier-equivalent alternative — both are parsed as Critical severity by downstream consumers. Prefer `critical:` for new reviews; `blocker:` is accepted when reviewer tooling drifts. Similarly, finding IDs beginning with `BL-` are treated as Critical-tier-equivalent to `CR-` IDs by the fixer and pipeline; prefer `CR-` as the canonical prefix.
|
||||
|
||||
The `files_reviewed_list` field is REQUIRED — it preserves the exact file scope for downstream consumers (e.g., --auto re-review in code-review-fix workflow). List every file that was reviewed, one per line in YAML list format.
|
||||
|
||||
@@ -59,6 +59,14 @@ GSD stores project settings in `.planning/config.json`. Created during `/gsd-new
|
||||
"build_command": null,
|
||||
"test_command": null
|
||||
},
|
||||
"code_quality": {
|
||||
"fallow": {
|
||||
"enabled": false,
|
||||
"scope": "phase",
|
||||
"profile": "standard",
|
||||
"mcp": false
|
||||
}
|
||||
},
|
||||
"ship": {
|
||||
"pr_body_sections": []
|
||||
},
|
||||
@@ -250,6 +258,17 @@ All workflow toggles follow the **absent = enabled** pattern. If a key is missin
|
||||
| `workflow.build_command` | string | (none) | Shell command to build the project in the post-merge build gate (Step A of step 5.6 in execute-phase). When unset, the gate auto-detects: Xcode (`.xcodeproj` present) → `xcodebuild build`, `Makefile` with `build:` target → `make build`, Justfile → `just build`, `Cargo.toml` → `cargo build`, `go.mod` → `go build ./...`, Python → `python -m py_compile`, `package.json` with `build` script → `npm run build`. Runs with a 5-minute timeout; failure increments `WAVE_FAILURE_COUNT`. Added in v1.39 |
|
||||
| `workflow.test_command` | string | (none) | Shell command to run the project's test suite in the post-merge test gate (Step B of step 5.6 in execute-phase) and the regression gate. When unset, the gate auto-detects: Xcode (`.xcodeproj` present) → `xcodebuild test`, `Makefile` with `test:` target → `make test`, Justfile → `just test`, `package.json` → `npm test`, `Cargo.toml` → `cargo test`, `go.mod` → `go test ./...`, Python → `python -m pytest`. Runs with a 5-minute timeout; failure increments `WAVE_FAILURE_COUNT`. Added in v1.39 |
|
||||
|
||||
## Code Quality Settings
|
||||
|
||||
The `code_quality.*` namespace gates optional structural-analysis tooling that augments `/gsd-code-review`. Settings are additive: each tool is independently opt-in and off by default.
|
||||
|
||||
| Setting | Type | Default | Description |
|
||||
|---------|------|---------|-------------|
|
||||
| `code_quality.fallow.enabled` | boolean | `false` | Enables fallow structural pre-pass for `/gsd-code-review`. When `false`, no fallow binary probe or JSON artifact is produced. |
|
||||
| `code_quality.fallow.scope` | string | `phase` | Scope for fallow analysis: `phase` (current review file scope) or `repo` (entire repository). |
|
||||
| `code_quality.fallow.profile` | string | `standard` | Fallow profile selector passed to the pre-pass runner (`minimal`, `standard`, `strict`). |
|
||||
| `code_quality.fallow.mcp` | boolean | `false` | **Reserved — not yet implemented.** When `true`, enables MCP-backed structural findings mode for runtimes that support MCP server routing. Setting this to `true` is currently a no-op and emits a runtime warning. |
|
||||
|
||||
## Ship Settings
|
||||
|
||||
`ship.pr_body_sections` adds additional PR body sections for project-specific PRD/PR body content in `/gsd-ship` without editing `get-shit-done/workflows/ship.md`.
|
||||
|
||||
@@ -273,6 +273,7 @@
|
||||
"decisions.cjs",
|
||||
"docs.cjs",
|
||||
"drift.cjs",
|
||||
"fallow-runner.cjs",
|
||||
"frontmatter.cjs",
|
||||
"gap-checker.cjs",
|
||||
"graphify.cjs",
|
||||
|
||||
@@ -360,7 +360,7 @@ The `gsd-planner` agent is decomposed into a core agent plus reference modules t
|
||||
|
||||
---
|
||||
|
||||
## CLI Modules (58 shipped)
|
||||
## CLI Modules (59 shipped)
|
||||
|
||||
Full listing: `get-shit-done/bin/lib/*.cjs`.
|
||||
|
||||
@@ -381,6 +381,7 @@ Full listing: `get-shit-done/bin/lib/*.cjs`.
|
||||
| `decisions.cjs` | Shared parser for CONTEXT.md `<decisions>` blocks (D-NN entries); used by `gap-checker.cjs` and intended for #2492 plan/verify decision gates |
|
||||
| `docs.cjs` | Docs-update workflow init, Markdown scanning, monorepo detection |
|
||||
| `drift.cjs` | Post-execute codebase structural drift detector (#2003): classifies file changes into new-dir/barrel/migration/route categories and round-trips `last_mapped_commit` frontmatter |
|
||||
| `fallow-runner.cjs` | Fallow audit adapter for `/gsd-code-review`: binary resolution (`PATH` then `node_modules/.bin`), actionable missing-binary errors, and structural findings normalization |
|
||||
| `frontmatter.cjs` | YAML frontmatter CRUD operations |
|
||||
| `gap-checker.cjs` | Post-planning gap analysis (#2493): unified REQUIREMENTS.md + CONTEXT.md decisions vs PLAN.md coverage report (`gsd-tools gap-analysis`) |
|
||||
| `graphify.cjs` | Knowledge-graph build/query/status/diff for `/gsd-graphify` |
|
||||
|
||||
@@ -43,6 +43,10 @@ const VALID_CONFIG_KEYS = new Set([
|
||||
'workflow.security_block_on',
|
||||
'workflow.drift_threshold',
|
||||
'workflow.drift_action',
|
||||
'code_quality.fallow.enabled',
|
||||
'code_quality.fallow.scope',
|
||||
'code_quality.fallow.profile',
|
||||
'code_quality.fallow.mcp',
|
||||
'ship.pr_body_sections',
|
||||
'git.branching_strategy', 'git.base_branch', 'git.phase_branch_template', 'git.milestone_branch_template', 'git.quick_branch_template',
|
||||
'planning.commit_docs', 'planning.search_gitignored', 'planning.sub_repos',
|
||||
|
||||
@@ -442,6 +442,16 @@ function cmdConfigSet(cwd, keyPath, value, raw) {
|
||||
error(`Invalid workflow.human_verify_mode '${value}'. Valid values: ${VALID_HUMAN_VERIFY_MODES.join(', ')}`);
|
||||
}
|
||||
|
||||
// Fallow scope + profile enum validation (#3424)
|
||||
const VALID_FALLOW_SCOPES = ['phase', 'repo'];
|
||||
if (keyPath === 'code_quality.fallow.scope' && !VALID_FALLOW_SCOPES.includes(String(parsedValue))) {
|
||||
error(`Invalid code_quality.fallow.scope '${value}'. Valid values: ${VALID_FALLOW_SCOPES.join(', ')}`);
|
||||
}
|
||||
const VALID_FALLOW_PROFILES = ['minimal', 'standard', 'strict'];
|
||||
if (keyPath === 'code_quality.fallow.profile' && !VALID_FALLOW_PROFILES.includes(String(parsedValue))) {
|
||||
error(`Invalid code_quality.fallow.profile '${value}'. Valid values: ${VALID_FALLOW_PROFILES.join(', ')}`);
|
||||
}
|
||||
|
||||
if (keyPath === 'review.default_reviewers') {
|
||||
const normalized = normalizeConfiguredDefaultReviewers(parsedValue);
|
||||
if (normalized.errors.length > 0) {
|
||||
|
||||
109
get-shit-done/bin/lib/fallow-runner.cjs
Normal file
109
get-shit-done/bin/lib/fallow-runner.cjs
Normal file
@@ -0,0 +1,109 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
function candidateNames() {
|
||||
return process.platform === 'win32'
|
||||
? ['fallow.exe', 'fallow.cmd', 'fallow.bat', 'fallow']
|
||||
: ['fallow'];
|
||||
}
|
||||
|
||||
function isExecutableFile(filePath) {
|
||||
try {
|
||||
const stat = fs.statSync(filePath);
|
||||
if (!stat.isFile()) return false;
|
||||
if (process.platform === 'win32') return true;
|
||||
fs.accessSync(filePath, fs.constants.X_OK);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function findInPath(envPath) {
|
||||
if (!envPath) return null;
|
||||
const names = candidateNames();
|
||||
const segments = envPath.split(path.delimiter).filter(Boolean);
|
||||
for (const segment of segments) {
|
||||
for (const name of names) {
|
||||
const candidate = path.join(segment, name);
|
||||
if (isExecutableFile(candidate)) return candidate;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function findInNodeModules(cwd) {
|
||||
const names = candidateNames();
|
||||
const binDir = path.join(cwd, 'node_modules', '.bin');
|
||||
for (const name of names) {
|
||||
const candidate = path.join(binDir, name);
|
||||
if (isExecutableFile(candidate)) return candidate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function resolveFallowBinary({ cwd, envPath = process.env.PATH || '' }) {
|
||||
return findInNodeModules(cwd) || findInPath(envPath) || null;
|
||||
}
|
||||
|
||||
function requireFallowBinary({ cwd, envPath = process.env.PATH || '' }) {
|
||||
const binary = resolveFallowBinary({ cwd, envPath });
|
||||
if (binary) return binary;
|
||||
throw new Error(
|
||||
'Fallow is enabled but no binary was found. Please install fallow via `npm install -D fallow` or `cargo install fallow`.',
|
||||
);
|
||||
}
|
||||
|
||||
function normalizeFallowReport(report) {
|
||||
const unused = Array.isArray(report?.unusedExports) ? report.unusedExports : [];
|
||||
const duplicates = Array.isArray(report?.duplicates) ? report.duplicates : [];
|
||||
const circular = Array.isArray(report?.circularDependencies) ? report.circularDependencies : [];
|
||||
|
||||
const findings = [];
|
||||
|
||||
for (const item of unused) {
|
||||
findings.push({
|
||||
type: 'unused_export',
|
||||
message: `Unused export ${item.symbol || '<unknown>'}`,
|
||||
file: item.file || '',
|
||||
line: item.line ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of duplicates) {
|
||||
findings.push({
|
||||
type: 'duplicate_block',
|
||||
message: `Duplicate block (${Math.round((item.similarity || 0) * 100)}% similarity)`,
|
||||
file: item.left?.file || '',
|
||||
line: item.left?.start ?? null,
|
||||
related_file: item.right?.file || '',
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of circular) {
|
||||
findings.push({
|
||||
type: 'circular_dependency',
|
||||
message: `Circular dependency: ${(item.cycle || []).join(' -> ')}`,
|
||||
file: Array.isArray(item.cycle) && item.cycle.length > 0 ? item.cycle[0] : '',
|
||||
line: null,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
summary: {
|
||||
unused_exports: unused.length,
|
||||
duplicates: duplicates.length,
|
||||
circular_dependencies: circular.length,
|
||||
total: findings.length,
|
||||
},
|
||||
findings,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
normalizeFallowReport,
|
||||
requireFallowBinary,
|
||||
resolveFallowBinary,
|
||||
};
|
||||
@@ -16,6 +16,7 @@ Agent output guidance for review mode. Loaded when `context: review` is set in c
|
||||
- Performance — unnecessary allocations, O(n^2) patterns, missing caching
|
||||
- Style and consistency — naming, formatting, import order
|
||||
- Test coverage — untested branches, missing assertions, flaky patterns
|
||||
- Structural Findings (fallow) — machine-derived cross-module facts injected as `<structural_findings>{ findings: [...], summary: { total, unusedExports, duplicates, circularDependencies } }</structural_findings>`. Render in REVIEW.md under `## Structural Findings (fallow)` as a separate section from narrative findings. Treat as ground truth for cross-module facts; do not re-derive.
|
||||
|
||||
## Verbosity
|
||||
|
||||
|
||||
@@ -318,6 +318,78 @@ No source files changed in phase ${PHASE_ARG}. Skipping review.
|
||||
Exit workflow. Do NOT spawn agent or create REVIEW.md.
|
||||
</step>
|
||||
|
||||
<step name="structural_pre_pass">
|
||||
Optional structural cross-module pass powered by fallow.
|
||||
|
||||
Read fallow config gates:
|
||||
```bash
|
||||
FALLOW_ENABLED=$(gsd-sdk query config-get code_quality.fallow.enabled 2>/dev/null || echo "false")
|
||||
FALLOW_SCOPE=$(gsd-sdk query config-get code_quality.fallow.scope 2>/dev/null || echo "phase")
|
||||
FALLOW_PROFILE=$(gsd-sdk query config-get code_quality.fallow.profile 2>/dev/null || echo "standard")
|
||||
FALLOW_MCP=$(gsd-sdk query config-get code_quality.fallow.mcp 2>/dev/null || echo "false")
|
||||
```
|
||||
|
||||
Defaults are fail-closed and opt-in:
|
||||
- `enabled=false` (skip entirely)
|
||||
- `scope=phase`
|
||||
- `profile=standard`
|
||||
- `mcp=false`
|
||||
|
||||
When `FALLOW_ENABLED=true`:
|
||||
|
||||
1) Resolve binary via PATH first, then `node_modules/.bin/fallow`.
|
||||
```bash
|
||||
FALLOW_BIN=$(FALLOW_CWD="$(pwd)" node -e "
|
||||
const { resolveFallowBinary } = require('./get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
const resolved = resolveFallowBinary({ cwd: process.env.FALLOW_CWD });
|
||||
if (resolved) process.stdout.write(resolved);
|
||||
")
|
||||
```
|
||||
|
||||
2) If binary is missing, fail with actionable message:
|
||||
```bash
|
||||
if [ -z \"$FALLOW_BIN\" ]; then
|
||||
echo \"Error: fallow is enabled but no binary was found.\"
|
||||
echo \"Install fallow via \`npm install -D fallow\` or \`cargo install fallow\`.\"
|
||||
# Exit workflow
|
||||
fi
|
||||
```
|
||||
|
||||
3) Execute structural pass and persist JSON (bounded at 120s; on timeout, behaves as a fallow crash):
|
||||
```bash
|
||||
FALLOW_JSON_PATH="${PHASE_DIR}/FALLOW.json"
|
||||
FALLOW_STDERR_TMP=$(mktemp)
|
||||
if [ \"$FALLOW_SCOPE\" = \"repo\" ]; then
|
||||
timeout 120 \"$FALLOW_BIN\" audit --json --profile \"$FALLOW_PROFILE\" > \"${FALLOW_JSON_PATH}.tmp\" 2>\"$FALLOW_STDERR_TMP\"
|
||||
FALLOW_EXIT=$?
|
||||
else
|
||||
# phase scope: pass the already-computed review file set
|
||||
printf '%s\n' \"${REVIEW_FILES[@]}\" | timeout 120 \"$FALLOW_BIN\" audit --json --profile \"$FALLOW_PROFILE\" --stdin-files > \"${FALLOW_JSON_PATH}.tmp\" 2>\"$FALLOW_STDERR_TMP\"
|
||||
FALLOW_EXIT=$?
|
||||
fi
|
||||
if [ $FALLOW_EXIT -ne 0 ]; then
|
||||
FALLOW_STDERR_SUMMARY=$(head -5 \"$FALLOW_STDERR_TMP\")
|
||||
rm -f \"${FALLOW_JSON_PATH}.tmp\" \"$FALLOW_STDERR_TMP\"
|
||||
echo \"WARNING: fallow structural pre-pass failed: ${FALLOW_STDERR_SUMMARY}\"
|
||||
FALLOW_JSON_PATH=""
|
||||
else
|
||||
mv \"${FALLOW_JSON_PATH}.tmp\" \"$FALLOW_JSON_PATH\"
|
||||
rm -f \"$FALLOW_STDERR_TMP\"
|
||||
fi
|
||||
```
|
||||
|
||||
On any failure of the structural pre-pass (binary missing, non-zero exit, timeout, or JSON parse error), the workflow continues with no `<structural_findings>` injection; the reviewer agent receives a normal review request.
|
||||
|
||||
4) Optional MCP bridge path (runtime-dependent):
|
||||
- If `FALLOW_MCP=true`, set reviewer input mode to MCP-backed structural findings.
|
||||
- Otherwise pass static JSON findings from `FALLOW.json`.
|
||||
|
||||
When disabled, set:
|
||||
```bash
|
||||
FALLOW_JSON_PATH=""
|
||||
```
|
||||
</step>
|
||||
|
||||
<step name="spawn_reviewer">
|
||||
Compute the review output path:
|
||||
```bash
|
||||
@@ -350,6 +422,22 @@ for file in "${REVIEW_FILES[@]}"; do
|
||||
done
|
||||
```
|
||||
|
||||
Build structural findings block for agent:
|
||||
```bash
|
||||
STRUCTURAL_FINDINGS_BLOCK=""
|
||||
MAX_FINDINGS_SIZE=50000
|
||||
if [ -n "$FALLOW_JSON_PATH" ] && [ -f "$FALLOW_JSON_PATH" ]; then
|
||||
FALLOW_JSON_SIZE=$(wc -c < "$FALLOW_JSON_PATH" | tr -d '[:space:]')
|
||||
if [ "$FALLOW_JSON_SIZE" -le "$MAX_FINDINGS_SIZE" ]; then
|
||||
# Escape any literal closing tag before embedding; the closing tag literal is escaped to prevent prompt-structure breakage if a fallow finding's file path or message contains the sequence.
|
||||
SAFE_FALLOW_JSON=$(sed 's#</structural_findings>#<\/structural_findings>#g' "$FALLOW_JSON_PATH")
|
||||
STRUCTURAL_FINDINGS_BLOCK=$(printf '<structural_findings>\n%s\n</structural_findings>\n' "$SAFE_FALLOW_JSON")
|
||||
else
|
||||
echo "Warning: skipping structural findings embed (${FALLOW_JSON_SIZE} bytes > ${MAX_FINDINGS_SIZE} bytes). Re-run with narrower scope/profile if needed."
|
||||
fi
|
||||
fi
|
||||
```
|
||||
|
||||
Spawn the gsd-code-reviewer agent:
|
||||
|
||||
```
|
||||
@@ -358,6 +446,8 @@ Agent(subagent_type="gsd-code-reviewer", prompt="
|
||||
${FILES_TO_READ}
|
||||
</files_to_read>
|
||||
|
||||
${STRUCTURAL_FINDINGS_BLOCK}
|
||||
|
||||
<config>
|
||||
depth: ${REVIEW_DEPTH}
|
||||
phase_dir: ${PHASE_DIR}
|
||||
|
||||
146
package-lock.json
generated
146
package-lock.json
generated
@@ -22,6 +22,9 @@
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=22.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"fallow": "^2.70.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@anthropic-ai/claude-agent-sdk": {
|
||||
@@ -205,6 +208,110 @@
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@fallow-cli/darwin-arm64": {
|
||||
"version": "2.70.0",
|
||||
"resolved": "https://registry.npmjs.org/@fallow-cli/darwin-arm64/-/darwin-arm64-2.70.0.tgz",
|
||||
"integrity": "sha512-qxNnT18gxlVwq1PqGF4ZPRaziSXYrglB6f3gplpDdbN977ayYAIMlsurL/+ZSOdg6p4Q53NE6ea9GgG4rGrVMQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
]
|
||||
},
|
||||
"node_modules/@fallow-cli/darwin-x64": {
|
||||
"version": "2.70.0",
|
||||
"resolved": "https://registry.npmjs.org/@fallow-cli/darwin-x64/-/darwin-x64-2.70.0.tgz",
|
||||
"integrity": "sha512-9zn2HocNIdugLSj4lrkLjIDkRyXroewAwJDGTJctYfFnjZfW8RkK6wXQUDQhH5ZNU3gRRX5e+rGkibndKQZAWw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
]
|
||||
},
|
||||
"node_modules/@fallow-cli/linux-arm64-gnu": {
|
||||
"version": "2.70.0",
|
||||
"resolved": "https://registry.npmjs.org/@fallow-cli/linux-arm64-gnu/-/linux-arm64-gnu-2.70.0.tgz",
|
||||
"integrity": "sha512-M6OT7LK++P6NUh+mU8RwtHk4JbIB+/bI98h3Wwe1NzeVTnaSNpAd0wS/pM/VJk4XiWEyJEMnbk2/iHdLq3k0Dw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
]
|
||||
},
|
||||
"node_modules/@fallow-cli/linux-arm64-musl": {
|
||||
"version": "2.70.0",
|
||||
"resolved": "https://registry.npmjs.org/@fallow-cli/linux-arm64-musl/-/linux-arm64-musl-2.70.0.tgz",
|
||||
"integrity": "sha512-GbQt6ydIFZc0IW9yqzAKoj7MZtCGODiVsLfI2hknsMZQ2siEHNC8KLscuJwClYdUG8owPj5z/zjpRpY2ep4G7Q==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
]
|
||||
},
|
||||
"node_modules/@fallow-cli/linux-x64-gnu": {
|
||||
"version": "2.70.0",
|
||||
"resolved": "https://registry.npmjs.org/@fallow-cli/linux-x64-gnu/-/linux-x64-gnu-2.70.0.tgz",
|
||||
"integrity": "sha512-LYz8vjgMLy7ohfgw+/ZQoMoZs59xkRMCxrr3qJ29MT+w3+XyQXbal2z+ockGNq+KlHkqviyoXjctVSenpHljEA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
]
|
||||
},
|
||||
"node_modules/@fallow-cli/linux-x64-musl": {
|
||||
"version": "2.70.0",
|
||||
"resolved": "https://registry.npmjs.org/@fallow-cli/linux-x64-musl/-/linux-x64-musl-2.70.0.tgz",
|
||||
"integrity": "sha512-yQSvXnKJW8cVSgcI61j4GVULk3o269ipzkQWXVemdc5YQlu6MZFEb15vCBpPtbrmyLNn/t0URLvF6u2UrNux9A==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
]
|
||||
},
|
||||
"node_modules/@fallow-cli/win32-arm64-msvc": {
|
||||
"version": "2.70.0",
|
||||
"resolved": "https://registry.npmjs.org/@fallow-cli/win32-arm64-msvc/-/win32-arm64-msvc-2.70.0.tgz",
|
||||
"integrity": "sha512-KFCV0tq5QSlP2pOuXFhNGCHUM9uybsObqnr1t3KDZwSF/afOB3KNTqbAm0cG5AQN9nixTNbwmCheYkdcP9J1AA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
]
|
||||
},
|
||||
"node_modules/@fallow-cli/win32-x64-msvc": {
|
||||
"version": "2.70.0",
|
||||
"resolved": "https://registry.npmjs.org/@fallow-cli/win32-x64-msvc/-/win32-x64-msvc-2.70.0.tgz",
|
||||
"integrity": "sha512-479acpOWbtdDQ7T+YMsKbc6uPWPEOIKXfejdrCqlpv1UOehcagUTP0bS0vmCbXsfFsIAbn9HHNAljvLkrWqGqA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
]
|
||||
},
|
||||
"node_modules/@hono/node-server": {
|
||||
"version": "1.19.14",
|
||||
"resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-1.19.14.tgz",
|
||||
@@ -632,6 +739,16 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/detect-libc": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
|
||||
"integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
|
||||
"license": "Apache-2.0",
|
||||
"optional": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/dunder-proto": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||
@@ -805,6 +922,35 @@
|
||||
"express": ">= 4.11"
|
||||
}
|
||||
},
|
||||
"node_modules/fallow": {
|
||||
"version": "2.70.0",
|
||||
"resolved": "https://registry.npmjs.org/fallow/-/fallow-2.70.0.tgz",
|
||||
"integrity": "sha512-AXUkSV2AgmtuvgLGf8e5DIigpBm0VHJp1b6fvkjnr15hrGoKhqEzb0KDSzuuZvTaoGuZrb2vLTN2rp5eUd6D/w==",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
"detect-libc": "2.1.2"
|
||||
},
|
||||
"bin": {
|
||||
"fallow": "bin/fallow",
|
||||
"fallow-lsp": "bin/fallow-lsp",
|
||||
"fallow-mcp": "bin/fallow-mcp"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@fallow-cli/darwin-arm64": "2.70.0",
|
||||
"@fallow-cli/darwin-x64": "2.70.0",
|
||||
"@fallow-cli/linux-arm64-gnu": "2.70.0",
|
||||
"@fallow-cli/linux-arm64-musl": "2.70.0",
|
||||
"@fallow-cli/linux-x64-gnu": "2.70.0",
|
||||
"@fallow-cli/linux-x64-musl": "2.70.0",
|
||||
"@fallow-cli/win32-arm64-msvc": "2.70.0",
|
||||
"@fallow-cli/win32-x64-msvc": "2.70.0"
|
||||
}
|
||||
},
|
||||
"node_modules/fast-deep-equal": {
|
||||
"version": "3.1.3",
|
||||
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
||||
|
||||
@@ -54,6 +54,9 @@
|
||||
"devDependencies": {
|
||||
"c8": "^11.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"fallow": "^2.70.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build:hooks": "node scripts/build-hooks.js",
|
||||
"build:sdk": "cd sdk && npm ci && npm run build",
|
||||
|
||||
@@ -45,6 +45,10 @@ export const VALID_CONFIG_KEYS: ReadonlySet<string> = new Set([
|
||||
'workflow.security_block_on',
|
||||
'workflow.drift_threshold',
|
||||
'workflow.drift_action',
|
||||
'code_quality.fallow.enabled',
|
||||
'code_quality.fallow.scope',
|
||||
'code_quality.fallow.profile',
|
||||
'code_quality.fallow.mcp',
|
||||
'ship.pr_body_sections',
|
||||
'git.branching_strategy', 'git.base_branch', 'git.phase_branch_template', 'git.milestone_branch_template', 'git.quick_branch_template',
|
||||
'planning.commit_docs', 'planning.search_gitignored', 'planning.sub_repos',
|
||||
|
||||
88
sdk/src/query/fallow-audit.ts
Normal file
88
sdk/src/query/fallow-audit.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
export interface FallowUnusedExport {
|
||||
file?: string;
|
||||
symbol?: string;
|
||||
line?: number | null;
|
||||
}
|
||||
|
||||
export interface FallowDuplicateBlock {
|
||||
left?: { file?: string; start?: number | null; end?: number | null };
|
||||
right?: { file?: string; start?: number | null; end?: number | null };
|
||||
similarity?: number;
|
||||
}
|
||||
|
||||
export interface FallowCircularDependency {
|
||||
cycle?: string[];
|
||||
}
|
||||
|
||||
export interface FallowReport {
|
||||
unusedExports?: FallowUnusedExport[];
|
||||
duplicates?: FallowDuplicateBlock[];
|
||||
circularDependencies?: FallowCircularDependency[];
|
||||
}
|
||||
|
||||
export interface NormalizedFallowFinding {
|
||||
type: 'unused_export' | 'duplicate_block' | 'circular_dependency';
|
||||
message: string;
|
||||
file: string;
|
||||
line: number | null;
|
||||
related_file?: string;
|
||||
}
|
||||
|
||||
export interface NormalizedFallowReport {
|
||||
summary: {
|
||||
unused_exports: number;
|
||||
duplicates: number;
|
||||
circular_dependencies: number;
|
||||
total: number;
|
||||
};
|
||||
findings: NormalizedFallowFinding[];
|
||||
}
|
||||
|
||||
// TODO(parity): SDK lacks a TS test harness for normalizeFallowReport. CJS parity tests live in
|
||||
// tests/feat-3210-fallow-integration.test.cjs (H1 suite). When a TS test runner is added,
|
||||
// mirror those cases here — especially the line:0 preservation assertions.
|
||||
export function normalizeFallowReport(report: FallowReport | null | undefined): NormalizedFallowReport {
|
||||
const unused = Array.isArray(report?.unusedExports) ? report.unusedExports : [];
|
||||
const duplicates = Array.isArray(report?.duplicates) ? report.duplicates : [];
|
||||
const circular = Array.isArray(report?.circularDependencies) ? report.circularDependencies : [];
|
||||
|
||||
const findings: NormalizedFallowFinding[] = [];
|
||||
|
||||
for (const item of unused) {
|
||||
findings.push({
|
||||
type: 'unused_export',
|
||||
message: `Unused export ${item.symbol || '<unknown>'}`,
|
||||
file: item.file || '',
|
||||
line: item.line ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of duplicates) {
|
||||
findings.push({
|
||||
type: 'duplicate_block',
|
||||
message: `Duplicate block (${Math.round((item.similarity || 0) * 100)}% similarity)`,
|
||||
file: item.left?.file || '',
|
||||
line: item.left?.start ?? null,
|
||||
related_file: item.right?.file || '',
|
||||
});
|
||||
}
|
||||
|
||||
for (const item of circular) {
|
||||
findings.push({
|
||||
type: 'circular_dependency',
|
||||
message: `Circular dependency: ${(item.cycle || []).join(' -> ')}`,
|
||||
file: Array.isArray(item.cycle) && item.cycle.length > 0 ? item.cycle[0] : '',
|
||||
line: null,
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
summary: {
|
||||
unused_exports: unused.length,
|
||||
duplicates: duplicates.length,
|
||||
circular_dependencies: circular.length,
|
||||
total: findings.length,
|
||||
},
|
||||
findings,
|
||||
};
|
||||
}
|
||||
372
tests/feat-3210-fallow-integration.test.cjs
Normal file
372
tests/feat-3210-fallow-integration.test.cjs
Normal file
@@ -0,0 +1,372 @@
|
||||
// allow-test-rule: source-text-is-the-product
|
||||
// This test validates workflow/agent/config contracts stored in shipped .md/.ts/.cjs
|
||||
// artifacts. Source text is the runtime product for those surfaces.
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const os = require('node:os');
|
||||
const { createTempProject, cleanup, runGsdTools } = require('./helpers.cjs');
|
||||
|
||||
const ROOT = path.resolve(__dirname, '..');
|
||||
|
||||
// N2: single helper — on macOS os.tmpdir() already returns /private/tmp; the
|
||||
// existsSync guard is kept only as defense-in-depth fallback.
|
||||
function getWritableTmp() {
|
||||
const candidates = ['/private/tmp', '/tmp', os.tmpdir()];
|
||||
return candidates.find((dir) => {
|
||||
try {
|
||||
fs.accessSync(dir, fs.constants.W_OK);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
describe('feat-3210: fallow integration module', () => {
|
||||
test('normalizes structural findings from a fallow report', () => {
|
||||
const { normalizeFallowReport } = require('../get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
const fixture = JSON.parse(
|
||||
fs.readFileSync(path.join(ROOT, 'tests', 'fixtures', 'fallow', 'sample-findings.json'), 'utf8'),
|
||||
);
|
||||
|
||||
const normalized = normalizeFallowReport(fixture);
|
||||
// M6: fixture: 1 unusedExport + 1 duplicate + 1 circularDep = 3; counts derived from fixture, not hardcoded
|
||||
const expectedUnused = fixture.unusedExports.length;
|
||||
const expectedDuplicates = fixture.duplicates.length;
|
||||
const expectedCircular = fixture.circularDependencies.length;
|
||||
const expectedTotal = expectedUnused + expectedDuplicates + expectedCircular;
|
||||
assert.deepStrictEqual(normalized.summary, {
|
||||
unused_exports: expectedUnused,
|
||||
duplicates: expectedDuplicates,
|
||||
circular_dependencies: expectedCircular,
|
||||
total: expectedTotal,
|
||||
});
|
||||
assert.strictEqual(normalized.findings.length, expectedTotal);
|
||||
});
|
||||
|
||||
test('falls back to node_modules/.bin/fallow when PATH does not contain fallow', () => {
|
||||
const { resolveFallowBinary } = require('../get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
// N2: use shared helper
|
||||
const baseTmp = getWritableTmp();
|
||||
const tmp = fs.mkdtempSync(path.join(baseTmp, 'gsd-fallow-bin-'));
|
||||
const binDir = path.join(tmp, 'node_modules', '.bin');
|
||||
fs.mkdirSync(binDir, { recursive: true });
|
||||
const fallowPath = path.join(binDir, 'fallow');
|
||||
fs.writeFileSync(fallowPath, '#!/usr/bin/env sh\n');
|
||||
if (process.platform !== 'win32') fs.chmodSync(fallowPath, 0o755);
|
||||
|
||||
const resolved = resolveFallowBinary({ cwd: tmp, envPath: '' });
|
||||
assert.strictEqual(resolved, fallowPath);
|
||||
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
// H6: replaced wholesale win32 skip with platform-adapted assertion
|
||||
test('ignores non-executable PATH candidate on non-Windows; prefers .cmd over bare extensionless on Windows', () => {
|
||||
const { resolveFallowBinary } = require('../get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
// N2: use shared helper
|
||||
const baseTmp = getWritableTmp();
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// H6: Windows — .cmd extension candidate must be preferred over bare extensionless file
|
||||
const tmp = fs.mkdtempSync(path.join(baseTmp, 'gsd-fallow-win-'));
|
||||
try {
|
||||
const pathDir = path.join(tmp, 'bin');
|
||||
fs.mkdirSync(pathDir, { recursive: true });
|
||||
const bareFile = path.join(pathDir, 'fallow');
|
||||
const cmdFile = path.join(pathDir, 'fallow.cmd');
|
||||
fs.writeFileSync(bareFile, '@echo off\r\n');
|
||||
fs.writeFileSync(cmdFile, '@echo off\r\n');
|
||||
const resolved = resolveFallowBinary({ cwd: tmp, envPath: pathDir });
|
||||
assert.strictEqual(
|
||||
resolved,
|
||||
cmdFile,
|
||||
'Windows: .cmd candidate must be preferred over bare extensionless file',
|
||||
);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
} else {
|
||||
// H6: non-Windows — non-executable file in PATH must be ignored
|
||||
const tmp = fs.mkdtempSync(path.join(baseTmp, 'gsd-fallow-nonexec-'));
|
||||
try {
|
||||
const pathDir = path.join(tmp, 'bin');
|
||||
fs.mkdirSync(pathDir, { recursive: true });
|
||||
const nonExec = path.join(pathDir, 'fallow');
|
||||
fs.writeFileSync(nonExec, '#!/usr/bin/env sh\n');
|
||||
fs.chmodSync(nonExec, 0o644);
|
||||
const resolved = resolveFallowBinary({ cwd: tmp, envPath: pathDir });
|
||||
assert.strictEqual(resolved, null);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('normalizes empty fallow report to zero findings', () => {
|
||||
const { normalizeFallowReport } = require('../get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
const fixture = JSON.parse(
|
||||
fs.readFileSync(path.join(ROOT, 'tests', 'fixtures', 'fallow', 'sample-empty.json'), 'utf8'),
|
||||
);
|
||||
const normalized = normalizeFallowReport(fixture);
|
||||
assert.deepStrictEqual(normalized.summary, {
|
||||
unused_exports: 0,
|
||||
duplicates: 0,
|
||||
circular_dependencies: 0,
|
||||
total: 0,
|
||||
});
|
||||
assert.deepStrictEqual(normalized.findings, []);
|
||||
});
|
||||
|
||||
test('throws actionable error when fallow is enabled but binary is unavailable', () => {
|
||||
const { requireFallowBinary } = require('../get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
// N2: use shared helper
|
||||
const baseTmp = getWritableTmp();
|
||||
const tmp = fs.mkdtempSync(path.join(baseTmp, 'gsd-fallow-missing-'));
|
||||
assert.throws(
|
||||
() => requireFallowBinary({ cwd: tmp, envPath: '' }),
|
||||
/install fallow via `npm install -D fallow` or `cargo install fallow`/,
|
||||
);
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
// L3: runFallowAudit against a non-zero-exit binary must surface error state
|
||||
test('runFallowAudit surfaces error state when binary exits non-zero', async () => {
|
||||
const { runFallowAudit } = require('../get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
// N2: use shared helper
|
||||
const baseTmp = getWritableTmp();
|
||||
const tmp = fs.mkdtempSync(path.join(baseTmp, 'gsd-fallow-fail-'));
|
||||
const shimName = process.platform === 'win32' ? 'fallow.cmd' : 'fallow';
|
||||
const shimPath = path.join(tmp, shimName);
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
fs.writeFileSync(shimPath, '@echo fallow-error-stderr 1>&2\r\n@exit 1\r\n');
|
||||
} else {
|
||||
fs.writeFileSync(shimPath, '#!/usr/bin/env sh\necho "fallow-error-stderr" >&2\nexit 1\n');
|
||||
fs.chmodSync(shimPath, 0o755);
|
||||
}
|
||||
|
||||
try {
|
||||
let errorState;
|
||||
try {
|
||||
errorState = await runFallowAudit({ cwd: tmp, env: { ...process.env, FALLOW_BIN_PATH: shimPath } });
|
||||
} catch (err) {
|
||||
// acceptable: some implementations throw rather than returning error state
|
||||
assert.ok(
|
||||
err.message.includes('fallow-error-stderr') || err.exitCode !== 0 || err.code !== 0,
|
||||
`expected thrown error to carry stderr content or non-zero exit; got: ${err.message}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
assert.ok(
|
||||
errorState && (errorState.error || errorState.exitCode !== 0 || errorState.failed),
|
||||
'runFallowAudit must return error state (error/exitCode/failed) when binary exits non-zero',
|
||||
);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
// M5: edge-case fixture — missing severity, similarity extremes, 3-node cycle, unicode path
|
||||
test('normalizes edge-case fixture: missing severity, similarity extremes, 3-node cycle, unicode path', () => {
|
||||
const { normalizeFallowReport } = require('../get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
const fixture = JSON.parse(
|
||||
fs.readFileSync(
|
||||
path.join(ROOT, 'tests', 'fixtures', 'fallow', 'sample-edge-cases.json'),
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
|
||||
// M5: unusedExport with no severity field — round-trips without throwing
|
||||
assert.strictEqual(fixture.unusedExports.length, 1);
|
||||
assert.strictEqual(
|
||||
Object.prototype.hasOwnProperty.call(fixture.unusedExports[0], 'severity'),
|
||||
false,
|
||||
'edge-case fixture: unusedExport severity field must be absent',
|
||||
);
|
||||
// M5: unicode file path is preserved in fixture
|
||||
assert.ok(
|
||||
fixture.unusedExports[0].file.includes('café'),
|
||||
'edge-case fixture: unicode file path must be present',
|
||||
);
|
||||
|
||||
// M5: duplicate entries with similarity at extremes 0.0 and 1.0
|
||||
assert.strictEqual(fixture.duplicates.length, 2);
|
||||
assert.strictEqual(fixture.duplicates[0].similarity, 0.0);
|
||||
assert.strictEqual(fixture.duplicates[1].similarity, 1.0);
|
||||
|
||||
// M5: 3-node circular dependency cycle (cycle array has 4 elements: A→B→C→A)
|
||||
assert.strictEqual(fixture.circularDependencies.length, 1);
|
||||
const cycle = fixture.circularDependencies[0].cycle;
|
||||
const uniqueNodes = new Set(cycle.slice(0, -1)); // last element repeats first
|
||||
assert.strictEqual(uniqueNodes.size, 3, 'edge-case: cycle must have exactly 3 unique nodes');
|
||||
|
||||
// normalization round-trips without throwing
|
||||
const normalized = normalizeFallowReport(fixture);
|
||||
const expectedTotal =
|
||||
fixture.unusedExports.length + fixture.duplicates.length + fixture.circularDependencies.length;
|
||||
assert.strictEqual(normalized.findings.length, expectedTotal);
|
||||
assert.strictEqual(normalized.summary.total, expectedTotal);
|
||||
|
||||
// M5: unicode path survives normalization
|
||||
const unicodeFinding = normalized.findings.find(
|
||||
(f) => typeof f.file === 'string' && f.file.includes('café'),
|
||||
);
|
||||
assert.ok(unicodeFinding, 'unicode file path must survive normalization round-trip');
|
||||
});
|
||||
});
|
||||
|
||||
describe('feat-3210: H1 - line:0 preservation', () => {
|
||||
test('normalizeFallowReport preserves line:0 for unused_export (not coerced to null)', () => {
|
||||
const { normalizeFallowReport } = require('../get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
const report = {
|
||||
unusedExports: [{ file: 'src/a.ts', symbol: 'foo', line: 0 }],
|
||||
duplicates: [],
|
||||
circularDependencies: [],
|
||||
};
|
||||
const normalized = normalizeFallowReport(report);
|
||||
assert.strictEqual(normalized.findings[0].line, 0, 'line:0 must not be coerced to null via ||');
|
||||
});
|
||||
|
||||
test('normalizeFallowReport preserves line:0 for duplicate_block left.start (not coerced to null)', () => {
|
||||
const { normalizeFallowReport } = require('../get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
const report = {
|
||||
unusedExports: [],
|
||||
duplicates: [{ left: { file: 'src/a.ts', start: 0 }, right: { file: 'src/b.ts', start: 5 }, similarity: 0.9 }],
|
||||
circularDependencies: [],
|
||||
};
|
||||
const normalized = normalizeFallowReport(report);
|
||||
assert.strictEqual(normalized.findings[0].line, 0, 'left.start:0 must not be coerced to null via ||');
|
||||
});
|
||||
});
|
||||
|
||||
describe('feat-3210: M2 - node_modules/.bin resolution order', () => {
|
||||
test('resolveFallowBinary prefers node_modules/.bin over PATH when both exist', () => {
|
||||
const { resolveFallowBinary } = require('../get-shit-done/bin/lib/fallow-runner.cjs');
|
||||
// N2: use shared helper
|
||||
const baseTmp = getWritableTmp();
|
||||
const tmp = fs.mkdtempSync(path.join(baseTmp, 'gsd-fallow-order-'));
|
||||
try {
|
||||
// local node_modules/.bin/fallow
|
||||
const binDir = path.join(tmp, 'node_modules', '.bin');
|
||||
fs.mkdirSync(binDir, { recursive: true });
|
||||
const localFallow = path.join(binDir, 'fallow');
|
||||
fs.writeFileSync(localFallow, '#!/usr/bin/env sh\necho local\n');
|
||||
if (process.platform !== 'win32') fs.chmodSync(localFallow, 0o755);
|
||||
|
||||
// PATH fallow (a different file)
|
||||
const pathDir = path.join(tmp, 'pathbin');
|
||||
fs.mkdirSync(pathDir, { recursive: true });
|
||||
const pathFallow = path.join(pathDir, 'fallow');
|
||||
fs.writeFileSync(pathFallow, '#!/usr/bin/env sh\necho path\n');
|
||||
if (process.platform !== 'win32') fs.chmodSync(pathFallow, 0o755);
|
||||
|
||||
const resolved = resolveFallowBinary({ cwd: tmp, envPath: pathDir });
|
||||
assert.strictEqual(resolved, localFallow, 'node_modules/.bin/fallow must win over PATH fallow');
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('feat-3210: workflow and config contracts', () => {
|
||||
test('config schema allows code_quality.fallow.* keys in CJS and SDK', () => {
|
||||
const cjsSchema = fs.readFileSync(
|
||||
path.join(ROOT, 'get-shit-done', 'bin', 'lib', 'config-schema.cjs'),
|
||||
'utf8',
|
||||
);
|
||||
const sdkSchema = fs.readFileSync(
|
||||
path.join(ROOT, 'sdk', 'src', 'query', 'config-schema.ts'),
|
||||
'utf8',
|
||||
);
|
||||
for (const key of [
|
||||
'code_quality.fallow.enabled',
|
||||
'code_quality.fallow.scope',
|
||||
'code_quality.fallow.profile',
|
||||
'code_quality.fallow.mcp',
|
||||
]) {
|
||||
assert.ok(cjsSchema.includes(`'${key}'`), `missing CJS config key: ${key}`);
|
||||
assert.ok(sdkSchema.includes(`'${key}'`), `missing SDK config key: ${key}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('config-set accepts code_quality.fallow keys', () => {
|
||||
const originalTmpDir = process.env.TMPDIR;
|
||||
// L2: fail loudly if no writable tmp dir is found (was silent skip)
|
||||
const writableTmp = getWritableTmp(); // N2: use shared helper
|
||||
assert.ok(writableTmp, 'no writable tmp directory found'); // L2: explicit fail-loud assertion
|
||||
process.env.TMPDIR = writableTmp;
|
||||
const tmpDir = createTempProject('gsd-fallow-config-');
|
||||
try {
|
||||
const cases = [
|
||||
['code_quality.fallow.enabled', 'true'],
|
||||
['code_quality.fallow.scope', 'repo'],
|
||||
['code_quality.fallow.profile', 'strict'],
|
||||
['code_quality.fallow.mcp', 'false'],
|
||||
];
|
||||
for (const [key, value] of cases) {
|
||||
const result = runGsdTools(['config-set', key, value], tmpDir);
|
||||
assert.ok(result.success, `config-set failed for ${key}: ${result.error || result.output}`);
|
||||
}
|
||||
} finally {
|
||||
cleanup(tmpDir);
|
||||
if (originalTmpDir === undefined) delete process.env.TMPDIR;
|
||||
else process.env.TMPDIR = originalTmpDir;
|
||||
}
|
||||
});
|
||||
|
||||
// B4: replaced 5x source-grep tautologies with parse-based structural checks.
|
||||
// The workflow .md uses XML-like <step> tags as its runtime DSL; we parse the step block
|
||||
// structurally and assert on structural properties, not on prose strings.
|
||||
test('code-review workflow structural_pre_pass step is parseable and references FALLOW.json output', () => {
|
||||
const workflow = fs.readFileSync(
|
||||
path.join(ROOT, 'get-shit-done', 'workflows', 'code-review.md'),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
// Parse: the <step name="structural_pre_pass"> block must exist and be closed
|
||||
const stepMatch = workflow.match(/<step\s+name="structural_pre_pass">([\s\S]*?)<\/step>/);
|
||||
assert.ok(
|
||||
stepMatch,
|
||||
'workflow must contain a parseable <step name="structural_pre_pass">...</step> block',
|
||||
);
|
||||
|
||||
const stepBody = stepMatch[1];
|
||||
|
||||
// Structural property: the step body must reference the FALLOW.json output artifact
|
||||
assert.ok(
|
||||
stepBody.includes('FALLOW.json'),
|
||||
'structural_pre_pass step body must reference the FALLOW.json output artifact',
|
||||
);
|
||||
|
||||
// Structural property: the step body must gate on the fallow enabled config key
|
||||
assert.ok(
|
||||
stepBody.includes('code_quality.fallow.enabled'),
|
||||
'structural_pre_pass step body must gate on code_quality.fallow.enabled',
|
||||
);
|
||||
});
|
||||
|
||||
// B4: agent output contract — doc-parity check (approved fallback per config-schema-docs-parity
|
||||
// pattern). We confirm the heading exists in the shipped artifact, not in a live agent response.
|
||||
// Live agent output is covered by /gsd-code-review e2e runs downstream.
|
||||
test('reviewer prompt defines ## Structural Findings (fallow) heading and review context echoes it', () => {
|
||||
const reviewer = fs.readFileSync(path.join(ROOT, 'agents', 'gsd-code-reviewer.md'), 'utf8');
|
||||
const reviewContext = fs.readFileSync(path.join(ROOT, 'get-shit-done', 'contexts', 'review.md'), 'utf8');
|
||||
|
||||
// Doc-parity: section heading must exist in the shipped agent file (the heading is a contract,
|
||||
// not prose — renaming it would break every consumer that parses agent output by section)
|
||||
assert.ok(
|
||||
reviewer.includes('## Structural Findings (fallow)'),
|
||||
'gsd-code-reviewer.md must define ## Structural Findings (fallow) section heading',
|
||||
);
|
||||
|
||||
// Doc-parity: review context that agents receive must reference the same section
|
||||
assert.ok(
|
||||
reviewContext.includes('Structural Findings (fallow)'),
|
||||
'review.md context must reference Structural Findings (fallow) so agents recognize the section',
|
||||
);
|
||||
});
|
||||
});
|
||||
175
tests/feat-3210-fallow-schema-enum.test.cjs
Normal file
175
tests/feat-3210-fallow-schema-enum.test.cjs
Normal file
@@ -0,0 +1,175 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Enum validation for code_quality.fallow.scope and code_quality.fallow.profile.
|
||||
*
|
||||
* Fixes H5 from #3424 review: config-set silently accepted invalid enum values
|
||||
* (e.g. scope=fullrepo) and fell through to default behavior. This test asserts
|
||||
* that invalid values are rejected with a helpful error, and valid values pass.
|
||||
*/
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { createTempProject, cleanup, runGsdTools } = require('./helpers.cjs');
|
||||
|
||||
describe('feat-3210 / H5: enum validation for code_quality.fallow.scope and .profile', () => {
|
||||
// --- code_quality.fallow.scope ---
|
||||
|
||||
test('config-set code_quality.fallow.scope=fullrepo is REJECTED with helpful error', (t) => {
|
||||
const tmpDir = createTempProject();
|
||||
t.after(() => cleanup(tmpDir));
|
||||
|
||||
const result = runGsdTools(
|
||||
['config-set', 'code_quality.fallow.scope', 'fullrepo'],
|
||||
tmpDir
|
||||
);
|
||||
assert.ok(
|
||||
!result.success,
|
||||
'config-set code_quality.fallow.scope=fullrepo must fail, but it succeeded'
|
||||
);
|
||||
const combined = (result.output || '') + (result.error || '');
|
||||
assert.ok(
|
||||
combined.includes('phase') && combined.includes('repo'),
|
||||
`Error message must mention valid values "phase" and "repo", got: ${combined}`
|
||||
);
|
||||
});
|
||||
|
||||
test('config-set code_quality.fallow.scope=phase is ACCEPTED', (t) => {
|
||||
const tmpDir = createTempProject();
|
||||
t.after(() => cleanup(tmpDir));
|
||||
|
||||
const result = runGsdTools(
|
||||
['config-set', 'code_quality.fallow.scope', 'phase'],
|
||||
tmpDir
|
||||
);
|
||||
assert.ok(
|
||||
result.success,
|
||||
[
|
||||
'config-set code_quality.fallow.scope=phase must succeed,',
|
||||
'stdout: ' + result.output,
|
||||
'stderr: ' + result.error,
|
||||
].join('\n')
|
||||
);
|
||||
});
|
||||
|
||||
test('config-set code_quality.fallow.scope=repo is ACCEPTED', (t) => {
|
||||
const tmpDir = createTempProject();
|
||||
t.after(() => cleanup(tmpDir));
|
||||
|
||||
const result = runGsdTools(
|
||||
['config-set', 'code_quality.fallow.scope', 'repo'],
|
||||
tmpDir
|
||||
);
|
||||
assert.ok(
|
||||
result.success,
|
||||
[
|
||||
'config-set code_quality.fallow.scope=repo must succeed,',
|
||||
'stdout: ' + result.output,
|
||||
'stderr: ' + result.error,
|
||||
].join('\n')
|
||||
);
|
||||
});
|
||||
|
||||
test('config-set code_quality.fallow.scope=PHASE (wrong case) is REJECTED', (t) => {
|
||||
const tmpDir = createTempProject();
|
||||
t.after(() => cleanup(tmpDir));
|
||||
|
||||
const result = runGsdTools(
|
||||
['config-set', 'code_quality.fallow.scope', 'PHASE'],
|
||||
tmpDir
|
||||
);
|
||||
assert.ok(
|
||||
!result.success,
|
||||
'config-set code_quality.fallow.scope=PHASE must fail (values are case-sensitive)'
|
||||
);
|
||||
});
|
||||
|
||||
// --- code_quality.fallow.profile ---
|
||||
|
||||
test('config-set code_quality.fallow.profile=aggressive is REJECTED with helpful error', (t) => {
|
||||
const tmpDir = createTempProject();
|
||||
t.after(() => cleanup(tmpDir));
|
||||
|
||||
const result = runGsdTools(
|
||||
['config-set', 'code_quality.fallow.profile', 'aggressive'],
|
||||
tmpDir
|
||||
);
|
||||
assert.ok(
|
||||
!result.success,
|
||||
'config-set code_quality.fallow.profile=aggressive must fail, but it succeeded'
|
||||
);
|
||||
const combined = (result.output || '') + (result.error || '');
|
||||
assert.ok(
|
||||
combined.includes('minimal') && combined.includes('standard') && combined.includes('strict'),
|
||||
`Error message must mention valid values "minimal", "standard", "strict", got: ${combined}`
|
||||
);
|
||||
});
|
||||
|
||||
test('config-set code_quality.fallow.profile=minimal is ACCEPTED', (t) => {
|
||||
const tmpDir = createTempProject();
|
||||
t.after(() => cleanup(tmpDir));
|
||||
|
||||
const result = runGsdTools(
|
||||
['config-set', 'code_quality.fallow.profile', 'minimal'],
|
||||
tmpDir
|
||||
);
|
||||
assert.ok(
|
||||
result.success,
|
||||
[
|
||||
'config-set code_quality.fallow.profile=minimal must succeed,',
|
||||
'stdout: ' + result.output,
|
||||
'stderr: ' + result.error,
|
||||
].join('\n')
|
||||
);
|
||||
});
|
||||
|
||||
test('config-set code_quality.fallow.profile=standard is ACCEPTED', (t) => {
|
||||
const tmpDir = createTempProject();
|
||||
t.after(() => cleanup(tmpDir));
|
||||
|
||||
const result = runGsdTools(
|
||||
['config-set', 'code_quality.fallow.profile', 'standard'],
|
||||
tmpDir
|
||||
);
|
||||
assert.ok(
|
||||
result.success,
|
||||
[
|
||||
'config-set code_quality.fallow.profile=standard must succeed,',
|
||||
'stdout: ' + result.output,
|
||||
'stderr: ' + result.error,
|
||||
].join('\n')
|
||||
);
|
||||
});
|
||||
|
||||
test('config-set code_quality.fallow.profile=strict is ACCEPTED', (t) => {
|
||||
const tmpDir = createTempProject();
|
||||
t.after(() => cleanup(tmpDir));
|
||||
|
||||
const result = runGsdTools(
|
||||
['config-set', 'code_quality.fallow.profile', 'strict'],
|
||||
tmpDir
|
||||
);
|
||||
assert.ok(
|
||||
result.success,
|
||||
[
|
||||
'config-set code_quality.fallow.profile=strict must succeed,',
|
||||
'stdout: ' + result.output,
|
||||
'stderr: ' + result.error,
|
||||
].join('\n')
|
||||
);
|
||||
});
|
||||
|
||||
test('config-set code_quality.fallow.profile=unknown is REJECTED', (t) => {
|
||||
const tmpDir = createTempProject();
|
||||
t.after(() => cleanup(tmpDir));
|
||||
|
||||
const result = runGsdTools(
|
||||
['config-set', 'code_quality.fallow.profile', 'unknown'],
|
||||
tmpDir
|
||||
);
|
||||
assert.ok(
|
||||
!result.success,
|
||||
'config-set code_quality.fallow.profile=unknown must fail'
|
||||
);
|
||||
});
|
||||
});
|
||||
47
tests/fixtures/fallow/sample-edge-cases.json
vendored
Normal file
47
tests/fixtures/fallow/sample-edge-cases.json
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"unusedExports": [
|
||||
{
|
||||
"file": "src/café/utils.ts",
|
||||
"symbol": "helperFn",
|
||||
"line": 42
|
||||
}
|
||||
],
|
||||
"duplicates": [
|
||||
{
|
||||
"left": {
|
||||
"file": "src/a.ts",
|
||||
"start": 1,
|
||||
"end": 5
|
||||
},
|
||||
"right": {
|
||||
"file": "src/b.ts",
|
||||
"start": 1,
|
||||
"end": 5
|
||||
},
|
||||
"similarity": 0.0
|
||||
},
|
||||
{
|
||||
"left": {
|
||||
"file": "src/c.ts",
|
||||
"start": 10,
|
||||
"end": 20
|
||||
},
|
||||
"right": {
|
||||
"file": "src/d.ts",
|
||||
"start": 10,
|
||||
"end": 20
|
||||
},
|
||||
"similarity": 1.0
|
||||
}
|
||||
],
|
||||
"circularDependencies": [
|
||||
{
|
||||
"cycle": [
|
||||
"src/x.ts",
|
||||
"src/y.ts",
|
||||
"src/z.ts",
|
||||
"src/x.ts"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
5
tests/fixtures/fallow/sample-empty.json
vendored
Normal file
5
tests/fixtures/fallow/sample-empty.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"unusedExports": [],
|
||||
"duplicates": [],
|
||||
"circularDependencies": []
|
||||
}
|
||||
33
tests/fixtures/fallow/sample-findings.json
vendored
Normal file
33
tests/fixtures/fallow/sample-findings.json
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"unusedExports": [
|
||||
{
|
||||
"file": "sdk/src/query/commit.ts",
|
||||
"symbol": "commitToSubrepo",
|
||||
"line": 289
|
||||
}
|
||||
],
|
||||
"duplicates": [
|
||||
{
|
||||
"left": {
|
||||
"file": "get-shit-done/bin/lib/config-schema.cjs",
|
||||
"start": 14,
|
||||
"end": 22
|
||||
},
|
||||
"right": {
|
||||
"file": "sdk/src/query/config-schema.ts",
|
||||
"start": 9,
|
||||
"end": 17
|
||||
},
|
||||
"similarity": 0.98
|
||||
}
|
||||
],
|
||||
"circularDependencies": [
|
||||
{
|
||||
"cycle": [
|
||||
"src/a.ts",
|
||||
"src/b.ts",
|
||||
"src/a.ts"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user