@@ -111,18 +111,35 @@ const seed = Effect.fn("seedAutoSettleEvidence")(function* (databasePath: string |
111 | 111 | }); |
112 | 112 | await Effect.runPromise( |
113 | 113 | Effect.gen(function* () { |
| 114 | + const fs = yield* FileSystem.FileSystem; |
114 | 115 | const path = yield* Path.Path; |
115 | | - // Resolve before checking so `..` segments cannot leave this worktree's .t3. |
116 | | - const isolatedHome = path.resolve(import.meta.dirname, "../../../.t3"); |
| 116 | + // SQLite follows symlinks, so compare real paths. Missing tails resolve |
| 117 | + // through their nearest existing ancestor and are created as plain entries; |
| 118 | + // a dangling symlink has no real path but SQLite would still create its target. |
| 119 | + const realPathOf: (target: string) => Effect.Effect<string | undefined> = Effect.fn( |
| 120 | + "seedAutoSettleEvidence.realPathOf", |
| 121 | + )(function* (target: string) { |
| 122 | + const real = yield* Effect.option(fs.realPath(target)); |
| 123 | + if (Option.isSome(real)) return real.value; |
| 124 | + const parent = path.dirname(target); |
| 125 | + if (parent === target || Option.isSome(yield* Effect.option(fs.readLink(target)))) |
| 126 | + return undefined; |
| 127 | + const realParent = yield* realPathOf(parent); |
| 128 | + return realParent && path.join(realParent, path.basename(target)); |
| 129 | + }); |
| 130 | + // Resolve the worktree but not .t3 itself: a .t3 link elsewhere is rejected. |
| 131 | + const worktree = yield* realPathOf(path.resolve(import.meta.dirname, "../../..")); |
| 132 | + const isolatedHome = worktree && path.join(worktree, ".t3"); |
117 | 133 | const databasePath = path.resolve(databaseArg ?? ""); |
118 | | - const relative = path.relative(isolatedHome, databasePath); |
119 | | - if ( |
120 | | - databaseArg === undefined || |
121 | | - !relative || |
122 | | - relative.startsWith("..") || |
123 | | - path.isAbsolute(relative) |
124 | | - ) |
125 | | - return yield* Effect.die(new Error(`Expected a database inside ${isolatedHome}`)); |
| 134 | + const isInside = (real: string | undefined) => { |
| 135 | + const relative = isolatedHome && real && path.relative(isolatedHome, real); |
| 136 | + return !!relative && !relative.startsWith("..") && !path.isAbsolute(relative); |
| 137 | + }; |
| 138 | + // Sidecar files are opened next to the database and could be planted links too. |
| 139 | + for (const suffix of ["", "-wal", "-shm", "-journal"]) { |
| 140 | + if (databaseArg === undefined || !isInside(yield* realPathOf(databasePath + suffix))) |
| 141 | + return yield* Effect.die(new Error(`Expected a database inside ${isolatedHome}`)); |
| 142 | + } |
126 | 143 | const database = Sqlite.layerFromPath(databasePath); |
127 | 144 | const stores = Layer.mergeAll( |
128 | 145 | database, |
|