Skip to content

Speed up integration-test fixtures on Windows (shrink copied transcripts; skip symlink tests when unavailable)#249

Merged
cboos merged 3 commits into
mainfrom
dev/win-test-speedup
Jun 30, 2026
Merged

Speed up integration-test fixtures on Windows (shrink copied transcripts; skip symlink tests when unavailable)#249
cboos merged 3 commits into
mainfrom
dev/win-test-speedup

Conversation

@cboos

@cboos cboos commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Part of #248.

Problem

The test suite is far slower on Windows than Linux. Profiling the worst
offenders — the test_integration_realistic.py family (18 of the 25
slowest tests, 30–45s each) — showed the cost is not the
shutil.copytree of the fixture data (~0.15s) but the repeated
rendering + cache build of the large fixture transcripts, which every
function-scoped test re-does. A couple of fixture session files are ~5 MB
each and dominate.

Change

  • Shrink oversized transcripts in the copied fixture data only
    (_shrink_large_transcripts), leaving the source tree pristine so
    volume-sensitive tests (test_performance, test_dag*, …) keep the
    full data. The truncation is a leading-prefix cut, which is DAG-safe:
    an entry's parentUuid always refers to an earlier line, so dropping
    the tail removes only leaf descendants. agent-/subagents files and
    content-sensitive fixtures stay below the 600 KB threshold.
  • Skip the symlink-based aggregate tests when symlinks aren't
    available.
    On Windows without Developer Mode/elevation, os.symlink
    raises OSError [WinError 1314]; the tests now probe capability once
    and skipif, so they still run everywhere symlinks work
    (Linux/macOS/elevated Windows).

Results (local Windows)

Scope Before After
test_integration_realistic.py (serial) 150.3s 93.2s (−38%)
Full unit suite (-n auto) 185.7s 146.9s (−21%)

No production code is touched; the coverage trade-off is documented in the
fixture module. This is an absolute speedup (it helps Linux
proportionally too); the Windows/Linux ratio is addressed by the
companion PRs tracked in #248.

Summary by CodeRabbit

  • Bug Fixes
    • Improved test reliability and speed by reducing oversized temporary transcript files during realistic integration runs.
    • Adjusted scan/characterization tests to automatically skip on platforms that don’t permit symlink creation, avoiding failures in restricted environments.

cboos and others added 2 commits June 25, 2026 10:17
The realistic-integration tests exercise behavior (hierarchy
processing, caching, CLI flags, regeneration), not raw data volume,
yet rendering cost scales with transcript size. Two fixture session
files are ~5 MB each and get re-rendered in every function-scoped
copy, dominating suite wall-time — on Windows especially, where the
per-message render work (not copytree, which measured at ~0.15s) is
the bottleneck.

Prefix-truncate oversized session files in the *copy* only, leaving
the source tree pristine so volume-sensitive tests (test_performance,
test_json_real_projects, test_dag*) keep the full data. A leading
prefix is DAG-safe: an entry's parentUuid always refers to an earlier
line, so dropping the tail removes only leaf descendants. agent-/
subagents files and the teammates/JSSoundRecorder fixtures are left
intact (the 600 KB threshold sits above their largest files).

Before/after (Windows, this file, serial):
  150.3s -> 93.2s  (-38%)
Full unit suite (-n auto --dist=worksteal):
  185.7s -> 146.9s (-21%)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
TestIndexInlineAggregateLoopCharacterization creates a symlink to
discover a synthetic project. On Windows without elevation/Developer
Mode, os.symlink raises OSError [WinError 1314], failing all three
tests. Probe symlink capability once at import and skipif the class,
so the suite is green on stock Windows while still running the tests
everywhere symlinks work (Linux/macOS/elevated Windows).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 486f3dd3-6c65-4733-b514-9d0276d0ce89

📥 Commits

Reviewing files that changed from the base of the PR and between f3bc27c and 9014816.

📒 Files selected for processing (1)
  • test/test_integration_realistic.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/test_integration_realistic.py

📝 Walkthrough

Walkthrough

Integration test fixtures now shrink oversized standalone JSONL transcripts after copying project trees, and characterization tests now skip symlink-dependent coverage when symlink creation is unavailable.

Changes

Test Stability Improvements

Layer / File(s) Summary
Large transcript shrinking in integration fixtures
test/test_integration_realistic.py
Adds module-level constants and a _shrink_large_transcripts(projects_dir) helper; temp_projects_copy and projects_with_cache fixtures call it after shutil.copytree.
Symlink capability probe and skipif guard
test/test_session_scan_characterization.py
Adds module-level _symlinks_supported() probe and _SYMLINKS_SUPPORTED constant; applies pytest.mark.skipif to the index inline-aggregate characterization test class.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • daaain/claude-code-log#186: Introduced the index inline-aggregate characterization tests in test/test_session_scan_characterization.py that are now guarded with the symlink skipif decorator.

Poem

🐇 Hop hop, the tests grow light,
Trimming transcripts down just right.
Where symlinks cannot start their dance,
The tests take a respectful chance.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 changes: speeding up Windows integration tests by shrinking copied transcripts and skipping symlink tests when unsupported.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev/win-test-speedup

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/test_integration_realistic.py`:
- Around line 71-77: The truncation logic in the JSONL fixture copy path can
still write a partial record when no complete line exists within the kept
prefix. Update the truncation step around the `cut`/`last_newline` handling so
that `load_transcript()` only receives complete JSONL lines: if `last_newline`
is not found within the kept prefix, skip writing the truncated file (or
otherwise avoid writing any partial object) before `jsonl_file.write_bytes` is
called.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ba425536-a218-4d4d-8a49-0e92d235b323

📥 Commits

Reviewing files that changed from the base of the PR and between 4bd633f and f3bc27c.

📒 Files selected for processing (2)
  • test/test_integration_realistic.py
  • test/test_session_scan_characterization.py

Comment thread test/test_integration_realistic.py
In _shrink_large_transcripts, if the kept prefix contains no newline
(the first record alone exceeds the keep size), skip truncating that
file rather than writing a partial JSON record that would parse as
malformed JSONL.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cboos cboos merged commit ac3cc22 into main Jun 30, 2026
17 checks passed
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