Skip to content

refactor(tasks): simplify TaskRepository.UpdateAsync audit-event blocks (#197) - #360

Merged
nevridge merged 3 commits into
mainfrom
feature/simplify-taskrepository-audit-blocks
Oct 30, 2026
Merged

nevridge merged 3 commits into
mainfrom
feature/simplify-taskrepository-audit-blocks

Conversation

@nevridge

Copy link
Copy Markdown
Owner

Closes #197

Summary

Pure refactor of TaskRepository.UpdateAsync: the four near-identical "if changed, emit history event" blocks (Title, Priority, Description, DueDate) are replaced by one private helper, AddFieldChangedEvent(int taskId, bool changed, string eventType, Func<string> summary), placed after FormatDueDate. Task history is unchanged for users.

  • Each call site keeps its own explicit comparison: Ordinal string.Equals for Title and Description, != for Priority and DueDate.
  • EventType and ChangeSummary strings are byte-identical to main, because the frontend TaskHistoryPanel maps them.
  • Event order is unchanged (Title, Priority, Description, DueDate, then the status block).
  • Each event keeps its own DateTime.UtcNow.
  • The combined Completed/Reopened/StatusChanged/Blocked block and the originals resolution are untouched.
  • The Detached branch is kept, with a comment explaining it is a safety net for callers that pass untracked entities. It is not removable: an existing test exercises it.
  • No API, database, migration, controller or frontend change.

Files changed

Tests

As reported by the test-verifier (CI will run them again):

  • dotnet format TaskFlow.sln --verify-no-changes: exit 0
  • dotnet build TaskFlow.sln -c Release: 0 warnings, 0 errors
  • Full backend suite: 663 passed, 0 failed
  • Coverage threshold of 75%: passed (exit 0)

New tests cover exact summaries for each field, Priority-only, single-event assertions, ordering (including field events before the status event), the case-only Title change, an Ordinal-only Description change, null/empty Description swaps, same-value no-ops, a DueDate with a different Kind (no event), InProgress falling through to StatusChanged, and Detached title and priority changes.

Validator status

Critical 0, Important 0, Minor 1 (after one rework pass).

Residual, for awareness:

  • The Detached comment says the branch is covered by "the Detached-entity tests in TaskRepositoryTests"; only one such test is there, and the others are in the new file. Wording only.
  • The Ordinal Description test catches a case-insensitive comparer but not a case-sensitive culture-sensitive one. Production code uses StringComparison.Ordinal.

Suggested follow-up issue (not filed)

Possible missed Description/DueDate event on the Detached path when the persisted value is null. The originals use persisted?.X ?? entry.OriginalValues..., and after Update(task) the fallback already equals the incoming value. This was found by code reading and is unverified, and no production caller reaches the Detached path. This PR neither hides nor alters it, and no test asserts it. It is worth verifying and fixing separately.

@nevridge
nevridge force-pushed the feature/simplify-taskrepository-audit-blocks branch from 5c6b3ec to 582918d Compare October 30, 2026 22:56

@nevridge nevridge left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review: 💬 Comments

No issues found in this diff.


Reviewed at 582918d · findings from pr-review + code-review, verified and triaged by @nevridge with Claude Code

@nevridge
nevridge merged commit d81d6fc into main Oct 30, 2026
15 checks passed
@nevridge
nevridge deleted the feature/simplify-taskrepository-audit-blocks branch October 30, 2026 23:03
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.

[Cleanup] Simplify TaskRepository.UpdateAsync audit-event blocks

1 participant