@@ -52,6 +52,7 @@ const makeHarness = Effect.fn("TestProjectCommands.makeHarness")(function* () { |
52 | 52 | const readResponse = { |
53 | 53 | wait: Effect.void as Effect.Effect<void, ProjectReadFileError>, |
54 | 54 | missing: false, |
| 55 | + contents: "old", |
55 | 56 | }; |
56 | 57 | const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({ |
57 | 58 | target: new BearerConnectionTarget({ |
@@ -76,7 +77,12 @@ const makeHarness = Effect.fn("TestProjectCommands.makeHarness")(function* () { |
76 | 77 | truncated: false, |
77 | 78 | exists: false, |
78 | 79 | } |
79 | | - : { relativePath: "foo", byteLength, contents: "old", truncated: false }, |
| 80 | + : { |
| 81 | + relativePath: "foo", |
| 82 | + byteLength, |
| 83 | + contents: readResponse.contents, |
| 84 | + truncated: false, |
| 85 | + }, |
80 | 86 | ); |
81 | 87 | }), |
82 | 88 | [WS_METHODS.projectsWriteFile]: () => |
@@ -146,6 +152,37 @@ const makeHarness = Effect.fn("TestProjectCommands.makeHarness")(function* () { |
146 | 152 | return { registry, storedProject, openScratch, commands, metadataRequests, readResponse }; |
147 | 153 | }); |
148 | 154 |
|
| 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 | + |
149 | 186 | describe("writeFile metadata", () => { |
150 | 187 | it.effect("retires a saved overlay after an equal read succeeds, preserving newer drafts", () => |
151 | 188 | Effect.gen(function* () { |
|