{"draft":null,"from":43,"to":44,"files":[{"path":"client/test/client.test.ts","added":67,"removed":1,"diff":"--- a/client/test/client.test.ts\n+++ b/client/test/client.test.ts\n@@ -46,7 +46,7 @@\n \tuncomposedText,\n } from \"../src/core.ts\";\n import { unifiedDiff } from \"../src/diff.ts\";\n-import { absolute, writeFileAtomic } from \"../src/folder.ts\";\n+import { absolute, knownPath, unrecorded, writeFileAtomic } from \"../src/folder.ts\";\n import { runHook } from \"../src/hook.ts\";\n import { tryFolderLock } from \"../src/lock.ts\";\n import { boxServer, commandTable, main } from \"../src/main.ts\";\n@@ -3495,6 +3495,72 @@\n \t\tassert.deepEqual(after.json.unrecorded, []);\n \t});\n \n+\tit(\"status skips reading files it found unchanged before, never trusts one changed too recently, and record still reads every file\", async () => {\n+\t\tconst { folders } = await project({ \"a.txt\": \"a\\n\", \"b.txt\": \"b\\n\", \"c.txt\": \"c\\r\\n\" }, \"alice\", \"bob\");\n+\t\tconst root = folders.alice!;\n+\t\tconst record = join(stateDir(root), \"clean.json\");\n+\t\tconst old = new Date(Date.now() - 60_000);\n+\t\t// The file and its known copy a minute old, as after a quiet spell.\n+\t\tconst age = (...rels: string[]) => {\n+\t\t\tfor (const rel of rels) {\n+\t\t\t\tutimesSync(join(root, rel), old, old);\n+\t\t\t\tutimesSync(knownPath(root, rel), old, old);\n+\t\t\t}\n+\t\t};\n+\t\t// Changes a file without changing its size or time: only reading it can tell.\n+\t\tconst swap = (rel: string, text: string) => {\n+\t\t\tconst was = statSync(join(root, rel));\n+\t\t\twriteFileSync(join(root, rel), text);\n+\t\t\tutimesSync(join(root, rel), was.atime, was.mtime);\n+\t\t};\n+\t\twriteFileSync(join(root, \"c.txt\"), \"c\\r\\n\");\n+\n+\t\t// Files too new to trust are read, and not kept: a swap is still caught. A time a minute ahead stays\n+\t\t// too new however long the run takes.\n+\t\tconst soon = new Date(Date.now() + 60_000);\n+\t\tfor (const rel of [\"a.txt\", \"b.txt\", \"c.txt\"]) utimesSync(join(root, rel), soon, soon);\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, []);\n+\t\tswap(\"a.txt\", \"A\\n\");\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, [\"a.txt\"]);\n+\t\tswap(\"a.txt\", \"a\\n\");\n+\n+\t\t// Old files are kept after one status, and the next answers from the record without reading them.\n+\t\tage(\"a.txt\", \"b.txt\", \"c.txt\");\n+\t\tconst first = await avcs(root, \"status\");\n+\t\tassert.deepEqual(first.json.unrecorded, []);\n+\t\tassert.deepEqual(first.json.crlf, [\"c.txt\"]);\n+\t\tassert.deepEqual(Object.keys(JSON.parse(readFileSync(record, \"utf8\")).files).sort(), [\"a.txt\", \"b.txt\", \"c.txt\"]);\n+\t\tswap(\"b.txt\", \"B\\n\");\n+\t\tconst second = await avcs(root, \"status\");\n+\t\tassert.deepEqual(second.json.unrecorded, [], \"b.txt was answered from the record\");\n+\t\tassert.deepEqual(second.json.crlf, [\"c.txt\"]);\n+\t\t// What record sends is read from every file, whatever the record says.\n+\t\tassert.deepEqual([...unrecorded(root).files.keys()], [\"b.txt\"]);\n+\n+\t\t// A record of an unknown format, or one that doesn't parse, is not used.\n+\t\tconst kept = JSON.parse(readFileSync(record, \"utf8\"));\n+\t\twriteFileSync(record, JSON.stringify({ ...kept, format: 2 }));\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, [\"b.txt\"]);\n+\t\twriteFileSync(record, \"not json\");\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, [\"b.txt\"]);\n+\n+\t\t// An edit that changes the size or time is read at once.\n+\t\tswap(\"b.txt\", \"b\\n\");\n+\t\tage(\"b.txt\");\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, []);\n+\t\twriteFileSync(join(root, \"b.txt\"), \"bb\\n\");\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, [\"b.txt\"]);\n+\n+\t\t// A sync writes the file and its known copy, so what was kept for them no longer holds.\n+\t\twriteFileSync(join(root, \"b.txt\"), \"b\\n\");\n+\t\twrite(folders.bob!, { \"a.txt\": \"a2\\n\" });\n+\t\tassert.equal((await avcs(folders.bob!, \"publish\", \"-m\", \"a2\")).exit, 0);\n+\t\tassert.equal((await avcs(root, \"sync\")).exit, 0);\n+\t\tassert.equal(readFileSync(join(root, \"a.txt\"), \"utf8\"), \"a2\\n\");\n+\t\tswap(\"a.txt\", \"a3\\n\");\n+\t\tassert.deepEqual((await avcs(root, \"status\")).json.unrecorded, [\"a.txt\"]);\n+\t});\n+\n \tit(\"several files marked against one version get one settle --theirs hint\", () => {\n \t\tconst c = (file: string, version: number) => ({\n \t\t\tkind: \"lines\" as const,"}],"unmatched":[]}