fix(api): harden paper creation cleanup#139
Conversation
|
Deployment failed with the following error: Learn More: https://vercel.com/hirokis-projects-afd618c7?upgradeToPro=build-rate-limit |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the reliability of the paper creation process by hardening its cleanup mechanisms and improving error handling. It refines the construction of database batch commands for better type safety and introduces more rigorous testing to validate data insertion and tag normalization behaviors. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully hardens the cleanup logic for paper creation by ensuring that cleanup failures are logged without losing the original error. The changes also refactor the batch insert logic to be more streamlined and typed, and tighten the tests for more specific assertions.
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Summary
Validation
Split out of #138 to keep the review focused on the paper creation error-handling change set.
Greptile Summary
このPRは
POST /api/papersのエラーハンドリングを強化するもので、主に2点の改善を行っています。①バッチ構築をBatchItem[]型を使って型安全に統一し、org_only分岐をif/elseから条件的なpushに整理、②エラー発生時のR2/D1クリーンアップをtry/catchで保護し、クリーンアップ失敗をcleanupFailures配列に集約してログ出力後、必ず元のエラーを再スローする設計に変更しています。主な変更点:
papers.ts: バッチ操作配列をBatchItem型で統一し、R2/D1クリーンアップを独立したtry/catchで保護。cleanupFailuresでクリーンアップ失敗を収集しconsole.errorでロギングpapers.test.ts:insertモックをバッチ引数の内容検証が可能な形式に変更し、org_onlyテストでorgIdを含む挿入が正しくバッチに含まれることをアサートres2の結果を明示的にアサートするよう改善db.batch失敗時のR2/D1クリーンアップ呼び出しと元エラーの再スロー)に対するテストが追加されていないConfidence Score: 4/5
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[POST /api/papers] --> B[入力バリデーション] B --> C[R2 ファイルアップロード] C --> D{エラー?} D -- No --> E[BatchItem配列構築] E --> F{org_only + orgId?} F -- Yes --> G[insertOrg 追加] F -- No --> H[insertFiles 追加] G --> H H --> I[db.batch 実行] I --> J{エラー?} J -- No --> K[201 Created] J -- Yes --> L[catch error] L --> M[R2クリーンアップ\nPromise.allSettled] M --> N[D1子テーブル削除\npaperFiles / paperOrgs / paperAuthors] N --> O[papers 削除] O --> P{cleanupFailures\nあり?} P -- Yes --> Q[console.error ログ出力] P -- No --> R[throw error 再スロー] Q --> R style K fill:#22c55e,color:#fff style R fill:#ef4444,color:#fff style Q fill:#f97316,color:#fffComments Outside Diff (2)
apps/api/src/routes/__tests__/papers.test.ts, line 22-26 (link)このPRの主目的である「クリーンアップの堅牢化」(
db.batch失敗時にR2とD1のクリーンアップが実行され、元のエラーが再スローされる)を検証するテストが存在しません。例えば、次のようなシナリオのテストを追加することを検討してください:
現状のテストスイートはハッピーパス(正常系)のみをカバーしており、今回強化した例外ハンドリングのロジックが将来のリファクタリングで意図せず壊れた場合に検出できません。
Prompt To Fix With AI
apps/api/src/routes/__tests__/papers.test.ts, line 56-89 (link)このPRの主な変更点はエラー発生時のR2/D1クリーンアップの堅牢化ですが、そのパスに対するテストが追加されていません。
具体的に検証できていない挙動:
db.batchが失敗した場合、R2クリーンアップ (BUCKET.delete) が呼ばれることdb.batchが失敗した場合、D1クリーンアップ (delete paperFiles/paperOrgs/paperAuthors/papers) が呼ばれることthrow errorで再スローされることconsole.errorが呼ばれること例えば以下のようなテストケースを追加することで、新しいエラーハンドリングロジックが意図通りに動作することを保証できます:
Prompt To Fix With AI
Prompt To Fix All With AI
Last reviewed commit: 2d9bc3c