Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]> Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: codex <[email protected]>
123 lines
4.0 KiB
TypeScript
123 lines
4.0 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 { GitCoreLive } from "../../git/Layers/GitCore.ts";
|
|
import { GitCore } from "../../git/Services/GitCore.ts";
|
|
import { GitCommandError } 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 GitCoreTestLayer = GitCoreLive.pipe(
|
|
Layer.provide(ServerConfigLayer),
|
|
Layer.provide(NodeServices.layer),
|
|
);
|
|
const CheckpointStoreTestLayer = CheckpointStoreLive.pipe(
|
|
Layer.provide(GitCoreTestLayer),
|
|
Layer.provide(NodeServices.layer),
|
|
);
|
|
const TestLayer = Layer.mergeAll(NodeServices.layer, GitCoreTestLayer, CheckpointStoreTestLayer);
|
|
|
|
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, GitCommandError, GitCore> {
|
|
return Effect.gen(function* () {
|
|
const gitCore = yield* GitCore;
|
|
const result = yield* gitCore.execute({
|
|
operation: "CheckpointStore.test.git",
|
|
cwd,
|
|
args,
|
|
timeoutMs: 10_000,
|
|
});
|
|
return result.stdout.trim();
|
|
});
|
|
}
|
|
|
|
function initRepoWithCommit(
|
|
cwd: string,
|
|
): Effect.Effect<
|
|
void,
|
|
GitCommandError | PlatformError.PlatformError,
|
|
GitCore | FileSystem.FileSystem
|
|
> {
|
|
return Effect.gen(function* () {
|
|
const core = yield* GitCore;
|
|
yield* core.initRepo({ cwd });
|
|
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");
|
|
}),
|
|
);
|
|
});
|
|
});
|