|
1 | 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | +import * as NodeChildProcess from "node:child_process"; |
2 | 3 | import * as NodeFS from "node:fs"; |
3 | 4 | import * as NodeOS from "node:os"; |
4 | 5 | import * as NodePath from "node:path"; |
@@ -182,3 +183,28 @@ it.effect("starts fresh without V1 and never imports over existing V2 state", () |
182 | 183 | Effect.ensuring(Effect.sync(() => NodeFS.rmSync(directory, { recursive: true, force: true }))), |
183 | 184 | ); |
184 | 185 | }); |
| 186 | + |
| 187 | +it.effect("removes copies left by a killed start, but not one that is still running", () => { |
| 188 | + const directory = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-v2-abandoned-")); |
| 189 | + const killed = NodeChildProcess.spawnSync(process.execPath, ["-e", ""]).pid; |
| 190 | + const running = `.v2-import-${process.pid}-Kq81Zx`; |
| 191 | + const unrelated = ".v2-import-not-a-copy"; |
| 192 | + return Effect.gen(function* () { |
| 193 | + for (const name of [`.v2-import-${killed}-Wm3nPa`, ".v2-import-Q3xZ9a", running]) { |
| 194 | + NodeFS.mkdirSync(NodePath.join(directory, name)); |
| 195 | + NodeFS.writeFileSync(NodePath.join(directory, name, "snapshot.sqlite"), "partial copy"); |
| 196 | + } |
| 197 | + NodeFS.mkdirSync(NodePath.join(directory, unrelated)); |
| 198 | + const destinationPath = NodePath.join(directory, "statev2.sqlite"); |
| 199 | + NodeFS.writeFileSync(destinationPath, "existing V2 database"); |
| 200 | + yield* initializeV2Database(destinationPath); |
| 201 | + assert.deepEqual( |
| 202 | + NodeFS.readdirSync(directory).sort(), |
| 203 | + [running, unrelated, "statev2.sqlite"].sort(), |
| 204 | + ); |
| 205 | + assert.equal(NodeFS.readFileSync(destinationPath, "utf8"), "existing V2 database"); |
| 206 | + }).pipe( |
| 207 | + Effect.provide(NodeServices.layer), |
| 208 | + Effect.ensuring(Effect.sync(() => NodeFS.rmSync(directory, { recursive: true, force: true }))), |
| 209 | + ); |
| 210 | +}); |
0 commit comments