|
1 | 1 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
2 | 2 | import * as Effect from "effect/Effect"; |
3 | 3 | import * as Context from "effect/Context"; |
| 4 | +import * as Deferred from "effect/Deferred"; |
| 5 | +import * as Fiber from "effect/Fiber"; |
4 | 6 | import * as FileSystem from "effect/FileSystem"; |
5 | 7 | import * as Layer from "effect/Layer"; |
6 | 8 | import type * as Path from "effect/Path"; |
@@ -370,6 +372,47 @@ describe("storage cleanup reports and local file policies", () => { |
370 | 372 | }), |
371 | 373 | ), |
372 | 374 | ); |
| 375 | + it.live("keeps a worktree when its thread starts during size measurement", () => |
| 376 | + runCleanupTest( |
| 377 | + Effect.gen(function* () { |
| 378 | + const fs = yield* FileSystem.FileSystem; |
| 379 | + const measuring = yield* Deferred.make<void>(); |
| 380 | + const resume = yield* Deferred.make<void>(); |
| 381 | + let measuredPath: string | undefined; |
| 382 | + const fixture = yield* cleanupFixture.pipe( |
| 383 | + Effect.provideService(FileSystem.FileSystem, { |
| 384 | + ...fs, |
| 385 | + readDirectory: (directory) => |
| 386 | + Effect.gen(function* () { |
| 387 | + if (directory === measuredPath) { |
| 388 | + yield* Deferred.succeed(measuring, undefined); |
| 389 | + yield* Deferred.await(resume); |
| 390 | + } |
| 391 | + return yield* fs.readDirectory(directory); |
| 392 | + }), |
| 393 | + }), |
| 394 | + ); |
| 395 | + measuredPath = yield* fs.realPath(fixture.worktree); |
| 396 | + fixture.setPolicy("tracked-changes"); |
| 397 | + yield* fs.writeFileString(`${fixture.worktree}/notes.txt`, "untracked\n"); |
| 398 | + const cleanup = yield* fixture.service.runNow.pipe(Effect.forkChild); |
| 399 | + yield* Deferred.await(measuring); |
| 400 | + fixture.setThreads([ |
| 401 | + shell({ branch: "feature", worktreePath: fixture.worktree, status: "running" }), |
| 402 | + ]); |
| 403 | + yield* Deferred.succeed(resume, undefined); |
| 404 | + const report = yield* Fiber.join(cleanup); |
| 405 | + expect(report.entries[0]).toMatchObject({ |
| 406 | + outcome: "kept", |
| 407 | + reason: "Thread activity or shared worktree changed since check", |
| 408 | + bytes: null, |
| 409 | + }); |
| 410 | + expect(report.bytesFreed).toBe(0); |
| 411 | + expect(yield* fs.exists(fixture.worktree)).toBe(true); |
| 412 | + expect(yield* fs.readFileString(`${fixture.worktree}/notes.txt`)).toBe("untracked\n"); |
| 413 | + }), |
| 414 | + ), |
| 415 | + ); |
373 | 416 | it("decodes reports from servers without size fields", () => { |
374 | 417 | const report = decodeCleanupReport({ |
375 | 418 | trigger: "manual", |
|
0 commit comments