fix: normalize bridge errors and support nested group paths

Distinguish invalid KeePass requests from backend failures in the Python bridge, improve nested group path resolution, and add coverage for nested group creation plus payload forwarding.
This commit is contained in:
matmoul committed 2026-05-10 00:56:58 +02:00
1 parent ee0e2c85f4
commit 5fa30414d7
8 files changed
+99 -23

No files matched your search

+45
View File
@@ -85,6 +85,23 @@ describe("KeePassDatabase", () => {
await expect(db.listEntries()).rejects.toThrow("Invalid JSON from Python bridge");
});
test("throws a useful error when the bridge exits without output", async () => {
spawnMock.mockImplementation(() => {
const child = {
stdin: { write: () => undefined, end: () => undefined },
stdout: { on: () => undefined },
stderr: { on: (_event: string, cb: (chunk: Buffer | string) => void) => cb("bridge crashed") },
on: (event: string, cb: (code?: number | null) => void) => {
if (event === "close") queueMicrotask(() => cb(1));
},
};
return child as never;
});
const db = new KeePassDatabase("db.kdbx", { password: "secret" }, "python3", new URL("file:///tmp/bridge.py"));
await expect(db.listEntries()).rejects.toThrow("bridge crashed");
});
test("throws on spawn error", async () => {
spawnMock.mockImplementation(() => {
const child = {
@@ -122,6 +139,34 @@ describe("KeePassDatabase", () => {
expect(spawnMock).toHaveBeenCalled();
});
test("createEntry forwards nested group paths in the payload", async () => {
let payload = "";
spawnMock.mockImplementation(() => {
const child = {
stdin: {
write: (chunk: string) => {
payload += chunk;
},
end: () => undefined,
},
stdout: { on: (_event: string, cb: (chunk: Buffer | string) => void) => cb(JSON.stringify({ ok: true, data: { title: "New" } })) },
stderr: { on: () => undefined },
on: (event: string, cb: (code?: number | null) => void) => {
if (event === "close") queueMicrotask(() => cb(0));
},
};
return child as never;
});
const db = new KeePassDatabase("db.kdbx", { password: "secret" }, "python3", new URL("file:///tmp/bridge.py"));
await db.createEntry({ title: "New", groupPath: "Folder/SubFolder" });
expect(JSON.parse(payload)).toMatchObject({
command: "create-entry",
entry: { title: "New", groupPath: "Folder/SubFolder" },
});
});
test("save forwards the save command", async () => {
mockSuccessfulBridgeResponse(null);