GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(client-runtime): reopening a file shows changes saved on another … · Ryoku-dev/hyakki@104f4da

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/client-runtime/src/state
    • projectCommands.test.ts
    • projectCommands.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/client-runtime/src/state/projectCommands.test.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/projectCommands.test.ts
+38-1Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const makeHarness = Effect.fn("TestProjectCommands.makeHarness")(function* () {
5252
const readResponse = {
5353
wait: Effect.void as Effect.Effect<void, ProjectReadFileError>,
5454
missing: false,
55+
contents: "old",
5556
};
5657
const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
5758
target: new BearerConnectionTarget({
@@ -76,7 +77,12 @@ const makeHarness = Effect.fn("TestProjectCommands.makeHarness")(function* () {
7677
truncated: false,
7778
exists: false,
7879
}
79-
: { relativePath: "foo", byteLength, contents: "old", truncated: false },
80+
: {
81+
relativePath: "foo",
82+
byteLength,
83+
contents: readResponse.contents,
84+
truncated: false,
85+
},
8086
);
8187
}),
8288
[WS_METHODS.projectsWriteFile]: () =>
@@ -146,6 +152,37 @@ const makeHarness = Effect.fn("TestProjectCommands.makeHarness")(function* () {
146152
return { registry, storedProject, openScratch, commands, metadataRequests, readResponse };
147153
});
148154

155+
describe("readFile", () => {
156+
it.effect("reads the file afresh when it is reopened after another client changed it", () =>
157+
Effect.gen(function* () {
158+
const h = yield* makeHarness();
159+
const query = h.commands.readFile({
160+
environmentId: ENVIRONMENT_ID,
161+
input: { cwd: "/repo", relativePath: "foo" },
162+
});
163+
// Stale-while-revalidate refreshes from a task on the registry scheduler;
164+
// queue behind it so the read sees the revalidation instead of racing it.
165+
const afterScheduledTasks = Effect.callback<void>((resume) => {
166+
h.registry.schedulerAsync.makeDispatcher().scheduleTask(() => resume(Effect.void), 0);
167+
});
168+
const readContents = afterScheduledTasks.pipe(
169+
Effect.andThen(AtomRegistry.getResult(h.registry, query, { suspendOnWaiting: true })),
170+
Effect.map((result) => result.contents),
171+
);
172+
173+
const closeFile = h.registry.mount(query);
174+
expect(yield* readContents).toBe("old");
175+
closeFile();
176+
yield* afterScheduledTasks;
177+
178+
// Saved on another device; this client did not write it.
179+
h.readResponse.contents = "saved elsewhere";
180+
h.registry.mount(query);
181+
expect(yield* readContents).toBe("saved elsewhere");
182+
}),
183+
);
184+
});
185+
149186
describe("writeFile metadata", () => {
150187
it.effect("retires a saved overlay after an equal read succeeds, preserving newer drafts", () =>
151188
Effect.gen(function* () {
Collapse file

‎packages/client-runtime/src/state/projectCommands.ts‎

Copy file name to clipboardExpand all lines: packages/client-runtime/src/state/projectCommands.ts
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export function createProjectEnvironmentAtoms<R, E>(
103103
const readFile = createEnvironmentRpcQueryAtomFamily(runtime, {
104104
label: "environment-data:projects:read-file",
105105
tag: WS_METHODS.projectsReadFile,
106-
staleTimeMs: 30_000,
106+
// A file can change outside this client, so reopening it reads it again. The idle TTL only
107+
// keeps the last contents on screen while that read runs.
108+
staleTimeMs: 0,
107109
idleTtlMs: 5 * 60_000,
108110
onAnswer: (target, _value, registry): Effect.Effect<void> =>
109111
Effect.sync(() => {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.