Skip to content

feat: validate Ruby code by block conversion before saving#288

Merged
takaokouji merged 4 commits intodevelopfrom
feature/validate-before-save
Mar 13, 2026
Merged

feat: validate Ruby code by block conversion before saving#288
takaokouji merged 4 commits intodevelopfrom
feature/validate-before-save

Conversation

@takaokouji
Copy link

@takaokouji takaokouji commented Mar 13, 2026

Summary

Closes #287

Ruby タブの「ルビースクリプトを保存」実行前に、Ruby コードを命令ブロックに変換してバリデーションし、エラーがなければラウンドトリップでスプライト/ステージの状態を更新してから保存する。スモウルビー甲子園メニューも同様。

Implementation Steps

  • Phase 1: RubyDownloader に変換バリデーション追加
  • Phase 2: 「AIを試す」の実行順序変更(保存→モーダル表示)
  • Phase 3: エラー時のユーザーフィードバック改善(Ruby タブアクティブ化・アラート表示)
  • Phase Final: テスト追加

Changes Made

Phase 1: RubyDownloader に変換バリデーション追加

  • RubyDownloadervalidateAndConvert() メソッド追加
  • downloadProject() を async 化し、保存前に変換バリデーションを実行
  • 変換失敗時は onConversionError / onSaveError コールバックで保存中断
  • 変換成功時は converter.apply()convertedRubyCode() dispatch でラウンドトリップ完了

Phase 2: 「AIを試す」の実行順序変更

  • getTestAIHandler からモーダル表示を削除
  • handleTestAISaveFinished メソッド追加(保存完了後にモーダル表示)
  • Test AI の RubyDownloaderonSaveFinishedhandleTestAISaveFinished を設定

Phase 3: エラー時のユーザーフィードバック改善

  • menu-bar に handleConversionError メソッド追加(Ruby タブアクティブ化 + アラート表示 + エラー状態更新)
  • ruby-tab に handleConversionError コールバック追加(Monaco エディタでのエラーハイライト)
  • 全ての RubyDownloader インスタンスに onConversionError prop を設定

Phase Final: テスト追加

  • ファイル書き込みが変換失敗時にブロックされることを検証するテスト
  • ラウンドトリップ変換成功後のファイル書き込みを検証するテスト

Test Coverage

  • Unit tests: ruby-downloader.test.jsx (7 tests)
    • ファイルピッカーのエラーハンドリング
    • 未変更時の変換スキップ
    • 変更時の変換+apply呼び出し
    • 変換失敗時の中断+onConversionError呼び出し
    • 変換失敗時のファイル書き込みなし
    • 変換成功後のファイル書き込み
    • convertedRubyCode Redux action の dispatch
  • Lint: pass (warnings only)

RubyDownloader now validates Ruby code by converting to blocks before
saving. If conversion fails, the save is aborted and onConversionError
is called. On success, blocks are applied to update sprite/stage state
(round-trip) before generating the final Ruby output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

takaokouji and others added 3 commits March 13, 2026 10:00
Change the Test AI menu to save the Ruby script first and open the
Koshien test modal only after save succeeds (via onSaveFinished).
Previously the modal opened immediately before save completed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When block conversion fails during save (from Ruby tab or Koshien menu),
activate the Ruby tab, show the conversion error alert, and highlight
errors in the Monaco editor. Add onConversionError callback to all
RubyDownloader instances.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add tests verifying that file write is blocked when conversion fails
and that File System API write succeeds after successful round-trip
conversion.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@takaokouji takaokouji merged commit 04f7912 into develop Mar 13, 2026
9 checks passed
@takaokouji takaokouji deleted the feature/validate-before-save branch March 13, 2026 03:36
github-actions bot pushed a commit that referenced this pull request Mar 13, 2026
…ate-before-save

feat: validate Ruby code by block conversion before saving
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.

feat: validate Ruby code by block conversion before saving

1 participant