feat: CI: browser journey leaves first-task completion sync pending on main #1157

Merged
timmy merged 1 commits from timmy/1156-ci-browser-journey-leaves-first-task-completion- into main 2026-08-20 00:46:36 +00:00
2 changed files with 51 additions and 1 deletions

View File

@ -303,7 +303,10 @@ function createTodaySync({ storage, getLogin, fetchJson, onRemoteIds, onRemotePl
let operations = pending();
let plan;
let hadConflict = false;
if (!operations.length) plan = await fetchJson('api/v1/today');
if (!operations.length) {
plan = await fetchJson('api/v1/today');
operations = pending();
}
while (operations.length) {
if (key() !== ownerKey) return false;
const batch = operations.slice(0, 50);

View File

@ -84,6 +84,53 @@ sync.enqueue('add', 'issue:r:1:');
}
def test_activation_queued_during_an_empty_inflight_refresh_is_drained_before_it_settles():
script = f"""
const createTodaySync = require({json.dumps(str(TODAY_SYNC))});
const values = new Map();
const storage = {{get length(){{return values.size}},key:i=>[...values.keys()][i]||null,
getItem:k=>values.get(k)||null,setItem:(k,v)=>values.set(k,v),removeItem:k=>values.delete(k)}};
let releaseRefresh;
const refreshStarted = new Promise(resolve => {{ globalThis.refreshStarted = resolve; }});
const patches = [];
const statuses = [];
const sync = createTodaySync({{
storage, getLogin: () => 'timmy', createOperationId: () => 'activation-1',
fetchJson: async (_url, options={{}}) => {{
if (!options.method) {{
globalThis.refreshStarted();
await new Promise(resolve => {{ releaseRefresh = resolve; }});
return {{revision:0, ids:[]}};
}}
const operations = JSON.parse(options.body).operations;
patches.push(...operations);
return {{revision:1, ids:[], first_task_state:'complete',
accepted_operation_ids:operations.map(item => item.operation_id)}};
}},
onRemoteIds: () => {{}}, onStatus: state => statuses.push(state),
}});
(async () => {{
const refreshing = sync.flush();
await refreshStarted;
sync.enqueueActivation('complete');
const sharedFlush = sync.flush();
releaseRefresh();
await sharedFlush;
process.stdout.write(JSON.stringify({{
sharesInflight: refreshing === sharedFlush, patches, pending:sync.pending(), statuses,
}}));
}})();
"""
result = json.loads(subprocess.run(
["node", "-e", script], check=True, capture_output=True, text=True
).stdout)
assert result["sharesInflight"] is True
assert [operation["activation_state"] for operation in result["patches"]] == ["complete"]
assert result["pending"] == []
assert result["statuses"][-1] == "saved"
def test_operations_queued_in_the_same_millisecond_preserve_enqueue_order():
script = f"""
const createTodaySync = require({json.dumps(str(TODAY_SYNC))});