test(#146): add TestMainSubprocess_InvalidDocMapPath and TestMainSubprocess_InvalidDocMapFile #151
Reference in New Issue
Block a user
Delete Branch "issue-146"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds two missing subprocess tests for
--doc-mapflag validation inmain().Changes
cmd/review-bot/main.go
--doc-mappath validation earlier (before network I/O) so it can be tested without a running servercmd/review-bot/main_test.go
TestMainSubprocess_InvalidDocMapPath: passes--doc-map ../../../etc/passwdand asserts path traversal rejectionTestMainSubprocess_InvalidDocMapFile: passes--doc-map nonexistent.ymland asserts resolve failureBoth tests follow the existing
TEST_SUBPROCESS_MAIN=1env gate pattern withcleanEnv()+ explicitGITHUB_WORKSPACE.Closes #146
Original reviewSuperseded — see current review for up-to-date findings.
Previous findings (commit
40a16b75)Sonnet Review
Summary
Clean, focused PR that moves doc-map path validation earlier (fail-fast before network I/O) and adds two subprocess tests to cover the new early-exit paths. The changes follow established patterns in the codebase and are correct.
Findings
cmd/review-bot/main.go_). Then at the later doc-map processing block (Step 6c), validateWorkspacePath is called again on the same path. This is a double call to EvalSymlinks on the happy path. Consider storing the resolved path in a variable (e.g., a map or a local var) to avoid the redundant syscall, or restructure so the early check and the later usage share the resolved result.cmd/review-bot/main_test.goRecommendation
APPROVE — Approve. The production change is correct and well-motivated: moving the validation before network I/O prevents wasted round-trips on bad input, and the two new tests accurately exercise both failure modes (path traversal rejection and nonexistent file). The tests follow the established TEST_SUBPROCESS_MAIN=1 subprocess gate pattern with cleanEnv() + explicit GITHUB_WORKSPACE, matching the codebase convention. The only findings are minor nits — a redundant EvalSymlinks call on the happy path (the early check's resolved path is thrown away and recomputed later) and a bit of copy-paste in the test args setup — neither of which warrants blocking the PR.
Review by sonnet
Evaluated against
40a16b75@@ -173,6 +173,14 @@ func main() {os.Exit(1)}// Early validation of filesystem-path flags (fail fast before network I/O)[NIT] The early validation at line 176 calls validateWorkspacePath and discards the resolved path (using
_). Then at the later doc-map processing block (Step 6c), validateWorkspacePath is called again on the same path. This is a double call to EvalSymlinks on the happy path. Consider storing the resolved path in a variable (e.g., a map or a local var) to avoid the redundant syscall, or restructure so the early check and the later usage share the resolved result.@@ -1506,3 +1506,77 @@ func TestMainSubprocess_DeprecatedGiteaURLEnv(t *testing.T) {t.Errorf("expected deprecation warning for GITEA_URL, got: %s", out)}}[NIT] Both new subprocess tests pass the same set of required flags verbatim (copy-paste). If the required-flag set changes, both tests need updating. This is a minor maintainability concern, not a correctness issue — a shared helper (like the existing cleanEnv pattern) could be used to build the base args slice, but it's low priority given the established pattern in the file.
Original reviewSuperseded — see current review for up-to-date findings.
Previous findings (commit
40a16b75)Security Review
Summary
Security posture is improved by moving --doc-map path validation earlier, preventing path traversal attempts before any network I/O. Added subprocess tests robustly verify rejection of unsafe or nonexistent paths. CI passed and no new vulnerabilities are introduced.
Recommendation
APPROVE — The changes appropriately enforce workspace-bound path validation earlier in program execution and add targeted tests to prevent path traversal and invalid file usage for --doc-map. No security issues detected; proceed with merge.
Review by security
Evaluated against
40a16b75Original reviewSuperseded — see current review for up-to-date findings.
Previous findings (commit
40a16b75)Gpt Review
Summary
Change cleanly adds early validation for --doc-map and introduces two robust subprocess tests to cover path traversal and missing file cases. CI passed and the implementation is consistent with existing patterns and error handling.
Findings
cmd/review-bot/main.goRecommendation
APPROVE — The early validation for --doc-map is a good improvement, enabling failure before any network I/O and making the new subprocess tests feasible. Tests follow the established subprocess pattern and set GITHUB_WORKSPACE explicitly, which is correct for path validation. As a minor enhancement, consider storing the resolved doc-map path during early validation and reusing it later to avoid re-validating. Otherwise, the changes are sound and adhere to the repository’s error-handling and testing conventions.
Review by gpt
Evaluated against
40a16b75@@ -173,6 +173,14 @@ func main() {os.Exit(1)[NIT] The doc-map path is validated twice (early and again in Step 6c). Consider capturing and reusing the resolved path from the early validation to avoid duplicate work.
Self-Review: PR #151
Self-review against
40a16b75e0Phase 1: Independent Findings
None — diff looks clean. The production change is a small, focused early-validation guard that correctly uses the existing
validateWorkspacePathhelper and follows the established error-handling pattern (slog.Error+os.Exit(1)). Tests follow the existingTEST_SUBPROCESS_MAIN=1subprocess pattern with explicitGITHUB_WORKSPACEandcleanEnv(), which is correct for path validation testing.One observation (NIT-level): the early validation discards the resolved path, which is then recomputed at line 368. This is intentional — the early check is a fail-fast guard; the later call is the "real" usage. The extra
EvalSymlinkssyscall on the happy path is negligible cost for cleaner separation of concerns.Phase 2: Prior Review Verification
validateWorkspacePathcall (resolved path discarded early)EvalSymlinkssyscall — negligible. Keeping the early check as a pure guard (no state mutation) is arguably cleaner. Not worth restructuring.Assessment: ✅ Clean
All three bots approved. Findings are NIT-level only (duplicate syscall, test boilerplate). The production change is correct, focused, and well-tested. Ready for merge.
Fix Plan against
40a16b75e0:Findings Summary
All findings are NIT-level. All three bots approved.
main.go: DoublevalidateWorkspacePathcall — early guard discards resolved path, recomputed later at Step 6cEvalSymlinkssyscall.main_test.go: Copy-paste required flags across two test functionsPlan
FIX #1 — Capture resolved path from early
validateWorkspacePathcall and pass it to the later Step 6c block instead of callingvalidateWorkspacePathagain.DEFER #2 — Test helper refactor out of scope for this PR. Will file a separate issue.
Execution
Deferred — filed as #154 for a dedicated test-helper refactor pass.
Original reviewSuperseded — see current review for up-to-date findings.
Previous findings (commit
9b64c605)Sonnet Review
Summary
Clean, focused PR that moves
--doc-mappath validation earlier (before network I/O) and adds two subprocess tests to cover the path-traversal and nonexistent-file error paths. The refactor eliminates code duplication by resolving the path once and reusing the result. Tests follow the establishedTEST_SUBPROCESS_MAIN=1pattern withcleanEnv()+ explicitGITHUB_WORKSPACE.Findings
cmd/review-bot/main_test.goTestMainSubprocess_InvalidDocMapPathcallsmain()and returns, butGITHUB_WORKSPACEis set by the outer test via the environment string"GITHUB_WORKSPACE="+t.TempDir(). The subprocess process inherits that env var, so the temp dir created in the outer test process is passed as a string to the child — this is correct. Just worth noting that the outert.TempDir()is evaluated in the outer process beforecmd.Envis built, so it is a real, existing directory. No bug, just confirming the intent.Recommendation
APPROVE — Approve. The production change is a safe mechanical refactor (resolve once, reuse) with no behavioral difference for valid paths. The two new tests are well-structured, follow existing patterns exactly, and provide meaningful coverage for security-relevant validation that was previously untested. The only nit is a clarifying observation, not a defect.
Review by sonnet
Evaluated against
9b64c605@@ -1509,0 +1527,4 @@}cmd := exec.Command(os.Args[0], "-test.run=TestMainSubprocess_InvalidDocMapPath")cmd.Env = append(cleanEnv(),[NIT] The subprocess side of
TestMainSubprocess_InvalidDocMapPathcallsmain()and returns, butGITHUB_WORKSPACEis set by the outer test via the environment string"GITHUB_WORKSPACE="+t.TempDir(). The subprocess process inherits that env var, so the temp dir created in the outer test process is passed as a string to the child — this is correct. Just worth noting that the outert.TempDir()is evaluated in the outer process beforecmd.Envis built, so it is a real, existing directory. No bug, just confirming the intent.Original reviewSuperseded — see current review for up-to-date findings.
Previous findings (commit
9b64c605)Gpt Review
Summary
The changes correctly move doc-map path validation earlier to fail fast and add two subprocess tests that validate traversal and nonexistent file cases. CI is passing and the implementation is straightforward and idiomatic.
Recommendation
APPROVE — The early validation of --doc-map via validateWorkspacePath and reuse of the resolved path ensures errors surface before any network I/O, making the new subprocess tests reliable. The added tests follow the existing subprocess pattern and appropriately set GITHUB_WORKSPACE. No issues detected; proceed with merge.
Review by gpt
Evaluated against
9b64c605Original reviewSuperseded — see current review for up-to-date findings.
Previous findings (commit
9b64c605)Security Review
Summary
The PR moves validation of the --doc-map path earlier in main(), reducing risk and enabling deterministic testing, and adds subprocess tests that verify rejection of path traversal and nonexistent files. No new vulnerabilities are introduced; overall this improves security posture.
Recommendation
APPROVE — CI has passed, and the change improves security by validating user-supplied file paths before any network I/O. The validateWorkspacePath approach correctly restricts to the workspace and resolves symlinks to prevent traversal. The added tests exercise these cases as intended. As a defense-in-depth consideration (not a required change), you could re-validate or re-check the resolved path immediately before opening the file to further minimize any TOCTOU window, though in this CLI context the practical risk is low. Overall, this is a solid improvement.
Review by security
Evaluated against
9b64c605Self-Review: PR #151
Self-review against
9b64c605f878eff32e29cc108db360fd64066059Phase 1: Independent Findings
None — diff looks clean. The refactor correctly moves
validateWorkspacePathearlier, stores the resolved path inresolvedDocMapFile, and reuses it at Step 6c. Error handling follows the existing pattern (slog.Error+os.Exit(1)). Tests use the establishedTEST_SUBPROCESS_MAIN=1subprocess pattern withcleanEnv()and explicitGITHUB_WORKSPACE.Phase 2: Prior Review Verification
validateWorkspacePathcall (resolved path discarded early, recomputed later)resolvedDocMapFileand reuses it downstreamt.TempDir()evaluated in outer process (clarifying observation)Assessment: ✅ Clean
All three review bots approved. The one actionable finding from round 1 (double validation) has been fixed. The remaining NIT (test-helper refactor) is correctly deferred to #154. Ready to merge.
Self-Review: PR #151
Self-review against
9b64c605f878eff32e29cc108db360fd64066059Phase 1: Independent Findings
No issues found. The diff is clean and well-scoped:
Production change (
main.go): MovesvalidateWorkspacePathcall for--doc-mapearlier inmain(), before any network I/O. Stores the resolved path inresolvedDocMapFileand reuses it downstream at Step 6c. Error handling follows the establishedslog.Error+os.Exit(1)pattern. Variable scoping is correct —resolvedDocMapFileis declared in the outer scope and only assigned inside the conditional, so it flows cleanly to the later usage.Tests (
main_test.go): Two new subprocess tests covering path-traversal rejection (../../../etc/passwd) and nonexistent file rejection (nonexistent.yml). Both follow theTEST_SUBPROCESS_MAIN=1env gate pattern withcleanEnv()+ explicitGITHUB_WORKSPACE, consistent with all other subprocess tests in the file. Assertions are specific and meaningful (checking both the flag name and the error class).Phase 2: Prior Review Verification
validateWorkspacePathcall (resolved path discarded)resolvedDocMapFileand reuses at Step 6c — no duplicate syscallt.TempDir()evaluated in outer process (clarifying note)Assessment: ✅ Clean
All six bot reviews (3 bots × 2 rounds) approved. The one actionable finding (double validation) was fixed between rounds. Remaining deferred item (#154) is out of scope. No new findings on current HEAD.
Self-review against
9b64c605f8Assessment: ✅ Clean
No issues found — ready for human review.
Summary: Two-commit PR that (1) moves
--doc-mappath validation earlier inmain()before network I/O and adds the two required subprocess tests, then (2) eliminates the now-redundant secondvalidateWorkspacePathcall in Step 6c by reusing the resolved path from early validation. All acceptance criteria for #146 met. Build clean, vet clean, all tests pass.Acknowledging sonnet review NIT #1 (review 4107 @
9b64c605):Correct —
t.TempDir()is evaluated in the outer (test driver) process before buildingcmd.Env, so the subprocess receives a real, existing directory path. This is intentional: the outer test creates the workspace directory, the subprocess validates paths against it. No action needed; this is an observation, not a defect.Fix Plan
Addressing: Review #4107, Finding #1 (NIT)
Finding: The subprocess tests call
t.TempDir()inline when buildingcmd.Env, without a comment clarifying that it is evaluated in the outer test process (not the subprocess). The reviewer confirmed: no bug, just worth noting the intent.Fix: Added a comment above both
cmd.Env = append(cleanEnv(), ...)blocks inTestMainSubprocess_InvalidDocMapPathandTestMainSubprocess_InvalidDocMapFileto clarify thatt.TempDir()is evaluated in the outer process, producing a real directory that gets passed as theGITHUB_WORKSPACEenv string to the subprocess.Commit:
290ce99—test(#146): clarify t.TempDir() evaluation in subprocess env setupSonnet Review
Summary
The changes correctly move
--doc-mappath validation earlier inmain()to enable testing without network I/O, and add two well-structured subprocess tests that follow the establishedTEST_SUBPROCESS_MAIN=1pattern. The code is clean, idiomatic, and CI passes.Findings
cmd/review-bot/main_test.go// t.TempDir() is evaluated here in the outer process, producing a real directory / that is passed as the GITHUB_WORKSPACE env var string to the subprocess.is duplicated verbatim in both new test functions. It's accurate and useful, but could be a shared helper (e.g.workspaceEnv(t)) to avoid repeating the same comment+pattern four times total (two existing tests already use similar patterns). Minor — not worth blocking.Recommendation
APPROVE — Approve as-is. The refactor is minimal and correct: resolving the doc-map path once at the 'fail fast' boundary (before any client initialization or network I/O) is the right design, and the two new subprocess tests directly exercise the new early-exit paths. The only observation is minor test-code duplication in the workspace setup, which doesn't affect correctness or readability materially.
Review by sonnet
Evaluated against
290ce992@@ -1509,0 +1525,4 @@main()return}[NIT] The comment
// t.TempDir() is evaluated here in the outer process, producing a real directory / that is passed as the GITHUB_WORKSPACE env var string to the subprocess.is duplicated verbatim in both new test functions. It's accurate and useful, but could be a shared helper (e.g.workspaceEnv(t)) to avoid repeating the same comment+pattern four times total (two existing tests already use similar patterns). Minor — not worth blocking.Security Review
Summary
The change moves path validation for the --doc-map flag earlier to fail fast and adds subprocess tests covering path traversal and nonexistent file scenarios. This strengthens input validation and reduces risk by preventing any network I/O before rejecting unsafe paths.
Recommendation
APPROVE — CI has passed and the changes are security-positive: early validation with validateWorkspacePath prevents path traversal and symlink escapes, and the new tests exercise these failure modes. No new injection, auth, or secret-handling risks are introduced. Approve as is.
Review by security
Evaluated against
290ce992Gpt Review
Summary
The changes cleanly move --doc-map path validation earlier to fail fast and add two robust subprocess tests covering path traversal and nonexistent files. Error handling, logging, and test structure are consistent and idiomatic, and CI has passed.
Recommendation
APPROVE — The early validation of the doc-map path before any network I/O is a sensible design improvement that makes the new tests reliable and improves user feedback. The reuse of the resolvedDocMapFile variable later avoids redundant work and keeps logic clear. The new subprocess tests follow the established TEST_SUBPROCESS_MAIN gating pattern and correctly set a synthetic GITHUB_WORKSPACE for isolation. With CI passing and no issues found in the diff, this PR is ready to merge.
Review by gpt
Evaluated against
290ce992290ce99226to430e61fdbd