Strengthen test hygiene and fix vacuous assertions - #92
Conversation
Fixes tests that asserted less than they appeared to: - CanGetEmptyModelSnapshot asserted the Task was non-null (always true) and never awaited it; now awaits and asserts the empty-model shape. - Add missing assertions to smoke-only tests: DontAddTheSameSnapshotTwice, CanRecreateUniqueConstraintConflictingValueInOneCommit, CanCreate2EntriesOutOfOrder. - Turn DeleteStaleSnapshots_Works into a meaningful test of the skip-when-newer branch (renamed to DeleteStaleSnapshots_KeepsSnapshotsOlderThanTheCommit). - MultiThreading test now asserts each thread's entity converged to its final write instead of only checking that no exception was thrown. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 52 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR strengthens tests for commit ordering, empty model snapshots, snapshot retention, unique-constraint recreation, and concurrent entity writes. ChangesPersistence and concurrency test coverage
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/SIL.Harmony.Tests/DataModelSimpleChanges.cs (1)
180-184: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winMake the out-of-order assertion order-sensitive.
commit1andcommit2create different entities. BothGetLatestassertions pass whether the model applies commits by insertion order or timestamp order. The timestamp assertion verifies only the test setup.Assert that
DataModel.GetProjectSnapshot().LastChangeequalscommit1.DateTime. The existing snapshot contract is checked insrc/SIL.Harmony.Tests/ModelSnapshotTests.cs, Line [38]. Alternatively, add an ordering-sensitive update to the same entity.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/SIL.Harmony.Tests/DataModelSimpleChanges.cs` around lines 180 - 184, Update the out-of-order test around commit1, commit2, and the existing GetLatest assertions to verify ordering through DataModel.GetProjectSnapshot().LastChange, asserting it equals commit1.DateTime. Keep the current timestamp and entity assertions unless necessary, and do not rely on updates to separate entities as evidence of commit ordering.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/SIL.Harmony.Tests/MultiThreadingTests.cs`:
- Around line 23-24: Update CanApplyChangesWithoutError and its worker-thread
fixture creation to dispose all four DataModelTestBase instances, including the
read fixture and each per-thread fixture, by awaiting or synchronously
completing DisposeAsync before each fixture’s scope ends.
- Around line 23-24: Move DataModelTestBase construction and InitializeAsync
execution inside the worker thread’s existing try/catch so setup failures are
captured and returned as the Run result exception. After awaiting Task.WhenAll,
assert result.exception.Should().BeNull() to report any captured failure through
the test.
---
Nitpick comments:
In `@src/SIL.Harmony.Tests/DataModelSimpleChanges.cs`:
- Around line 180-184: Update the out-of-order test around commit1, commit2, and
the existing GetLatest assertions to verify ordering through
DataModel.GetProjectSnapshot().LastChange, asserting it equals commit1.DateTime.
Keep the current timestamp and entity assertions unless necessary, and do not
rely on updates to separate entities as evidence of commit ordering.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 26612e22-175d-426a-8a9a-1049edf6d684
📒 Files selected for processing (5)
src/SIL.Harmony.Tests/DataModelSimpleChanges.cssrc/SIL.Harmony.Tests/ModelSnapshotTests.cssrc/SIL.Harmony.Tests/MultiThreadingTests.cssrc/SIL.Harmony.Tests/RepositoryTests.cssrc/SIL.Harmony.Tests/SnapshotTests.cs
Per CodeRabbit review: the test created four DataModelTestBase instances (one in the test, one per worker thread) and never disposed them, leaking each DI ServiceProvider. Each worker thread now disposes its own fixture in a finally block, and the test-level fixture is an 'await using' so it is disposed after assertions. The test-level fixture keeps the shared in-memory SQLite database alive while the worker fixtures dispose. Also merges latest main (MTP runner migration) to keep the branch current. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Per CodeRabbit review: the two GetLatest assertions are on different entities and pass under either insertion-order or timestamp-order application, so they don't prove ordering. Assert GetProjectSnapshot().LastChange equals commit1.DateTime (the later timestamp) to verify commits are ordered by timestamp, not insertion order. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Addressed the remaining CodeRabbit nitpick on 🤖 Addressed by Claude Code |
- Guard worker-thread fixture disposal so a cleanup failure is logged instead of surfacing as an unhandled exception on the raw thread. - Restore coverage of the empty-snapshots branch that the reworked DeleteStaleSnapshots test had dropped (DeleteStaleSnapshots_WithNoSnapshots_DoesNothing). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Reviewed the Devin findings:
🤖 Addressed by Claude Code |
AI-generated summary
This PR fixes tests that passed without actually verifying behavior — the first batch from a broader test-suite review.
ModelSnapshotTests.CanGetEmptyModelSnapshotwas a non-async voidtest that calledDataModel.GetProjectSnapshot().Should().NotBeNull(). That asserted the returnedTaskwas non-null (always true) and never awaited it, so it verified nothing. It now awaits and asserts the empty-model shape (Snapshotsempty;LastChange/LastCommitId/LastCommitHashnull).DontAddTheSameSnapshotTwice(final converged value + word count),CanRecreateUniqueConstraintConflictingValueInOneCommit(original tag deleted, recreated tag present), andCanCreate2EntriesOutOfOrder(both entities present with correct values and ordering).RepositoryTests.DeleteStaleSnapshots_Workshad no assertion. Reworked intoDeleteStaleSnapshots_KeepsSnapshotsOlderThanTheCommit, which covers the skip-when-the-new-commit-is-newer-than-all-snapshots branch that previously had no coverage.MultiThreadingTestspreviously asserted only that concurrent writes threw no exception. It now returns each thread's entity id and final value and asserts the model converged to that final write, so a lost update or corruption that doesn't throw would now fail.No production code changed — test-only.
Test plan
dotnet teston the affected tests passes (6/6 locally).Summary by CodeRabbit