Skip to content

fix(aladin): use ItemLookUp for ISBN search instead of keyword lookup#470

Merged
neonsolstice merged 3 commits into
bookorbit:mainfrom
kyungw00k:BO-437-aladin-isbn-lookup
Jun 29, 2026
Merged

fix(aladin): use ItemLookUp for ISBN search instead of keyword lookup#470
neonsolstice merged 3 commits into
bookorbit:mainfrom
kyungw00k:BO-437-aladin-isbn-lookup

Conversation

@kyungw00k

@kyungw00k kyungw00k commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #437

The Aladin provider's search() was sending ISBNs to ItemSearch.aspx as a keyword query (QueryType: 'Keyword'). This endpoint misses ~24% of valid Korean ISBNs that ItemLookUp.aspx returns reliably. This PR routes ISBN searches through ItemLookUp.aspx with the correct ItemIdType (ISBN13 for 13-digit, ISBN for 10-digit), mirroring the pattern used by the Goodreads provider's ISBN-specific endpoint.

How did you test this?

  • vitest run src/modules/metadata-fetch/providers/aladin/ — 26 tests pass
  • pnpm run typecheck — passes (server + client + types)
  • New test cases cover: ISBN13 lookup, ISBN10 lookup, and keyword fallback for invalid formats

Screenshots

N/A — backend-only change.

Anything non-obvious in the diff?

  • buildLookupUrl() signature changed to accept an optional itemIdType parameter (default 'ItemId'). The existing lookupItem() path is unaffected — only search() benefits from the new ISBN routing.
  • ISBNs that don't match 10/13-digit patterns (e.g. malformed strings) fall back to the original keyword search, so there's no regression for edge cases.
  • normalizeIsbn() strips hyphens/spaces before sending, since ISBNs in the wild often contain them.

Checklist

  • I've read through my own diff
  • This PR was discussed in an issue and has maintainer approval
  • Lint and tests pass locally
  • No unintended files included

Summary by CodeRabbit

  • Bug Fixes

    • Improved ISBN searches so 13-digit and 10-digit ISBNs are handled more accurately.
    • ISBN inputs with spaces or hyphens are now normalized before searching.
    • Invalid ISBN formats now fall back to a broader keyword search instead of failing to match properly.
  • Tests

    • Expanded test coverage for ISBN-based search behavior.

ISBN queries were sent to ItemSearch.aspx as keywords, missing ~24%
of valid Korean ISBNs. Route ISBN searches through ItemLookUp.aspx
with ItemIdType=ISBN13 (13-digit) or ISBN (10-digit), falling back
to keyword search for unrecognised formats.

Closes bookorbit#437
@github-actions github-actions Bot added the server Changes affecting server-side code, APIs, or backend behavior. label Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

AladinProvider now routes ISBN-based searches to ItemLookUp.aspx instead of ItemSearch.aspx. Two helpers normalize ISBNs and detect ISBN13 vs ISBN type; a new searchByIsbn method performs the lookup and falls back to keyword search for unrecognized formats. Tests cover all three cases.

Aladin ISBN Lookup Routing

Layer / File(s) Summary
ISBN helpers and buildLookupUrl param
server/src/modules/metadata-fetch/providers/aladin/aladin.provider.ts
Adds normalizeIsbn and getItemIdType helpers; buildLookupUrl now accepts an optional itemIdType argument instead of a hardcoded 'ItemId'.
search routing, buildQuery cleanup, and searchByIsbn
server/src/modules/metadata-fetch/providers/aladin/aladin.provider.ts
search delegates to searchByIsbn when params.isbn is present; buildQuery drops the isbn special-case; searchByIsbn classifies the ISBN, calls ItemLookUp.aspx, and falls back to searchItems for unrecognized formats.
Updated ISBN tests
server/src/modules/metadata-fetch/providers/aladin/aladin.provider.test.ts
Three cases verify: ItemLookUp.aspx with ItemIdType=ISBN13 for 13-digit, ItemIdType=ISBN for 10-digit, and ItemSearch.aspx fallback for invalid ISBN strings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hoppity-hop through the ISBN lane,
No more lost books in keyword terrain!
ISBN13 or ISBN, we now detect,
ItemLookUp called with full respect.
The rabbit finds every Korean tome — correct! 📚

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: routing ISBN searches through ItemLookUp instead of keyword lookup.
Description check ✅ Passed The description includes the required summary, closing issue, testing, screenshots, non-obvious details, and checklist sections.
Linked Issues check ✅ Passed The changes match #437 by using ItemLookUp for valid ISBNs, choosing ISBN13 or ISBN, and falling back to keyword search for invalid formats.
Out of Scope Changes check ✅ Passed The diff stays focused on Aladin ISBN search behavior and related tests, with no obvious unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
server/src/modules/metadata-fetch/providers/aladin/aladin.provider.test.ts (1)

144-181: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover the normalization contract, not just the routed endpoint.

Line 150 and Line 165 only exercise already-normalized ISBNs, so a regression in the hyphen/space stripping path would still pass. Please add at least one hyphenated/spaced ISBN case and assert toHaveBeenCalledTimes(1) so these tests also fail if the provider accidentally hits both ItemLookUp.aspx and ItemSearch.aspx.

Example hardening
-      const result = await provider.search({ isbn: '9788912345678' });
+      const result = await provider.search({ isbn: '978-89-1234-567-8' });

       expect(global.fetch).toHaveBeenCalledWith(expect.stringContaining('ItemLookUp.aspx'), expect.any(Object));
       expect(global.fetch).toHaveBeenCalledWith(expect.stringContaining('ItemId=9788912345678'), expect.any(Object));
       expect(global.fetch).toHaveBeenCalledWith(expect.stringContaining('ItemIdType=ISBN13'), expect.any(Object));
+      expect(global.fetch).toHaveBeenCalledTimes(1);
🤖 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 `@server/src/modules/metadata-fetch/providers/aladin/aladin.provider.test.ts`
around lines 144 - 181, The Aladin provider search tests currently verify
routing for already-normalized ISBNs only, so they miss regressions in the
normalization path. Update the relevant `provider.search` cases in
`aladin.provider.test.ts` to include at least one hyphenated or spaced ISBN
input and assert `global.fetch` is called exactly once, while still checking the
expected `ItemLookUp.aspx` or `ItemSearch.aspx` URL. This should harden the
`search` contract so a bug that triggers both lookup and fallback search is
caught.
🤖 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 `@server/src/modules/metadata-fetch/providers/aladin/aladin.provider.ts`:
- Around line 18-26: The ISBN-10 detection in getIsbnItemIdType only accepts an
uppercase X, so valid lowercase x inputs are missed and fall back to keyword
search. Update the ISBN-10 regex in getIsbnItemIdType to accept both X and x
after normalizeIsbn, keeping the behavior for ISBN13 unchanged and preserving
the existing normalization flow in normalizeIsbn.

---

Nitpick comments:
In `@server/src/modules/metadata-fetch/providers/aladin/aladin.provider.test.ts`:
- Around line 144-181: The Aladin provider search tests currently verify routing
for already-normalized ISBNs only, so they miss regressions in the normalization
path. Update the relevant `provider.search` cases in `aladin.provider.test.ts`
to include at least one hyphenated or spaced ISBN input and assert
`global.fetch` is called exactly once, while still checking the expected
`ItemLookUp.aspx` or `ItemSearch.aspx` URL. This should harden the `search`
contract so a bug that triggers both lookup and fallback search is caught.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 210b3d0d-5d44-43fa-99ae-5b85c1668571

📥 Commits

Reviewing files that changed from the base of the PR and between b97bd66 and 1f06a0d.

📒 Files selected for processing (2)
  • server/src/modules/metadata-fetch/providers/aladin/aladin.provider.test.ts
  • server/src/modules/metadata-fetch/providers/aladin/aladin.provider.ts

Comment on lines +18 to +26
function normalizeIsbn(isbn: string): string {
return isbn.replace(/[-\s]/g, '');
}

function getIsbnItemIdType(isbn: string): 'ISBN13' | 'ISBN' | null {
const normalized = normalizeIsbn(isbn);
if (/^\d{13}$/.test(normalized)) return 'ISBN13';
if (/^\d{9}[\dX]$/.test(normalized)) return 'ISBN';
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Accept lowercase x in ISBN-10 normalization.

Line 25 only recognizes uppercase X, so valid inputs like 0-8044-2957-x now miss the new lookup path and fall back to keyword search.

Proposed fix
 function normalizeIsbn(isbn: string): string {
-  return isbn.replace(/[-\s]/g, '');
+  return isbn.replace(/[-\s]/g, '').toUpperCase();
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function normalizeIsbn(isbn: string): string {
return isbn.replace(/[-\s]/g, '');
}
function getIsbnItemIdType(isbn: string): 'ISBN13' | 'ISBN' | null {
const normalized = normalizeIsbn(isbn);
if (/^\d{13}$/.test(normalized)) return 'ISBN13';
if (/^\d{9}[\dX]$/.test(normalized)) return 'ISBN';
return null;
function normalizeIsbn(isbn: string): string {
return isbn.replace(/[-\s]/g, '').toUpperCase();
}
function getIsbnItemIdType(isbn: string): 'ISBN13' | 'ISBN' | null {
const normalized = normalizeIsbn(isbn);
if (/^\d{13}$/.test(normalized)) return 'ISBN13';
if (/^\d{9}[\dX]$/.test(normalized)) return 'ISBN';
return null;
🤖 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 `@server/src/modules/metadata-fetch/providers/aladin/aladin.provider.ts` around
lines 18 - 26, The ISBN-10 detection in getIsbnItemIdType only accepts an
uppercase X, so valid lowercase x inputs are missed and fall back to keyword
search. Update the ISBN-10 regex in getIsbnItemIdType to accept both X and x
after normalizeIsbn, keeping the behavior for ISBN13 unchanged and preserving
the existing normalization flow in normalizeIsbn.

@neonsolstice
neonsolstice merged commit 5e3b18e into bookorbit:main Jun 29, 2026
21 checks passed
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.74194% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...metadata-fetch/providers/aladin/aladin.provider.ts 67.74% 8 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions github-actions Bot added the released Issue or PR is included in a released version. label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Issue or PR is included in a released version. server Changes affecting server-side code, APIs, or backend behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Aladin provider misses valid Korean ISBNs (ItemSearch keyword lookup blind spot)

2 participants