perf(tui): batch persistence work off the render path

This commit is contained in:
Wolfgang Schoenberger
2026-07-30 15:35:38 -07:00
parent 4df68d6043
commit 070167dd4a
3 changed files with 72 additions and 14 deletions
@@ -87,6 +87,41 @@ class ControlledTitleUpdateBackend implements SessionStorageBackend {
this.#firstUpdate.reject(error);
}
}
describe("FileSessionStorage writer", () => {
let tempDir: string;
let storage: FileSessionStorage;
beforeEach(async () => {
tempDir = await fsp.mkdtemp(path.join(os.tmpdir(), "omp-session-writer-"));
storage = new FileSessionStorage();
});
afterEach(async () => {
await fsp.rm(tempDir, { recursive: true, force: true });
});
it("preserves append order through flush and close", async () => {
const sessionPath = path.join(tempDir, "batched.jsonl");
const writer = storage.openWriter(sessionPath, { flags: "w" });
await writer.append("one\n");
await writer.append("two\n");
await writer.flush();
expect(fs.readFileSync(sessionPath, "utf8")).toBe("one\ntwo\n");
await writer.close();
});
it("flushes queued appends before closing", async () => {
const sessionPath = path.join(tempDir, "closed.jsonl");
const writer = storage.openWriter(sessionPath, { flags: "w" });
await writer.append("one\n");
await writer.append("two\n");
await writer.close();
expect(fs.readFileSync(sessionPath, "utf8")).toBe("one\ntwo\n");
});
});
describe("FileSessionStorage.deleteSessionWithArtifacts", () => {
let tempDir: string;
let storage: FileSessionStorage;