diff --git a/app/PARITY.md b/app/PARITY.md index c6da5edd..a9e3a727 100644 --- a/app/PARITY.md +++ b/app/PARITY.md @@ -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 | diff --git a/app/lib/features/schedules/domain/editor/schedule_draft.dart b/app/lib/features/schedules/domain/editor/schedule_draft.dart index 1beb75cc..a07edc97 100644 --- a/app/lib/features/schedules/domain/editor/schedule_draft.dart +++ b/app/lib/features/schedules/domain/editor/schedule_draft.dart @@ -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() ?? {}; 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 ?? {}) @@ -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]'); diff --git a/app/notes/S1-draft.md b/app/notes/S1-draft.md index 27ca42db..57fa7d2c 100644 --- a/app/notes/S1-draft.md +++ b/app/notes/S1-draft.md @@ -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 diff --git a/app/test/features/schedules/domain/editor/schedule_draft_identity_test.dart b/app/test/features/schedules/domain/editor/schedule_draft_identity_test.dart new file mode 100644 index 00000000..d3512fd8 --- /dev/null +++ b/app/test/features/schedules/domain/editor/schedule_draft_identity_test.dart @@ -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); + }, + ); + } +}