Chat list: order chat_session_changed pushes by a registry revision

operator_sessions gains a revision bumped by a trigger on every update; the
wire row carries it, and the app ignores a push (or a list read) older than
the row it holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 00:34:16 +00:00
parent 9f13c93be6
commit fbc09528ec
6 changed files with 163 additions and 7 deletions
@@ -266,6 +266,45 @@ void main() {
expect(gateway.count('chat_sessions'), lists);
});
test('a push older than the row held is ignored', () async {
JsonMap push(int revision, String color) => {
'type': 'chat_session_changed',
'chat_session': {
'id': 's2',
'title': 'Plain chat',
'color': color,
'revision': revision,
},
};
// The server sends pushes concurrently: revision 7 lands before 6.
gateway.pushed.add(push(7, 'pink'));
gateway.pushed.add(push(6, 'blue'));
await pumpEventQueue();
expect(row('s2')['color'], 'pink');
expect(row('s2')['revision'], 7);
gateway.pushed.add(push(8, 'amber'));
await pumpEventQueue();
expect(row('s2')['color'], 'amber');
// A list read older than the applied push does not revert it.
var listed = <String, dynamic>{
'id': 's2',
'title': 'Plain chat',
'directory': '/w',
'revision': 5,
};
gateway.sessionsHandler = () async => {
'chat_sessions': [listed],
};
await controller.refresh();
expect(row('s2')['color'], 'amber');
expect(row('s2')['revision'], 8);
// A newer list row wins.
listed = {...listed, 'color': 'teal', 'revision': 9};
await controller.refresh();
expect(row('s2')['color'], 'teal');
expect(row('s2')['revision'], 9);
});
test('a refused colour is undone and the reason shown', () async {
gateway.failures['chat_color'] = 'unknown chat colour';
await controller.setColor('s2', 'blue');