Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ let filesystem = InMemoryFilesystem()
let workspace = Workspace(filesystem: filesystem)
```

After a workspace is created, `workspace.filesystem` exposes the backing filesystem as a normal
`FileSystem`. The property itself is immutable, but the returned filesystem keeps its read/write
capabilities:

```swift
let filesystem: any FileSystem = workspace.filesystem
let data = try await filesystem.readFile(path: "/notes/todo.txt")
```

Persist checkpoint artifacts with file-backed storage:

```swift
Expand Down
6 changes: 5 additions & 1 deletion Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public actor Workspace {

public nonisolated let workspaceId: UUID

let filesystem: any FileSystem
/// The workspace's backing filesystem.
///
/// The property is immutable after initialization, but the returned filesystem retains its normal
/// ``FileSystem`` capabilities.
public nonisolated let filesystem: any FileSystem
let store: any CheckpointStore
let baseCheckpointId: UUID?

Expand Down
13 changes: 13 additions & 0 deletions Tests/WorkspaceTests/CoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,19 @@ struct CoreTests {
#expect(error.description.contains("workspace shim check"))
}

@Test
func `workspace exposes immutable filesystem property`() async throws {
let workspace = Workspace(filesystem: InMemoryFilesystem())

try await workspace.writeFile("/note.txt", content: "hello")

let filesystem: any FileSystem = workspace.filesystem
#expect(try await filesystem.readFile(path: "/note.txt") == Data("hello".utf8))

try await filesystem.writeFile(path: "/direct.txt", data: Data("normal".utf8), append: false)
#expect(try await workspace.readFile("/direct.txt") == "normal")
}

@Test
func `readJSON and writeJSON roundtrip`() async throws {
let fs = InMemoryFilesystem()
Expand Down
Loading