Open History to see the last commit
1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5
6import * as BootService from "../cloud/bootService.ts";
7import { runDoctor } from "./doctor.ts";
8import { DatabaseMaintenance } from "../persistence/DatabaseMaintenance.ts";
9
10it.effect(
11 "--fix reclaims space with the service paused and keeps the V1 database, and --dry-run changes nothing",
12 () =>
13 Effect.gen(function* () {
14 const calls: string[] = [];
15 const doctor = (dryRun: boolean) =>
16 runDoctor("/test/statev2.sqlite", { fix: true, dryRun, interactive: false }).pipe(
17 Effect.provide(
18 Layer.mergeAll(
19 NodeServices.layer,
20 Layer.mock(BootService.BootService)({
21 withStopped: (operation) =>
22 Effect.sync(() => calls.push("pause")).pipe(
23 Effect.andThen(operation),
24 Effect.ensuring(Effect.sync(() => calls.push("resume"))),
25 ),
26 }),
27 Layer.succeed(DatabaseMaintenance, {
28 inspect: () =>
29 Effect.succeed({
30 databaseBytes: 2000,
31 reclaimableBytes: 1000,
32 incrementalVacuumEnabled: false,
33 legacyDatabaseBytes: 4000,
34 }),
35 compact: () =>
36 Effect.sync(() => {
37 calls.push("compact");
38 return {
39 beforeBytes: 2000,
40 afterBytes: 1000,
41 deletedEventCount: 1,
42 deletedReceiptCount: 0,
43 };
44 }),
45 removeLegacyDatabase: () => Effect.sync(() => calls.push("remove legacy")),
46 }),
47 ),
48 ),
49 );
50 yield* doctor(true);
51 assert.deepEqual(calls, []);
52 yield* doctor(false);
53 assert.deepEqual(calls, ["pause", "compact", "resume"]);
54 }),
55);