Repository navigation
computer: Export WorkspaceFileStore and WORKSPACE_ROOT #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@cloudflare/computer": patch | ||
| --- | ||
|
|
||
| `WorkspaceFileStore` and `WORKSPACE_ROOT` are exported from `@cloudflare/computer`, so code outside the tools can read and write workspace files without its own helper. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import { SQLiteTestStorage } from "@cloudflare/dofs/testing"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { getWorkspace, Workspace, WORKSPACE_ROOT, WorkspaceFileStore } from "./index.js"; | ||
|
|
||
| describe("the file helper from @cloudflare/computer", () => { | ||
| it("reads missing files as null and writes into new directories", async () => { | ||
| const workspace = new Workspace({ storage: new SQLiteTestStorage() }); | ||
| const files = new WorkspaceFileStore(workspace); | ||
| const path = `${WORKSPACE_ROOT}/notes/today.md`; | ||
|
|
||
| await expect(files.readAll(path)).resolves.toBeNull(); | ||
| await files.write(path, new TextEncoder().encode("ship it")); | ||
| const written = await files.readAll(path); | ||
| expect(written && new TextDecoder().decode(written)).toBe("ship it"); | ||
| await workspace.close(); | ||
| }); | ||
|
|
||
| it("works on a client that has not loaded yet", async () => { | ||
| const workspace = new Workspace({ storage: new SQLiteTestStorage() }); | ||
| const client = getWorkspace({ __getWorkspaceStub: () => Promise.resolve(workspace.stub()) }); | ||
| const files = new WorkspaceFileStore(client); | ||
| const path = `${WORKSPACE_ROOT}/a/b.txt`; | ||
|
|
||
| await expect(files.readAll(path)).resolves.toBeNull(); | ||
| await files.write(path, new TextEncoder().encode("hello")); | ||
| await expect(files.stat(path)).resolves.toMatchObject({ size: 5 }); | ||
| client[Symbol.dispose](); | ||
| await workspace.close(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /** The directory Computer's backends and tools treat as the working root. */ | ||
| export const WORKSPACE_ROOT = "/workspace"; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 New public exports lack example coverage
After adding
WorkspaceFileStoreandWORKSPACE_ROOTto the public API, no runnable example uses either export. The repository requires example updates for public API changes.Learn more
Add a runnable example that imports
WorkspaceFileStoreandWORKSPACE_ROOTfrom the package entrypoint and uses the store with a workspace. Keep the existing source-level test; an example exercises the public integration separately.Was this helpful? React with 👍 or 👎 to provide feedback.