fix: preserve large Unicode drafts with bounded keepalive transport

This commit is contained in:
2026-10-29 23:08:09 +02:00
parent fa2ece10de
commit ed96fd10b9
7 changed files with 305 additions and 25 deletions
@@ -581,6 +581,55 @@ const buttonNamed = (tree, label) =>
(node) => node.type === 'button' && node.props.children === label,
);
const settlePreview = () => new Promise((resolve) => setImmediate(resolve));
void test('large multi-opportunity draft is offered to the transport on exit without truncation', () => {
const previousWindow = globalThis.window;
let flush;
globalThis.window = {
addEventListener(_name, callback) {
flush = callback;
},
removeEventListener() {},
};
let cleanup;
try {
const harness = contextPreviewHarness();
const initial = harness.render();
cleanup = harness.effects
.find(
(effect) =>
effect.dependencies?.length === 1 &&
effect.dependencies[0] === 'synthetic',
)
.callback();
const choices = Array.from({ length: 100 }, (_, index) => ({
opportunity: {
key: `opportunity:${index + 1}`,
title: `Synthetic ${index + 1}`,
},
territory: null,
location_reason: 'Descrição '.repeat(80),
}));
flat(initial)
.find(
(node) =>
Array.isArray(node.props.choices) && node.props.onChange,
)
.props.onChange(choices);
harness.render();
flush();
assert.equal(harness.pending.length, 1);
assert.match(harness.pending[0].url, /\/rascunho$/);
assert.equal(harness.pending[0].body.opportunity_choices.length, 100);
assert.equal(
harness.pending[0].body.opportunity_choices[99].location_reason,
choices[99].location_reason,
);
assert.ok(JSON.stringify(harness.pending[0].body).length > 60000);
} finally {
cleanup?.();
globalThis.window = previousWindow;
}
});
void test('successful save followed by failed recovery offers read-only retry and never restores a stale draft', async () => {
const previousWindow = globalThis.window;
const listeners = new Map();