mirror of
https://github.com/penpot/penpot.git
synced 2026-11-18 16:12:24 +00:00
* 🐛 Make execute_code wait for save before success * 🐛 Address review feedback on waitForSave Reject with an Error carrying a `code`: save-timeout, rolled-back, save-retrying, or the failure code (save-failed by default). Lower the default timeout from 90s to 60s, leaving room for the 30s layout wait and the code under the MCP tool timeout. When persistence is already in error at the start of the wait, keep the stored failure code, and tell a failure Penpot keeps retrying apart from one that needs the file reopened. Share timeout validation with waitForLayoutUpdate through app.plugins.utils, and make reject-not-valid reject with an Error, which also fixes the string rejections of connectLibrary, restore, remove, pin, export, findVersions and saveVersion. The MCP execute_code handler now waits for the save only when the workspace is ready, like the layout wait, so dashboard calls no longer fail on a save error from an earlier file. Move the waitForSave tests to frontend-tests.plugins, add tests for the error codes, the retrying state and a failure during the wait, and add plugin API suite and MCP handler tests. Update the docs, CHANGELOG and the generated API files. AI-assisted-by: claude-opus-5-5
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { expect, expectReject } from '../framework/expect';
|
|
import { describe, test } from '../framework/registry';
|
|
|
|
// waitForSave: resolves once the pending file changes are saved, or when
|
|
// there is nothing to save. It waits on the shared persistence queue, so the
|
|
// edits of earlier tests may be in flight too; each test only asserts what
|
|
// holds whatever else is queued.
|
|
|
|
describe('WaitForSave', () => {
|
|
test('resolves after an edit is saved', async (ctx) => {
|
|
const r = ctx.penpot.createRectangle();
|
|
ctx.board.appendChild(r);
|
|
r.name = 'wait-save-probe';
|
|
|
|
const value = await ctx.penpot.waitForSave();
|
|
expect(value).toBeUndefined();
|
|
expect(r.name).toBe('wait-save-probe');
|
|
});
|
|
|
|
test('resolves when there is nothing to save', async (ctx) => {
|
|
await ctx.penpot.waitForSave();
|
|
await ctx.penpot.waitForSave(5000);
|
|
});
|
|
|
|
test('rejects an invalid timeout with an Error', async (ctx) => {
|
|
for (const value of [
|
|
-1,
|
|
0,
|
|
Number.NaN,
|
|
Number.POSITIVE_INFINITY,
|
|
2 ** 31,
|
|
]) {
|
|
const p = ctx.penpot.waitForSave(value);
|
|
expect(p instanceof Promise).toBe(true);
|
|
await expectReject(p, /not valid/);
|
|
const error = await p.catch((e: unknown) => e);
|
|
expect(error instanceof Error).toBe(true);
|
|
}
|
|
});
|
|
});
|