Skip to content

Commit c8e7263

Browse files
committed
test(config): accept IOException from the atomic config-write path
The atomic-write seam (AtomicFile, introduced earlier in this change) replaces a File.WriteAllText with a temp-write + File.Move. Writing to a path that is a directory therefore now throws IOException ('Is a directory') from File.Move rather than the UnauthorizedAccessException that File.WriteAllText raised, so SubmitCurrentConfigurationAsync_surfaces_persistence_exception_to_awaited_caller asserted the wrong exact type. The test's contract is that the awaited path surfaces (does not swallow) a persistence failure. Assert that a persistence IO exception propagates — either IOException or UnauthorizedAccessException, robust across OS/write mechanism — while still rejecting an unexpected exception type. Production write surfaces already catch both types, so there is no runtime gap.
1 parent 9ce209b commit c8e7263

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/Netclaw.Cli.Tests/Tui/Config/SearchConfigEditorViewModelTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,15 @@ public async Task SubmitCurrentConfigurationAsync_surfaces_persistence_exception
150150
using var vm = CreateBraveEditorWithSuccessfulProbe();
151151
ReplaceConfigFileWithDirectory();
152152

153-
await Assert.ThrowsAsync<UnauthorizedAccessException>(
153+
// The awaited path surfaces the persistence failure to the caller (unlike the from-input path,
154+
// which catches it into a status). The exact type depends on the OS/write mechanism — the
155+
// atomic write's File.Move onto a directory throws IOException, a denied open throws
156+
// UnauthorizedAccessException — so accept either persistence-IO exception rather than pinning
157+
// one, while still rejecting an unexpected exception.
158+
var ex = await Assert.ThrowsAnyAsync<SystemException>(
154159
() => vm.SubmitCurrentConfigurationAsync(TestContext.Current.CancellationToken));
160+
Assert.True(ex is IOException or UnauthorizedAccessException,
161+
$"Expected a persistence IO exception, got {ex.GetType().Name}: {ex.Message}");
155162
}
156163

157164
[Fact]

0 commit comments

Comments
 (0)