Skip to content

refactor(api): Extract JobStore and image request utilities - #53

Merged
chottokun merged 1 commit into
mainfrom
refactor/api-separation-of-concerns-1701715953450701877
Sep 1, 2026
Merged

chottokun merged 1 commit into
mainfrom
refactor/api-separation-of-concerns-1701715953450701877

Conversation

@chottokun

Copy link
Copy Markdown
Owner

概要

コード品質向上と責務分離を目的として、src/api/main.py 内に混在していた InMemoryJobStore および _get_image_from_request ヘルパー・各種セキュリティ定数をそれぞれ以下の新モジュールに抽出・分割しました。

  • src/api/job_store.py: InMemoryJobStore(LRU / TTL 退避およびスレッドセーフなインメモリジョブ管理)
  • src/api/image_utils.py: _get_image_from_request(multipart/JSON Base64 入力検証・画像抽出・制限チェック)

後方互換性維持のため、src/api/main.py にてインポートおよび再エクスポートを行い、既存のAPIシグネチャや monkeypatch を用いたテスト環境との互換性を完全に確保しています。

各ステップでの変更内容およびテスト実行結果

  1. Step 1: ベースライン確認
    • PYTHONPATH=. uv run pytest を実行し、既存の69件のテストがすべて成功(Green)することを確認。
  2. Step 2: 仕様固定のためのテスト補強
    • 既存のテストスイート (test_job_store_limits.py, test_limits.py, test_boundary_conditions.py) により対象の挙動がカバーされていることを確認。
  3. Step 3: インクリメンタルなリファクタリング
    • (a) InMemoryJobStore を src/api/job_store.py に分割し、動作検証(Pytest 69件全パス)。
    • (b) _get_image_from_request およびセキュリティ定数を src/api/image_utils.py に分割し、main.py から再エクスポート。動的属性参照 (getattr) に対応させて monkeypatch テストとの互換性を確保・検証(Pytest 69件全パス)。
  4. Step 4: 最終検証 & クリーンアップ
    • リンター (uv run ruff check) および全ユニットテストを実行し、すべて正常に完了。

PR created automatically by Jules for task 1701715953450701877 started by @chottokun

Extract InMemoryJobStore to src/api/job_store.py and image extraction logic with security limits to src/api/image_utils.py for improved modularity and separation of concerns while preserving backward compatibility.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@chottokun
chottokun merged commit 8c61c50 into main Sep 1, 2026
1 check passed
@chottokun
chottokun deleted the refactor/api-separation-of-concerns-1701715953450701877 branch September 1, 2026 10:52
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