Skip to content

test(sessions): run the session lock test on Windows and add a cross-process one - #1115

Merged
kevincodex1 merged 2 commits into
Twigpine:mainfrom
PierrunoYT:test/sessions-windows-lock
Oct 14, 2026
Merged

kevincodex1 merged 2 commits into
Twigpine:mainfrom
PierrunoYT:test/sessions-windows-lock

Conversation

@PierrunoYT

@PierrunoYT PierrunoYT commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

TestSessionFileLockSerializesAcrossStores was skipped on Windows (flock semantics differ on windows), so the LockFileEx implementation in internal/sessions/filelock_windows.go was never covered by a test on the only platform that uses it.

The skip was not needed: LockFileEx locks are per handle, and two Store instances open separate handles, so the test's expectation (the second store's AppendEvent blocks until the first releases) holds on Windows. This PR removes the skip.

It also adds TestSessionFileLockBlocksAnotherProcessUntilItExits, a helper-process test in the same style as lockutil_test.go: a child process takes the session lock and exits without unlocking, and the parent checks that its AppendEvent blocks while the child holds the lock and proceeds once the child exits (the OS releases the lock). It runs on all platforms.

Test-only change. The other skips the issue lists (oauth/store_test.go, config/writer_test.go) and migrating sessions onto lockutil are not included.

Linked issue

Fixes #1104

Note: #1104 does not currently carry the issue-approved label. Opening this anyway at the author's request; it can be held until the issue is approved.

Verification

  • Both tests pass on Windows; the unskipped test passed 20 of 20 runs, the new one 10 of 10.
  • Mutation check on Windows: replacing the LockFileEx call with a no-op makes both fail (storeB AppendEvent completed while storeA held the OS lock, and AppendEvent completed while another process held the session lock); the original code was restored afterwards. So the tests now guard the Windows lock.
  • go build ./..., go vet ./internal/sessions/, gofmt -l internal/sessions, git diff --cached --check clean; go test ./internal/sessions/ passes.
  • Only run on Windows. The unix path (flock) should behave the same for both tests, but that is left to CI. -race, full go test ./..., smoke and make targets were not run locally.

Checklist

  • The linked issue already has the issue-approved label. (not yet)
  • go build ./..., go vet ./..., and go test ./... pass locally. (build passes; vet and tests only for internal/sessions)
  • gofmt clean.
  • Tests added/updated for the change (and run under -race where relevant). (tests added; -race not run locally)
  • UI changes include screenshots or a short recording where possible. (no UI change)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added coverage verifying that session event appends wait for a lock held by another process and proceed after it exits.
    • Enabled the cross-store session-lock serialization test on Windows.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 17:58
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: Twigpine/zero/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 699ac88c-66c0-4fb2-8651-9acb82fdf676
📥 Commits

Reviewing files that changed from the base of the PR and between 4dc603f and 921342e.

📒 Files selected for processing: 2
  • internal/sessions/filelock_process_test.go
  • internal/sessions/rewind_test.go
💤 Files with no reviewable changes: 1
  • internal/sessions/rewind_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

The changes add a test that checks session-lock blocking across processes and remove the Windows skip from the existing cross-store lock test.

Changes

Session Lock Tests

Layer / File(s) Summary
Cross-process lock coverage
internal/sessions/filelock_process_test.go, internal/sessions/rewind_test.go
A helper process holds a session lock while the test checks that AppendEvent remains blocked until the helper exits. The existing cross-store serialization test now runs on Windows.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 92134

The session-lock tests can proceed to merge with normal checks; no material issue is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the two main changes: enabling the session-lock test on Windows and adding a cross-process session-lock test.
Linked Issues check Passed Issue #1104 requires coverage for the Windows LockFileEx session-lock path. The PR removes the Windows skip from TestSessionFileLockSerializesAcrossStores and adds `TestSessionFileLockBlocksAnothe…
Out of Scope Changes check Passed The PR changes only session-lock tests. The removed skip and the helper-process test directly support issue #1104. The helper-process setup and synchronization code are required test infrastructure fo…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The helper may release its lock early because the lock-retaining closure is not kept alive.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds Windows and cross-process coverage for session file locking.

Changes:

  • Enables the existing cross-store lock test on Windows.
  • Adds a helper-process test for lock release on process exit.
File Description
internal/​sessions/​rewind_test.go Removes the Windows test skip.
internal/​sessions/​filelock_process_test.go Adds cross-process lock coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/sessions/filelock_process_test.go Outdated
@kevincodex1

Copy link
Copy Markdown
Member

please address copilot comments

PierrunoYT and others added 2 commits October 14, 2026 12:55
…process one

TestSessionFileLockSerializesAcrossStores was skipped on Windows with
"flock semantics differ on windows", so the LockFileEx path in
filelock_windows.go was never exercised by a test on the platform that
uses it. LockFileEx locks are per handle, which is what the test relies
on, so the skip was unnecessary: remove it.

Also add a helper-process test (same pattern as lockutil's) proving the
session lock blocks a different process and is released by the OS when
the holder exits without unlocking.

Both fail on Windows when the lock is replaced by a no-op.

Fixes Twigpine#1104

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The helper discarded the unlock closure returned by lockSession, which is the only reference to the open lock file/handle. GC finalization could close it while the helper waits on stdin, releasing the OS lock early and making the cross-process test pass for the wrong reason. Retain the closure and runtime.KeepAlive it after io.Copy, as the lockutil helper does.
@PierrunoYT
PierrunoYT force-pushed the test/sessions-windows-lock branch from 5709d13 to 921342e Compare October 14, 2026 10:56
@PierrunoYT

Copy link
Copy Markdown
Contributor Author

@kevincodex1 The Copilot comment is addressed in 921342e: the helper now keeps the unlock closure and calls runtime.KeepAlive(unlock) after io.Copy, so GC can't release the lock while the helper waits. The branch is rebased on current main and the thread is resolved. -race couldn't run locally (no cgo toolchain), so that's left to CI.

@kevincodex1
kevincodex1 merged commit e0fb65f into Twigpine:main Oct 14, 2026
10 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.

Windows cross-process session lock test is skipped on Windows

3 participants