Skip to content

fix: accept BackupOrRestore and reject flushing through a closed handle - #1114

Merged
vbreuss merged 1 commit into
Testably:mainfrom
Mpdreamz:fix/openhandle-options-and-flush
Oct 1, 2026
Merged

vbreuss merged 1 commit into
Testably:mainfrom
Mpdreamz:fix/openhandle-options-and-flush

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

Two small differences from the real file system in the handle support that shipped in 7.1.0.

  • BackupOrRestore: File.OpenHandle rejected FileOptions 0x02000000 (BackupOrRestore). The runtime's options check accepts it from .NET 9 onwards. .NET 8 still rejects it, and the mock now does the same per target.
  • Flushing a closed handle: a stream created from a handle kept accepting Flush, Flush(bool) and FlushAsync after the handle was closed. FileStream throws ObjectDisposedException for these, with the same "Cannot access a closed file." message. Disposing the stream still succeeds in both. The check sits in ThrowIfDisposed, so the other members that use it follow suit.

Both have tests in Testably.Abstractions.Tests, so they also run against the real file system:

  • OpenHandleTests: accepted on .NET 9+, rejected on .NET 8.
  • OpenHandleStreamTests: flushing after the handle is closed.

Testably.Abstractions.Tests passes in Release on net8.0 (12,810 tests), net9.0 (13,289) and net10.0 (13,319), real file system included, and so does Testably.Abstractions.Testing.Tests.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TymoqrVYgZwdNSper5ZZB1

…ndle

- `OpenHandle` accepts `FileOptions` 0x02000000 (BackupOrRestore) on
  .NET 9 and later, as the runtime's options check does. .NET 8 still
  rejects it, and so does the mock there.
- A stream on a handle throws `ObjectDisposedException` from `Flush`,
  `Flush(bool)` and `FlushAsync` once the handle is closed, as
  `FileStream` does. Disposing it still succeeds.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TymoqrVYgZwdNSper5ZZB1
Copilot AI balanced review requested due to automatic review settings September 30, 2026 20:08

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The implementation is targeted, version-aware, and covered by real-versus-mock parity tests.

Review effort: Balanced
Findings: None

What changed in this PR

Aligns mock handle behavior with the real file system across supported .NET versions.

Changes:

  • Accepts BackupOrRestore on .NET 9+.
  • Rejects flush operations after an owned handle closes.
  • Adds parity tests for both behaviors.
File Description
OpenHandleStreamTests.cs Tests flushing through a closed handle.
OpenHandleTests.cs Tests version-specific BackupOrRestore handling.
MockSafeFileHandleRegistry.cs Allows the option on .NET 9+.
FileStreamMock.cs Treats a closed owned handle as disposed.

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

@mergify

mergify Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@vbreuss
vbreuss merged commit 955dbd4 into Testably:main Oct 1, 2026
13 checks passed
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

This is addressed in release v7.1.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants