Skip to content

[Measurement run – do not merge] STORY-142: private article bookmarks API (backend) - #1203

Closed
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/story-142-fusion
Closed

devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/story-142-fusion

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

[Measurement run – do not merge] STORY-142 Fusion measurement rerun. Built fresh from the default branches; earlier-run PRs and branches were not read or reused. Only one implementation should land.

Story: STORY-142 source and acceptance criteria
Paired frontend PR: COG-GTM/angular-realworld-example-app#84 (draft Fusion rerun).

Summary

Adds private, per-user article bookmarks, modeled on the existing favorites stack (ArticleFavoriteApi / core/favorite / ArticleFavoriteMapper / ArticleFavoritesReadService).

Contract (bare /articles paths, same as the other controllers; local e2e runs with --server.servlet.context-path=/api):

  • POST /articles/{slug}/bookmark and DELETE /articles/{slug}/bookmark return {article: ArticleData}. bookmarked is specific to the viewer. An unknown slug returns 404. Both calls are idempotent.
  • GET /articles/bookmarked?limit=&offset= returns {articles, articlesCount} for the current user only (no owner param), newest saved first.
  • All three require auth and return 401 when unauthenticated (/articles/bookmarked is added to the authenticated GET matcher, ahead of the public /articles/**). There's no public bookmark count.
  • ArticleData.bookmarked: boolean is now on every REST article response (single, list, feed). It's false for anonymous viewers.

Things that aren't obvious from the diff:

  • V2__create_article_bookmarks.sql: article_bookmarks(article_id, user_id, created_at) with a primary key on (article_id, user_id) and an index on (user_id, created_at).
  • Saves are idempotent with no reordering: the insert is ... ON CONFLICT(article_id, user_id) DO NOTHING, so a repeated POST keeps the original created_at.
  • Ordering is ORDER BY B.created_at DESC, B.rowid DESC. rowid gives a deterministic insertion-order tie-break (this app only runs on SQLite).
  • ArticleReadService.findArticles(ids) always orders by A.created_at DESC, so ArticleQueryService.findBookmarkedArticles puts the hydrated rows back into saved order afterwards.
  • The schema has no FK enforcement, so MyBatisArticleRepository.remove is now @Transactional and deletes the article's bookmarks first (ArticleBookmarkMapper.deleteByArticleId).
  • GraphQL schema and datafetchers are untouched (REST scope only).

Tests

JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 ./gradlew clean test: 84 tests, 0 failures, 0 errors, 0 skipped. compileJava compileTestJava passes.

  • ArticleBookmarkApiTest: bookmark and unbookmark, 404 on an unknown slug, 401 on POST and DELETE without a token
  • ListArticleApiTest: GET /articles/bookmarked passes the user and Page(offset, limit), returns 401 without a token; list responses include bookmarked
  • MyBatisArticleBookmarkRepositoryTest: save and find, a repeated save keeps the original created_at, removing a missing bookmark does nothing
  • ArticleQueryServiceTest: bookmarked per viewer on single/recent/feed, saved-time ordering with a tie-break (independent of article created_at), pagination and total count, isolation between users, no reorder on re-save, cleanup when an article is deleted

spotlessJavaCheck fails only on DefaultJwtServiceTest.java, which is already unformatted on master. I left it out of this diff on purpose.

UI coverage limits: network-failure/concurrent-mutation scenarios and non-Chromium browsers were not exercised end to end. Unit tests cover request-error handling.

Devin-Org: engineering

Open in Devin Desktop: https://devin-gtm.devinenterprise.com/desktop/session/1ab6e443eb49449d9482f7c1a6d9e583?variant=devin

Real-backend integration evidence

Verified both feature branches together: Angular on localhost:4200 → Spring Boot on localhost:8080/api with real SQLite persistence, not mocked responses. Two users (ana and eric) registered through the UI; a third fixture author allowed the same shared article to be compared as a reader under both identities.

  • Annotated UI verification passed: Save/Saved synchronization and refresh persistence, newest-save order opposite article-creation order, own-profile-only tab and authenticated reload, other-user direct-route denial and independent state, anonymous Save → /login, removal and exact empty text. No public save count.
  • Supplementary UI check with 11 real saves passed: pages of 10+1, first-page removal backfills, removing the last second-page card returns to page 1.
  • Independent local HTTP probe: 24 checks passed (all three anonymous endpoints return 401, invalid-token 401, viewer isolation including ignored owner-like query parameters, mutation booleans, idempotency/no reordering, pagination/count, 404s, favorite independence and article-delete cleanup).
  • Local-only API URL override is uncommitted and absent from the PR diff. Default external avatar URLs fail to load; screenshots retain the app's actual avatar rendering.

The paired frontend PR contains both design-frame screenshots and the animated recording. Backend security checks passed (3/3). The unchanged baseline Spotless violation remains unresolved; it was reproduced on clean master with identical output and file content.

UI coverage limits: network-failure/concurrent-mutation scenarios and non-Chromium browsers were not exercised end to end. Unit tests cover request-error handling.

Devin-Org: engineering


Devin Review

Status Commit
⚪ Not started —

Run Devin Review

Enable auto-review to review your pull requests automatically.

Devin Review (Staging)

Co-Authored-By: Pedro Tabio <paltat@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration

Copy link
Copy Markdown
Author

Real-backend STORY-142 verification passed with signed-in users and SQLite persistence; independent API checks: 24 passed. Supplementary UI pagination/backfill checks also passed. Default external avatars were unavailable.

Saved article
Own private Reading list
Annotated real-backend flow

Backend suite: 84 passed. Security checks: 3/3 passed. The unchanged baseline Spotless violation is documented in the description.

Not exercised in UI: network-failure/concurrent-mutation scenarios or other browsers.

@devin-ai-integration
devin-ai-integration Bot marked this pull request as ready for review October 28, 2026 20:27

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Devin Review found 2 potential issues.

Devin Review

Comment on lines +48 to +49
@GetMapping(path = "bookmarked")
public ResponseEntity getBookmarked(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🟡 Articles named bookmarked become inaccessible

When an article has slug bookmarked, getBookmarked takes its GET route instead of the article handler. Anonymous readers receive 401; signed-in readers receive their bookmark list instead of that article.

Learn more

Article titles are converted into slugs by toSlug. The existing article handler accepts any slug at the same path depth as this new fixed route. Spring MVC selects the fixed route for bookmarked, so it never reaches the article handler for that slug. The security configuration also requires authentication for the fixed route, making a formerly public article URL return 401 to anonymous readers.

Example: Creating an article titled Bookmarked creates slug bookmarked. GET /articles/bookmarked now returns 401 without a token, or the caller's saved articles with a token, rather than the new article.

Recommended fix: Reserve bookmarked during article slug creation and migration with a clear validation error, or put the bookmark-list route at a path that cannot collide with article slugs. Account for existing articles with the slug before deploying.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Confirmed: an article with slug bookmarked would be shadowed. This is the same trade-off GET /articles/feed already makes on master: a literal route wins over /articles/{slug} and needs auth. The path GET /articles/bookmarked is fixed by the shared STORY-142 contract the frontend PR codes against, so I'm not moving it in this PR. Reserving feed and bookmarked as slugs would be a separate hardening change. I've flagged it to the coordinator. Leaving this unresolved.

@PathVariable("slug") String slug, @AuthenticationPrincipal User user) {
Article article =
articleRepository.findBySlug(slug).orElseThrow(ResourceNotFoundException::new);
articleBookmarkRepository.save(new ArticleBookmark(article.getId(), user.getId()));

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🟡 Concurrent deletion leaves orphan bookmarks

If deletion finishes between bookmarkArticle resolving a slug and inserting, the POST saves a bookmark for a deleted article. remove already cleared bookmarks, and the response lookup fails while the orphan remains stored.

Learn more

The bookmark POST checks the article before inserting its bookmark. Article deletion removes bookmarks and then deletes the article, but the POST does not hold the article lookup and insert in that transaction. The bookmark schema has no foreign key, so an insert after deletion succeeds. The subsequent article lookup returns empty and the POST fails, while the orphan bookmark persists. Normal bookmark-list reads hide it because the list query joins existing articles.

Example: Alice starts bookmarking Bob's article and passes the slug lookup. Bob deletes it, clearing bookmarks. Alice's insert then succeeds; her POST fails and an invisible bookmark row remains.

Recommended fix: Enforce article existence with a foreign key and deletion cascade where supported, or synchronize the bookmark insert with article deletion in one transaction with a database-level existence check. Handle the deleted-article outcome as a missing article rather than returning a server error.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Confirmed: the race is real, but the window is narrow and the effect is limited.

  • Users can't see the orphan row. findBookmarkedArticleIds and countBookmarkedArticles both join articles, and isUserBookmark/userBookmarks are only queried with ids of articles that still exist.
  • The racing POST would return 500 (findBySlug(...).get() on an empty result) instead of 404. ArticleFavoriteApi has the same pattern.

A minimal fix that doesn't need a schema change:

  1. Make the insert INSERT ... SELECT ... WHERE EXISTS (SELECT 1 FROM articles WHERE id = ?) ON CONFLICT DO NOTHING. SQLite serializes write transactions, so this can't interleave with the @Transactional delete.
  2. Map an empty response lookup to ResourceNotFoundException.

I'm holding off because the coordinator froze implementation on this PR. I've raised it with them and will apply the fix if they approve.

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.

0 participants