Repository navigation
feat(search): execute booru queries end-to-end (AST → SQL) - #11
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (10)
🚧 Files skipped from review as they are similar to previous changes (10)
📝 WalkthroughWalkthroughAdds booru search query support to asset listing: a new ChangesAsset Search Query Pipeline
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 1
🧹 Nitpick comments (1)
packages/core/test/asset-search.test.ts (1)
105-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd one positive tag-match case.
This only proves tag queries return zero when no
asset_tagsrows exist. A brokenEXISTSjoin or*→%translation would still pass, so the end-to-end tag path is still unverified.🤖 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 `@packages/core/test/asset-search.test.ts` around lines 105 - 106, The current asset-search test only covers the no-tags case, so it does not verify that tag matching actually works end to end. Update the test in asset-search.test.ts, near the existing “compiles tag terms but matches nothing until tags exist” case, to add one positive assertion that creates an asset_tags row and confirms service.list({ query: "1girl" }) returns a matching result. Use the existing service.list path and tag-query handling to ensure the EXISTS join and wildcard translation are both exercised.
🤖 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 `@packages/core/src/search/asset-query.ts`:
- Around line 93-100: The range parser in rangeCondition currently accepts
malformed multi-bound inputs like size:1..2..3 because split("..") only uses the
first two segments and silently truncates the rest. Update rangeCondition in
asset-query.ts to reject any value that contains more than one ".." separator
(or otherwise has extra segments) and return undefined for such invalid syntax,
while preserving the existing valid single-bound and between handling.
---
Nitpick comments:
In `@packages/core/test/asset-search.test.ts`:
- Around line 105-106: The current asset-search test only covers the no-tags
case, so it does not verify that tag matching actually works end to end. Update
the test in asset-search.test.ts, near the existing “compiles tag terms but
matches nothing until tags exist” case, to add one positive assertion that
creates an asset_tags row and confirms service.list({ query: "1girl" }) returns
a matching result. Use the existing service.list path and tag-query handling to
ensure the EXISTS join and wildcard translation are both exercised.
🪄 Autofix (Beta)
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: 12644d21-1c34-4e75-9e59-2e8392e73dd4
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (11)
.env.example.github/workflows/ci.yml.gitignoreapps/api/src/server.tsapps/api/test/server.test.tspackages/core/package.jsonpackages/core/src/search/asset-query.tspackages/core/src/services/asset-service.tspackages/core/test/asset-search.test.tspackages/db/src/repositories/asset-repository.tspackages/db/test/asset-repository.test.ts
`rangeCondition` split on every `..` and destructured the first two parts, so an invalid range like `width:1..2..3` silently compiled to `BETWEEN 1 AND 2` and returned the wrong assets. Require exactly one separator; treat anything else as malformed → ignored, consistent with how the compiler drops other invalid terms. Adds a regression test. Addresses CodeRabbit review on PR #11. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Complete the search pipeline started in #5: the parsed query AST compiles to a Drizzle WHERE and filters the assets listing. - core: add the Search Engine (`compileAssetSearch`) — walks the query AST into a Drizzle condition. Metatags map to asset columns (`rating:` enum equality; `width`/`height`/`size` numeric eq/gt/gte/lt/lte and `lo..hi` ranges, with malformed multi-bound ranges like `1..2..3` ignored, not silently truncated); tag terms compile to an `asset_tags` EXISTS subquery (valid SQL now, matching once tagging lands). and/or/not via Drizzle; unknown keys and invalid values are dropped, not errored. - db: `findMany`/`count` accept an optional prebuilt `where: SQL` so the page and its total share one filter (db never parses text). - core: `AssetService.list` accepts `query`; trims then compiles it once. - api: `GET /api/v1/assets?q=` (capped at 1024 chars) forwards to the service. - tests: integration coverage for rating/numeric/range/negation/tag and pagination metadata under a filter; API q-forwarding unit test. Test safety: the destructive integration suites (they TRUNCATE) read a dedicated, opt-in `TEST_DATABASE_URL` instead of the app's `DATABASE_URL`, so a misconfigured dev/prod env can never be wiped — unset → they skip. CI sets it to its ephemeral Postgres; `.env.example` documents it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
01a0c3d to
9893499
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
Completes the search pipeline started in #5: the parsed query AST now compiles to a Drizzle
WHEREand filters the assets listing. Honors the Search Rule —dbnever parses text; the Core-owned Search Engine walks the AST → SQL.What's included
compileAssetSearch(query): walks the query AST into a Drizzle condition.rating:(enum equality),width/height/size(numericeq/gt/gte/lt/lteandlo..hi,lo..,..hiranges).asset_tagsEXISTS subquery (valid SQL now; matches once tagging lands), with*→%LIKE.and/or/notvia Drizzle; unknown metatag keys and invalid values are dropped, not errored.findMany/countaccept an optional prebuiltwhere: SQLso a page and its total share one filter.AssetService.listacceptsquery; trims then compiles it once per call (count + page reuse the same filter).GET /api/v1/assets?q=(capped at 1024 chars) forwards to the service.Tests
q-forwarding unit test (stubbed core).Test safety
The destructive integration suites (they
TRUNCATE) now read a dedicated, opt-inTEST_DATABASE_URLinstead of the app'sDATABASE_URL, so a misconfigured dev/prod env can never be wiped — unset → they skip. CI points it at its ephemeral Postgres;.env.exampledocuments it. Applied to the pre-existing repository suite too for a consistent guarantee.Validation
bun run typecheck✓bun run test✓ (111 pass; 19 integration skip withoutTEST_DATABASE_URL)bun run lint:boundaries✓🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests