fix(webui): sp17 a Save in flight holds the workflow poll: each organization counts its workflow writes, and a read that began before a write ended, or answers while one is in flight, is dropped so it cannot draw the file from before the Save over the saved step; the page takes the saved workflow and the revision from the write's answer instead of reading again; the test holds the write, starts a poll whose read holds the old file, lets the write answer and then the read, and sees the saved title and a second Save on the answered revision (red before the fix: the step went back to Ship) (#1873, lane sp17-workflow-clicks)
This commit is contained in:
1 parent
ff096afa27
commit
02e053866a
2 files changed
+80
-9
No files matched your search
@@ -46,10 +46,22 @@
|
||||
}
|
||||
// E2E6 P1-1: a poll reloads the data but keeps the page's own state: an open editor and its draft,
|
||||
// a pending delete confirmation and the last receipt.
|
||||
// SP17: a write in flight holds the poll. Each organization counts its writes (epoch moves when one starts
|
||||
// and when it ends); a read that began before a write ended, or answers while one is in flight, is dropped
|
||||
// and the page keeps what it has, which the write's answer brings up to date (written()).
|
||||
const writes = new Map();
|
||||
const writeState = org => { if (!writes.has(org)) writes.set(org, { epoch: 0, inflight: 0 }); return writes.get(org); };
|
||||
async function writing(org, fn) {
|
||||
const w = writeState(org);
|
||||
w.epoch++; w.inflight++;
|
||||
try { return await fn(); } finally { w.inflight--; w.epoch++; }
|
||||
}
|
||||
async function load(org) {
|
||||
const prev = states.get(org);
|
||||
const prev = states.get(org), w = writeState(org), began = w.epoch;
|
||||
const s = { data: null, known: new Set(), error: null, editing: prev?.editing ?? null, confirm: prev?.confirm ?? null, status: prev?.status ?? '' };
|
||||
try { await read(org, s); } catch (error) {
|
||||
const raced = () => !!prev?.data && (w.inflight > 0 || w.epoch !== began);
|
||||
try { await read(org, s); if (raced()) return; } catch (error) {
|
||||
if (raced()) return;
|
||||
// Review P3: a failed poll while an editor is open keeps the last good read, so the fresh section
|
||||
// still carries its data-live-key and graftLive puts the held section, editor and focus back.
|
||||
if (prev?.editing && prev.data) Object.assign(s, { data: prev.data, known: prev.known });
|
||||
@@ -631,6 +643,17 @@
|
||||
if (btn.hasAttribute('data-wfg-delete')) { d.confirm = true; return paint('wfg-delete-no'); }
|
||||
if (btn.hasAttribute('data-wfg-delete-no')) { d.confirm = false; return paint('wfg-delete'); }
|
||||
});
|
||||
// SP17: the page's read brought up to date from a write's answer: the workflow as sent (or gone) and the
|
||||
// revision the write answered. Without a revision in the answer the page reads the file again.
|
||||
async function written(org, s, scope, name, workflow, answer) {
|
||||
const now = states.get(org) ?? s, flows = now.data ? flowsIn(now, scope) : null;
|
||||
if (plain(flows) && typeof answer?.revision === 'string' && /^[0-9a-f]{64}$/.test(answer.revision)) {
|
||||
if (workflow) flows[name] = workflow; else delete flows[name];
|
||||
now.data.revision = answer.revision;
|
||||
return;
|
||||
}
|
||||
try { await read(org, now); } catch { /* the next poll reads it */ }
|
||||
}
|
||||
async function save({ org, name, scope, s, key }) {
|
||||
const d = drafts.get(key);
|
||||
if (!d || d.busy) return;
|
||||
@@ -640,10 +663,10 @@
|
||||
if (refused) { d.status = refused; say(refused); return paint('wfg-save'); }
|
||||
d.busy = true; d.status = 'Saving…'; paint();
|
||||
try {
|
||||
await saveFlow(org, s, { scope, name, revision: d.revision, workflow: shape(d.flow) });
|
||||
const workflow = shape(d.flow);
|
||||
await writing(org, async () => written(org, s, scope, name, workflow, await saveFlow(org, s, { scope, name, revision: d.revision, workflow })));
|
||||
drafts.delete(key);
|
||||
notes.set(key, `Saved ${name}.`);
|
||||
try { await read(org, states.get(org) ?? s); } catch { /* the next poll reads it */ }
|
||||
say(`Saved ${name}.`);
|
||||
paint(selected() ? `wfg-step:${selected()}` : 'wfg-delete');
|
||||
} catch (error) {
|
||||
@@ -660,11 +683,10 @@
|
||||
try {
|
||||
// The revision of the workflow the page shows (settle moves it on only while this workflow is unchanged):
|
||||
// a change made to it since is refused, not deleted over.
|
||||
await removeFlow(org, s, { scope, name, revision: d.revision });
|
||||
await writing(org, async () => written(org, s, scope, name, null, await removeFlow(org, s, { scope, name, revision: d.revision })));
|
||||
drafts.delete(key);
|
||||
notes.set(dkey(org, '', ''), `Deleted ${name}.`);
|
||||
say(`Deleted ${name}.`);
|
||||
try { await read(org, s); } catch { /* the next poll reads it */ }
|
||||
location.hash = `${orgHash(org)}/workflows`;
|
||||
} catch (error) {
|
||||
d.busy = false; d.confirm = false;
|
||||
|
||||
Reference in new issue
Block a user