fix(startup): recheck sizes after reading storage

This commit is contained in:
vorotamoroz committed 2026-10-24 11:41:56 +00:00
1 parent fc2b35e0dc
commit fd2eebdf38
3 files changed
+41

No files matched your search

@@ -182,6 +182,39 @@ describe("checkIncompleteDocuments", () => {
expect(fixture.dependencies.keyValueDB.set).not.toHaveBeenCalled();
});
it("does not offer repair when all sizes agree after reading storage", async () => {
const healthy = documentFixture("settled.md", { storageContent: "abc" });
const fixture = createDependencies(documentsFrom([healthy]), [healthy]);
vi.mocked(fixture.dependencies.storageAccess.statHidden).mockResolvedValueOnce({ ...healthy.stub.stat, size: 4 });
await expect(checkIncompleteDocuments(fixture.dependencies)).resolves.toBe(true);
expect(fixture.readHiddenFileBinary).toHaveBeenCalledWith("settled.md");
expect(fixture.askSelectStringDialogue).not.toHaveBeenCalled();
expect(fixture.storeFileToDB).not.toHaveBeenCalled();
expect(fixture.dependencies.keyValueDB.set).toHaveBeenCalledWith("checkIncompleteDocs", true);
});
it("uses the bytes read from storage when a size mismatch remains", async () => {
const mismatched = documentFixture("changing.md", { recordedSize: 3, storageContent: "abcde" });
const fixture = createDependencies(documentsFrom([mismatched]), [mismatched]);
vi.mocked(fixture.dependencies.storageAccess.statHidden).mockResolvedValueOnce({
...mismatched.stub.stat,
size: 4,
});
fixture.askSelectStringDialogue.mockImplementation(selectButton(0));
await expect(checkIncompleteDocuments(fixture.dependencies)).resolves.toBe(true);
expect(fixture.readHiddenFileBinary).toHaveBeenCalledWith("changing.md");
expect(fixture.askSelectStringDialogue).toHaveBeenCalledOnce();
expect(fixture.askSelectStringDialogue.mock.calls[0]?.[0]).toEqual(
expect.stringContaining("changing.md (M: 3, A: 3, S: 5)")
);
expect(fixture.storeFileToDB).not.toHaveBeenCalled();
expect(fixture.dependencies.keyValueDB.set).not.toHaveBeenCalled();
});
it("still reads conflicted storage for the existing repair dialogue", async () => {
const conflicted = documentFixture("conflicted.md", { storageContent: "abc", conflicts: ["2-other"] });
const fixture = createDependencies(documentsFrom([conflicted]), [conflicted]);