The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | // @effect-diagnostics nodeBuiltinImport:off globalJsonInEffect:off - the scenario seeds an 8 MB file and rewrites settings.json as the repro wrote it. |
| 2 | import * as NodeCrypto from "node:crypto"; |
| 3 | import { expect } from "e2e"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as FileSystem from "effect/FileSystem"; |
| 6 | import * as Schema from "effect/Schema"; |
| 7 | |
| 8 | import { T3_HOME } from "../e2e.config.ts"; |
| 9 | import { run } from "./shell.ts"; |
| 10 | import { runPromise, test, WEB } from "./t3.ts"; |
| 11 | |
| 12 | const decodeSettings = Schema.decodeSync( |
| 13 | Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown)), |
| 14 | ); |
| 15 | |
| 16 | test( |
| 17 | "Cleanup updates the displayed size of a kept worktree", |
| 18 | WEB, |
| 19 | async ({ t3, app, browser, screen }) => { |
| 20 | const project = await t3.project("cleanup-size", { "README.md": "Example project" }); |
| 21 | const settingsPath = `${T3_HOME}/userdata/settings.json`; |
| 22 | const original = await runPromise( |
| 23 | Effect.flatMap(FileSystem.FileSystem, (fs) => fs.readFileString(settingsPath)), |
| 24 | ); |
| 25 | const worktree = `${T3_HOME}/worktrees/cleanup-size-orphan`; |
| 26 | const build = `${worktree}/build`; |
| 27 | const git = (...args: ReadonlyArray<string>) => runPromise(run("git", args, { cwd: project })); |
| 28 | await git("worktree", "add", "--detach", worktree, "HEAD"); |
| 29 | try { |
| 30 | await runPromise( |
| 31 | Effect.gen(function* () { |
| 32 | const fs = yield* FileSystem.FileSystem; |
| 33 | yield* fs.makeDirectory(build); |
| 34 | yield* fs.writeFile(`${build}/bundle.js`, NodeCrypto.randomBytes(8 * 1024 * 1024)); |
| 35 | yield* fs.utimes(worktree, 1, 1); |
| 36 | const settings = decodeSettings(original); |
| 37 | const storageCleanup = |
| 38 | typeof settings.storageCleanup === "object" && settings.storageCleanup !== null |
| 39 | ? settings.storageCleanup |
| 40 | : {}; |
| 41 | yield* fs.writeFileString( |
| 42 | settingsPath, |
| 43 | JSON.stringify({ |
| 44 | ...settings, |
| 45 | storageCleanup: { ...storageCleanup, worktreeOnDelete: true }, |
| 46 | }), |
| 47 | ); |
| 48 | }), |
| 49 | ); |
| 50 | |
| 51 | await t3.open("/settings/maintenance"); |
| 52 | const runCleanup = screen.getByRole("button", "Delete now", { exact: true }); |
| 53 | await runCleanup.tap(); |
| 54 | await screen.getByRole("button", /^Last run/).tap(); |
| 55 | await screen.getByText(/^8\.\d{2} MB$/).waitFor(); |
| 56 | const orphanRow = browser |
| 57 | .locator('#storage-cleanup-last-run [data-slot="settings-row"]') |
| 58 | .filter({ has: screen.getByText(worktree, { exact: true }) }); |
| 59 | await orphanRow.getByText(/^8\.\d{2} MB$/).waitFor(); |
| 60 | |
| 61 | await runPromise( |
| 62 | Effect.gen(function* () { |
| 63 | const fs = yield* FileSystem.FileSystem; |
| 64 | yield* fs.remove(`${build}/bundle.js`); |
| 65 | }), |
| 66 | ); |
| 67 | await runCleanup.tap(); |
| 68 | await runCleanup.waitFor(); |
| 69 | await screen.getByText("No thread uses this worktree", { exact: true }).scrollIntoView(); |
| 70 | try { |
| 71 | await expect(orphanRow.getByText(/^\d+(?:\.\d+)? KB$/)).toBeVisible(); |
| 72 | await expect(browser.locator("#storage-cleanup-last-run")).toContainText( |
| 73 | /\b\d+(?:\.\d+)? KB\b/, |
| 74 | ); |
| 75 | } finally { |
| 76 | await app.screenshot("kept-worktree-after-build-file-removal"); |
| 77 | } |
| 78 | } finally { |
| 79 | await git("worktree", "remove", "--force", worktree); |
| 80 | await runPromise( |
| 81 | Effect.flatMap(FileSystem.FileSystem, (fs) => fs.writeFileString(settingsPath, original)), |
| 82 | ); |
| 83 | } |
| 84 | }, |
| 85 | ); |