fix(app): reject schedule edits without exact identity and revision

This commit is contained in:
2026-10-21 20:21:48 +01:00
parent 8807f2b1c3
commit 87220fe886
4 changed files with 52 additions and 3 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ or scratch servers only, never real operator sessions/runs/workflows.
| Chat model/Info/background tasks | Source request facade | current-model selection, numeric Info modal (unknown !=0), bounded running shell pages |
| Chat commands/notices/scroll | Missing | slash palette/actions, unknown-command send-as-message, dismissible local notices, saved scroll/follow intent |
| Saved schedule list | Source | pipeline entry and route registration, exact timer provenance vocabulary |
| Schedule editor | Active lossless draft74 | native fields, stable create key, revision-CAS edit/pause/delete, conflict keeps draft, Schedule this run seed |
| Schedule editor | Source lossless draft74 + identity/CAS guard | native fields, stable create key, edit/pause/delete, conflict keeps draft, Schedule this run seed |
| Search | Source screen | shell entry, close/focus/selection retention, exact pipeline/version/run/field/visit/artifact target routing |
| Needs you | Missing | derived failed/waiting counts, native list/sheet, open/dismiss/clear snapshot, persisted identities |
| Notifications | Missing | explicit permission/rationale, secure/unsupported/denied states, transition-only dedupe, background question notices |
@@ -81,6 +81,18 @@ class ScheduleDraft {
void fail(String field, String message) =>
errors.putIfAbsent(field, () => message);
final selectedPipeline = source?.pipelineId ?? pipelineId;
if (!_validIdentity(selectedPipeline)) {
fail('pipelineId', 'Choose a valid pipeline.');
}
if (source != null &&
(!_validIdentity(source!.id) || !_validIdentity(source!.revision))) {
fail(
'record',
'Schedule identity or revision is missing. Refresh before editing.',
);
}
if (name.trim().isEmpty) fail('name', 'Enter a schedule name.');
if (prompt.trim().isEmpty) fail('prompt', 'Enter a prompt.');
final pinned = int.tryParse(version);
@@ -123,8 +135,7 @@ class ScheduleDraft {
final record = source?.toJson() ?? <String, dynamic>{};
if (source == null) record['id'] = 0;
record['name'] = name.trim();
final pipeline = source?.pipelineId ?? pipelineId;
if (pipeline != null) record['pipeline_id'] = pipeline;
record['pipeline_id'] = selectedPipeline;
record['version'] = pinned;
record['enabled'] = enabled;
record['input'] = (source?.input ?? <String, dynamic>{})
@@ -157,6 +168,8 @@ class ScheduleDraft {
}
const _maxSafeInteger = 9007199254740991;
bool _validIdentity(int? value) =>
value != null && value > 0 && value <= _maxSafeInteger;
final _digits = RegExp(r'^\d+$');
final _timeOfDay = RegExp(r'^([01]\d|2[0-3]):[0-5]\d$');
final _workspaceBreaks = RegExp(r'[\x00\r\n]');
+6
View File
@@ -1,5 +1,11 @@
# S1-draft — pure saved-schedule editor draft and validation
Manager integration guard: invalid pipeline IDs and edited records without a
positive exact server identity/revision cannot build save payloads. This prevents
a malformed/historical edit from becoming a create or bypassing CAS. Three new
regressions failed against the original draft and pass after the fail-closed
guard. The original snapshot remains unchanged; no production save was tested.
## What changed
New files only; no existing feature, shell, transport, `main` or pubspec source
@@ -0,0 +1,30 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/schedules/domain/editor/schedule_draft.dart';
import 'package:pipelines_app/features/schedules/domain/saved_schedule.dart';
import 'draft_fixtures.dart';
void main() {
test('an invalid pipeline identity cannot become a create payload', () {
final draft =
ScheduleDraft.create(pipelineId: 0, version: '1', workspace: '/srv')
..name = 'Topic'
..prompt = 'Research this';
expect(draft.build().record, isNull);
expect(draft.build().errors, contains('pipelineId'));
});
for (final missing in ['id', 'revision']) {
test(
'missing $missing never turns an edit into an unconditional create',
() {
final raw = completeRecord()..remove(missing);
final source = SavedSchedule(raw);
final draft = ScheduleDraft.fromSchedule(source);
expect(draft.build().record, isNull);
expect(draft.build().errors, contains('record'));
expect(source.raw.containsKey(missing), isFalse);
},
);
}
}