Skip to content

refactor+test: mutation hardening — extract helpers and kill survivors#385

Merged
cmbays merged 7 commits intomainfrom
worktree-rosy-twirling-petal
Mar 16, 2026
Merged

refactor+test: mutation hardening — extract helpers and kill survivors#385
cmbays merged 7 commits intomainfrom
worktree-rosy-twirling-petal

Conversation

@cmbays
Copy link
Owner

@cmbays cmbays commented Mar 16, 2026

Summary

  • Extract pure helper functions from three hotspot files into their helpers modules with targeted unit tests
  • Replace inline endsWith JSON filters across 4 files with shared isJsonFile helper
  • Export and test saved kata CRUD functions that previously had zero test coverage
  • Add targeted unit tests for terminal-state dispatch rejection, diary writing guards, force bypass, synthesis depth override, and nextKeiko no-op paths

Mutation score improvement

File Before After Survived delta
execute.ts 66.74% 69.21% 128 → 116
session-bridge.ts 74.40% 74.68% 45 → 38
cooldown-session.ts 65.38% 65.70% 49 → 48
Overall 71.33% 72.19% 234 → 215

19 surviving mutants killed. Focus on ConditionalExpression, LogicalOperator, EqualityOperator, BlockStatement, MethodExpression, ObjectLiteral mutants (StringLiteral skipped per #375).

New helpers extracted

cooldown-session.helpers.ts: isSyncableBet, collectBridgeRunIds, hasObservations, shouldSyncOutcomes, hasMethod

session-bridge.helpers.ts: findEarliestTimestamp, matchesCycleRef, resolveAgentId, computeBudgetPercent, extractHistoryTokenTotal, sumTokenTotals, countJsonlContent, mapBridgeRunStatus

execute.helpers.ts: hasNoGapsToBridge, hasBlockedGaps, hasBridgedGaps, formatConfidencePercent, hasPipelineLearnings

Test plan

  • npm run typecheck passes
  • npm run lint passes
  • npm run test:unit — 3245 tests pass
  • npm test (unit + integration) — all pass
  • npm run test:mutation — 72.19% (above break threshold 70)
  • CRAP analysis passes on changed files

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added public API for managing saved katas: list, load, save, and delete operations.
    • Enhanced budget and token tracking with improved calculations and reporting.
    • Improved file filtering and status handling across session management.
  • Bug Fixes

    • Enhanced error handling for non-existent and terminal run states.
    • Better validation of gap bridging and outcome synchronization.
  • Tests

    • Expanded test coverage for kata management, helper utilities, and session state transitions.

cmbays and others added 7 commits March 16, 2026 06:57
Extract isSyncableBet, collectBridgeRunIds, hasObservations,
shouldSyncOutcomes, and hasMethod into cooldown-session.helpers.ts
to make them testable independent of side-effecting orchestration.
Wire the helpers back into cooldown-session.ts methods.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extract findEarliestTimestamp, matchesCycleRef, resolveAgentId,
computeBudgetPercent, extractHistoryTokenTotal, sumTokenTotals,
countJsonlContent, and mapBridgeRunStatus into session-bridge.helpers.ts.
Replace inline .endsWith('.json') with shared isJsonFile filter.
Simplify tautological in-progress status mapping.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extract hasNoGapsToBridge, hasBlockedGaps, hasBridgedGaps,
formatConfidencePercent, and hasPipelineLearnings into
execute.helpers.ts with targeted tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Exercise diary writing guards, force bypass, depth override,
nextKeiko no-op without runsDir, and empty incompleteRuns path.
These kill ConditionalExpression and BooleanLiteral mutants in
cooldown-session.ts private orchestration methods.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use the shared isJsonFile helper from file-filters.ts in
workflow-runner.ts and execute.ts instead of inline
.endsWith('.json') callbacks. Kills MethodExpression mutants.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Exercise the ConditionalExpression and EqualityOperator mutants
in getAgentContext by asserting that completed and failed runs
reject dispatch, and non-existent runs throw descriptive errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Export listSavedKatas, loadSavedKata, saveSavedKata, and
deleteSavedKata from execute.ts and add direct tests covering
existsSync guards, JSON parsing errors, schema validation,
and file deletion paths. These kill ConditionalExpression,
BlockStatement, and ObjectLiteral mutants.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR extracts pure helper functions across execute, cooldown-session, and session-bridge modules, then refactors existing code to use these centralized utilities. New saved-kata CRUD functions are exported, and comprehensive test coverage is added for all new helpers and refactored workflows.

Changes

Cohort / File(s) Summary
Execute command helpers
src/cli/commands/execute.helpers.ts, src/cli/commands/execute.helpers.test.ts
Adds five pure helpers: hasNoGapsToBridge, hasBridgedGaps, hasBlockedGaps, formatConfidencePercent, hasPipelineLearnings; each tested for edge cases and typical usage.
Execute command refactoring
src/cli/commands/execute.ts, src/cli/commands/execute.test.ts
Integrates new helpers into execute flow; exports four public CRUD functions for saved katas (listSavedKatas, loadSavedKata, saveSavedKata, deleteSavedKata) with error handling and comprehensive test coverage.
Cooldown session helpers
src/features/cycle-management/cooldown-session.helpers.ts, src/features/cycle-management/cooldown-session.helpers.test.ts
Adds five helpers: isSyncableBet, collectBridgeRunIds, hasObservations, shouldSyncOutcomes, hasMethod; all stateless predicates and collectors with thorough edge-case testing.
Cooldown session refactoring
src/features/cycle-management/cooldown-session.ts, src/features/cycle-management/cooldown-session.unit.test.ts
Replaces inline checks (length, pending-status, method existence) with new helpers; updates runExpiryCheck, loadBridgeRunIdsByBetId, and autoSyncBetOutcomesFromBridgeRuns; adds unit tests for writeRunDiary, complete, and run behavior under various config states.
Session bridge helpers
src/infrastructure/execution/session-bridge.helpers.ts, src/infrastructure/execution/session-bridge.helpers.test.ts
Adds eight utilities: mapBridgeRunStatus, findEarliestTimestamp, matchesCycleRef, resolveAgentId, computeBudgetPercent, extractHistoryTokenTotal, sumTokenTotals, countJsonlContent; includes budget math, token extraction, and JSONL counting.
Session bridge refactoring
src/infrastructure/execution/session-bridge.ts, src/infrastructure/execution/session-bridge.unit.test.ts
Centralizes JSON-file filtering via isJsonFile; replaces manual timestamp, cycle-ref, agent-id, token, and budget computations with helpers; adds three unit tests for getAgentContext rejection on terminal/non-existent runs.
Workflow runner filter update
src/features/execute/workflow-runner.ts
Replaces endsWith('.json') string checks with centralized isJsonFile predicate in artifact scanning and listing.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Possibly related PRs

Poem

🐰 Helpers hop and gather near,
Pure and tested, crystal clear!
No more checks scattered 'round,
Centralized logic, safe and sound!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main objective: extracting helper functions (mutation hardening) and improving test coverage to eliminate surviving mutants.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch worktree-rosy-twirling-petal
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@cmbays cmbays merged commit ec2fea2 into main Mar 16, 2026
1 of 3 checks passed
@cmbays cmbays deleted the worktree-rosy-twirling-petal branch March 16, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant