Skip to content

Commit 60668ae

Browse files
8bitAlexclaude
andauthored
fix(test): portable MkdirAll-failure path for Windows (#101)
* fix(test): portable MkdirAll-failure path for Windows TestWriteIDExclusive_mkdirFailure passed `/dev/null/impossible/path/id` expecting MkdirAll to fail because `/dev/null` is a char-device file. That's only true on POSIX — on Windows there is no `/dev/null`, so MkdirAll happily creates `C:\dev\null\impossible\path\` and the test failed. Switch to a portable trick: create a regular file in t.TempDir(), then pass `<that-file>/impossible/id` as the path. Every OS treats a regular file as a non-directory and refuses to descend into it (POSIX: ENOTDIR, Windows: ERROR_DIRECTORY). MkdirAll returns non-nil either way, which is the contract the test pins. No production code change — the writeIDExclusive function itself behaves correctly on both platforms; only the test setup was platform-specific. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: bump version to 0.17.3 for Windows test hotfix Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0b7d0c8 commit 60668ae

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

site/docs/whats-new.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ description: Feature-by-feature release notes for Raid.
99

1010
User-visible changes per release, latest first. For full commit history see the [GitHub releases page](https://github.com/8bitalex/raid/releases).
1111

12+
## 0.17.3 — upcoming
13+
14+
Test-only hotfix. No behavior change to the shipped binary.
15+
16+
**`TestWriteIDExclusive_mkdirFailure` now passes on Windows.** The test pinned `writeIDExclusive`'s "MkdirAll fails → error returned" contract by passing `/dev/null/impossible/path/id` — a path that only forces `MkdirAll` to fail on POSIX, where `/dev/null` is a char-device file the kernel refuses to descend into. On Windows there is no `/dev/null`, so `MkdirAll` happily created `C:\dev\null\impossible\path\` and the test failed with no returned error. Replaced with a portable file-as-parent-dir trick (write a regular file, then pass a path that treats it as a directory component) which fails `MkdirAll` on both POSIX (ENOTDIR) and Windows (ERROR_DIRECTORY).
17+
1218
## 0.17.2 — upcoming
1319

1420
Eighteen High and Medium pre-v1.0 review fixes. No new features; behavior changes are surgical and called out individually below.

src/internal/telemetry/telemetry_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,9 +1064,24 @@ func TestPurgeID_alreadyAbsent(t *testing.T) {
10641064

10651065
func TestWriteIDExclusive_mkdirFailure(t *testing.T) {
10661066
setupTestEnv(t)
1067-
_, err := writeIDExclusive("/dev/null/impossible/path/id", "test-id")
1067+
// Force MkdirAll to fail in a portable way: create a regular file
1068+
// and pass a path that treats it as a directory component. On
1069+
// POSIX this yields ENOTDIR; on Windows it yields ERROR_DIRECTORY
1070+
// / "the directory name is invalid". Either way MkdirAll returns
1071+
// non-nil, which is the contract the test pins.
1072+
//
1073+
// The previous version passed `/dev/null/impossible/path/id`,
1074+
// which only fails on POSIX (where /dev/null is a char-device
1075+
// file). On Windows there is no /dev/null and MkdirAll happily
1076+
// creates the chain under the current drive, so the test failed.
1077+
dir := t.TempDir()
1078+
blocker := filepath.Join(dir, "blocker")
1079+
if err := os.WriteFile(blocker, []byte("x"), 0600); err != nil {
1080+
t.Fatalf("setup blocker file: %v", err)
1081+
}
1082+
_, err := writeIDExclusive(filepath.Join(blocker, "impossible", "id"), "test-id")
10681083
if err == nil {
1069-
t.Fatal("writeIDExclusive() with impossible path should error")
1084+
t.Fatal("writeIDExclusive() with file-as-parent-dir path should error")
10701085
}
10711086
}
10721087

src/resources/app.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version=0.17.2
1+
version=0.17.3
22
environment=development

0 commit comments

Comments
 (0)