{"draft":null,"from":42,"to":43,"files":[{"path":"client/test/install.test.ts","added":65,"removed":0,"diff":"--- a/client/test/install.test.ts\n+++ b/client/test/install.test.ts\n@@ -27,6 +27,7 @@\n import {\n \tAVCS_MOD,\n \tinstallMod,\n+\tkeptModCommit,\n \ttype ModSpec,\n \tmodsBehindText,\n \tretireOldMod,\n@@ -301,6 +302,70 @@\n \t\t// Outside a git checkout there is no commit to add.\n \t\tassert.equal(versionFor(spec, null), \"0.1.0\");\n \t});\n+\n+\tit(\"keeps the mod's commit between runs, and asks git again when the checkout or a file moves, or a file is too new to trust\", {\n+\t\tskip: !hasGit,\n+\t}, () => {\n+\t\tconst spec = source();\n+\t\tconst home = temp();\n+\t\tconst kept = join(home, \".abso\", \"mod-commits.json\");\n+\t\tconst git = (...args: string[]) =>\n+\t\t\tspawnSync(\"git\", [\"-c\", \"user.name=t\", \"-c\", \"user.email=t@t\", \"-C\", spec.from, ...args], {\n+\t\t\t\tencoding: \"utf8\",\n+\t\t\t}).stdout.trim();\n+\t\t// Every mod file a minute old, so a kept answer can be trusted.\n+\t\tconst age = () => {\n+\t\t\tconst old = new Date(Date.now() - 60_000);\n+\t\t\tfor (const rel of FILES) utimesSync(at(spec.from, rel), old, old);\n+\t\t};\n+\t\t// Swaps every kept answer for a made-up one: what comes back says whether git ran.\n+\t\tconst plant = () => {\n+\t\t\tconst file = JSON.parse(readFileSync(kept, \"utf8\"));\n+\t\t\tfor (const k of Object.keys(file.mods)) file.mods[k].commit = \"fffffff\";\n+\t\t\twriteFileSync(kept, JSON.stringify(file));\n+\t\t};\n+\t\t// Not a git checkout yet: no commit, and nothing kept.\n+\t\tassert.equal(keptModCommit(spec, home), null);\n+\t\tassert.equal(existsSync(kept), false);\n+\t\tgit(\"init\", \"-q\");\n+\t\tgit(\"add\", \".\");\n+\t\tgit(\"commit\", \"-q\", \"-m\", \"mod\");\n+\t\tconst mod = git(\"rev-parse\", \"--short=7\", \"HEAD\");\n+\t\tage();\n+\t\tassert.equal(keptModCommit(spec, home), mod);\n+\t\tplant();\n+\t\tassert.equal(keptModCommit(spec, home), \"fffffff\", \"a kept answer is used while nothing moved\");\n+\n+\t\t// A file changed in the same moment the answer was kept is never trusted, even when its size and time match.\n+\t\twrite(spec.from, \"src/core.ts\", \"export const core = 2\\n\");\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`);\n+\t\tplant();\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`, \"too new to trust: git runs again\");\n+\n+\t\t// An edit that keeps the size, with its time set back a minute, still isn't the time that was kept.\n+\t\tage();\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`);\n+\t\tplant();\n+\t\twrite(spec.from, \"src/core.ts\", \"export const core = 3\\n\");\n+\t\tage();\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`);\n+\n+\t\t// A commit moves the checkout.\n+\t\tgit(\"commit\", \"-q\", \"-am\", \"core\");\n+\t\tage();\n+\t\tconst next = git(\"rev-parse\", \"--short=7\", \"HEAD\");\n+\t\tassert.equal(keptModCommit(spec, home), next);\n+\t\tplant();\n+\t\tgit(\"commit\", \"-q\", \"--allow-empty\", \"-m\", \"empty\");\n+\t\tassert.equal(keptModCommit(spec, home), next, \"a new commit asks git again\");\n+\n+\t\t// A file it can't read, or doesn't know the format of, is the same as none.\n+\t\tplant();\n+\t\twriteFileSync(kept, JSON.stringify({ format: 2, mods: JSON.parse(readFileSync(kept, \"utf8\")).mods }));\n+\t\tassert.equal(keptModCommit(spec, home), next);\n+\t\twriteFileSync(kept, \"not json\");\n+\t\tassert.equal(keptModCommit(spec, home), next);\n+\t});\n });\n \n describe(\"which client this is\", () => {"}],"unmatched":[]}