feat(HAI-020): complete Step 2 — simplify safeReadTaskJson to readTaskJson, remove truncation recovery

This commit is contained in:
Dustin Byrne
2026-03-25 21:37:44 -04:00
parent 6d2c234d89
commit 6975fae33f
2 changed files with 17 additions and 35 deletions

View File

@@ -90,19 +90,17 @@ describe("TaskStore", () => {
// ── Defensive parsing test ───────────────────────────────────────
describe("defensive JSON parsing", () => {
it("recovers from corrupted task.json with trailing duplicate content", async () => {
it("throws on corrupted task.json with trailing duplicate content (atomic writes prevent this)", async () => {
const task = await createTestTask();
const taskJsonPath = join(rootDir, ".hai", "tasks", task.id, "task.json");
// Corrupt the file: append duplicate trailing content (like HAI-015)
// Corrupt the file: append duplicate trailing content
const validJson = await readFile(taskJsonPath, "utf-8");
const corrupted = validJson + validJson.slice(validJson.length / 2);
await writeFile(taskJsonPath, corrupted);
// getTask should recover
const recovered = await store.getTask(task.id);
expect(recovered.id).toBe(task.id);
expect(recovered.description).toBe("Test task");
// With atomic writes, corruption indicates a real bug — should throw
await expect(store.getTask(task.id)).rejects.toThrow("Failed to parse task.json");
});
it("throws a clear error when JSON is completely unrecoverable", async () => {