Skip to content

test: add file system test suite - #6555

Merged
tim-smart merged 3 commits into
Effect-TS:mainfrom
lloydrichards:test/file-system-suite
Oct 21, 2026
Merged

tim-smart merged 3 commits into
Effect-TS:mainfrom
lloydrichards:test/file-system-suite

Conversation

@lloydrichards

@lloydrichards lloydrichards commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Type

  • Optimization for v4

Description

Extends the shared FileSystem conformance suite (testLayer in packages/effect/test/FileSystem.test-utils.ts) with the cross-adapter coverage from this PR that main did not already have. Node and Deno both run it through their existing test files.

This branch was rebuilt on current main. Since this PR was opened, main gained a shared testLayer that already covers the write flags, cursor and truncate behavior, seek results and overwrite: false, so the new FileSystemTest.ts file was dropped. The remaining additions cover:

  • makeDirectory, remove, copy and rename semantics, including trailing separators and missing sources
  • the full open flag matrix (creation, exclusivity, read and write access)
  • NotFound normalization across path operations, and BadResource when a file is used as a directory
  • zero-filling on extension, scoped temp cleanup when the scope fails, stream and sink edge cases
  • links and symlinks, utimes and preserveTimestamps (mtime only), glob excludes

Where adapters currently disagree (copy with overwrite: false, glob path form, atime under preserveTimestamps), the suite asserts only the behavior both share. Aligning them would be a runtime change and is left for a separate PR.

Test-only, so no changeset.

Closes EFF-2673

Related

@changeset-bot

changeset-bot Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 57585e4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ff8382e-38b3-43e1-9327-f970955e84d9

📥 Commits

Reviewing files that changed from the base of the PR and between cf04641 and f1758ca.

📒 Files selected for processing (1)
  • packages/effect/test/FileSystemTest.ts

📝 Walkthrough

Walkthrough

Adds a reusable layered filesystem conformance suite covering paths, temporary resources, streams, handles, mutations, and adapter capabilities. Node filesystem tests now consume the shared suite and retain focused fixture and truncation-cursor checks.

Changes

Filesystem adapter conformance

Layer / File(s) Summary
Suite harness and path operations
packages/effect/test/FileSystemTest.ts
Adds shared test utilities, layered suite registration, normalized system-error assertions, and coverage for file paths, directories, flags, copying, renaming, and truncation.
Resource and stream lifecycle
packages/effect/test/FileSystemTest.ts
Verifies temporary resource cleanup, unique naming, bounded reads, sink writes, empty and out-of-range streams, and finalization on success or failure.
Handles and file mutations
packages/effect/test/FileSystemTest.ts
Covers handle cursors, open modes, truncation, sparse writes, open-file state, copy overwrite behavior, and rename failure handling.
Adapter capabilities and Node wiring
packages/effect/test/FileSystemTest.ts, packages/platform-node-shared/test/NodeFileSystem.test.ts
Tests links, access checks, timestamps, globbing, watch errors, and symlink errors; wires Node to the shared suite and retains focused fixture and truncation tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested labels: enhancement

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
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.

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

Comment thread packages/effect/test/FileSystemTest.ts Resolved
@coderabbitai coderabbitai Bot added the enhancement New feature or request label Jul 23, 2026
Comment thread packages/effect/test/FileSystemTest.ts Resolved
Comment thread packages/effect/test/FileSystemTest.ts Resolved

@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.

🧹 Nitpick comments (1)
packages/platform-node-shared/test/NodeFileSystem.test.ts (1)

13-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Wrap these Effect test bodies with Effect.fnUntraced.

Each callback only returns Effect.gen; pass Effect.fnUntraced(function*() { ... }) directly to it.effect instead. As per coding guidelines, “In Effect TypeScript code, prefer Effect.fnUntraced over functions that only return Effect.gen.”

Proposed pattern
-  it.effect("...", () =>
-    Effect.gen(function*() {
+  it.effect("...", Effect.fnUntraced(function*() {
       // assertions
-    }))
+    }))

Also applies to: 21-33, 35-46

🤖 Prompt for 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.

In `@packages/platform-node-shared/test/NodeFileSystem.test.ts` around lines 13 -
19, Update the affected it.effect callbacks, including the test at “should read
a pre-existing host file when the fixture exists” and the tests at the
referenced ranges, to pass Effect.fnUntraced(function*() { ... }) directly
instead of an arrow function returning Effect.gen. Preserve each generator’s
existing filesystem operations and assertions.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@packages/platform-node-shared/test/NodeFileSystem.test.ts`:
- Around line 13-19: Update the affected it.effect callbacks, including the test
at “should read a pre-existing host file when the fixture exists” and the tests
at the referenced ranges, to pass Effect.fnUntraced(function*() { ... })
directly instead of an arrow function returning Effect.gen. Preserve each
generator’s existing filesystem operations and assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 10852250-fd39-471d-a7aa-7a8663c896cc

📥 Commits

Reviewing files that changed from the base of the PR and between ed2afb3 and b140b7e.

📒 Files selected for processing (2)
  • packages/effect/test/FileSystemTest.ts
  • packages/platform-node-shared/test/NodeFileSystem.test.ts

Comment thread packages/effect/test/FileSystemTest.ts Outdated
assert.strictEqual(yield* fs.readFileString(renameDestination), "renamed")
}))

// TODO: Define whether overwrite: false succeeds without changing an existing destination or fails with AlreadyExists.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Define whether overwrite: false succeeds without changing an existing destination or fails with AlreadyExists.

What remains undecided:

  • Successful no-op <- copying to an existing destination with overwrite: false succeeds but leaves it untouched. This suits idempotent setup flows.
  • AlreadyExists failure <- it reports that the requested copy did not happen. This suits callers that need to distinguish "copied" from "skipped"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This remains a public-contract question. Node skips an existing destination with overwrite: false; Deno reports AlreadyExists, with its error mapping addressed in #7086. The suite still accepts either outcome and checks that the destination contents are preserved. I updated the TODO with that concrete difference. Leaving this open for a decision on whether success/failure must agree across adapters.

Comment thread packages/effect/test/FileSystemTest.ts Outdated
assertSystemError(error, { tag: "NotFound", method: "open", pathOrDescriptor: missing })
}))

// TODO: Add a deterministic synchronization point before covering stream and sink finalization after interruption.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Add a deterministic synchronization point before covering stream and sink finalization after interruption.

Add a test-only synchronization hook that blocks after the derived handle is acquired? Then interrupt the stream or sink and assert that its handle finalizer runs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The remaining work is a test addition, not a public synchronization API. The existing trackedFs.open wrapper can signal acquisition through a Deferred; then the test can interrupt a blocked stream or sink and assert finalization. I made the TODO specific. Leaving this open because interruption coverage has not been implemented in this comment-only cleanup.

Comment thread packages/effect/test/FileSystemTest.ts Resolved
Comment thread packages/effect/test/FileSystemTest.ts Resolved
Comment thread packages/effect/test/FileSystemTest.ts Outdated
assertSystemError(error, { method: "realPath", pathOrDescriptor: first })
}))

// TODO: Add positive chmod and chown conformance in a POSIX-only metadata capability suite.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Add positive chmod and chown conformance in a POSIX-only metadata capability suite.

should an in memory adapter intentionally omit identity/permission modeling?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Partially answered by #7943: Deno now uses successful chmod to test that writing an existing file preserves its mode. The MemoryFileSystem proposal in #6573 stores permissions and ownership without enforcing a virtual identity. The remaining TODO is positive chmod/chown conformance gated by adapter/host support and ownership privileges. I removed the empty test placeholder. Leaving the coverage work open.

Comment thread packages/effect/test/FileSystemTest.ts Outdated
}
}))

// TODO: Define whether preserveTimestamps guarantees only mtime or both atime and mtime. Node preserves mtime but resets atime.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Define whether preserveTimestamps guarantees only mtime or both atime and mtime.

Node preserves mtime but resets atime, so baseline conformance currently checks only mtime

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The shared test continues to assert mtime preservation. I narrowed the TODO to the unanswered part: whether preserveTimestamps must also preserve atime. The previous blanket statement about Node resetting atime is removed; this cleanup does not establish a stronger timestamp guarantee. Leaving the contract question open.

Comment thread packages/effect/test/FileSystemTest.ts Outdated
assert.isTrue(matches[0].endsWith("src/index.ts"))
}))

// TODO: Add deterministic watcher-registration and subscription-control hooks before specifying event ordering,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Add deterministic watcher-registration and subscription-control hooks before specifying event ordering, normalized paths, or watcher cleanup

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Partially addressed: the Node-specific startWatch helper already waits for a sentinel event before testing changes. I split the TODO into adapter readiness/cleanup coverage and a separate portable event-path decision. Node emits filenames while Deno forwards native event paths; exact native event ordering should not be a prerequisite for cleanup tests. Leaving the remaining work open.

Comment thread packages/effect/test/FileSystemTest.ts Resolved
@lloydrichards lloydrichards changed the title Test/file system suite test: add file system test suite Jul 23, 2026
@lloydrichards
lloydrichards force-pushed the test/file-system-suite branch from b140b7e to cf04641 Compare July 23, 2026 09:36
@IMax153 IMax153 added the 4.0 label Jul 23, 2026
@lloydrichards
lloydrichards force-pushed the test/file-system-suite branch from cf04641 to f1758ca Compare July 23, 2026 19:09
@coderabbitai coderabbitai Bot mentioned this pull request Jul 28, 2026
@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.12 KB 39.12 KB 0.00 KB (0.00%)
basic.ts 7.02 KB 7.02 KB 0.00 KB (0.00%)
batching.ts 10.89 KB 10.89 KB 0.00 KB (0.00%)
brand.ts 6.71 KB 6.71 KB 0.00 KB (0.00%)
cache.ts 11.33 KB 11.33 KB 0.00 KB (0.00%)
config.ts 22.49 KB 22.49 KB 0.00 KB (0.00%)
differ.ts 21.64 KB 21.64 KB 0.00 KB (0.00%)
http-client.ts 26.00 KB 26.00 KB 0.00 KB (0.00%)
http-router.ts 35.67 KB 35.67 KB 0.00 KB (0.00%)
logger.ts 11.68 KB 11.68 KB 0.00 KB (0.00%)
metric.ts 9.26 KB 9.26 KB 0.00 KB (0.00%)
optic.ts 6.93 KB 6.93 KB 0.00 KB (0.00%)
pubsub.ts 15.77 KB 15.77 KB 0.00 KB (0.00%)
queue.ts 12.59 KB 12.59 KB 0.00 KB (0.00%)
schedule.ts 11.57 KB 11.57 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 13.82 KB 13.82 KB 0.00 KB (0.00%)
schema-binary.ts 40.52 KB 40.52 KB 0.00 KB (0.00%)
schema-class.ts 21.34 KB 21.34 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 32.31 KB 32.31 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.50 KB 27.50 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.07 KB 15.07 KB 0.00 KB (0.00%)
schema-string.ts 12.08 KB 12.08 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.00 KB 16.00 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.64 KB 38.64 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 25.69 KB 25.69 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.57 KB 20.57 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.75 KB 20.75 KB 0.00 KB (0.00%)
schema-toFormatter.ts 20.86 KB 20.86 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 25.50 KB 25.50 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 20.86 KB 20.86 KB 0.00 KB (0.00%)
schema.ts 20.53 KB 20.53 KB 0.00 KB (0.00%)
stm.ts 13.87 KB 13.87 KB 0.00 KB (0.00%)
stream.ts 10.12 KB 10.12 KB 0.00 KB (0.00%)

@lloydrichards

Copy link
Copy Markdown
Contributor Author

Since Deno was added in the mean time I've added this too with the suite and even managed to find a bug with the open flag and error normalization

@lloydrichards
lloydrichards force-pushed the test/file-system-suite branch from 206ff16 to 9ea3814 Compare August 3, 2026 12:49
@lloydrichards

lloydrichards commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor Author

I noticed that with #6682 there was a testLayer added that had a bit of overlap with the FileSystemTest suite that I'm adding here. I've ported what was missing and removed it as I feel that it was still a bit thin compared to what I was testing the MemoryFileSystem against (#6573)

@lloydrichards

Copy link
Copy Markdown
Contributor Author

@tim-smart since its been a minute on this PR I just wanted to give you a gentle judge to see if you still want to review it. I understand reviewing tests isn't much fun but there are some open questions i've added comments to which could be points for discussion or further development.

That said, if you think the testLayer from the Deno PR is all you need and don't want to add this test suite then you are also welcome to let me know and close the PR. I can still work with this as a local branch for the work on the MemoryFileSystem as needed.

@lloydrichards

Copy link
Copy Markdown
Contributor Author

I revisited the open questions against the recent Deno work and updated the inline threads. Seek, truncate-cursor behavior, and missing-watch errors are covered now. Working-directory and permission semantics stay adapter-specific.

The two contract questions I’d appreciate input on are:

  1. overwrite: false: Node skips an existing destination successfully, while Deno reports AlreadyExists. Should the shared suite allow both, provided the destination stays unchanged, or require the same outcome?
  2. preserveTimestamps: Is preserving mtime enough for shared conformance, or should this also guarantee atime?

My preference is to keep the current minimum guarantees for this PR and handle stronger guarantees separately. I’ve made the remaining test and error-normalization TODOs concrete so those can progress independently.

@tim-smart
tim-smart enabled auto-merge (squash) October 21, 2026 04:27
@tim-smart
tim-smart merged commit b53e850 into Effect-TS:main Oct 21, 2026
9 of 10 checks passed

This branch had an error being deployed

1 failed deployment
fork — 57585e41 Deployed Oct 21, 2026 by effect-bot via approval-gate #21810
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants