mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 18:55:22 +00:00
51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
buildReplacementHistory,
|
|
findNativeCheckpoint,
|
|
parseNativeCompactionDetails,
|
|
type NativeCompactionDetails,
|
|
} from "../src/native-compaction.ts";
|
|
|
|
const details: NativeCompactionDetails = {
|
|
kind: "pi-compaction",
|
|
version: 1,
|
|
checkpoint: "native",
|
|
modelKey: "openai-codex/openai-codex-responses/gpt-test",
|
|
replacementHistory: [{ type: "compaction", encrypted_content: "opaque" }],
|
|
portableSummary: "portable",
|
|
sourceFingerprint: "abc",
|
|
};
|
|
|
|
test("recognizes only the unified native checkpoint format", () => {
|
|
assert.deepEqual(parseNativeCompactionDetails(details), details);
|
|
assert.equal(parseNativeCompactionDetails({ ...details, kind: "openai-codex-native-compaction" }), undefined);
|
|
assert.equal(parseNativeCompactionDetails({ ...details, portableSummary: undefined }), undefined);
|
|
});
|
|
|
|
test("latest Pi compaction entry is the authoritative native checkpoint", () => {
|
|
const branch = [
|
|
{ type: "message", id: "m1" },
|
|
{ type: "compaction", id: "c1", details },
|
|
] as any;
|
|
const found = findNativeCheckpoint(branch);
|
|
assert.equal(found.status, "valid");
|
|
if (found.status === "valid") assert.equal(found.checkpoint.entryIndex, 1);
|
|
|
|
const shadowed = findNativeCheckpoint([...branch, { type: "compaction", id: "c2", details: { kind: "other" } }] as any);
|
|
assert.equal(shadowed.status, "none");
|
|
const portable = findNativeCheckpoint([
|
|
...branch,
|
|
{ type: "compaction", id: "c3", details: { kind: "pi-compaction", version: 1, checkpoint: "portable" } },
|
|
] as any);
|
|
assert.equal(portable.status, "none");
|
|
});
|
|
|
|
test("replacement history ends with exactly one native item", () => {
|
|
const history = buildReplacementHistory([
|
|
{ role: "user", content: [{ type: "input_text", text: "recent" }] },
|
|
], { type: "compaction", encrypted_content: "opaque" }, 1_000);
|
|
assert.equal(history.at(-1)?.type, "compaction");
|
|
assert.equal(history.filter((item) => item.type === "compaction").length, 1);
|
|
});
|