.
This commit is contained in:
parent
25f64ec690
commit
ff1f474324
1 changed files with 3271 additions and 2003 deletions
|
|
@ -13,7 +13,7 @@ for (const equal of [false, true])
|
|||
};
|
||||
const next = structuredClone(f.database.state);
|
||||
next.local = { a: "b.md", b: "a.md" };
|
||||
await f.files.apply(next);
|
||||
await f.files.applyChanges(next);
|
||||
assert.deepEqual(f.database.state.local, next.local);
|
||||
assert.deepEqual(
|
||||
f.disk.userFiles(),
|
||||
|
|
@ -40,7 +40,7 @@ for (const direction of ["file-to-directory", "directory-to-file"])
|
|||
? { [ids[0]]: "folder/a.md", [ids[1]]: "b.md" }
|
||||
: { [ids[0]]: "folder", [ids[1]]: "other.md" };
|
||||
const expected = structuredClone(next.local);
|
||||
await f.files.apply(next);
|
||||
await f.files.applyChanges(next);
|
||||
assert.deepEqual(f.database.state.local, expected);
|
||||
assert.deepEqual(
|
||||
new Set(f.disk.userFiles().keys()),
|
||||
|
|
@ -59,7 +59,7 @@ test("an unexpected occupant is preserved under a visible conflict name", async
|
|||
await f.disk.userWrite("remote.md", bytes("unexpected"));
|
||||
const next = structuredClone(f.database.state);
|
||||
next.local.a = "remote.md";
|
||||
await f.files.apply(next);
|
||||
await f.files.applyChanges(next);
|
||||
assert.equal(f.database.state.local.a, "remote.md");
|
||||
assert.equal(f.disk.userFiles().size, 2);
|
||||
assert.deepEqual(
|
||||
|
|
@ -73,9 +73,9 @@ test("an unexpected occupant is preserved under a visible conflict name", async
|
|||
|
||||
test("content edited after planning is merged with the incoming snapshot", async () => {
|
||||
const f = await fixture({ "a.md": "base\n" });
|
||||
const expected = (await f.files.snapshot("a.md"))!;
|
||||
const expected = (await f.files.readSnapshot("a.md"))!;
|
||||
await f.disk.userWrite("a.md", bytes("base\nlocal\n"));
|
||||
await f.files.apply(structuredClone(f.database.state), {
|
||||
await f.files.applyChanges(structuredClone(f.database.state), {
|
||||
a: {
|
||||
expected,
|
||||
replacement: await hashSnapshot({
|
||||
|
|
@ -94,7 +94,7 @@ test("deleting the source after planning does not resurrect it", async () => {
|
|||
const next = structuredClone(f.database.state);
|
||||
next.local.a = "remote.md";
|
||||
await f.disk.userDelete("a.md");
|
||||
await f.files.apply(next, {
|
||||
await f.files.applyChanges(next, {
|
||||
a: { replacement: await hashSnapshot({ content: bytes("remote") }) }
|
||||
});
|
||||
assert.deepEqual(f.disk.userFiles(), new Map());
|
||||
|
|
@ -109,7 +109,7 @@ for (const protect of ["ignore", "size"] as const)
|
|||
if (protect === "ignore")
|
||||
await f.settings.setSetting("ignorePatterns", ["a.md"]);
|
||||
else await f.settings.setSetting("maxFileSizeMB", 0);
|
||||
await f.files.apply(next, {
|
||||
await f.files.applyChanges(next, {
|
||||
a: {
|
||||
replacement: await hashSnapshot({
|
||||
content: bytes("remote")
|
||||
|
|
@ -149,12 +149,12 @@ for (const when of ["planning", "installed"])
|
|||
next.local = { a: "b.md", b: "a.md" };
|
||||
if (when === "planning")
|
||||
await assert.rejects(
|
||||
f.files.apply(next),
|
||||
f.files.applyChanges(next),
|
||||
LocalChangesDuringReconciliation
|
||||
);
|
||||
else await f.files.apply(next);
|
||||
else await f.files.applyChanges(next);
|
||||
assert(changed);
|
||||
await f.internals.scan();
|
||||
await f.internals.refreshLocalFiles();
|
||||
assert.equal(f.database.state.local.a, "editor.md");
|
||||
assert.deepEqual(
|
||||
f.disk.userFiles().get(f.database.state.local.a),
|
||||
|
|
@ -189,9 +189,9 @@ for (const action of ["move", "delete"] as const)
|
|||
};
|
||||
const next = structuredClone(f.database.state);
|
||||
next.local = { a: "remote-a.md", b: "remote-b.md" };
|
||||
await f.files.apply(next);
|
||||
await f.files.applyChanges(next);
|
||||
assert(changed);
|
||||
await f.internals.scan();
|
||||
await f.internals.refreshLocalFiles();
|
||||
assert.deepEqual(f.disk.userFiles().get("b.md"), bytes("replacement"));
|
||||
assert.equal(f.disk.userFiles().has("remote-b.md"), false);
|
||||
assert.equal(
|
||||
|
|
@ -207,7 +207,7 @@ test("a file and nested directory exchange their exact paths", async () => {
|
|||
const [a, b] = Object.keys(f.database.state.local);
|
||||
const next = structuredClone(f.database.state);
|
||||
next.local = { [a]: "b", [b]: "a/deep/child" };
|
||||
await f.files.apply(next);
|
||||
await f.files.applyChanges(next);
|
||||
assert.deepEqual(f.database.state.local, { [a]: "b", [b]: "a/deep/child" });
|
||||
assert.deepEqual(
|
||||
f.disk.userFiles(),
|
||||
|
|
@ -223,7 +223,7 @@ for (const phase of ["before", "durable"])
|
|||
const f = await fixture({ "a.md": "base\n" });
|
||||
const original = structuredClone(f.database.state);
|
||||
const write = {
|
||||
expected: (await f.files.snapshot("a.md"))!,
|
||||
expected: (await f.files.readSnapshot("a.md"))!,
|
||||
replacement: await hashSnapshot({
|
||||
content: bytes("remote\nbase\n")
|
||||
})
|
||||
|
|
@ -239,25 +239,25 @@ for (const phase of ["before", "durable"])
|
|||
}
|
||||
};
|
||||
await assert.rejects(
|
||||
f.files.apply(structuredClone(original), { a: write }),
|
||||
f.files.applyChanges(structuredClone(original), { a: write }),
|
||||
/save failed/
|
||||
);
|
||||
f.persistence.boundary = () => {};
|
||||
await f.database.recoverPersistence();
|
||||
await f.files.apply(structuredClone(original), { a: write });
|
||||
await f.files.applyChanges(structuredClone(original), { a: write });
|
||||
assert.deepEqual(
|
||||
f.disk.userFiles().get("a.md"),
|
||||
bytes("remote\nbase\nlocal\n")
|
||||
);
|
||||
assert.equal(
|
||||
f.database.state.documents.a.observedHash,
|
||||
(await f.files.snapshot("a.md"))!.hash
|
||||
(await f.files.readSnapshot("a.md"))!.hash
|
||||
);
|
||||
});
|
||||
|
||||
test("atomic updater includes an edit made after the last snapshot without unlinking the file", async () => {
|
||||
const f = await fixture({ "a.md": "base\n" });
|
||||
const expected = (await f.files.snapshot("a.md"))!;
|
||||
const expected = (await f.files.readSnapshot("a.md"))!;
|
||||
let edited = false;
|
||||
f.disk.boundary = async (label) => {
|
||||
assert(
|
||||
|
|
@ -269,7 +269,7 @@ test("atomic updater includes an edit made after the last snapshot without unlin
|
|||
await f.disk.userWrite("a.md", bytes("base\nlatest edit\n"));
|
||||
}
|
||||
};
|
||||
await f.files.apply(structuredClone(f.database.state), {
|
||||
await f.files.applyChanges(structuredClone(f.database.state), {
|
||||
a: {
|
||||
expected,
|
||||
replacement: await hashSnapshot({
|
||||
|
|
@ -284,7 +284,7 @@ test("atomic updater includes an edit made after the last snapshot without unlin
|
|||
);
|
||||
assert.equal(
|
||||
f.database.state.documents.a.observedHash,
|
||||
(await f.files.snapshot("a.md"))!.hash
|
||||
(await f.files.readSnapshot("a.md"))!.hash
|
||||
);
|
||||
});
|
||||
|
||||
|
|
@ -295,9 +295,9 @@ test("a failed atomic update leaves database metadata unchanged", async () => {
|
|||
if (label === "before:write:a.md") throw new Error("update failed");
|
||||
};
|
||||
await assert.rejects(
|
||||
f.files.apply(structuredClone(original), {
|
||||
f.files.applyChanges(structuredClone(original), {
|
||||
a: {
|
||||
expected: (await f.files.snapshot("a.md"))!,
|
||||
expected: (await f.files.readSnapshot("a.md"))!,
|
||||
replacement: await hashSnapshot({
|
||||
content: bytes("remote")
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue