|
9 | 9 | ProviderDriverKind, |
10 | 10 | ProviderInstanceId, |
11 | 11 | ProjectId, |
| 12 | + retainedTerminalHistory, |
12 | 13 | TerminalProviderInstanceNotFoundError, |
13 | 14 | } from "@t3tools/contracts"; |
14 | 15 | import * as HostProcess from "@t3tools/shared/HostProcess"; |
@@ -2262,6 +2263,57 @@ it.layer( |
2262 | 2263 | }).pipe(Effect.scoped), |
2263 | 2264 | ); |
2264 | 2265 |
|
| 2266 | + it.effect("sends bounded attach streams only the history the client retains", () => |
| 2267 | + Effect.gen(function* () { |
| 2268 | + const { manager, ptyAdapter } = yield* createManager(); |
| 2269 | + const maxHistoryBytes = 9; |
| 2270 | + yield* manager.open(openInput()); |
| 2271 | + const process = ptyAdapter.processes[0]!; |
| 2272 | + const published = yield* Deferred.make<void>(); |
| 2273 | + const unsubscribe = yield* manager.subscribe((event) => |
| 2274 | + event.type === "output" && event.data === "yz\n" |
| 2275 | + ? Deferred.succeed(published, undefined).pipe(Effect.asVoid) |
| 2276 | + : Effect.void, |
| 2277 | + ); |
| 2278 | + process.emitData("aaaa\nx名😀"); |
| 2279 | + process.emitData("yz\n"); |
| 2280 | + yield* Deferred.await(published); |
| 2281 | + unsubscribe(); |
| 2282 | + |
| 2283 | + const full = yield* Stream.toPull(manager.attachOutputStream(openInput(), "full")); |
| 2284 | + const bounded = yield* Stream.toPull( |
| 2285 | + manager.attachOutputStream({ ...openInput(), maxHistoryBytes }, "bounded"), |
| 2286 | + ); |
| 2287 | + const expectRetained = Effect.fnUntraced(function* () { |
| 2288 | + const [fullEvents, boundedEvents] = [yield* full, yield* bounded]; |
| 2289 | + const fullSnapshot = fullEvents.at(-1); |
| 2290 | + if (fullSnapshot?.type !== "snapshot") throw new Error("Expected a full snapshot"); |
| 2291 | + expect(boundedEvents.at(-1)).toEqual({ |
| 2292 | + ...fullSnapshot, |
| 2293 | + snapshot: { |
| 2294 | + ...fullSnapshot.snapshot, |
| 2295 | + history: retainedTerminalHistory(fullSnapshot.snapshot.history, maxHistoryBytes), |
| 2296 | + }, |
| 2297 | + }); |
| 2298 | + return fullSnapshot.snapshot.history; |
| 2299 | + }); |
| 2300 | + |
| 2301 | + expect(yield* expectRetained()).toBe("aaaa\nx名😀yz\n"); |
| 2302 | + // The cap starts inside 名, so the tail begins at the next code point. |
| 2303 | + expect(retainedTerminalHistory("aaaa\nx名😀yz\n", maxHistoryBytes)).toBe("😀yz\n"); |
| 2304 | + process.emitData("after\n"); |
| 2305 | + expect(yield* full).toEqual(yield* bounded); |
| 2306 | + |
| 2307 | + yield* publishPastOutputBudget(manager, process); |
| 2308 | + expect(yield* expectRetained()).toMatch(/last\n$/); |
| 2309 | + |
| 2310 | + process.emitExit({ exitCode: 0, signal: 0 }); |
| 2311 | + expect(yield* full).toEqual(yield* bounded); |
| 2312 | + yield* manager.attachStream({ ...openInput(), restartIfNotRunning: true }, () => Effect.void); |
| 2313 | + yield* expectRetained(); |
| 2314 | + }).pipe(Effect.scoped), |
| 2315 | + ); |
| 2316 | + |
2265 | 2317 | it.effect("does not replay in-flight output already included in an observer snapshot", () => |
2266 | 2318 | Effect.gen(function* () { |
2267 | 2319 | const { manager, ptyAdapter } = yield* createManager(); |
|
0 commit comments