The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { expect } from "e2e"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as FileSystem from "effect/FileSystem"; |
| 4 | import * as Schema from "effect/Schema"; |
| 5 | |
| 6 | import { T3_HOME } from "../e2e.config.ts"; |
| 7 | import { runPromise, test, WEB } from "./t3.ts"; |
| 8 | |
| 9 | const decodeSettings = Schema.decodeSync( |
| 10 | Schema.fromJsonString(Schema.Record(Schema.String, Schema.Unknown)), |
| 11 | ); |
| 12 | |
| 13 | test( |
| 14 | "Maintenance reflects edits to a symlinked settings file after restoring its directory", |
| 15 | WEB, |
| 16 | async ({ t3, app, screen }) => { |
| 17 | await t3.project("settings-restore"); |
| 18 | const settingsPath = `${T3_HOME}/userdata/settings.json`; |
| 19 | const active = `${T3_HOME}/active-settings`; |
| 20 | const previous = `${T3_HOME}/old-settings`; |
| 21 | const restored = `${T3_HOME}/restored-settings`; |
| 22 | const original = await runPromise( |
| 23 | Effect.gen(function* () { |
| 24 | const fs = yield* FileSystem.FileSystem; |
| 25 | return yield* fs.readFileString(settingsPath); |
| 26 | }), |
| 27 | ); |
| 28 | const settings = decodeSettings(original); |
| 29 | const contents = (days: number) => |
| 30 | JSON.stringify({ |
| 31 | ...settings, |
| 32 | storageCleanup: { logsAfterDays: days }, |
| 33 | }); |
| 34 | |
| 35 | await runPromise( |
| 36 | Effect.gen(function* () { |
| 37 | const fs = yield* FileSystem.FileSystem; |
| 38 | yield* fs.makeDirectory(active); |
| 39 | yield* fs.makeDirectory(restored); |
| 40 | yield* fs.writeFileString(`${active}/settings.json`, contents(5)); |
| 41 | yield* fs.writeFileString(`${restored}/settings.json`, contents(7)); |
| 42 | yield* fs.symlink(`${active}/settings.json`, `${settingsPath}.link`); |
| 43 | yield* fs.rename(`${settingsPath}.link`, settingsPath); |
| 44 | }), |
| 45 | ); |
| 46 | try { |
| 47 | await t3.open("/settings/maintenance"); |
| 48 | const days = screen.getByLabel("Delete old rotated logs in days"); |
| 49 | await days.scrollIntoView(); |
| 50 | await expect(days).toHaveValue("5"); |
| 51 | await runPromise( |
| 52 | Effect.flatMap(FileSystem.FileSystem, (fs) => |
| 53 | fs.writeFileString(`${active}/settings.json`, contents(7)), |
| 54 | ), |
| 55 | ); |
| 56 | await expect(days).toHaveValue("7"); |
| 57 | |
| 58 | await runPromise( |
| 59 | Effect.gen(function* () { |
| 60 | const fs = yield* FileSystem.FileSystem; |
| 61 | yield* fs.writeFileString(`${restored}/settings.json`, contents(8)); |
| 62 | yield* fs.rename(active, previous); |
| 63 | yield* fs.rename(restored, active); |
| 64 | }), |
| 65 | ); |
| 66 | try { |
| 67 | await expect(days).toHaveValue("8"); |
| 68 | } catch (error) { |
| 69 | await app.screenshot("retention-after-settings-directory-restore"); |
| 70 | throw error; |
| 71 | } |
| 72 | await runPromise( |
| 73 | Effect.gen(function* () { |
| 74 | const fs = yield* FileSystem.FileSystem; |
| 75 | yield* fs.writeFileString(`${active}/settings.json`, contents(9)); |
| 76 | }), |
| 77 | ); |
| 78 | try { |
| 79 | await expect(days).toHaveValue("9"); |
| 80 | await runPromise( |
| 81 | Effect.flatMap(FileSystem.FileSystem, (fs) => |
| 82 | fs.writeFileString(`${active}/settings.json`, contents(11)), |
| 83 | ), |
| 84 | ); |
| 85 | await expect(days).toHaveValue("11"); |
| 86 | } finally { |
| 87 | await app.screenshot("retention-after-settings-directory-restore"); |
| 88 | } |
| 89 | } finally { |
| 90 | await runPromise( |
| 91 | Effect.gen(function* () { |
| 92 | const fs = yield* FileSystem.FileSystem; |
| 93 | yield* fs.writeFileString(`${settingsPath}.original`, original); |
| 94 | yield* fs.rename(`${settingsPath}.original`, settingsPath); |
| 95 | for (const directory of [active, previous, restored]) { |
| 96 | yield* fs.remove(directory, { recursive: true, force: true }); |
| 97 | } |
| 98 | }), |
| 99 | ); |
| 100 | } |
| 101 | }, |
| 102 | ); |