{"draft":null,"from":178,"to":318,"files":[{"path":"server/test/project-object-disk-first.test.ts","added":165,"removed":1,"diff":"--- a/server/test/project-object-disk-first.test.ts\n+++ b/server/test/project-object-disk-first.test.ts\n@@ -5,6 +5,7 @@\n import { Project } from \"../../worker/project/project.ts\";\n import { EngineProject } from \"../src/engine-project.ts\";\n import { GitDiskIntake } from \"../src/git-disk-intake.ts\";\n+import { GitIntakeLimitError } from \"../src/git-intake-limit.ts\";\n import { MemoryFS } from \"../src/memory-fs.ts\";\n import { memoryStorage } from \"./helpers.ts\";\n \n@@ -21,6 +22,160 @@\n const { ProjectObject } = await import(\"../src/project-object.ts\");\n hooks.deregister();\n \n+for (const disk of [false, true])\n+\ttest(`failed intake retries across cold objects with disk mode ${disk}`, async (t) => {\n+\t\tconst storage = memoryStorage();\n+\t\tt.after(() => storage.db.close());\n+\t\tconst values = new Map<string, unknown>();\n+\t\tlet alarm: number | null = null;\n+\t\tconst context = {\n+\t\t\tid: { toString: () => \"retry\" },\n+\t\t\tstorage: {\n+\t\t\t\t...storage,\n+\t\t\t\tget: async (key: string) => values.get(key),\n+\t\t\t\tput: async (key: string | Record<string, unknown>, value?: unknown) => {\n+\t\t\t\t\tif (typeof key === \"string\") values.set(key, value);\n+\t\t\t\t\telse for (const [name, item] of Object.entries(key)) values.set(name, item);\n+\t\t\t\t},\n+\t\t\t\tdelete: async (key: string) => values.delete(key),\n+\t\t\t\tgetAlarm: async () => alarm,\n+\t\t\t\tsetAlarm: async (value: number) => {\n+\t\t\t\t\talarm = value;\n+\t\t\t\t},\n+\t\t\t},\n+\t\t};\n+\t\tconst object = (enabled: boolean) =>\n+\t\t\tnew ProjectObject(\n+\t\t\t\tcontext as never,\n+\t\t\t\t{\n+\t\t\t\t\tABSO_DISK_FIRST: disk ? \"on\" : \"off\",\n+\t\t\t\t\tABSO_ARTIFACTS: enabled ? \"on\" : \"off\",\n+\t\t\t\t\tARTIFACTS: {},\n+\t\t\t\t} as never,\n+\t\t\t);\n+\t\tassert.equal((await object(false).call(\"retry\", \"init\", undefined, { files: { \"a.txt\": \"first\\n\" } })).status, 200);\n+\t\tlet ready = false;\n+\t\tfor (let page = 0; page < 100; page++) {\n+\t\t\tif ((await object(false).call(\"retry\", \"status\", undefined, {})).status === 200) {\n+\t\t\t\tready = true;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t}\n+\t\tassert.equal(ready, true);\n+\t\tlet fails = true;\n+\t\tt.mock.method(ProjectObject.prototype, \"gitSync\", async () => {\n+\t\t\tif (fails) throw Error(\"transient intake failure\");\n+\t\t\treturn null;\n+\t\t});\n+\t\tfor (const [index, minutes] of [1, 5, 15, 15].entries()) {\n+\t\t\talarm = null;\n+\t\t\tconst before = Date.now();\n+\t\t\tawait object(true).alarm();\n+\t\t\tassert.equal(values.get(\"git:retry-attempts\"), index + 1);\n+\t\t\tassert.ok(alarm !== null && alarm >= before + minutes * 60000 && alarm <= Date.now() + minutes * 60000);\n+\t\t\tassert.equal(values.get(\"pushed\"), undefined);\n+\t\t}\n+\t\tfails = false;\n+\t\tvalues.set(\"pushed\", { version: Number.MAX_SAFE_INTEGER });\n+\t\talarm = null;\n+\t\tawait object(true).alarm();\n+\t\tassert.equal(values.has(\"git:retry-attempts\"), false);\n+\t\tassert.equal(values.has(\"git:error\"), false);\n+\t});\n+\n+test(\"size refusals survive cold objects, retry changed heads or policy, and prevent outgoing pushes\", async (t) => {\n+\tlet scheduled = 0;\n+\tconst storage = memoryStorage();\n+\tt.after(() => storage.db.close());\n+\tconst values = new Map<string, unknown>();\n+\tconst context = {\n+\t\tid: { toString: () => \"size-refusal\" },\n+\t\tstorage: {\n+\t\t\t...storage,\n+\t\t\tget: async (key: string) => values.get(key),\n+\t\t\tput: async (key: string | Record<string, unknown>, value?: unknown) => {\n+\t\t\t\tif (typeof key === \"string\") values.set(key, value);\n+\t\t\t\telse for (const [name, item] of Object.entries(key)) values.set(name, item);\n+\t\t\t},\n+\t\t\tdelete: async (key: string) => values.delete(key),\n+\t\t\tgetAlarm: async () => null,\n+\t\t\tsetAlarm: async (value: number) => {\n+\t\t\t\tscheduled = value;\n+\t\t\t},\n+\t\t},\n+\t};\n+\tconst artifacts = {\n+\t\tget: async () => ({\n+\t\t\tinfo: async () => ({ remote: \"https://artifacts.invalid/size\" }),\n+\t\t\tcreateToken: async () => ({ plaintext: \"invented-test-token\" }),\n+\t\t\t[Symbol.dispose]() {},\n+\t\t}),\n+\t};\n+\tconst object = (enabled = true) =>\n+\t\tnew ProjectObject(\n+\t\t\tcontext as never,\n+\t\t\t{\n+\t\t\t\tABSO_DISK_FIRST: \"on\",\n+\t\t\t\tABSO_ARTIFACTS: enabled ? \"on\" : \"off\",\n+\t\t\t\tARTIFACTS: artifacts,\n+\t\t\t} as never,\n+\t\t);\n+\tassert.equal(\n+\t\t(await object(false).call(\"size-refusal\", \"init\", undefined, { files: { \"a.txt\": \"original\\n\" } })).status,\n+\t\t200,\n+\t);\n+\tlet ready = false;\n+\tfor (let page = 0; page < 100; page++) {\n+\t\tconst result = await object(false).call(\"size-refusal\", \"status\", undefined, {});\n+\t\tif (result.status === 200) {\n+\t\t\tready = true;\n+\t\t\tbreak;\n+\t\t}\n+\t\tassert.equal(result.status, 503);\n+\t}\n+\tassert.equal(ready, true, \"project indexing must finish before testing intake refusals\");\n+\tlet head = \"a\".repeat(40),\n+\t\tdownloads = 0,\n+\t\tpushes = 0,\n+\t\ttransient = false;\n+\tt.mock.method(git, \"listServerRefs\", async () => [{ ref: \"refs/heads/main\", oid: head }]);\n+\tt.mock.method(git, \"clone\", async () => {\n+\t\tdownloads++;\n+\t\tif (transient) throw Error(\"temporary network failure\");\n+\t\tthrow new GitIntakeLimitError(\"decoded\", \"Git pack exceeds total decoded byte limit\");\n+\t});\n+\tt.mock.method(git, \"push\", async () => {\n+\t\tpushes++;\n+\t\treturn { ok: true };\n+\t});\n+\tawait assert.rejects(() => object().gitSync(), /decoded byte limit/);\n+\tawait assert.rejects(() => object().gitSync(), /decoded byte limit/);\n+\tassert.equal(downloads, 1);\n+\tassert.equal(values.get(\"git:head\"), undefined);\n+\tassert.equal((await object().out()).version, 0);\n+\tassert.match(JSON.stringify((await object().out()).git.error), /decoded byte limit/);\n+\tawait object().alarm();\n+\tassert.ok(scheduled >= Date.now() + 59_000);\n+\tassert.equal(values.get(\"git:retry-attempts\"), 1);\n+\tassert.equal(downloads, 1);\n+\tassert.equal(pushes, 0);\n+\thead = \"b\".repeat(40);\n+\tawait assert.rejects(() => object().gitSync(), /decoded byte limit/);\n+\tassert.equal(downloads, 2);\n+\tvalues.set(\"git:size-refusal\", { ...(values.get(\"git:size-refusal\") as object), policy: \"old-policy\" });\n+\tawait assert.rejects(() => object().gitSync(), /decoded byte limit/);\n+\tassert.equal(downloads, 3);\n+\thead = \"c\".repeat(40);\n+\ttransient = true;\n+\tawait assert.rejects(() => object().gitSync(), /temporary network failure/);\n+\tawait assert.rejects(() => object().gitSync(), /temporary network failure/);\n+\tassert.equal(downloads, 5);\n+\tassert.equal(values.has(\"git:size-refusal\"), false);\n+\tawait object().alarm();\n+\tassert.equal(pushes, 0);\n+\tassertGitScratchEmpty(storage);\n+});\n+\n function assertGitScratchEmpty(storage: ReturnType<typeof memoryStorage>) {\n \tfor (const table of [\n \t\t\"git_pack_spool\",\n@@ -333,7 +488,16 @@\n \t\tconst blob = await git.readBlob({ fs: options.fs, dir: options.dir, oid, filepath: \"a.txt\" });\n \t\tassert.equal(new TextDecoder().decode(blob.blob), \"Alice's change\\n\");\n \t\tpushed++;\n-\t\tremoteFiles = options.fs as MemoryFS;\n+\t\t// The remote owns its copy; the export's scratch files expire when push returns.\n+\t\tremoteFiles = new MemoryFS();\n+\t\tfor (const [path, entry] of (options.fs as MemoryFS).entries) {\n+\t\t\tremoteFiles.entries.set(\n+\t\t\t\tpath,\n+\t\t\t\tentry.kind === \"file\"\n+\t\t\t\t\t? { ...entry, data: new Uint8Array((await (options.fs as MemoryFS).readFile(path)) as Uint8Array) }\n+\t\t\t\t\t: { ...entry },\n+\t\t\t);\n+\t\t}\n \t\treturn { ok: true };\n \t});\n \tconst artifacts = {"}],"unmatched":[]}