Skip to content

fix(books): address CodeRabbit findings on the series autocomplete (#179)#188

Merged
fabiodalez-dev merged 2 commits into
mainfrom
fix/179-coderabbit-findings
Jun 23, 2026
Merged

fix(books): address CodeRabbit findings on the series autocomplete (#179)#188
fabiodalez-dev merged 2 commits into
mainfrom
fix/179-coderabbit-findings

Conversation

@fabiodalez-dev

@fabiodalez-dev fabiodalez-dev commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Applies CodeRabbit's 5 inline Major findings from #187 (autocomplete serie/universo/ciclo). They were posted after #187 had already been merged, and the docs follow-up commit hit CodeRabbit's review rate-limit, so they were never addressed — this PR closes that gap.

Findings addressed

# File Type Fix
1 book_form.php 🔒 Security/convention The 4 series autocomplete fields used HtmlHelper::e(); views must use htmlspecialchars(..., ENT_QUOTES, 'UTF-8') (12 occurrences)
2 book_form.php 🎯 Correctness (#74 class) _onEnterKey only committed the typed value when nothing was highlighted. With a highlighted suggestion ≠ typed text, Enter committed the wrong value. Apply the same highlighted-vs-typed guard the publisher field already uses + new regression test
3 full-test.spec.js test robustness collana fill now drives the real Choices widget (open → type → Enter) instead of poking the hidden input
4 issue-179 spec 🩺 Stability skip guard now also requires E2E_ADMIN_PASS, not just the email
5 series-cycles.spec.js test robustness setSeriesAutocomplete drives the real widget; stays context-aware — pages without the widget (series-detail form) fall back to a plain fill

Validation

  • PHPStan L5 ✅, php -l
  • issue-179-series-autocomplete 6/6 (incl. new adding new author #74 regression)
  • series-cycles 15/15
  • full-test 135/135 (0 failed)

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Migliorato il comportamento dell'autocomplete nei campi "Serie e collana": quando si digita un valore parziale e si navigano i suggerimenti, il sistema ora registra correttamente il testo digitato anziché la selezione evidenziata.
  • Tests

    • Aggiornati test E2E per validare il nuovo flusso dell'autocomplete e garantire il corretto salvataggio dei valori nei campi serie.

)

CodeRabbit's inline review (5 Major findings) landed after #187 was merged
and the docs follow-up commit was rate-limited, so they went unaddressed.
This applies them.

- Security/convention: the four series autocomplete fields used HtmlHelper::e()
  in the view; views must use htmlspecialchars(..., ENT_QUOTES, 'UTF-8')
  (12 occurrences across option value/text + hidden input).
- Correctness (#74 class): the series _onEnterKey only committed the typed
  value when NOTHING was highlighted. With a highlighted suggestion that
  differs from the typed text, Enter fell through to Choices and committed the
  wrong value. Apply the same highlighted-vs-typed guard the publisher field
  already uses; add a dedicated regression test.
- Tests: the issue-179 skip guard now also requires E2E_ADMIN_PASS (not just
  the email), so a missing password skips instead of failing at login.
- Tests: setSeriesAutocomplete (series-cycles) and the collana fill (full-test)
  now drive the real Choices widget (open -> type -> Enter) instead of poking
  the hidden input, so they catch widget regressions. The helper stays
  context-aware: pages without the widget (series-detail admin form) fall back
  to a plain fill.

Validated: PHPStan L5, php -l, issue-179 6/6, series-cycles 15/15,
full-test 135/135.
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@fabiodalez-dev, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 36 minutes and 46 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5bd13f5f-20c7-409b-8201-00adf544fa7d

📥 Commits

Reviewing files that changed from the base of the PR and between 65f8a77 and 9d89f65.

📒 Files selected for processing (2)
  • tests/full-test.spec.js
  • tests/series-cycles.spec.js
📝 Walkthrough

Walkthrough

Fix del monkey-patch _onEnterKey di Choices.js in book_form.php per impedire la selezione automatica del suggerimento evidenziato quando il testo digitato differisce (case-insensitive). Le opzioni pre-selezionate dei selettori serie passano da HtmlHelper::e() a htmlspecialchars. I test E2E vengono aggiornati per simulare il flusso reale del widget anziché usare setter globali.

Modifiche

Fix autocomplete serie e aggiornamento test

Layer / File(s) Descrizione
Sanitizzazione HTML e fix Enter-key
app/Views/libri/partials/book_form.php
Le opzioni pre-selezionate di gruppo_serie_select, serie_padre_select, collana_select e ciclo_serie_select usano htmlspecialchars(..., ENT_QUOTES, 'UTF-8'). Il monkey-patch di _onEnterKey aggiunge un ramo che chiama preventDefault() e commitTyped(typed) quando il testo digitato differisce case-insensitively dall'elemento evidenziato nel dropdown.
Test E2E refactoring e nuovo caso di test
tests/series-cycles.spec.js, tests/full-test.spec.js, tests/issue-179-series-autocomplete.spec.js
setSeriesAutocomplete rileva il widget Choices tramite .choices/#${field}_select e simula click, fill e Enter reali. full-test.spec.js usa lo stesso flusso per collana. Aggiunto test #74 che verifica il commit del valore digitato (Seed: Fairy) quando l'highlight è su un suggerimento diverso; la condizione di skip ora richiede anche ADMIN_PASS.

Diagrammi di sequenza

sequenceDiagram
    actor Utente
    participant ChoicesWidget as Choices.js Widget
    participant MonkeyPatch as _onEnterKey patch
    participant HiddenInput as `#serie_padre`

    Utente->>ChoicesWidget: digita "Seed: Fairy"
    ChoicesWidget-->>Utente: mostra suggerimento evidenziato "Seed: Fairy Tail Universe"
    Utente->>MonkeyPatch: preme Enter
    MonkeyPatch->>MonkeyPatch: typed="Seed: Fairy", hl="Seed: Fairy Tail Universe"
    MonkeyPatch->>MonkeyPatch: typed != hl (case-insensitive) → preventDefault()
    MonkeyPatch->>HiddenInput: commitTyped("Seed: Fairy")
    HiddenInput-->>Utente: valore = "Seed: Fairy"
Loading

Stima dello sforzo di revisione

🎯 3 (Moderate) | ⏱️ ~20 minuti

PR correlate

  • fabiodalez-dev/Pinakes#187: Introduce la logica initializeSeriesAutocompletes/choice._onEnterKey e il wiring di test con window.__seriesAutocomplete che questa PR modifica direttamente.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Il titolo descrive accuratamente il cambiamento principale: l'indirizzo dei problemi trovati da CodeRabbit sulla funzionalità autocomplete delle serie.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/179-coderabbit-findings

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: 3

🤖 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 `@tests/full-test.spec.js`:
- Around line 690-700: The test for the collana (series) Choices.js field is
using an incorrect pattern for E2E stability. Replace the current approach where
collanaSearch.press('Enter') commits the value directly. Instead, after filling
the collanaSearch input with seriesValue, add a waitForTimeout to allow the
Choices dropdown suggestions to render, then click on the matching suggestion
element that appears. This follows the required fill + waitForTimeout + click
suggestion pattern for Choices.js tests to ensure stable E2E behavior and avoid
flakiness.

In `@tests/issue-179-series-autocomplete.spec.js`:
- Line 15: The test.skip() condition on the test declaration only checks for
ADMIN_EMAIL and ADMIN_PASS environment variables, but should also include checks
for the E2E database credentials (E2E_DB_*) to be consistent with the rest of
the E2E suite. Expand the condition to skip the test if either the admin
credentials or the database credentials are missing, preventing avoidable test
failures when database credentials are not configured and ensuring the skip
behavior is aligned across all E2E tests.

In `@tests/series-cycles.spec.js`:
- Around line 154-187: The setSeriesAutocomplete function currently uses
press('Enter') immediately after filling the search input, which doesn't follow
the established E2E contract for Choices.js interactions. Replace the
search.press('Enter') call with the proper sequence: after search.fill(v), add a
waitForTimeout to allow the dropdown suggestions to render, then locate and
click on the suggestion matching the value instead of relying on the Enter
keypress. This will make the test more deterministic and consistent with the
repository's E2E testing conventions.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 16285ab3-a8c6-4788-b37b-da874147922e

📥 Commits

Reviewing files that changed from the base of the PR and between 64a198d and 65f8a77.

📒 Files selected for processing (4)
  • app/Views/libri/partials/book_form.php
  • tests/full-test.spec.js
  • tests/issue-179-series-autocomplete.spec.js
  • tests/series-cycles.spec.js

Comment thread tests/full-test.spec.js
Comment thread tests/issue-179-series-autocomplete.spec.js
Comment thread tests/series-cycles.spec.js
…ries fields (#179)

CodeRabbit (#188): the setSeriesAutocomplete helper and the full-test collana
fill committed via Enter; the repo convention (.coderabbit.yaml) is
fill + waitForTimeout + click suggestion. Switch both to it. The earlier click
attempt failed only because the dropdown locator was page-scoped and matched a
hidden dropdown of one of the other Choices widgets on the page — scope it to
the field's own .choices wrapper. The typed value is offered as a create-option
so it works for new names too.

Validated: series-cycles 15/15, full-test 135/135.
@fabiodalez-dev fabiodalez-dev merged commit 50ce3a4 into main Jun 23, 2026
6 checks passed
@fabiodalez-dev fabiodalez-dev deleted the fix/179-coderabbit-findings branch June 23, 2026 18:12
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.

1 participant