# Story 1.9: Seed System Reference Values & Rule Defaults Status: done ## Story As a a developer, I want the system seeded with default reference values, required-field rules, and escalation rule defaults, so that Epics 2–5 are immediately functional without requiring administrator configuration before use. ## Acceptance Criteria 1. **Given** the application initializes for the first time **When** the seed operation runs **Then** operational status sets, service template defaults, and extension-layer reference values are populated in the database 2. **Given** the seed runs **When** required-field rules are evaluated **Then** default readiness fields for election-cycle jobs are defined and evaluable by Epic 2's readiness status feature (FR29) 3. **Given** the seed runs **When** escalation rule defaults are checked **Then** at least one default rule exists covering overdue milestone alert scenarios (FR30) 4. **Given** the seed operation is run multiple times **When** it completes **Then** no duplicate records are created — the operation is fully idempotent 5. **Given** Epic 6 admin UIs update reference values or rules **When** the changes are saved **Then** they persist independently of the seed — rerunning the seed does not overwrite admin-managed values ## Tasks / Subtasks - [x] Implement story behavior in aligned backend/frontend modules (AC: #1) - [x] Add or update API/service/UI components required by the story scope - [x] Keep legacy Access entities read-only and route writes to extension-layer structures - [x] Cover acceptance criteria #2 in implementation and tests (AC: #2) - [x] Add validation/error handling and UX state updates as needed - [x] Cover acceptance criteria #3 in implementation and tests (AC: #3) - [x] Add validation/error handling and UX state updates as needed - [x] Cover acceptance criteria #4 in implementation and tests (AC: #4) - [x] Add validation/error handling and UX state updates as needed - [x] Validate and document completion evidence - [x] Verify build/tests for touched modules - [x] Capture changed files and any migration/config implications ### Review Findings - [x] [Review][Patch] `SeedServiceTests.cs` contains terminal escape/control bytes instead of C# and blocks the backend test project from compiling [Campaign_Tracker.Server.Tests/SeedServiceTests.cs:1] - [x] [Review][Patch] `SeedAsync()` is a no-op placeholder and does not populate operational statuses, service template defaults, reference values, required-field rules, or overdue escalation defaults [Campaign_Tracker.Server/Seed/SeedService.cs:7] - [x] [Review][Patch] `IsSeededAsync()` always returns `true`, so a fresh system can be treated as already seeded [Campaign_Tracker.Server/Seed/SeedService.cs:20] - [x] [Review][Patch] Seed service is not registered or invoked during application initialization, so even a completed seed implementation would not run on first startup [Campaign_Tracker.Server/Program.cs:106] - [x] [Review][Patch] Seed models lack immutable seed keys/source metadata needed for idempotency and for preserving admin-managed values on rerun [Campaign_Tracker.Server/Seed/Models/ReferenceValue.cs:7] - [x] [Review][Patch] Required-field and escalation rules are raw strings with no evaluator-facing scope or validated metadata, so Epic 2 readiness and overdue milestone alerts cannot evaluate them deterministically [Campaign_Tracker.Server/Seed/Models/RequiredFieldRule.cs:16] ## Dev Notes - Follow Epic 1 architecture constraints: ASP.NET Core + React separation, RBAC-aware patterns, and immutable legacy tables. - Reuse shared component and workflow patterns defined in UX and architecture docs; avoid parallel custom implementations. - Keep changes scoped to this story; do not pull forward Epic 2+ features. ### Project Structure Notes - Backend: `Campaign_Tracker.Server/` - Frontend: `campaign-tracker-client/` - Story artifacts: `_bmad-output/implementation-artifacts/` ### References - Story source: `_bmad-output/planning-artifacts/epics.md` (Epic 1 / Story 1.9) - Architecture constraints: `_bmad-output/planning-artifacts/architecture.md` - UX patterns: `_bmad-output/planning-artifacts/ux-design-specification.md` ## Dev Agent Record ### Agent Model Used GPT-5 Codex ### Debug Log References - Story generated from epic source and architecture/UX planning artifacts. - Code review run for Story 1.9. - Fixed review findings and verified with `dotnet test .\Campaign_Tracker.Server.Tests\Campaign_Tracker.Server.Tests.csproj /p:UseAppHost=false` (117 passed). ### Completion Notes List - Implemented startup seeding for system reference values, election-cycle readiness required-field rules, and overdue milestone escalation defaults. - Added stable seed keys and source metadata to support idempotency and admin-managed persistence on rerun. - Added durable JSON-backed seed store plus in-memory test store; JSON seed output is ignored from source control. - Replaced corrupted seed tests with AC-focused tests covering first seed, idempotency, persistence, FR29 rule scope, FR30 escalation defaults, and admin override preservation. ### File List - `_bmad-output/implementation-artifacts/1-9-seed-system-reference-values-rule-defaults.md` - `.gitignore` - `Campaign_Tracker.Server/Program.cs` - `Campaign_Tracker.Server/Seed/ISeedService.cs` - `Campaign_Tracker.Server/Seed/ISeedDataStore.cs` - `Campaign_Tracker.Server/Seed/SeedDataSet.cs` - `Campaign_Tracker.Server/Seed/SeedService.cs` - `Campaign_Tracker.Server/Seed/SeedHostedService.cs` - `Campaign_Tracker.Server/Seed/FileSeedDataStore.cs` - `Campaign_Tracker.Server/Seed/InMemorySeedDataStore.cs` - `Campaign_Tracker.Server/Seed/README.md` - `Campaign_Tracker.Server/Seed/Models/EscalationRule.cs` - `Campaign_Tracker.Server/Seed/Models/ReferenceValue.cs` - `Campaign_Tracker.Server/Seed/Models/RequiredFieldRule.cs` - `Campaign_Tracker.Server/Seed/Models/SeedRecordSource.cs` - `Campaign_Tracker.Server.Tests/SeedServiceTests.cs`