Skip to content

ADFA-3802 make documentation bookshelf dynamic#1353

Merged
hal-eisen-adfa merged 11 commits into
stagefrom
ADFA-3802-Make-documentation-bookshelf-dynamic
Jun 4, 2026
Merged

ADFA-3802 make documentation bookshelf dynamic#1353
hal-eisen-adfa merged 11 commits into
stagefrom
ADFA-3802-Make-documentation-bookshelf-dynamic

Conversation

@jimturner-adfa
Copy link
Copy Markdown
Collaborator

@jimturner-adfa jimturner-adfa commented May 29, 2026

First working version of dynamic bookshelf from curl
TODO: Need to add HTML template to the documentation.db file

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

Adds /pr/bs routing and a two-stage bookshelf handler: a wrapper that optionally clears template cache and gates error sends, plus realHandleBsEndpoint which queries the debug DB for a single JSON row, lazily caches a Pebble template ID, renders via instantiatePebbleTemplate with added debug logs, and writes the response.

Changes

Bookshelf Endpoint Feature

Layer / File(s) Summary
Server config & fields
app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Adds Cursor import, updates external-storage debug paths and adds clearCacheEnablePath to ServerConfig, introduces clearCacheEnabled, Pebble engine/template cache fields, and resets bookshelfTemplateId on debug DB reload.
HTTP error standardization & endpoint KDoc
app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Standardizes handler exception responses to HTTP_INTERNAL_SERVER_ERROR/HTTP_NOT_FOUND, updates accept-loop and /pr/* routing responses, and adds KDoc for DB and PR endpoints (ensuring exception paths pass outputStarted to sendError).
Pebble instantiation and debug logs
app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Adds/updates KDoc for instantiatePebbleTemplate, logs the fetched templateBlob string before evaluation, and ensures template ID caching behavior with debug DB lifecycle.
handleBsEndpoint wrapper
app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Replaces prior handler with a wrapper that clears templateCache when enabled, delegates to realHandleBsEndpoint, captures outputStarted, and gates sendError by output state.
realHandleBsEndpoint implementation
app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Implements bookshelf flow: execute SQL to produce a single JSON cursor row of categories/books, validate single-row result, lazily fetch/cache bookshelf template ID, render via instantiatePebbleTemplate, write via writeNormalToClient, and return boolean success.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • hal-eisen-adfa
  • davidschachterADFA

Poem

🐇 I hopped through routes and cached a key,
Pebble ink turned JSON to tea,
Bookshelf rows wrapped in a debug glow,
Output watched so errors don't overflow,
A rabbit cheers — templates safe to see!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title accurately describes the main objective of making the documentation bookshelf dynamic, which aligns with the primary changes in the WebServer implementation for dynamic bookshelf generation.
Description check ✅ Passed The pull request description directly relates to the changeset, which implements dynamic bookshelf functionality via curl as described.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ADFA-3802-Make-documentation-bookshelf-dynamic

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 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 `@app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt`:
- Around line 696-708: The code in WebServer.kt overwrites the existing cursor
when running the template-ID query (affecting bookshelfTemplateId) and never
closes the original cursor; fix by ensuring each Cursor is closed — either use a
second local variable for the template query (e.g., templateCursor) or wrap each
rawQuery result in a Kotlin use { } block so cursor.close() is called
automatically before assigning or returning; update the block around the
rawQuery/cursor.moveToFirst()/getInt(0) logic that sets bookshelfTemplateId and
any sendError branches to close the appropriate cursor(s).
- Around line 67-69: When the DB handle is reopened/rotated (the block that
reassigns the database variable), clear the template caches so old templates
from the previous DB aren’t reused: call templateCache.clear() and reset
bookshelfTemplateId = -1 immediately after the database swap (the same place
where the code reopens/assigns database). This ensures PebbleTemplate entries in
templateCache and the cached bookshelfTemplateId are invalidated when the
database changes.
- Around line 567-578: The catch block can append a second 500 because
outputStarted is only set true after realHandleBsEndpoint returns; modify the
flow so outputStarted is set to true as soon as any headers/body are written
(i.e., inside the write path) rather than only on return. Concretely, update
realHandleBsEndpoint (or the helper that calls writeNormalToClient) to accept a
mutable flag (e.g., AtomicBoolean or a setter lambda) or return a result object
so it flips outputStarted to true immediately when the first write/flush
happens, then keep the existing try/catch in handleBsEndpoint to rely on that
flag. Ensure references: handleBsEndpoint, realHandleBsEndpoint, and the write
method (writeNormalToClient) are changed accordingly so the catch sees the
correct outputStarted state.
- Around line 713-721: The catch block that logs the fetch error and calls
sendError must stop further processing so instantiatePebbleTemplate(...) is not
called with uninitialized jsonText or bookshelfTemplateId; modify the catch
(Exception e) handling around the fetch to, after logging and calling
sendError(writer, output, 500, ...), immediately return (or otherwise
short-circuit) from the surrounding method so cursor.close() remains in finally
and instantiatePebbleTemplate(...) is never reached when an exception occurred.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7f80d995-fb24-456b-a5b1-4809b7f61d43

📥 Commits

Reviewing files that changed from the base of the PR and between 7defc84 and ccfea34.

📒 Files selected for processing (1)
  • app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt

Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt Outdated
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
jatezzz
jatezzz previously requested changes Jun 1, 2026
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt Outdated
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 1, 2026

Note

Docstrings generation - SUCCESS
Generated docstrings and committed to branch ADFA-3802-Make-documentation-bookshelf-dynamic (commit: b32a684c2cbd44fcf8ac0fabab5e4d412aedf88a)

Comment thread app/src/main/java/com/itsaky/androidide/localWebServer/WebServer.kt
@hal-eisen-adfa hal-eisen-adfa changed the title Adfa 3802 make documentation bookshelf dynamic ADFA-3802 make documentation bookshelf dynamic Jun 4, 2026
@hal-eisen-adfa hal-eisen-adfa merged commit 634def7 into stage Jun 4, 2026
2 checks passed
@hal-eisen-adfa hal-eisen-adfa deleted the ADFA-3802-Make-documentation-bookshelf-dynamic branch June 4, 2026 23:20
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.

4 participants