mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-10-30 17:27:09 +00:00
test(studio-server): pin how an older history log takes in the media ledger (#5021)
* test(studio-server): pin how an older history log takes in the media ledger Four guards in the take-in had no test that failed without them: the start already naming the ledger, a change that made it, setting the keepsLedger mark, and saving it. * test(studio-server): put the undoNewest note back on undoNewest
This commit is contained in:
@@ -70,20 +70,20 @@ async function project(files: Record<string, string | Buffer>, options = {}) {
|
||||
return { projectDir, historyRoot, history, write, read, has };
|
||||
}
|
||||
|
||||
/** Undoes the newest change still in effect, whoever made it; Cmd+Z steps only over the caller's own. */
|
||||
/** What 0.8.123 leaves: a log whose baseline never names the media ledger and carries no marker. */
|
||||
function asWrittenBy0_8_123(logFile: string) {
|
||||
/** A log as an older version leaves it: no marker; 0.8.123's baseline also never names the media ledger. */
|
||||
function asWrittenBy(version: "0.8.122" | "0.8.123", logFile: string) {
|
||||
const lines = readFileSync(logFile, "utf-8")
|
||||
.trim()
|
||||
.split("\n")
|
||||
.map((line) => JSON.parse(line));
|
||||
for (const record of lines.filter((line) => line.type === "baseline")) {
|
||||
delete record.files[".media/manifest.jsonl"];
|
||||
if (version === "0.8.123") delete record.files[".media/manifest.jsonl"];
|
||||
delete record.keepsLedger;
|
||||
}
|
||||
writeFileSync(logFile, lines.map((record) => JSON.stringify(record)).join("\n") + "\n");
|
||||
}
|
||||
|
||||
/** Undoes the newest change still in effect, whoever made it; Cmd+Z steps only over the caller's own. */
|
||||
async function undoNewest(history: ProjectHistory) {
|
||||
const newest = [...history.list()].reverse().find((entry) => !entry.undoes && !entry.undone);
|
||||
return history.undo(newest!.id, { who: you });
|
||||
@@ -221,7 +221,7 @@ describe("openProjectHistory", () => {
|
||||
});
|
||||
await change(history, you, "Your edit", () => write("index.html", "B"));
|
||||
await history.close();
|
||||
asWrittenBy0_8_123(join(historyRoot, history.projectId, "log.jsonl"));
|
||||
asWrittenBy("0.8.123", join(historyRoot, history.projectId, "log.jsonl"));
|
||||
const reopened = await open(projectDir, historyRoot);
|
||||
expect(await reopened.step("back", you)).toMatchObject({ ok: true });
|
||||
expect([read("index.html"), read(".media/manifest.jsonl")]).toEqual(["A", "{}\n"]);
|
||||
@@ -236,7 +236,7 @@ describe("openProjectHistory", () => {
|
||||
{ quietMs: 30 },
|
||||
);
|
||||
await history.close();
|
||||
asWrittenBy0_8_123(join(historyRoot, history.projectId, "log.jsonl"));
|
||||
asWrittenBy("0.8.123", join(historyRoot, history.projectId, "log.jsonl"));
|
||||
const outside = tempDir("hf-history-linked-");
|
||||
writeFileSync(join(outside, "manifest.jsonl"), "{}\n");
|
||||
symlinkSync(outside, join(projectDir, ".media"), "dir");
|
||||
@@ -265,6 +265,50 @@ describe("openProjectHistory", () => {
|
||||
expect([read("index.html"), has(".media/manifest.jsonl")]).toEqual(["A", false]);
|
||||
});
|
||||
|
||||
it("a log 0.8.123 wrote without a ledger takes none in, and one made later while closed is a change", async () => {
|
||||
const { history, write, projectDir, historyRoot } = await project(
|
||||
{ "index.html": "A" },
|
||||
{ quietMs: 30 },
|
||||
);
|
||||
await history.close();
|
||||
asWrittenBy("0.8.123", join(historyRoot, history.projectId, "log.jsonl"));
|
||||
await (await open(projectDir, historyRoot, { quietMs: 30 })).close();
|
||||
write(".media/manifest.jsonl", "{}\n");
|
||||
const reopened = await open(projectDir, historyRoot, { quietMs: 30 });
|
||||
await reopened.flush();
|
||||
expect(reopened.list().map((entry) => entry.files.map((file) => file.path))).toEqual([
|
||||
[".media/manifest.jsonl"],
|
||||
]);
|
||||
});
|
||||
|
||||
it("an older log keeps a ledger one of its changes made out of the start", async () => {
|
||||
const { history, write, has, projectDir, historyRoot } = await project({ "index.html": "A" });
|
||||
await change(history, agent, "Cut out the logo", () => {
|
||||
write("index.html", "B");
|
||||
write(".media/manifest.jsonl", "{}\n");
|
||||
});
|
||||
await history.close();
|
||||
asWrittenBy("0.8.122", join(historyRoot, history.projectId, "log.jsonl"));
|
||||
const reopened = await open(projectDir, historyRoot);
|
||||
await reopened.restore(START, you);
|
||||
expect(has(".media/manifest.jsonl")).toBe(false);
|
||||
});
|
||||
|
||||
it("an older log keeps the ledger its start names, so a change made while closed is filed", async () => {
|
||||
const { history, write, projectDir, historyRoot } = await project(
|
||||
{ "index.html": "A", ".media/manifest.jsonl": "{}\n" },
|
||||
{ quietMs: 30 },
|
||||
);
|
||||
await history.close();
|
||||
asWrittenBy("0.8.122", join(historyRoot, history.projectId, "log.jsonl"));
|
||||
write(".media/manifest.jsonl", '{}\n{"id":"logo"}\n');
|
||||
const reopened = await open(projectDir, historyRoot, { quietMs: 30 });
|
||||
await reopened.flush();
|
||||
expect(reopened.list().map((entry) => entry.files.map((file) => file.path))).toEqual([
|
||||
[".media/manifest.jsonl"],
|
||||
]);
|
||||
});
|
||||
|
||||
it("takes the media ledger back with the film when a change is undone", async () => {
|
||||
const { history, write, read } = await project({
|
||||
"index.html": "<h1>Hello</h1>",
|
||||
|
||||
Reference in New Issue
Block a user