Skip to content

chore(#107): backend code-health — error-code contract, EF migration consolidation, perf, validators, deps - #205

Merged
thomasluizon merged 5 commits into
mainfrom
chore/107-code-health-sweep
Jun 13, 2026
Merged

chore(#107): backend code-health — error-code contract, EF migration consolidation, perf, validators, deps#205
thomasluizon merged 5 commits into
mainfrom
chore/107-code-health-sweep

Conversation

@thomasluizon

@thomasluizon thomasluizon commented Jun 13, 2026

Copy link
Copy Markdown
Owner

What

Consolidated backend code-health PR for the #107 umbrella (orbit-api side). Paired with the frontend PR in thomasluizon/orbit-ui-mobile.

Consumer PR: thomasluizon/orbit-ui-mobile#172
Refs thomasluizon/orbit-ui-mobile#107

Squash-merge this first — the errorCode change is additive on the wire (error string preserved + errorCode added), so the consumer PR depends on it being live.

Highlights

  • Error-code contract: every controller failure now ships a stable errorCode alongside the English fallback (ToErrorResult/ToErrorBody uniform path; ~36 controller sites + AuthController migrated). New AppError catalog pairs each message with a code in ErrorMessages/DomainErrors; clients localize on the code.
  • EF migration consolidation (Strand 6): the Persistence/Migrations folder merged into Migrations under one namespace via git mv — migration ids, class names, and the model snapshot untouched, so no migration re-applies and the production schema is unaffected. Also adopted the previously-orphaned performance indexes into a real AdoptPerformanceIndexes migration (they were never in the EF chain) + added a notifications (UserId, CreatedAtUtc) index.
  • Performance: filtered Include(h => h.Logs) on the hot log/skip/bulk paths (was loading full 400-day history); bulk-log gamification batched (was N×6 queries); FindAsync().Count materializations → Any/CountAsync.
  • Validators & rate limits: added the missing date-range / bulk-cap validators; rate-limited account-deletion endpoints.
  • Deps: FileSignatures 6→7.2.1 clears the OpenMcdf DoS advisories (0 vulnerable across all 8 projects); JWT/test-tooling bumps.
  • Quality: the 11 oversized C# methods split (BuildCapabilities 794→25 + named builders, etc.); audit-write swallows now log; naming fixes; analyzer (ORBIT0001) clean.

Validation

dotnet build Orbit.slnx 0 errors / 0 warnings; dotnet test Orbit.slnx 3,255 passing.

Deferral

SyncController.GetChanges (v1 sync) kept, not deleted — old Play app builds may still call it, the agent capability catalog references it, and two tests exercise it. Revisit when min-supported-version telemetry confirms it's safe to drop (justification on issue #107).

🤖 Generated with Claude Code

Comment thread src/Orbit.Api/Controllers/SyncController.cs

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One contract break to resolve before merge.

High-signal finding: The 410 Gone response body on both GET /api/sync/changes and GET /api/sync/changes/v2 silently changed the field name from code to errorCode (line 156 / 238 in SyncController.cs). Every other controller in this PR goes from no error-code field to adding errorCode — genuinely additive. These two endpoints are the exception: they already had a field named code, and this PR renames it. Any client that branches on .code === 'SYNC_WINDOW_EXCEEDED' to trigger a full re-sync now gets undefined instead. The inline comment has the specifics and the resolution options.

Everything else in this PR is solid — the uniform errorCode contract across ~36 controller sites, filtered includes on the hot log/skip paths, N+1 gamification batching, new validators and rate limits on account-deletion, migration consolidation, and the FileSignatures DoS advisory fix all look correct and well-tested. 3,255 tests passing, zero warnings. Happy to approve once the sync 410 body contract question is answered.

@sonarqubecloud

Copy link
Copy Markdown

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid, well-scoped code-health sweep. The error-code contract is clean: AppError records pair code + message, Result.Failure(AppError) propagates both, and ToErrorResult/ToErrorBody unify the controller surface — every failure path now emits { error, errorCode } consistently. The migration consolidation is safe: the three pre-existing partial Habits indexes are guarded with IF NOT EXISTS, and the new IX_Notifications_UserId_CreatedAtUtc index is genuinely new so no collision risk. Filtered Include on the log/skip/bulk hot paths and the gamification N+1 batch fix are correct and non-breaking. All five new validators (ConfirmAccountDeletion, GetAllHabitLogs, GetCalendarMonth, GetDailySummary, UnsubscribePush) ship with test files. The GET /api/habits/logs REST endpoint removal is intentional and explicitly paired with the consumer PR (#172). The SonarCloud reliability gate tripped before the last commit (the null-check fix) — the build and 3,255-test suite are green, so I'm not treating the stale gate result as a blocker.

@thomasluizon
thomasluizon merged commit 955cc84 into main Jun 13, 2026
6 checks passed
@thomasluizon
thomasluizon deleted the chore/107-code-health-sweep branch June 13, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant