fix(koshien): Test AI のURL最大長超過にファイル出力フォールバックを追加 (#845)#846
Conversation
Complex AIs (e.g. path-finding) produce a base64 player1 query parameter that overflows the viewer URL length limit, so the iframe fails to load. Add buildKoshienTestPlan: when the URL exceeds MAX_KOSHIEN_TEST_URL_LENGTH (8000), load the viewer without the AI (default AI) and show a banner letting the user save the AI as a .rb file to load into the viewer manually. Short AIs keep the previous URL-embedded behavior. This is the editor-only fallback (案C of #845). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🤖 autopilot status
Linked issue #845. Maintained by autopilot (single writer); do not edit. |
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/topic/autopilot-845/ |
🤖 autopilot 敵対的レビュー (review フェーズ)別の批判的レビュアーとして差分をレビューしました。ブロッカーなし。自動修正が必要な明白な問題は見つかりませんでした。 確認済み(良い点)
非ブロッキングの指摘(人間判断 / 任意)
人間レビューへ引き継ぎます。 |
|
ファイルサイズが大きいAIを指定して、AIを試すを選択したが、
とは、なりませんでした。AIもバナー + ダウンロードボタンが表示されるかどうかためしてください。表示されなければ、表示されるように改修してください。 |
| 'gui.alerts.thumbnailError': 'サムネイルを設定できませんでした。あとでもう一度お試しください。', | ||
|
|
||
| 'gui.koshienTestModal.title': 'スモウルビー甲子園のAIを試す', | ||
| 'gui.koshienTestModal.tooLong': |
…banner shows (#845) The "Test AI" modal generated code only from the editing target (`generatePreviewCode(vm.editingTarget)`), while the actual AI — what "Save AI" writes — is the whole project (stage + every sprite, plus any unsaved Ruby-tab edits). For a multi-class AI whose logic lives in a sprite (or when the stage is selected, or before edits are converted back to blocks), the editing target's slice is small, so the viewer URL stayed under the length limit and the download-fallback banner never appeared. Make "Test AI" generate the full-project code via a new shared `generateProjectCode` helper, and refactor "Save AI" (RubyDownloader) to use the same helper so testing and saving can never diverge again (the divergence was the root cause). The test path keeps the preview format (no `forSave`) that the game viewer URL has always accepted; save keeps `forSave: true`. - ruby-script-preview.js: add `generateProjectCode(vm, {stage, sprites, version, rubyCode, forSave})` (all targets, stage-first, pending Ruby injected via targetsCode). - koshien-test-modal.jsx: use it; connect stage/sprites/rubyCode. - ruby-downloader.jsx: saveRuby() delegates to the shared helper. - Tests: full-project generation includes sprite code with an empty stage, pending edits are injected, modal calls the whole-project generator and still shows/hides the banner correctly + a generation-throws fallback case. - docs/extension-koshien/README.md updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@takaokouji ご指摘ありがとうございます。原因を特定して修正しました( 原因「AIを試す」モーダルは 編集中スプライト単体 のコードしか生成していませんでした 添付いただいた
※ 修正「AIを試す」を 「AIを保存」と同一のコード生成(プロジェクト全体 + 未保存の Ruby 編集も反映)に
再確認のお願いプレビュー(このブランチの再デプロイ後)で、添付の |
…ot-845 fix(koshien): Test AI のURL最大長超過にファイル出力フォールバックを追加 (#845)
Summary
ルビータブの「AIを試す」で、複雑な(=ソースが長い)AI が URL 最大長を超えてビューア起動に失敗する 問題を修正する(#845)。
AI ソースを base64 化して
?player1=data:<base64>クエリパラメータに詰める方式のため、AI が長くなるほど URL が肥大化し、ブラウザ/ビューア/iframe の URL 長制限に引っかかってロードできなくなっていた。Issue の修正方針のうち、editor 単独で完結する案C(ファイル出力フォールバック) を実装した(案A: postMessage / 案B: 圧縮 はビューア側=別リポジトリの対応が必要なため別途検討)。
Changes Made
lib/koshien-test-url.js:MAX_KOSHIEN_TEST_URL_LENGTH(8000 文字)とisKoshienTestUrlTooLong(url)を追加。buildKoshienTestPlan(code)を追加。URL が長すぎる場合はtooLong: trueを返し、AI 無しの base URL をurlとして返す(ビューアはデフォルト AI で起動)。components/koshien-test-modal/koshien-test-modal.jsx:buildKoshienTestPlanを使い、tooLongのときは AI 無し URL でビューアをロードしつつ、AI を.rbファイルとして保存する導線(バナー + ダウンロードボタン)を表示。<sprite>.rb、不正文字は_置換、フォールバックkoshien_ai.rb)。KoshienTestModal)。ja.js/ja-Hira.js)を追加。docs/extension-koshien/README.mdにフォールバック挙動を追記。短い AI の従来挙動(URL 直結)は維持される。
Test Coverage
test/unit/lib/koshien-test-url.test.js:isKoshienTestUrlTooLongの境界、buildKoshienTestPlan(短い AI は player1 埋め込み / 大きい AI は too long + base URL フォールバック / カスタム base URL)。test/unit/components/koshien-test-modal.test.jsx(新規): 短い AI は iframe にplayer1=を含みバナー非表示 / 大きい AI はバナー表示・iframe に AI 無し / ダウンロードボタンが<sprite>.rbを保存。format:checkpass、変更ファイルの eslint 0 errors を確認。DoD(実機確認の観点)
.rb保存導線が出る。保存した.rbをビューアから読み込んで AI を動かせる。Related Issues
Closes #845
関連: Epic #738(甲子園拡張)、#840(「AIを試す」の保存処理)