debug-mcp 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/CHANGELOG.md +83 -0
  4. data/LICENSE +21 -0
  5. data/README.ja.md +383 -0
  6. data/README.md +384 -0
  7. data/examples/01_simple_bug.rb +43 -0
  8. data/examples/02_data_pipeline.rb +93 -0
  9. data/examples/03_recursion.rb +96 -0
  10. data/examples/RAILS_SCENARIOS.md +350 -0
  11. data/examples/SCENARIOS.md +142 -0
  12. data/examples/rails_test_app/setup.sh +428 -0
  13. data/examples/rails_test_app/testapp/.dockerignore +10 -0
  14. data/examples/rails_test_app/testapp/.ruby-version +1 -0
  15. data/examples/rails_test_app/testapp/Dockerfile +23 -0
  16. data/examples/rails_test_app/testapp/Gemfile +17 -0
  17. data/examples/rails_test_app/testapp/README.md +65 -0
  18. data/examples/rails_test_app/testapp/Rakefile +6 -0
  19. data/examples/rails_test_app/testapp/app/assets/images/.keep +0 -0
  20. data/examples/rails_test_app/testapp/app/assets/stylesheets/application.css +1 -0
  21. data/examples/rails_test_app/testapp/app/controllers/application_controller.rb +4 -0
  22. data/examples/rails_test_app/testapp/app/controllers/concerns/.keep +0 -0
  23. data/examples/rails_test_app/testapp/app/controllers/dashboard_controller.rb +38 -0
  24. data/examples/rails_test_app/testapp/app/controllers/health_controller.rb +11 -0
  25. data/examples/rails_test_app/testapp/app/controllers/orders_controller.rb +100 -0
  26. data/examples/rails_test_app/testapp/app/controllers/posts_controller.rb +82 -0
  27. data/examples/rails_test_app/testapp/app/controllers/sessions_controller.rb +25 -0
  28. data/examples/rails_test_app/testapp/app/controllers/users_controller.rb +44 -0
  29. data/examples/rails_test_app/testapp/app/helpers/application_helper.rb +2 -0
  30. data/examples/rails_test_app/testapp/app/models/application_record.rb +3 -0
  31. data/examples/rails_test_app/testapp/app/models/comment.rb +8 -0
  32. data/examples/rails_test_app/testapp/app/models/concerns/.keep +0 -0
  33. data/examples/rails_test_app/testapp/app/models/order.rb +56 -0
  34. data/examples/rails_test_app/testapp/app/models/order_item.rb +16 -0
  35. data/examples/rails_test_app/testapp/app/models/post.rb +29 -0
  36. data/examples/rails_test_app/testapp/app/models/user.rb +34 -0
  37. data/examples/rails_test_app/testapp/app/services/order_report_service.rb +40 -0
  38. data/examples/rails_test_app/testapp/app/views/layouts/application.html.erb +28 -0
  39. data/examples/rails_test_app/testapp/app/views/pwa/manifest.json.erb +22 -0
  40. data/examples/rails_test_app/testapp/app/views/pwa/service-worker.js +26 -0
  41. data/examples/rails_test_app/testapp/bin/ci +6 -0
  42. data/examples/rails_test_app/testapp/bin/dev +2 -0
  43. data/examples/rails_test_app/testapp/bin/rails +4 -0
  44. data/examples/rails_test_app/testapp/bin/rake +4 -0
  45. data/examples/rails_test_app/testapp/bin/setup +35 -0
  46. data/examples/rails_test_app/testapp/config/application.rb +42 -0
  47. data/examples/rails_test_app/testapp/config/boot.rb +3 -0
  48. data/examples/rails_test_app/testapp/config/ci.rb +14 -0
  49. data/examples/rails_test_app/testapp/config/database.yml +32 -0
  50. data/examples/rails_test_app/testapp/config/environment.rb +5 -0
  51. data/examples/rails_test_app/testapp/config/environments/development.rb +54 -0
  52. data/examples/rails_test_app/testapp/config/environments/production.rb +67 -0
  53. data/examples/rails_test_app/testapp/config/environments/test.rb +42 -0
  54. data/examples/rails_test_app/testapp/config/initializers/content_security_policy.rb +29 -0
  55. data/examples/rails_test_app/testapp/config/initializers/filter_parameter_logging.rb +8 -0
  56. data/examples/rails_test_app/testapp/config/initializers/inflections.rb +16 -0
  57. data/examples/rails_test_app/testapp/config/locales/en.yml +31 -0
  58. data/examples/rails_test_app/testapp/config/puma.rb +39 -0
  59. data/examples/rails_test_app/testapp/config/routes.rb +34 -0
  60. data/examples/rails_test_app/testapp/config.ru +6 -0
  61. data/examples/rails_test_app/testapp/db/migrate/20260216002916_create_users.rb +12 -0
  62. data/examples/rails_test_app/testapp/db/migrate/20260216002919_create_posts.rb +13 -0
  63. data/examples/rails_test_app/testapp/db/migrate/20260216002922_create_comments.rb +11 -0
  64. data/examples/rails_test_app/testapp/db/migrate/20260222000001_create_orders.rb +14 -0
  65. data/examples/rails_test_app/testapp/db/migrate/20260222000002_create_order_items.rb +13 -0
  66. data/examples/rails_test_app/testapp/db/schema.rb +71 -0
  67. data/examples/rails_test_app/testapp/db/seeds.rb +85 -0
  68. data/examples/rails_test_app/testapp/docker-compose.yml +21 -0
  69. data/examples/rails_test_app/testapp/docker-entrypoint.sh +10 -0
  70. data/examples/rails_test_app/testapp/lib/tasks/.keep +0 -0
  71. data/examples/rails_test_app/testapp/log/.keep +0 -0
  72. data/examples/rails_test_app/testapp/public/400.html +135 -0
  73. data/examples/rails_test_app/testapp/public/404.html +135 -0
  74. data/examples/rails_test_app/testapp/public/406-unsupported-browser.html +135 -0
  75. data/examples/rails_test_app/testapp/public/422.html +135 -0
  76. data/examples/rails_test_app/testapp/public/500.html +135 -0
  77. data/examples/rails_test_app/testapp/public/icon.png +0 -0
  78. data/examples/rails_test_app/testapp/public/icon.svg +3 -0
  79. data/examples/rails_test_app/testapp/public/robots.txt +1 -0
  80. data/examples/rails_test_app/testapp/script/.keep +0 -0
  81. data/examples/rails_test_app/testapp/storage/.keep +0 -0
  82. data/examples/rails_test_app/testapp/tmp/.keep +0 -0
  83. data/examples/rails_test_app/testapp/tmp/pids/.keep +0 -0
  84. data/examples/rails_test_app/testapp/tmp/storage/.keep +0 -0
  85. data/examples/rails_test_app/testapp/vendor/.keep +0 -0
  86. data/exe/debug-mcp +39 -0
  87. data/exe/debug-rails +127 -0
  88. data/lib/debug_mcp/client_cleanup.rb +102 -0
  89. data/lib/debug_mcp/code_safety_analyzer.rb +124 -0
  90. data/lib/debug_mcp/debug_client.rb +1143 -0
  91. data/lib/debug_mcp/exit_message_builder.rb +112 -0
  92. data/lib/debug_mcp/pending_http_helper.rb +25 -0
  93. data/lib/debug_mcp/rails_helper.rb +155 -0
  94. data/lib/debug_mcp/server.rb +364 -0
  95. data/lib/debug_mcp/session_manager.rb +436 -0
  96. data/lib/debug_mcp/stop_event_annotator.rb +152 -0
  97. data/lib/debug_mcp/tcp_session_discovery.rb +226 -0
  98. data/lib/debug_mcp/tools/connect.rb +669 -0
  99. data/lib/debug_mcp/tools/continue_execution.rb +161 -0
  100. data/lib/debug_mcp/tools/disconnect.rb +169 -0
  101. data/lib/debug_mcp/tools/evaluate_code.rb +354 -0
  102. data/lib/debug_mcp/tools/finish.rb +84 -0
  103. data/lib/debug_mcp/tools/get_context.rb +217 -0
  104. data/lib/debug_mcp/tools/get_source.rb +193 -0
  105. data/lib/debug_mcp/tools/inspect_object.rb +107 -0
  106. data/lib/debug_mcp/tools/list_debug_sessions.rb +60 -0
  107. data/lib/debug_mcp/tools/list_files.rb +189 -0
  108. data/lib/debug_mcp/tools/list_paused_sessions.rb +108 -0
  109. data/lib/debug_mcp/tools/next.rb +70 -0
  110. data/lib/debug_mcp/tools/rails_info.rb +200 -0
  111. data/lib/debug_mcp/tools/rails_model.rb +362 -0
  112. data/lib/debug_mcp/tools/rails_routes.rb +186 -0
  113. data/lib/debug_mcp/tools/read_file.rb +214 -0
  114. data/lib/debug_mcp/tools/remove_breakpoint.rb +173 -0
  115. data/lib/debug_mcp/tools/run_debug_command.rb +55 -0
  116. data/lib/debug_mcp/tools/run_script.rb +293 -0
  117. data/lib/debug_mcp/tools/set_breakpoint.rb +206 -0
  118. data/lib/debug_mcp/tools/step.rb +67 -0
  119. data/lib/debug_mcp/tools/trigger_request.rb +515 -0
  120. data/lib/debug_mcp/version.rb +5 -0
  121. data/lib/debug_mcp.rb +40 -0
  122. metadata +251 -0
@@ -0,0 +1,32 @@
1
+ # SQLite. Versions 3.8.0 and up are supported.
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem "sqlite3"
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ max_connections: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: storage/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: storage/test.sqlite3
22
+
23
+
24
+ # SQLite3 write its data on the local filesystem, as such it requires
25
+ # persistent disks. If you are deploying to a managed service, you should
26
+ # make sure it provides disk persistence, as many don't.
27
+ #
28
+ # Similarly, if you deploy your application as a Docker container, you must
29
+ # ensure the database is located in a persisted volume.
30
+ production:
31
+ <<: *default
32
+ # database: path/to/persistent/storage/production.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative "application"
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,54 @@
1
+ require "active_support/core_ext/integer/time"
2
+
3
+ Rails.application.configure do
4
+ # Settings specified here will take precedence over those in config/application.rb.
5
+
6
+ # Make code changes take effect immediately without server restart.
7
+ config.enable_reloading = true
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports.
13
+ config.consider_all_requests_local = true
14
+
15
+ # Enable server timing.
16
+ config.server_timing = true
17
+
18
+ # Enable/disable Action Controller caching. By default Action Controller caching is disabled.
19
+ # Run rails dev:cache to toggle Action Controller caching.
20
+ if Rails.root.join("tmp/caching-dev.txt").exist?
21
+ config.action_controller.perform_caching = true
22
+ config.action_controller.enable_fragment_cache_logging = true
23
+ config.public_file_server.headers = { "cache-control" => "public, max-age=#{2.days.to_i}" }
24
+ else
25
+ config.action_controller.perform_caching = false
26
+ end
27
+
28
+ # Change to :null_store to avoid any caching.
29
+ config.cache_store = :memory_store
30
+
31
+ # Print deprecation notices to the Rails logger.
32
+ config.active_support.deprecation = :log
33
+
34
+ # Raise an error on page load if there are pending migrations.
35
+ config.active_record.migration_error = :page_load
36
+
37
+ # Highlight code that triggered database queries in logs.
38
+ config.active_record.verbose_query_logs = true
39
+
40
+ # Append comments with runtime information tags to SQL queries in logs.
41
+ config.active_record.query_log_tags_enabled = true
42
+
43
+ # Highlight code that triggered redirect in logs.
44
+ config.action_dispatch.verbose_redirect_logs = true
45
+
46
+ # Raises error for missing translations.
47
+ # config.i18n.raise_on_missing_translations = true
48
+
49
+ # Annotate rendered view with file names.
50
+ config.action_view.annotate_rendered_view_with_filenames = true
51
+
52
+ # Raise error when a before_action's only/except options reference missing actions.
53
+ config.action_controller.raise_on_missing_callback_actions = true
54
+ end
@@ -0,0 +1,67 @@
1
+ require "active_support/core_ext/integer/time"
2
+
3
+ Rails.application.configure do
4
+ # Settings specified here will take precedence over those in config/application.rb.
5
+
6
+ # Code is not reloaded between requests.
7
+ config.enable_reloading = false
8
+
9
+ # Eager load code on boot for better performance and memory savings (ignored by Rake tasks).
10
+ config.eager_load = true
11
+
12
+ # Full error reports are disabled.
13
+ config.consider_all_requests_local = false
14
+
15
+ # Turn on fragment caching in view templates.
16
+ config.action_controller.perform_caching = true
17
+
18
+ # Cache assets for far-future expiry since they are all digest stamped.
19
+ config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" }
20
+
21
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
22
+ # config.asset_host = "http://assets.example.com"
23
+
24
+ # Assume all access to the app is happening through a SSL-terminating reverse proxy.
25
+ config.assume_ssl = true
26
+
27
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
28
+ config.force_ssl = true
29
+
30
+ # Skip http-to-https redirect for the default health check endpoint.
31
+ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
32
+
33
+ # Log to STDOUT with the current request id as a default log tag.
34
+ config.log_tags = [ :request_id ]
35
+ config.logger = ActiveSupport::TaggedLogging.logger(STDOUT)
36
+
37
+ # Change to "debug" to log everything (including potentially personally-identifiable information!).
38
+ config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info")
39
+
40
+ # Prevent health checks from clogging up the logs.
41
+ config.silence_healthcheck_path = "/up"
42
+
43
+ # Don't log any deprecations.
44
+ config.active_support.report_deprecations = false
45
+
46
+ # Replace the default in-process memory cache store with a durable alternative.
47
+ # config.cache_store = :mem_cache_store
48
+
49
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
50
+ # the I18n.default_locale when a translation cannot be found).
51
+ config.i18n.fallbacks = true
52
+
53
+ # Do not dump schema after migrations.
54
+ config.active_record.dump_schema_after_migration = false
55
+
56
+ # Only use :id for inspections in production.
57
+ config.active_record.attributes_for_inspect = [ :id ]
58
+
59
+ # Enable DNS rebinding protection and other `Host` header attacks.
60
+ # config.hosts = [
61
+ # "example.com", # Allow requests from example.com
62
+ # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
63
+ # ]
64
+ #
65
+ # Skip DNS rebinding protection for the default health check endpoint.
66
+ # config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
67
+ end
@@ -0,0 +1,42 @@
1
+ # The test environment is used exclusively to run your application's
2
+ # test suite. You never need to work with it otherwise. Remember that
3
+ # your test database is "scratch space" for the test suite and is wiped
4
+ # and recreated between test runs. Don't rely on the data there!
5
+
6
+ Rails.application.configure do
7
+ # Settings specified here will take precedence over those in config/application.rb.
8
+
9
+ # While tests run files are not watched, reloading is not necessary.
10
+ config.enable_reloading = false
11
+
12
+ # Eager loading loads your entire application. When running a single test locally,
13
+ # this is usually not necessary, and can slow down your test suite. However, it's
14
+ # recommended that you enable it in continuous integration systems to ensure eager
15
+ # loading is working properly before deploying your code.
16
+ config.eager_load = ENV["CI"].present?
17
+
18
+ # Configure public file server for tests with cache-control for performance.
19
+ config.public_file_server.headers = { "cache-control" => "public, max-age=3600" }
20
+
21
+ # Show full error reports.
22
+ config.consider_all_requests_local = true
23
+ config.cache_store = :null_store
24
+
25
+ # Render exception templates for rescuable exceptions and raise for other exceptions.
26
+ config.action_dispatch.show_exceptions = :rescuable
27
+
28
+ # Disable request forgery protection in test environment.
29
+ config.action_controller.allow_forgery_protection = false
30
+
31
+ # Print deprecation notices to the stderr.
32
+ config.active_support.deprecation = :stderr
33
+
34
+ # Raises error for missing translations.
35
+ # config.i18n.raise_on_missing_translations = true
36
+
37
+ # Annotate rendered view with file names.
38
+ # config.action_view.annotate_rendered_view_with_filenames = true
39
+
40
+ # Raise error when a before_action's only/except options reference missing actions.
41
+ config.action_controller.raise_on_missing_callback_actions = true
42
+ end
@@ -0,0 +1,29 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Define an application-wide content security policy.
4
+ # See the Securing Rails Applications Guide for more information:
5
+ # https://guides.rubyonrails.org/security.html#content-security-policy-header
6
+
7
+ # Rails.application.configure do
8
+ # config.content_security_policy do |policy|
9
+ # policy.default_src :self, :https
10
+ # policy.font_src :self, :https, :data
11
+ # policy.img_src :self, :https, :data
12
+ # policy.object_src :none
13
+ # policy.script_src :self, :https
14
+ # policy.style_src :self, :https
15
+ # # Specify URI for violation reports
16
+ # # policy.report_uri "/csp-violation-report-endpoint"
17
+ # end
18
+ #
19
+ # # Generate session nonces for permitted importmap, inline scripts, and inline styles.
20
+ # config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
21
+ # config.content_security_policy_nonce_directives = %w(script-src style-src)
22
+ #
23
+ # # Automatically add `nonce` to `javascript_tag`, `javascript_include_tag`, and `stylesheet_link_tag`
24
+ # # if the corresponding directives are specified in `content_security_policy_nonce_directives`.
25
+ # # config.content_security_policy_nonce_auto = true
26
+ #
27
+ # # Report violations without enforcing the policy.
28
+ # # config.content_security_policy_report_only = true
29
+ # end
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file.
4
+ # Use this to limit dissemination of sensitive information.
5
+ # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.
6
+ Rails.application.config.filter_parameters += [
7
+ :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc
8
+ ]
@@ -0,0 +1,16 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format. Inflections
4
+ # are locale specific, and you may define rules for as many different
5
+ # locales as you wish. All of these examples are active by default:
6
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ # inflect.plural /^(ox)$/i, "\\1en"
8
+ # inflect.singular /^(ox)en/i, "\\1"
9
+ # inflect.irregular "person", "people"
10
+ # inflect.uncountable %w( fish sheep )
11
+ # end
12
+
13
+ # These inflection rules are supported but not enabled by default:
14
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
15
+ # inflect.acronym "RESTful"
16
+ # end
@@ -0,0 +1,31 @@
1
+ # Files in the config/locales directory are used for internationalization and
2
+ # are automatically loaded by Rails. If you want to use locales other than
3
+ # English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t "hello"
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t("hello") %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more about the API, please read the Rails Internationalization guide
20
+ # at https://guides.rubyonrails.org/i18n.html.
21
+ #
22
+ # Be aware that YAML interprets the following case-insensitive strings as
23
+ # booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings
24
+ # must be quoted to be interpreted as strings. For example:
25
+ #
26
+ # en:
27
+ # "yes": yup
28
+ # enabled: "ON"
29
+
30
+ en:
31
+ hello: "Hello world"
@@ -0,0 +1,39 @@
1
+ # This configuration file will be evaluated by Puma. The top-level methods that
2
+ # are invoked here are part of Puma's configuration DSL. For more information
3
+ # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
4
+ #
5
+ # Puma starts a configurable number of processes (workers) and each process
6
+ # serves each request in a thread from an internal thread pool.
7
+ #
8
+ # You can control the number of workers using ENV["WEB_CONCURRENCY"]. You
9
+ # should only set this value when you want to run 2 or more workers. The
10
+ # default is already 1. You can set it to `auto` to automatically start a worker
11
+ # for each available processor.
12
+ #
13
+ # The ideal number of threads per worker depends both on how much time the
14
+ # application spends waiting for IO operations and on how much you wish to
15
+ # prioritize throughput over latency.
16
+ #
17
+ # As a rule of thumb, increasing the number of threads will increase how much
18
+ # traffic a given process can handle (throughput), but due to CRuby's
19
+ # Global VM Lock (GVL) it has diminishing returns and will degrade the
20
+ # response time (latency) of the application.
21
+ #
22
+ # The default is set to 3 threads as it's deemed a decent compromise between
23
+ # throughput and latency for the average Rails application.
24
+ #
25
+ # Any libraries that use a connection pool or another resource pool should
26
+ # be configured to provide at least as many connections as the number of
27
+ # threads. This includes Active Record's `pool` parameter in `database.yml`.
28
+ threads_count = ENV.fetch("RAILS_MAX_THREADS", 3)
29
+ threads threads_count, threads_count
30
+
31
+ # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
32
+ port ENV.fetch("PORT", 3000)
33
+
34
+ # Allow puma to be restarted by `bin/rails restart` command.
35
+ plugin :tmp_restart
36
+
37
+ # Specify the PID file. Defaults to tmp/pids/server.pid in development.
38
+ # In other environments, only set the PID file if requested.
39
+ pidfile ENV["PIDFILE"] if ENV["PIDFILE"]
@@ -0,0 +1,34 @@
1
+ Rails.application.routes.draw do
2
+ resources :users, only: [:index, :show, :create, :update, :destroy]
3
+
4
+ resources :posts, only: [:index, :show, :create, :update] do
5
+ collection do
6
+ get :trending
7
+ get :search
8
+ end
9
+ end
10
+
11
+ resources :orders, only: [:index, :show, :create, :update] do
12
+ member do
13
+ post :cancel
14
+ end
15
+ collection do
16
+ get :user_orders
17
+ get :report
18
+ end
19
+ end
20
+
21
+ # セッション管理
22
+ post "/login", to: "sessions#create"
23
+ get "/me", to: "sessions#show"
24
+ delete "/logout", to: "sessions#destroy"
25
+
26
+ # ヘルスチェック
27
+ get "/health", to: "health#show"
28
+
29
+ # ダッシュボード(HTML)
30
+ get "/dashboard", to: "dashboard#index"
31
+
32
+ # ルートパス
33
+ root "health#show"
34
+ end
@@ -0,0 +1,6 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative "config/environment"
4
+
5
+ run Rails.application
6
+ Rails.application.load_server
@@ -0,0 +1,12 @@
1
+ class CreateUsers < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :name
5
+ t.string :email
6
+ t.integer :role
7
+ t.boolean :active
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePosts < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+ t.text :body
6
+ t.integer :status
7
+ t.references :user, null: false, foreign_key: true
8
+ t.datetime :published_at
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class CreateComments < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :comments do |t|
4
+ t.text :body
5
+ t.references :user, null: false, foreign_key: true
6
+ t.references :post, null: false, foreign_key: true
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ class CreateOrders < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :orders do |t|
4
+ t.references :user
5
+ t.integer :status, default: 0, null: false
6
+ t.integer :total_cents, default: 0, null: false
7
+ t.string :discount_code
8
+ t.decimal :discount_percent, precision: 5, scale: 2
9
+ t.datetime :completed_at
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ class CreateOrderItems < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :order_items do |t|
4
+ t.references :order, null: false, foreign_key: true
5
+ t.string :product_name, null: false
6
+ t.integer :quantity, default: 1, null: false
7
+ t.decimal :unit_price, precision: 10, scale: 2, null: false
8
+ t.decimal :tax_rate, precision: 5, scale: 4, default: "0.0", null: false
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,71 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema[8.1].define(version: 2026_02_22_000002) do
14
+ create_table "comments", force: :cascade do |t|
15
+ t.text "body"
16
+ t.datetime "created_at", null: false
17
+ t.integer "post_id", null: false
18
+ t.datetime "updated_at", null: false
19
+ t.integer "user_id", null: false
20
+ t.index ["post_id"], name: "index_comments_on_post_id"
21
+ t.index ["user_id"], name: "index_comments_on_user_id"
22
+ end
23
+
24
+ create_table "order_items", force: :cascade do |t|
25
+ t.datetime "created_at", null: false
26
+ t.integer "order_id", null: false
27
+ t.string "product_name", null: false
28
+ t.integer "quantity", default: 1, null: false
29
+ t.decimal "tax_rate", precision: 5, scale: 4, default: "0.0", null: false
30
+ t.decimal "unit_price", precision: 10, scale: 2, null: false
31
+ t.datetime "updated_at", null: false
32
+ t.index ["order_id"], name: "index_order_items_on_order_id"
33
+ end
34
+
35
+ create_table "orders", force: :cascade do |t|
36
+ t.datetime "completed_at"
37
+ t.datetime "created_at", null: false
38
+ t.string "discount_code"
39
+ t.decimal "discount_percent", precision: 5, scale: 2
40
+ t.integer "status", default: 0, null: false
41
+ t.integer "total_cents", default: 0, null: false
42
+ t.datetime "updated_at", null: false
43
+ t.integer "user_id"
44
+ t.index ["user_id"], name: "index_orders_on_user_id"
45
+ end
46
+
47
+ create_table "posts", force: :cascade do |t|
48
+ t.text "body"
49
+ t.datetime "created_at", null: false
50
+ t.datetime "published_at"
51
+ t.integer "status"
52
+ t.string "title"
53
+ t.datetime "updated_at", null: false
54
+ t.integer "user_id", null: false
55
+ t.index ["user_id"], name: "index_posts_on_user_id"
56
+ end
57
+
58
+ create_table "users", force: :cascade do |t|
59
+ t.boolean "active"
60
+ t.datetime "created_at", null: false
61
+ t.string "email"
62
+ t.string "name"
63
+ t.integer "role"
64
+ t.datetime "updated_at", null: false
65
+ end
66
+
67
+ add_foreign_key "comments", "posts"
68
+ add_foreign_key "comments", "users"
69
+ add_foreign_key "order_items", "orders"
70
+ add_foreign_key "posts", "users"
71
+ end
@@ -0,0 +1,85 @@
1
+ puts "シードデータを作成中..."
2
+
3
+ # ユーザー
4
+ alice = User.create!(name: "Alice", email: "alice@example.com", role: :admin, active: true)
5
+ bob = User.create!(name: "Bob", email: "bob@example.com", role: :editor, active: true)
6
+ carol = User.create!(name: "Carol", email: "carol@example.com", role: :member, active: true)
7
+ dave = User.create!(name: "Dave", email: "dave@example.com", role: :guest, active: false)
8
+
9
+ # 投稿
10
+ post1 = Post.create!(
11
+ title: "Rails デバッグ入門",
12
+ body: "debug gemを使ったRailsアプリケーションのデバッグ方法について解説します。breakpointの設定、変数の確認、ステップ実行など基本的なデバッグ技法を紹介します。",
13
+ status: :published,
14
+ user: alice,
15
+ published_at: 2.days.ago
16
+ )
17
+
18
+ post2 = Post.create!(
19
+ title: "ActiveRecordのN+1問題を解決する",
20
+ body: "includesやpreloadを使ってN+1クエリを解消する方法を紹介します。BulletやProsopiteなどの検出ツールも併せて解説します。",
21
+ status: :published,
22
+ user: bob,
23
+ published_at: 1.day.ago
24
+ )
25
+
26
+ post3 = Post.create!(
27
+ title: "下書き: テスト駆動開発のすすめ",
28
+ body: "RSpecを使ったTDDの実践方法について。まだ書きかけです。",
29
+ status: :draft,
30
+ user: alice
31
+ )
32
+
33
+ post4 = Post.create!(
34
+ title: "アーカイブ済み: 古い記事",
35
+ body: "この記事はアーカイブされました。",
36
+ status: :archived,
37
+ user: carol
38
+ )
39
+
40
+ # コメント
41
+ Comment.create!(body: "とても分かりやすい記事です!", user: bob, post: post1)
42
+ Comment.create!(body: "binding.breakの使い方も知りたいです。", user: carol, post: post1)
43
+ Comment.create!(body: "N+1問題に困っていたので助かりました。", user: alice, post: post2)
44
+ Comment.create!(body: "Bulletの設定方法をもう少し詳しく書いてほしいです。", user: dave, post: post2)
45
+
46
+ # Ghost User(Scenario 3: レポートで孤立オーダーを作るため)
47
+ ghost_user = User.create!(name: "Ghost", email: "ghost@example.com", role: :member, active: true)
48
+
49
+ # ===== Orders =====
50
+
51
+ # Order 1: Alice, completed, 割引10%(Scenario 1: 浮動小数点バグトリガー)
52
+ order1 = Order.create!(user: alice, status: :completed, discount_code: "SAVE10", discount_percent: 10, completed_at: 3.days.ago)
53
+ OrderItem.create!(order: order1, product_name: "Ruby入門書", quantity: 1, unit_price: 33.33, tax_rate: 0.08)
54
+ OrderItem.create!(order: order1, product_name: "デバッグツール Pro", quantity: 2, unit_price: 14.99, tax_rate: 0.08)
55
+ order1.save! # recalculate_total を発動
56
+
57
+ # Order 2: Bob, completed(Scenario 2: cancel→再save シナリオ用)
58
+ order2 = Order.create!(user: bob, status: :completed, completed_at: 2.days.ago)
59
+ OrderItem.create!(order: order2, product_name: "Rails Guide", quantity: 1, unit_price: 45.00, tax_rate: 0.10)
60
+ OrderItem.create!(order: order2, product_name: "Testing Kit", quantity: 3, unit_price: 12.50, tax_rate: 0.10)
61
+ order2.save!
62
+
63
+ # Order 3: Ghost User, completed(Scenario 3: 孤立オーダー)
64
+ order3 = Order.create!(user: ghost_user, status: :completed, completed_at: 1.day.ago)
65
+ OrderItem.create!(order: order3, product_name: "Mystery Box", quantity: 1, unit_price: 25.00, tax_rate: 0.05)
66
+ order3.save!
67
+
68
+ # Order 4: Carol, completed(通常データ)
69
+ order4 = Order.create!(user: carol, status: :completed, completed_at: 1.day.ago)
70
+ OrderItem.create!(order: order4, product_name: "Keyboard", quantity: 1, unit_price: 89.99, tax_rate: 0.08)
71
+ order4.save!
72
+
73
+ # Order 5: Carol, cancelled(Scenario 4: default_scopeで不可視)
74
+ order5 = Order.create!(user: carol, status: :cancelled, completed_at: 5.days.ago)
75
+ OrderItem.create!(order: order5, product_name: "返品済みアイテム", quantity: 1, unit_price: 15.00, tax_rate: 0.08)
76
+
77
+ # Order 6: Alice, pending(一般データ)
78
+ order6 = Order.create!(user: alice, status: :pending)
79
+ OrderItem.create!(order: order6, product_name: "新ウィジェット", quantity: 2, unit_price: 19.99, tax_rate: 0.10)
80
+ order6.save!
81
+
82
+ # Ghost Userを削除して孤立オーダーを作成(Scenario 3のトリガー)
83
+ ghost_user.delete
84
+
85
+ puts "完了: ユーザー#{User.count}人、投稿#{Post.count}件、コメント#{Comment.count}件、注文#{Order.count}件"
@@ -0,0 +1,21 @@
1
+ services:
2
+ web:
3
+ build: .
4
+ ports:
5
+ - "3000:3000"
6
+ - "127.0.0.1:12345:12345"
7
+ environment:
8
+ - RUBY_DEBUG_OPEN=true
9
+ - RUBY_DEBUG_HOST=0.0.0.0
10
+ - RUBY_DEBUG_PORT=12345
11
+ - RAILS_ENV=development
12
+ volumes:
13
+ - .:/app
14
+ - bundle_cache:/usr/local/bundle
15
+ - storage:/app/storage
16
+ tmpfs:
17
+ - /app/tmp
18
+
19
+ volumes:
20
+ bundle_cache:
21
+ storage:
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ # Remove stale PID file (if server was killed previously)
5
+ rm -f tmp/pids/server.pid
6
+
7
+ # DB setup: create, migrate, seed (idempotent)
8
+ env -u RUBY_DEBUG_OPEN -u RUBY_DEBUG_PORT -u RUBY_DEBUG_HOST bin/rails db:prepare
9
+
10
+ exec "$@"
File without changes
File without changes