feat(app): persist pending pipeline run intents

This commit is contained in:
2026-10-22 23:48:33 +01:00
parent 26761ea0d3
commit a5874babc0
5 changed files with 280 additions and 9 deletions
@@ -0,0 +1,102 @@
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/pipelines/pipeline_repository.dart';
import 'package:pipelines_app/features/pipelines/pipelines_controller.dart';
import 'package:pipelines_app/features/pipelines/pending_run_store.dart';
import 'package:pipelines_app/features/pipelines/run_pipeline_intent.dart';
import 'fixtures.dart';
const _storedIntent = RunPipelineIntent(
pipelineId: 7,
version: 3,
prompt: 'stored',
workspace: '/work',
notifyMode: RunNotifyMode.notify,
requestKey: 'stored-key',
);
class _DelayedStore implements PendingRunStore {
final Completer<RunPipelineIntent?> readResult =
Completer<RunPipelineIntent?>();
@override
Future<RunPipelineIntent?> read(int pipelineId, int version) =>
readResult.future;
@override
Future<void> remove(int pipelineId, int version) async {}
@override
Future<void> write(RunPipelineIntent intent) async {}
}
void main() {
test(
'intent survives store reuse; clear and identities are isolated',
() async {
final store = MemoryPendingRunStore();
const intent = RunPipelineIntent(
pipelineId: 7,
version: 3,
prompt: 'do it',
workspace: '/work',
notifyMode: RunNotifyMode.notify,
requestKey: 'same-key',
);
await store.write(intent);
expect((await MemoryPendingRunStore(endpoint: '').read(7, 3)), isNull);
expect((await store.read(7, 3))?.requestKey, 'same-key');
expect(await store.read(7, 4), isNull);
expect(await store.read(8, 3), isNull);
store.values[pendingRunStorageKey('', 7, 4)] = '{bad';
expect(await store.read(7, 4), isNull);
store.values[pendingRunStorageKey('', 7, 4)] = intent.toJson().toString();
expect(await store.read(7, 4), isNull);
await store.remove(7, 3);
expect(await store.read(7, 3), isNull);
},
);
test(
'a delayed read cannot restore an intent after it was cleared',
() async {
final store = _DelayedStore();
final controller = PipelinesController(
PipelinesRepository(
FakeGateway((type, fields) => errorReply('unused')),
),
pendingRunStore: store,
);
expect(controller.pendingRunFor(7, 3), isNull);
controller.clearPendingRun(7, 3);
store.readResult.complete(_storedIntent);
await Future<void>.delayed(Duration.zero);
expect(controller.pendingRunFor(7, 3), isNull);
controller.dispose();
},
);
test('a delayed read cannot replace a newer remembered intent', () async {
final store = _DelayedStore();
final controller = PipelinesController(
PipelinesRepository(FakeGateway((type, fields) => errorReply('unused'))),
pendingRunStore: store,
);
expect(controller.pendingRunFor(7, 3), isNull);
const newer = RunPipelineIntent(
pipelineId: 7,
version: 3,
prompt: 'newer',
workspace: '/work',
notifyMode: RunNotifyMode.notify,
requestKey: 'newer-key',
);
controller.rememberPendingRun(newer);
store.readResult.complete(_storedIntent);
await Future<void>.delayed(Duration.zero);
expect(controller.pendingRunFor(7, 3)?.requestKey, 'newer-key');
controller.dispose();
});
}