Skip to content

fix(translate): 翻訳拡張を Smalruby CORS プロキシ経由に (#857)#858

Merged
takaokouji merged 2 commits into
developfrom
topic/autopilot-857
Jul 1, 2026
Merged

fix(translate): 翻訳拡張を Smalruby CORS プロキシ経由に (#857)#858
takaokouji merged 2 commits into
developfrom
topic/autopilot-857

Conversation

@smalruby3-editor-bot

Copy link
Copy Markdown

Summary

翻訳拡張 (scratch3_translate) が smalruby.app から実行すると CORS でブロックされる不具合を修正する。Scratch の翻訳サービス (translate-service.scratch.mit.edu) は Access-Control-Allow-Originscratch.mit.edu 限定に締めたため、smalruby.app からの直叩きが失敗していた。VM 実装の serverURL を Smalruby の CORS 回避プロキシ (https://api.smalruby.app/scratch-api-proxy/) に上書きする。

根本原因の調査(Issue コメントの依頼に対応)

「プロキシをはずしたコミットを特定。その前後で他にも影響する修正がないか把握。影響範囲を特定してまとめて修正」

  • プロキシは以前から存在していた: 74fb4c1f59(2026-01-20, "Restore Smalruby proxy URL for Translate extension")で serverURL = 'https://api.smalruby.app/scratch-api-proxy/' に上書きされていた。
  • 失われたコミットを特定: 4e2ddc1406upstream v13.7.2 マージ / PR feat: upstream merge 2026-05 (v13.7.2 — 284 commits, scratch-blocks v2) #630, 2026-05-03)で serverURL が upstream 値 (translate-service.scratch.mit.edu) に静かに revert された。マージ直前 (2026-03-08) までは Smalruby プロキシ値が残っていたことを確認済み。
  • なぜ検知できなかったか: 74fb4c1f59 の上書きに Smalruby マーカーが無かったため、upstream マージのコンフリクト解決でも fix: re-align pre-spork-reverted files to upstream v13.7.2 (#749) #751-754 の post-merge 監査でも検知されず、素通りで revert された。
  • 他の影響範囲: 同マージ直前の scratch-vm を調べた結果、マーカー無しの Smalruby サービス URL 上書きは translate が唯一api.smalruby.app / scratch-api-proxy の直書きは他に無し。mesh 系は別ディレクトリで Smalruby 固有ファイル)。したがってこのクラスの被害は translate のみで、他 VM 箇所への波及は無い。
  • 再発防止: 今回は Smalruby マーカーで囲みdocs/maintenance/smalruby-markers-vm.md に記録したため、次回以降の upstream マージでマーカーが差分検知の起点になる。

Changes Made

  • packages/scratch-vm/src/extensions/scratch3_translate/index.js: serverURL を Smalruby プロキシに上書き(=== Smalruby: Start/End of translate CORS proxy === マーカーで囲む)。リクエスト形 ?language=&text= はプロキシが透過するので変更不要。
  • packages/scratch-vm/test/unit/extension_translate_proxy.js: getTranslate が Smalruby プロキシ URL を fetch することを保証するガードテスト(実 fetch 無し・スタブ)。
  • packages/scratch-vm/.prettierignore: 新テストをホワイトリストに追加。
  • docs/maintenance/smalruby-markers-vm.md: マーカーを記録。
  • docs/extension-translate/README.md: upstream 区分を ⬆️ そのまま → 🔧 upstream 改良 に更新、プロキシ経由の説明を追記。

Test Coverage

  • プロキシ疎通確認 (curl): curl "https://api.smalruby.app/scratch-api-proxy/translate?language=en&text=%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF"{"result":"Hi"} (HTTP 200) を確認。
  • unit test: test/unit/extension_translate_proxy.js を追加(RED→GREEN 確認済み)。
  • lint: packages/scratch-vm の lint pass(0 errors)。

🙋 HITL: 実機での翻訳動作確認をお願いします

CORS の実挙動はコンテナ内 headless では確認できないため、本番またはプレビュー環境で以下の確認をお願いします:

  1. Ruby/ブロックタブで翻訳拡張を読み込む。
  2. 「〜を〜に翻訳する」ブロックを実行し、CORS エラーなく翻訳結果が返ること(DevTools Console に translate-service.scratch.mit.edu ... CORS policy エラーが出ないこと)。
  3. Network タブでリクエストが api.smalruby.app/scratch-api-proxy/translate に向いていること。

関連・留意

  • text2speech (synthesis-service.scratch.mit.edu) も同じ CORS 構造で将来壊れる可能性があるが、synthesis 用プロキシが未整備のため 本 PR のスコープ外(別 Issue 要検討)。

Related Issues

Closes #857

Scratch's translate service (translate-service.scratch.mit.edu) is CORS-locked to

scratch.mit.edu, so smalruby.app is blocked with an Access-Control-Allow-Origin

mismatch. Override serverURL to the Smalruby proxy (api.smalruby.app/scratch-api-proxy/)

which forwards server-side and returns permissive CORS headers.

Root cause: the override existed (74fb4c1) but had no Smalruby marker, so it was

silently reverted by the v13.7.2 upstream merge (4e2ddc1, PR #630). It is the only

unmarked Smalruby service-URL override in scratch-vm, so no other VM sites are affected.

Wrap in Smalruby markers + add a guard test + record in smalruby-markers-vm.md so future

upstream merges detect it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@smalruby3-editor-bot smalruby3-editor-bot Bot added the 🤖 autopilot autopilot(AI)が管理する PR/Issue(AI処理対象) label Jul 1, 2026
@smalruby3-editor-bot

smalruby3-editor-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown
Author

🤖 autopilot status

field value
Status Review
AI Status
HITL Yes
Size small

Linked issue #857. Maintained by autopilot (single writer); do not edit.

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/topic/autopilot-857/

The readme quoted the marker as '=== Smalruby: translate CORS proxy ==='
but the code uses the required Start of/End of form. Align the doc so a
future maintainer searching for the marker finds it.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@smalruby3-editor-bot

Copy link
Copy Markdown
Author

🤖 autopilot 敵対的レビュー結果

別レビュアー視点で差分を批判的に確認しました。重大な問題は無し。以下を確認済みです。

正確性

  • serverURL の上書きは唯一の参照箇所 (index.js:270) に効き、リクエスト形 translate?language=&text= は Lambda (scratch-api-translate.ts) が language/text をそのまま透過するため変更不要 — 配線は正しい。
  • serverURL を直叩き URL (translate-service.scratch.mit.edu) に戻す参照はコード中に残っていない(コメント内の説明のみ)。

規約・再発防止

  • upstream ファイルへの上書きを === Smalruby: Start/End of translate CORS proxy === マーカーで囲み、docs/maintenance/smalruby-markers-vm.md に登録済み。今回の revert 再発(マーカー欠如が原因)を構造的に防いでいる。
  • 新規テスト test/unit/extension_translate_proxy.js.prettierignore ホワイトリストに追加済み。
  • docs/extension-translate/README.md の upstream 区分を ⬆️→🔧 に更新済み。

テスト・lint

  • ガードテスト 3 アサーション green(proxy URL を叩く / 直叩きしない を検証、実 fetch なし)。
  • packages/scratch-vm lint: 0 errors(残 warning 3 件は本 PR 無関係の既存 fixture)。

自己修正(1 件)

  • README のマーカー表記が実コード (Start of/End of 形) と食い違っていたため、doc を実際のマーカー名に修正(a828deb)。

スコープ確認

  • text2speech (synthesis-service.scratch.mit.edu) も同型の CORS 構造だが専用プロキシ未整備のため本 PR スコープ外、で妥当(別 Issue 要検討)。

CORS の実挙動はコンテナ内 headless で確認できないため、PR 本文の 🙋 HITL 手順(本番/プレビューで翻訳ブロックが動くこと) の確認を人間にお願いします。

@smalruby3-editor-bot smalruby3-editor-bot Bot added the 🙋 HITL 人間の対応待ち(レビュー/判断/マージ) label Jul 1, 2026
@smalruby3-editor-bot smalruby3-editor-bot Bot marked this pull request as ready for review July 1, 2026 07:06
@takaokouji takaokouji merged commit 125eb38 into develop Jul 1, 2026
9 checks passed
@takaokouji takaokouji deleted the topic/autopilot-857 branch July 1, 2026 10:01
github-actions Bot pushed a commit that referenced this pull request Jul 1, 2026
…ot-857

fix(translate): 翻訳拡張を Smalruby CORS プロキシ経由に (#857)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤖 autopilot autopilot(AI)が管理する PR/Issue(AI処理対象) 🙋 HITL 人間の対応待ち(レビュー/判断/マージ)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(translate): 翻訳拡張が CORS で失敗(Scratch 直叩き→Smalruby プロキシ経由に)

1 participant