fix(flowchart): pre-await getUserDataPath to fix persistence; bump v4.9.0 → v4.9.1

Amit Haridas
This commit is contained in:
2026-09-14 22:24:27 +05:30
parent 58aa4da00f
commit 8c708b7abb
6 changed files with 51 additions and 7 deletions
+31
View File
@@ -67,6 +67,37 @@ describe('flowchart-panel: persistence', () => {
const readFile = jest.fn().mockResolvedValue('{not-json');
expect(() => mount({ readFile })).not.toThrow();
});
// Regression: src/renderer.js used to pass flowchartIO.getUserDataPath
// (which returns ipcRenderer.invoke's Promise) directly into the panel.
// The panel then coerced that Promise to "[object Promise]" in the
// template literal, producing a persistence path that fell outside the
// userData sandbox and was rejected by write-text-file. The fix is to
// await the path on the renderer side and cache it, then hand the panel
// a sync getter. This test mirrors that pattern: simulate the renderer's
// pre-resolve + cache, and assert the panel's persistence path is a
// real resolved string on mount.
test('handles an async getUserDataPath via renderer-side pre-resolve + cache', async () => {
const asyncGetUserDataPath = jest.fn().mockResolvedValue('/abs/path/to/userdata');
// Pre-resolve exactly the way src/renderer.js now does.
let cachedUserDataPath = null;
if (!cachedUserDataPath) cachedUserDataPath = await asyncGetUserDataPath();
const syncGetUserDataPath = () => cachedUserDataPath;
const writeFile = jest.fn().mockResolvedValue(undefined);
const { api } = mount({ getUserDataPath: syncGetUserDataPath, writeFile });
// read on mount must use the resolved (real) path, not "[object Promise]".
await Promise.resolve();
expect(asyncGetUserDataPath).toHaveBeenCalledTimes(1);
// mutate -> debounced write -> assert writeFile is called with the real path.
api.getStore().addNode({ kind: 'process', x: 0, y: 0, label: 'async-cache' });
jest.advanceTimersByTime(500);
await Promise.resolve();
expect(writeFile).toHaveBeenCalledTimes(1);
expect(writeFile.mock.calls[0][0]).toBe('/abs/path/to/userdata/flowchart-session.json');
});
});
describe('flowchart-panel: live preview', () => {