- Switch GitVcsDriver and VcsProcess usages to namespace imports - Update server and integration wiring to use `.layer` consistently - Keep test type annotations aligned with the exported service types
127 lines
4.2 KiB
TypeScript
127 lines
4.2 KiB
TypeScript
import path from "node:path";
|
|
|
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
import { it } from "@effect/vitest";
|
|
import { Effect, FileSystem, Layer, PlatformError, Scope } from "effect";
|
|
import { describe, expect } from "vitest";
|
|
|
|
import { checkpointRefForThreadTurn } from "../Utils.ts";
|
|
import { CheckpointStoreLive } from "./CheckpointStore.ts";
|
|
import { CheckpointStore } from "../Services/CheckpointStore.ts";
|
|
import * as GitVcsDriver from "../../vcs/GitVcsDriver.ts";
|
|
import * as VcsProcess from "../../vcs/VcsProcess.ts";
|
|
import { VcsProcess as VcsProcessService } from "../../vcs/VcsProcess.ts";
|
|
import type { VcsError } from "@t3tools/contracts";
|
|
import { ServerConfig } from "../../config.ts";
|
|
import { ThreadId } from "@t3tools/contracts";
|
|
|
|
const ServerConfigLayer = ServerConfig.layerTest(process.cwd(), {
|
|
prefix: "t3-checkpoint-store-test-",
|
|
});
|
|
const VcsProcessTestLayer = VcsProcess.layer.pipe(Layer.provide(NodeServices.layer));
|
|
const VcsDriverTestLayer = GitVcsDriver.layer.pipe(Layer.provide(VcsProcessTestLayer));
|
|
const CheckpointStoreTestLayer = CheckpointStoreLive.pipe(
|
|
Layer.provideMerge(VcsDriverTestLayer),
|
|
Layer.provideMerge(NodeServices.layer),
|
|
);
|
|
const TestLayer = CheckpointStoreTestLayer.pipe(
|
|
Layer.provideMerge(VcsProcessTestLayer),
|
|
Layer.provideMerge(VcsDriverTestLayer),
|
|
Layer.provideMerge(ServerConfigLayer),
|
|
Layer.provideMerge(NodeServices.layer),
|
|
);
|
|
|
|
function makeTmpDir(
|
|
prefix = "checkpoint-store-test-",
|
|
): Effect.Effect<string, PlatformError.PlatformError, FileSystem.FileSystem | Scope.Scope> {
|
|
return Effect.gen(function* () {
|
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
return yield* fileSystem.makeTempDirectoryScoped({ prefix });
|
|
});
|
|
}
|
|
|
|
function writeTextFile(
|
|
filePath: string,
|
|
contents: string,
|
|
): Effect.Effect<void, PlatformError.PlatformError, FileSystem.FileSystem> {
|
|
return Effect.gen(function* () {
|
|
const fileSystem = yield* FileSystem.FileSystem;
|
|
yield* fileSystem.writeFileString(filePath, contents);
|
|
});
|
|
}
|
|
|
|
function git(
|
|
cwd: string,
|
|
args: ReadonlyArray<string>,
|
|
): Effect.Effect<string, VcsError, VcsProcessService> {
|
|
return Effect.gen(function* () {
|
|
const process = yield* VcsProcessService;
|
|
const result = yield* process.run({
|
|
operation: "CheckpointStore.test.git",
|
|
command: "git",
|
|
cwd,
|
|
args,
|
|
timeoutMs: 10_000,
|
|
});
|
|
return result.stdout.trim();
|
|
});
|
|
}
|
|
|
|
function initRepoWithCommit(
|
|
cwd: string,
|
|
): Effect.Effect<
|
|
void,
|
|
VcsError | PlatformError.PlatformError,
|
|
VcsProcessService | FileSystem.FileSystem
|
|
> {
|
|
return Effect.gen(function* () {
|
|
yield* git(cwd, ["init"]);
|
|
yield* git(cwd, ["config", "user.email", "[email protected]"]);
|
|
yield* git(cwd, ["config", "user.name", "Test"]);
|
|
yield* writeTextFile(path.join(cwd, "README.md"), "# test\n");
|
|
yield* git(cwd, ["add", "."]);
|
|
yield* git(cwd, ["commit", "-m", "initial commit"]);
|
|
});
|
|
}
|
|
|
|
function buildLargeText(lineCount = 5_000): string {
|
|
return Array.from({ length: lineCount }, (_, index) => `line ${String(index).padStart(5, "0")}`)
|
|
.join("\n")
|
|
.concat("\n");
|
|
}
|
|
|
|
it.layer(TestLayer)("CheckpointStoreLive", (it) => {
|
|
describe("diffCheckpoints", () => {
|
|
it.effect("returns full oversized checkpoint diffs without truncation", () =>
|
|
Effect.gen(function* () {
|
|
const tmp = yield* makeTmpDir();
|
|
yield* initRepoWithCommit(tmp);
|
|
const checkpointStore = yield* CheckpointStore;
|
|
const threadId = ThreadId.make("thread-checkpoint-store");
|
|
const fromCheckpointRef = checkpointRefForThreadTurn(threadId, 0);
|
|
const toCheckpointRef = checkpointRefForThreadTurn(threadId, 1);
|
|
|
|
yield* checkpointStore.captureCheckpoint({
|
|
cwd: tmp,
|
|
checkpointRef: fromCheckpointRef,
|
|
});
|
|
yield* writeTextFile(path.join(tmp, "README.md"), buildLargeText());
|
|
yield* checkpointStore.captureCheckpoint({
|
|
cwd: tmp,
|
|
checkpointRef: toCheckpointRef,
|
|
});
|
|
|
|
const diff = yield* checkpointStore.diffCheckpoints({
|
|
cwd: tmp,
|
|
fromCheckpointRef,
|
|
toCheckpointRef,
|
|
});
|
|
|
|
expect(diff).toContain("diff --git");
|
|
expect(diff).not.toContain("[truncated]");
|
|
expect(diff).toContain("+line 04999");
|
|
}),
|
|
);
|
|
});
|
|
});
|