Clean up deterministic tests

This commit is contained in:
Andras Schmelczer 2026-03-28 11:12:43 +00:00
commit f36a84b275

View file

@ -1,56 +1,21 @@
import type { ClientState, TestDefinition } from "../test-definition";
import { assert } from "../utils/assert";
function verifyEditPreservedAtNewPath(state: ClientState): void {
const files = Array.from(state.files.keys()).sort();
// A.md should not exist (it was renamed to B.md)
assert(
!state.files.has("A.md"),
`A.md should not exist after rename. Files: ${files.join(", ")}`
);
// B.md should exist with Client 0's edit merged in
assert(
state.files.has("B.md"),
`Expected B.md to exist. Files: ${files.join(", ")}`
);
const content = state.files.get("B.md") ?? "";
assert(
content.includes("edited by client 0"),
`Expected B.md to contain Client 0's edit "edited by client 0", got: "${content}"`
);
assert(
state.files.size === 1,
`Expected exactly 1 file, got ${state.files.size}: ${files.join(", ")}`
);
}
import type { TestDefinition } from "../test-definition";
export const offlineEditRemoteRenameTest: TestDefinition = {
name: "Offline Edit + Remote Rename",
description:
"Client 0 goes offline and edits A.md. Meanwhile Client 1 renames " +
"A.md to B.md. When Client 0 reconnects, its edit should be applied " +
"to B.md (the renamed path). The edit must not be lost and A.md must " +
"not exist.",
"Client 0 edits A.md offline while client 1 renames A.md to B.md. " +
"After client 0 reconnects, the edit must appear in B.md and A.md must not exist.",
clients: 2,
steps: [
// Setup: create and sync
{ type: "create", client: 0, path: "A.md", content: "original" },
{ type: "enable-sync", client: 0 },
{ type: "enable-sync", client: 1 },
{ type: "sync" },
{ type: "barrier" },
{
type: "assert-content",
client: 1,
path: "A.md",
content: "original"
type: "assert-consistent",
verify: (s) => s.assertContent("A.md", "original")
},
// Client 0 goes offline and edits
{ type: "disable-sync", client: 0 },
{
type: "update",
@ -59,7 +24,6 @@ export const offlineEditRemoteRenameTest: TestDefinition = {
content: "edited by client 0"
},
// Client 1 renames A.md -> B.md while Client 0 is offline
{
type: "rename",
client: 1,
@ -68,13 +32,17 @@ export const offlineEditRemoteRenameTest: TestDefinition = {
},
{ type: "sync", client: 1 },
// Client 0 reconnects — edit must be preserved at new path
{ type: "enable-sync", client: 0 },
{ type: "sync" },
{ type: "barrier" },
{ type: "assert-not-exists", client: 0, path: "A.md" },
{ type: "assert-not-exists", client: 1, path: "A.md" },
{ type: "assert-consistent", verify: verifyEditPreservedAtNewPath }
{
type: "assert-consistent",
verify: (s) =>
s
.assertFileNotExists("A.md")
.assertFileCount(1)
.assertContains("B.md", "edited by client 0")
}
]
};