Repository navigation
test(cache,server): assert row counts via Ent - #1288
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughConverts standalone test raw SQL COUNT(*) assertions to Ent ORM Count(...) in cache and server tests; adds spec and task documents defining scope and exceptions, and implements replacements in two test files. ChangesTest SQL-to-ORM Count Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors standalone raw SQL SELECT COUNT(*) assertions in pkg/cache/cache_test.go and pkg/server/server_test.go to use the Ent ORM client's .Count(ctx) API, aligning with a new requirement in the database-orm specification. The review feedback suggests replacing context.Background() with the local helper newContext() in pkg/cache/cache_test.go to maintain consistency with the rest of the test suite and ensure proper test logger configuration.
895160e to
106d5e9
Compare
Switch the five converted Ent count assertions from context.Background() to the cache_test.go newContext() helper (a discard-logger context), matching the surrounding suite convention. Addresses review comments on PR #1288 (threads PRRT_kwDONV6tZs6Fv0I4, PRRT_kwDONV6tZs6Fv0JC, PRRT_kwDONV6tZs6Fv0JK, PRRT_kwDONV6tZs6Fv0JT, PRRT_kwDONV6tZs6Fv0Jb). Co-Authored-By: Claude Opus 4.8 <[email protected]>
1f40f94 to
b1088d5
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
openspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/proposal.md (1)
17-25: ⚡ Quick winConsider explicitly listing both spec requirements in Modified Capabilities.
The spec file (lines 148-168) adds a distinct requirement about using
database.IsNotFoundErroras the unified not-found predicate, in addition to the count-assertion requirement (lines 170-184). Line 25's phrasing "row presence/counts" is ambiguous—it could be read as covering both, but the not-found predicate change is a separate API-surface requirement that deserves explicit mention.Consider splitting line 25 into two bullets to match the spec's two new requirements:
- One for the count-assertion Ent requirement
- One for the
database.IsNotFoundErrorpredicate requirementThis would make the proposal's scope match the spec additions 1:1 and improve clarity for reviewers.
🤖 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 `@openspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/proposal.md` around lines 17 - 25, Update the "Modified Capabilities" section to explicitly show both new requirements: keep the existing bullet that requires tests to assert row presence/counts via the Ent client (`database-orm` behavior tests must use Ent for presence/count assertions), and add a second bullet that states the unified not-found predicate requirement (`database.IsNotFoundError` must be used as the not-found predicate in tests). Make sure the two bullets reference `database-orm`, the Ent client requirement, and the `database.IsNotFoundError` symbol so the proposal matches the spec changes one-to-one.
🤖 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.
Nitpick comments:
In `@openspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/proposal.md`:
- Around line 17-25: Update the "Modified Capabilities" section to explicitly
show both new requirements: keep the existing bullet that requires tests to
assert row presence/counts via the Ent client (`database-orm` behavior tests
must use Ent for presence/count assertions), and add a second bullet that states
the unified not-found predicate requirement (`database.IsNotFoundError` must be
used as the not-found predicate in tests). Make sure the two bullets reference
`database-orm`, the Ent client requirement, and the `database.IsNotFoundError`
symbol so the proposal matches the spec changes one-to-one.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1323134f-65b8-455b-a19a-4986881780d1
📒 Files selected for processing (8)
openspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/.openspec.yamlopenspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/design.mdopenspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/proposal.mdopenspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/specs/database-orm/spec.mdopenspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/tasks.mdopenspec/specs/database-orm/spec.mdpkg/cache/cache_test.gopkg/server/server_test.go
✅ Files skipped from review due to trivial changes (4)
- openspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/.openspec.yaml
- openspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/tasks.md
- openspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/design.md
- openspec/changes/archive/2026-05-29-trim-test-raw-sql-counts/specs/database-orm/spec.md
🚧 Files skipped from review as they are similar to previous changes (2)
- pkg/server/server_test.go
- pkg/cache/cache_test.go
106d5e9 to
014e8e3
Compare
Switch the five converted Ent count assertions from context.Background() to the cache_test.go newContext() helper (a discard-logger context), matching the surrounding suite convention. Addresses review comments on PR #1288 (threads PRRT_kwDONV6tZs6Fv0I4, PRRT_kwDONV6tZs6Fv0JC, PRRT_kwDONV6tZs6Fv0JK, PRRT_kwDONV6tZs6Fv0JT, PRRT_kwDONV6tZs6Fv0Jb). Co-Authored-By: Claude Opus 4.8 <[email protected]>
b1088d5 to
25088e5
Compare
014e8e3 to
0230e29
Compare
Switch the five converted Ent count assertions from context.Background() to the cache_test.go newContext() helper (a discard-logger context), matching the surrounding suite convention. Addresses review comments on PR #1288 (threads PRRT_kwDONV6tZs6Fv0I4, PRRT_kwDONV6tZs6Fv0JC, PRRT_kwDONV6tZs6Fv0JK, PRRT_kwDONV6tZs6Fv0JT, PRRT_kwDONV6tZs6Fv0Jb). Co-Authored-By: Claude Opus 4.8 <[email protected]>
25088e5 to
678d5e0
Compare
Client.DB() is a discouraged raw-*sql.DB escape hatch, yet the test suites reach for it ~110 times. Most uses are legitimate (migration verification, schema probes, adversarial setup, pool tuning). One pattern is a clean swap that loses no verification independence: standalone SELECT COUNT(*) row-count assertions in the cache and server behavior tests. Convert the 5 bare table-count assertions in cache_test.go and all 5 by-hash count assertions in server_test.go to the Ent API (dbClient.Ent().<Entity>.Query()[.Where(entnarinfo.HashEQ(h))] .Count(ctx)). Retain raw SQL everywhere it is the right tool, including the cache_test.go by-hash counts that are interleaved with raw-SQL idioms (rebind helper, ExecContext mutations, Eventually polling, concurrent wg flows) and all pkg/ncps migration-outcome checks (ORM-independent by design). The production pkg/ncps/migrate.go use of DB() is unchanged. Records a database-orm spec requirement scoping the Ent-count convention to standalone behavior-test assertions. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Switch the five converted Ent count assertions from context.Background() to the cache_test.go newContext() helper (a discard-logger context), matching the surrounding suite convention. Addresses review comments on PR #1288 (threads PRRT_kwDONV6tZs6Fv0I4, PRRT_kwDONV6tZs6Fv0JC, PRRT_kwDONV6tZs6Fv0JK, PRRT_kwDONV6tZs6Fv0JT, PRRT_kwDONV6tZs6Fv0Jb). Co-Authored-By: Claude Opus 4.8 <[email protected]>
678d5e0 to
52f977e
Compare
|
Automated stack merge failed during the rebase step. The |
Summary
Client.DB()is a discouraged raw-*sql.DBescape hatch, yet the test suites reach for it ~110 times. Most uses are legitimate (migration verification, schema probes, adversarial setup, pool tuning). One pattern is a clean swap that loses no verification independence: standaloneSELECT COUNT(*)row-count assertions in the cache and server behavior tests.cache_test.goand all 5 by-hash count assertions inserver_test.goto the Ent API (dbClient.Ent().<Entity>.Query()[.Where(entnarinfo.HashEQ(h))].Count(ctx)).cache_test.goby-hash counts interleaved with raw-SQL idioms (rebind helper,ExecContextmutations,Eventuallypolling, concurrentwgflows) and allpkg/ncpsmigration-outcome checks (ORM-independent by design).pkg/ncps/migrate.gouse ofDB()is unchanged.database-ormspec requirement scoping the Ent-count convention to standalone behavior-test assertions.Test plan
task fmt/task lint(0 issues) /task test(full suite green;pkg/cache+pkg/server)