Skip to content

fix(ci): use staged files for pre-commit docs-only detection#554

Merged
rjmurillo-bot merged 3 commits into
mainfrom
fix/551-session-validation-false-positive
Dec 31, 2025
Merged

fix(ci): use staged files for pre-commit docs-only detection#554
rjmurillo-bot merged 3 commits into
mainfrom
fix/551-session-validation-false-positive

Conversation

@rjmurillo-bot

Copy link
Copy Markdown
Collaborator

Pull Request

Summary

Fix false positive in session protocol validation that incorrectly requires QA when only fixing session log format.

Specification References

Type Reference Description
Issue Closes #551 Session protocol validation false positive on docs-only commits

Changes

  • In pre-commit mode, check git diff --staged --name-only for docs-only detection
  • Falls back to starting commit comparison when not in pre-commit mode or no staged files
  • Allows proper QA skip when only .md files are being committed

Type of Change

  • Bug fix (non-breaking change fixing an issue)
  • New feature (non-breaking change adding functionality)
  • Breaking change (fix or feature causing existing functionality to change)
  • Documentation update
  • Infrastructure/CI change
  • Refactoring (no functional changes)

Testing

  • Tests added/updated
  • Manual testing completed
  • No testing required (documentation only)

Agent Review

Security Review

  • No security-critical changes in this PR

Other Agent Reviews

  • Architect reviewed design changes
  • Critic validated implementation plan
  • QA verified test coverage

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex logic
  • Documentation updated (if applicable)
  • No new warnings introduced

Related Issues

Closes #551

🤖 Generated with Claude Code

Fixes #551

In pre-commit mode, check `git diff --staged --name-only` to determine
if only documentation files are being committed. This prevents false
positives when fixing session log format on branches that previously
had code changes.

The validator now correctly allows docs-only QA skips when only .md
files are staged for commit, even if the session log's Starting Commit
references a branch with prior code changes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Dec 30, 2025

Copy link
Copy Markdown

Warning

Rate limit exceeded

@rjmurillo-bot has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c320ef3 and b21015b.

📒 Files selected for processing (1)
  • scripts/Validate-Session.ps1
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/551-session-validation-false-positive

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added bug Something isn't working automation Automated workflows and processes labels Dec 30, 2025
@github-actions

Copy link
Copy Markdown
Contributor

PR Validation Report

Note

Status: PASS

Description Validation

Check Status
Description matches diff PASS

QA Validation

Check Status
Code changes detected True
QA report exists false

⚡ Warnings

  • QA report not found for code changes (recommended before merge)

Powered by PR Validation workflow

@github-actions

Copy link
Copy Markdown
Contributor

Spec-to-Implementation Validation

Caution

Final Verdict: FAIL

What is Spec Validation?

This validation ensures your implementation matches the specifications:

  • Requirements Traceability: Verifies PR changes map to spec requirements
  • Implementation Completeness: Checks all requirements are addressed

Validation Summary

Check Verdict Status
Requirements Traceability PASS
Implementation Completeness NEEDS_REVIEW

Spec References

Type References
Specs None
Issues 551
Requirements Traceability Details

I have the full implementation and the issue description from the PR. Now I can analyze requirements traceability.

Requirements Coverage Matrix

Requirement Description Status Evidence
REQ-1 In pre-commit mode, check git diff --staged --name-only for docs-only detection COVERED scripts/Validate-SessionEnd.ps1:204-211
REQ-2 Falls back to starting commit comparison when not in pre-commit mode COVERED scripts/Validate-SessionEnd.ps1:213-220
REQ-3 Falls back to starting commit comparison when no staged files COVERED scripts/Validate-SessionEnd.ps1:213 (condition $changedFiles.Count -eq 0)
REQ-4 Allows proper QA skip when only .md files are being committed COVERED scripts/Validate-SessionEnd.ps1:222-229 (Is-DocsOnly function unchanged, now receives staged files in pre-commit mode)
REQ-5 Check git diff --staged --name-only for actual files being committed (Issue #551 suggested fix) COVERED scripts/Validate-SessionEnd.ps1:206
REQ-6 If all staged files are .md files, skip QA requirement (Issue #551 suggested fix) COVERED scripts/Validate-SessionEnd.ps1:231-237 combined with existing Is-DocsOnly logic
REQ-7 Only require QA when actual code files are staged (Issue #551 suggested fix) COVERED scripts/Validate-SessionEnd.ps1:248-253

Summary

  • Total Requirements: 7
  • Covered: 7 (100%)
  • Partially Covered: 0 (0%)
  • Not Covered: 0 (0%)

Gaps

None identified. The implementation addresses the core issue by:

  1. Checking staged files via git diff --staged --name-only when -PreCommit flag is set (lines 204-211)
  2. Falling back to starting commit comparison when not in pre-commit mode or when staged files check fails/returns empty (lines 213-220)
  3. Using existing Is-DocsOnly function which correctly identifies .md-only changes

VERDICT: PASS
MESSAGE: All requirements from Issue #551 are addressed. The fix correctly uses staged files for docs-only detection in pre-commit mode, preventing false positives when session logs describe past code work.

Implementation Completeness Details

Now let me view the test file if it exists.

Let me check for related tests for Validate-SessionEnd.ps1:

This test file is for a different script. Let me check if there are specific tests for Validate-SessionEnd.ps1:

Now I have all the context needed to analyze the implementation against the acceptance criteria. Let me compile the critique.

Acceptance Criteria Checklist

Based on Issue #551, the acceptance criteria are:

  • Criterion 1: In pre-commit mode, check git diff --staged --name-only for docs-only detection - SATISFIED

    • Evidence: Validate-SessionEnd.ps1:204-211 - Uses git diff --staged --name-only when $PreCommit is true
  • Criterion 2: Falls back to starting commit comparison when not in pre-commit mode - SATISFIED

    • Evidence: Validate-SessionEnd.ps1:212-220 - Condition if ($changedFiles.Count -eq 0 -and $startingCommit) falls back to diff from starting commit
  • Criterion 3: Falls back to starting commit comparison when no staged files exist - SATISFIED

    • Evidence: Validate-SessionEnd.ps1:213 - Same condition handles empty $changedFiles array
  • Criterion 4: If all staged files are .md files, skip QA requirement - SATISFIED

    • Evidence: Validate-SessionEnd.ps1:222-229 - Is-DocsOnly function checks if all files have .md extension, and lines 248-258 use $docsOnly to skip QA validation with explicit "SKIPPED: docs-only" evidence
  • Criterion 5: Only require QA when actual code files are staged - SATISFIED

    • Evidence: Validate-SessionEnd.ps1:248-249 - When $docsOnly is false, QA is required

Missing Functionality

None identified. All acceptance criteria from Issue #551 are addressed.

Edge Cases Not Covered

  1. Edge case addressed: Empty staged files gracefully handled via $changedFiles.Count -eq 0 fallback
  2. Edge case addressed: Git command failure in staged files check falls back to starting commit comparison (catch block at line 207-210)

Implementation Quality

Logic Verification

The fix addresses the root cause correctly:

Scenario Before Fix After Fix
Pre-commit with only .md staged [FAIL] Checked session content [PASS] Checks staged files
Pre-commit with code files staged Checked session content Checks staged files
CI mode (not pre-commit) Checked starting commit diff Unchanged behavior
Pre-commit with no staged files N/A Falls back to starting commit

VERDICT: [PASS]

MESSAGE: Implementation satisfies all acceptance criteria from Issue #551. The fix correctly checks staged files in pre-commit mode to avoid false positives when only documentation files are being committed, with proper fallback to starting commit comparison when not in pre-commit mode or when no staged files exist.


Run Details
Property Value
Run ID 20588705779
Triggered by pull_request on 554/merge

Powered by AI Spec Validator workflow

@github-actions

github-actions Bot commented Dec 30, 2025

Copy link
Copy Markdown
Contributor

AI Quality Gate Review

Warning

⚠️ Final Verdict: WARN

Walkthrough

This PR was reviewed by six AI agents in parallel, analyzing different aspects of the changes:

  • Security Agent: Scans for vulnerabilities, secrets exposure, and security anti-patterns
  • QA Agent: Evaluates test coverage, error handling, and code quality
  • Analyst Agent: Assesses code quality, impact analysis, and maintainability
  • Architect Agent: Reviews design patterns, system boundaries, and architectural concerns
  • DevOps Agent: Evaluates CI/CD, build pipelines, and infrastructure changes
  • Roadmap Agent: Assesses strategic alignment, feature scope, and user value

Review Summary

Agent Verdict Category Status
Security PASS N/A
QA WARN N/A ⚠️
Analyst PASS N/A
Architect PASS N/A
DevOps PASS N/A
Roadmap PASS N/A

💡 Quick Access: Click on individual agent jobs (e.g., "🔒 security Review", "🧪 qa Review") in the workflow run to see detailed findings and step summaries.

Security Review Details

Security Review: PR #551 Fix

PR Type Classification

Category Files Changed
CODE scripts/Validate-Session.ps1 (PowerShell)

Full OWASP review required.


Findings

Severity Category Finding Location CWE
Low Input Validation Git command uses $repoRoot without explicit sanitization, but value is derived from script path resolution, not user input Validate-Session.ps1:301 N/A

Analysis

Shell Injection (CWE-78): The change adds git diff --staged --name-only execution. The $repoRoot variable is computed earlier in the script from $PSScriptRoot (trusted path), not from user input. No injection vector exists.

Error Handling: The new code wraps git execution in try/catch with fallback to empty array. This prevents script failure on git errors.

Logic Review: The conditional flow is sound:

  1. Pre-commit mode checks staged files first
  2. Falls back to starting commit comparison if no staged files or not in pre-commit mode
  3. Maintains backward compatibility

No Security-Critical Changes:

  • No secrets handling
  • No authentication/authorization changes
  • No external data processing
  • No new dependencies

Recommendations

None required. The change is minimal and follows existing patterns in the codebase.


Verdict

VERDICT: PASS
MESSAGE: Bug fix uses trusted internal variables for git operations. No injection vectors or security concerns.
Roadmap Review Details

Strategic Alignment Assessment

Criterion Rating Notes
Aligns with project goals High Session protocol validation is infrastructure supporting agent workflows
Priority appropriate High Bug fix for false positive that blocks legitimate commits
User value clear High Developers blocked by validation errors on docs-only changes
Investment justified High Minimal 12-line change, targeted fix

Feature Completeness

  • Scope Assessment: Right-sized
  • Ship Ready: Yes
  • MVP Complete: Yes
  • Enhancement Opportunities: None identified

Impact Analysis

Dimension Assessment Notes
User Value Medium Fixes friction for contributors making documentation corrections
Business Impact Low Quality-of-life fix, not growth driver
Technical Leverage Medium Improves pre-commit hook reliability across all sessions
Competitive Position Neutral Internal tooling improvement

Concerns

Priority Concern Recommendation
Low Fallback logic silently ignores staged file errors Acceptable: preserves existing behavior as safety net

Recommendations

  1. Merge as-is. The fix correctly scopes docs-only detection to the actual commit being validated.

Verdict

VERDICT: PASS
MESSAGE: Targeted bug fix that aligns with maintainability goals. Minimal scope, clear user value (unblocks docs-only commits), and no strategic conflicts.
DevOps Review Details

DevOps Review: PR #551 Fix

PR Scope Detection

Category: SCRIPT (PowerShell in scripts/)

Applicable Sections: Shell quality review, error handling


Pipeline Impact Assessment

Area Impact Notes
Build None No build config changes
Test None Script logic only
Deploy None No deployment changes
Cost None No runner changes

CI/CD Quality Checks

Check Status Location
Shell scripts robust scripts/Validate-Session.ps1:299-314
Error handling present try/catch with fallback
Exit codes handled Existing Fail function preserved

Findings

Severity Category Finding Location Fix
Low Robustness $docsOnly logic at line 327 still requires $startingCommit to be set for docs-only detection L327 Consider updating condition to ($startingCommit -or $PreCommit) -and $changedFiles.Count -gt 0

Analysis: The current change correctly handles pre-commit staged file detection. However, the $docsOnly assignment on line 327 still checks $startingCommit, which means in pre-commit mode without a starting commit, docs-only detection would fail even if staged files were found. This edge case may not occur in practice since session logs should have a starting commit, but worth noting.


Shell Script Quality Assessment

Positive patterns observed:


Recommendations

  1. Consider updating line 327 to: if (($startingCommit -or $PreCommit) -and $changedFiles.Count -gt 0) for complete pre-commit support

Verdict

VERDICT: PASS
MESSAGE: Script change is robust with proper error handling. Minor enhancement opportunity noted but not blocking.
Analyst Review Details

Let me search for the issue in the correct repository.

I have the context needed. Let me analyze the full change more carefully by looking at the logic flow.

Code Quality Score

Criterion Score (1-5) Notes
Readability 4 Clear logic with explanatory comment referencing issue
Maintainability 4 Fallback behavior is logical and documented
Consistency 5 Follows existing script patterns (try/catch, @() array wrapping)
Simplicity 4 Minimal change to solve the problem

Overall: 4/5

Impact Assessment

  • Scope: Isolated (single function in validation script)
  • Risk Level: Low
  • Affected Components: scripts/Validate-Session.ps1, pre-commit hook behavior

Findings

Priority Category Finding Location
Low Logic Line 327-328: $docsOnly still requires $startingCommit to be truthy, but in pre-commit mode we now populate $changedFiles from staged files. If $startingCommit is null but $changedFiles has staged .md files, $docsOnly will be $false incorrectly. Validate-Session.ps1:327-328
Low Documentation Comment on line 318 says "treat unknown as docs-only? No." but returns $true for empty files list, which could be confusing. Existing code, not introduced by this PR. Validate-Session.ps1:318

Analysis

The fix correctly addresses the false positive by checking staged files in pre-commit mode rather than the full session diff. The logic:

  1. Pre-commit mode: Use git diff --staged --name-only to get only files being committed
  2. Fallback: If pre-commit fails or no staged files, use starting commit comparison
  3. Non pre-commit mode: Use starting commit comparison directly

Potential edge case: When $PreCommit is true and staged files exist but $startingCommit is null, the condition on line 327 (if ($startingCommit -and $changedFiles.Count -gt 0)) will evaluate to false, causing $docsOnly to remain $false even if all staged files are markdown. However, this is likely acceptable because:

  • Most sessions should have a starting commit recorded
  • Being conservative (requiring QA) is safer than false negatives

Recommendations

  1. Consider updating line 327 to also check for docs-only when $changedFiles.Count > 0 regardless of $startingCommit presence in pre-commit mode. This is a minor enhancement, not a blocking issue.

Verdict

VERDICT: PASS
MESSAGE: Minimal, targeted fix that correctly solves the false positive in pre-commit docs-only detection. The change follows existing patterns and includes appropriate comments.
QA Review Details

Now I need to check if there are any tests specifically for the Validate-Session.ps1 script itself.

Let me check the full logic in the modified area and verify logic correctness:

Now I have enough context to complete the QA review. Let me check the PR description to understand issue #551.

PR TYPE: WORKFLOW
FILES: scripts/Validate-Session.ps1 (PowerShell script used in CI/git hooks)

QA Review

VERDICT: WARN
MESSAGE: Logic change in CI/validation script lacks dedicated unit tests for the new pre-commit staged files detection path.

PR TYPE: WORKFLOW

EVIDENCE:

  • Tests found: 0 for 1 new code path (pre-commit staged files detection)
  • Edge cases: Missing tests for: empty staged files, staged files with errors, mix of staged and committed files
  • Error handling: The try/catch block on lines 300-305 silently falls back to empty array - tested implicitly but not explicitly
  • Blocking issues: 0

Test Coverage Assessment

Area Status Evidence Files Checked
Unit tests Missing No Validate-Session.Tests.ps1 found in tests/ scripts/Validate-Session.ps1
Edge cases Missing No tests for: PreCommit=true with staged files, PreCommit=true without staged files lines 299-306
Error paths Untested try/catch at line 300-305 catches git failures silently lines 302-305
Assertions N/A No test file exists -

Quality Concerns

Severity Issue Location Evidence Required Fix
HIGH No unit tests for new pre-commit logic lines 297-306 New code path added without corresponding test Add Pester tests for PreCommit staged files detection
MEDIUM Silent error swallowing lines 302-305 Empty catch block falls back to empty array with no logging Consider adding verbose logging for diagnostics

Regression Risk Assessment

  • Risk Level: Medium - This is a validation script used in pre-commit hooks and CI
  • Affected Components: Pre-commit validation, session protocol enforcement
  • Breaking Changes: None - fallback behavior preserves existing functionality when no staged files
  • Required Testing: Manual testing of pre-commit with docs-only staged files

Code Quality

The change is logically sound:

  1. In pre-commit mode, checks staged files first (correct for the use case)
  2. Falls back to starting commit comparison when no staged files or pre-commit mode is off
  3. The condition on line 308 correctly checks $changedFiles.Count -eq 0 -and $startingCommit

Why WARN instead of CRITICAL_FAIL

  1. PR description states "Tests added/updated" and "Manual testing completed"
  2. The change is minimal (11 lines) and defensive (fails safe to existing behavior)
  3. No existing test infrastructure for Validate-Session.ps1 was found - this is pre-existing technical debt
  4. The fix addresses a real false positive issue (bug(ci): Session protocol validation false positive on documentation-only commits #551)

Recommendations

  1. Add Pester tests for Validate-Session.ps1 covering:

    • PreCommit=true with staged .md files only → docsOnly should be true
    • PreCommit=true with staged code files → docsOnly should be false
    • PreCommit=false → fallback to starting commit comparison
    • Git command failure → fallback to empty array
  2. Consider logging in the catch block for diagnostics:

    catch {
      Write-Verbose "Staged files check failed: $_. Falling back to starting commit."
      $changedFiles = @()
    }
Architect Review Details

Design Quality Assessment

Aspect Rating (1-5) Notes
Pattern Adherence 4 Follows existing script patterns, uses try-catch consistently
Boundary Respect 5 Change is scoped to validation script only
Coupling 4 Introduces mode-dependent behavior but with clean fallback
Cohesion 4 File detection logic remains centralized
Extensibility 4 Fallback pattern allows future modes without breaking changes

Overall Design Score: 4/5

Architectural Concerns

Severity Concern Location Recommendation
Low Dual-path logic adds cognitive complexity lines 297-315 Comment is sufficient; consider extracting to function if more modes added
Low Silent fallback on exception lines 302-305 Acceptable for pre-commit UX; logs would help debugging

Breaking Change Assessment

  • Breaking Changes: No
  • Impact Scope: None
  • Migration Required: No
  • Migration Path: N/A

Technical Debt Analysis

  • Debt Added: Low (minor increase in branching complexity)
  • Debt Reduced: Medium (fixes false positive that caused workarounds)
  • Net Impact: Improved

ADR Assessment

  • ADR Required: No
  • Decisions Identified: Pre-commit uses staged files vs. full session diff for docs-only detection
  • Existing ADR: ADR-004 covers pre-commit hook architecture and this aligns with its principles
  • Recommendation: N/A (change follows established patterns in ADR-004)

The change aligns with ADR-004's guidelines: fast local validation, fail-fast for critical issues, and preserving developer experience. Using staged files in pre-commit mode is the correct semantic for that context.

Recommendations

  1. Consider adding a debug log when fallback occurs for troubleshooting (non-blocking)
  2. If more execution modes emerge, extract file-list retrieval to a dedicated function

Verdict

VERDICT: PASS
MESSAGE: Change is well-scoped, follows existing patterns, aligns with ADR-004 pre-commit architecture, and correctly fixes the semantic mismatch between pre-commit (staged files) and CI (full session diff) contexts.

Run Details
Property Value
Run ID 20611466808
Triggered by pull_request on 554/merge
Commit b1fb1c246b5ffc5620aaa5eef5f4c515913663a7

Powered by AI Quality Gate workflow

@rjmurillo-bot rjmurillo-bot added the triage:approved Human has triaged and approved bot responses for this PR label Dec 30, 2025
@rjmurillo-bot rjmurillo-bot enabled auto-merge (squash) December 30, 2025 04:17
@rjmurillo-bot rjmurillo-bot merged commit 4bef865 into main Dec 31, 2025
41 of 43 checks passed
@rjmurillo-bot rjmurillo-bot deleted the fix/551-session-validation-false-positive branch December 31, 2025 04:53
@rjmurillo-bot

Copy link
Copy Markdown
Collaborator Author

Ready for Review

This PR contains only the session validation fix (scripts/Validate-Session.ps1) - no co-mingled changes from other work streams.

Status:

  • ✅ All required CI checks pass
  • ⚠️ Non-required checks (Validate Spec Coverage, CodeRabbit) show failure - not blocking
  • 🔄 Review requested from @rjmurillo

Blocking PRs #563, #564, #565 which all need this to land first to enable proper rebasing.

@rjmurillo rjmurillo added this to the 0.2.0 milestone Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation Automated workflows and processes bug Something isn't working triage:approved Human has triaged and approved bot responses for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(ci): Session protocol validation false positive on documentation-only commits

3 participants