fix: preserve Today sync enqueue order
All checks were successful
CI / lint (pull_request) Successful in 2m38s
CI / build-release (pull_request) Successful in 5s
CI / browser-journey (pull_request) Successful in 2m9s
CI / release-candidate (pull_request) Has been skipped

This commit is contained in:
timmy 2026-08-17 20:43:13 +00:00
parent 4a85f02eae
commit 442d0a157d
3 changed files with 27 additions and 2 deletions

View File

@ -173,7 +173,7 @@ function createTodaySync({ storage, getLogin, fetchJson, onRemoteIds, onRemotePl
const recordKey = storageKey + '.operation.' + encodeURIComponent(operation.operation_id);
let saved = false;
try {
storage.setItem(recordKey, JSON.stringify({ operation, queued_at: now() }));
storage.setItem(recordKey, JSON.stringify({ operation, queued_at: now() + operations.length }));
knownOperationKeys.add(recordKey);
saved = true;
coordinator?.notify('today');

View File

@ -38,7 +38,7 @@ FEATURE_SOURCES = {
"static/today-rollover.js", "static/later-work.js", "static/later-picker.js", "static/drafts.js", "static/unfiled-captures.js", "static/unfiled-draft-sync.js",
"static/assign-and-start.js", "static/filed-claim.js", "static/queue-today.js", "static/create-and-start.js",
"static/draft-filing-session.js", "static/draft-capacity-dialog.js", "static/work-selection.js",
"static/today-work.js", "static/pick-work.js", "static/batch-find-work.js",
"static/today-work.js", "static/today-sync.js", "static/pick-work.js", "static/batch-find-work.js",
"static/search-batch-plan.js", "static/mention-composer.js", "static/issue-evidence-review.js", "static/issue-evidence-editor.js",
"static/issue-attachment.js", "static/checklist-conflict.js", "static/issue-outbox.js", "static/authored-outbox.js", "static/issue-sheet.js", "static/mobile-issue-detail-nav.js", "static/issue-filing-review.js", "static/issue-filing-receipt.js",
),

View File

@ -83,6 +83,31 @@ sync.enqueue('add', 'issue:r:1:');
}
def test_operations_queued_in_the_same_millisecond_preserve_enqueue_order():
script = f"""
const createTodaySync = require({json.dumps(str(TODAY_SYNC))});
const values = new Map();
const storage = {{
get length() {{ return values.size; }}, key: index => [...values.keys()][index] || null,
getItem: key => values.get(key) || null,
setItem: (key, value) => values.set(key, value), removeItem: key => values.delete(key),
}};
const operationIds = ['z-add-first', 'a-move-second'];
const sync = createTodaySync({{
storage, getLogin: () => 'timmy', now: () => 1000,
createOperationId: () => operationIds.shift(),
fetchJson: async () => ({{revision: 0, ids: []}}),
}});
sync.enqueue('add', 'issue:r:1:');
sync.enqueue('move', 'issue:r:1:', 'up');
process.stdout.write(JSON.stringify(sync.pending().map(operation => operation.operation_id)));
"""
assert json.loads(subprocess.run(
["node", "-e", script], check=True, capture_output=True, text=True
).stdout) == ["z-add-first", "a-move-second"]
def test_today_capacity_configuration_syncs_offline_and_adopts_remote_plan():
script = f"""
const createTodaySync = require({json.dumps(str(TODAY_SYNC))});