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("--fix reclaims space with the service paused, and --dry-run changes nothing", () =>
11 Effect.gen(function* () {
12 const calls: string[] = [];
13 const doctor = (dryRun: boolean) =>
14 runDoctor("/test/statev2.sqlite", { fix: true, dryRun, interactive: false }).pipe(
15 Effect.provide(
16 Layer.mergeAll(
17 NodeServices.layer,
18 Layer.mock(BootService.BootService)({
19 withStopped: (operation) =>
20 Effect.sync(() => calls.push("pause")).pipe(
21 Effect.andThen(operation),
22 Effect.ensuring(Effect.sync(() => calls.push("resume"))),
23 ),
24 }),
25 Layer.succeed(DatabaseMaintenance, {
26 // An unconverted database: reclaiming space is recommended.
27 inspect: () =>
28 Effect.succeed({
29 databaseBytes: 2000,
30 reclaimableBytes: 1000,
31 incrementalVacuumEnabled: false,
32 }),
33 compact: () =>
34 Effect.sync(() => {
35 calls.push("compact");
36 return {
37 beforeBytes: 2000,
38 afterBytes: 1000,
39 deletedEventCount: 1,
40 deletedReceiptCount: 0,
41 };
42 }),
43 }),
44 ),
45 ),
46 );
47 yield* doctor(true);
48 assert.deepEqual(calls, []);
49 yield* doctor(false);
50 assert.deepEqual(calls, ["pause", "compact", "resume"]);
51 }),
52);