Skip to content

Commit f6fdb7e

Browse files
CopilotiHiD
andcommitted
Fix Ruby version managers reference and add comprehensive documentation structure
Co-authored-by: iHiD <[email protected]>
1 parent 93ca4e0 commit f6fdb7e

File tree

3 files changed

+748
-52
lines changed

3 files changed

+748
-52
lines changed

.github/copilot-instructions.md

Lines changed: 98 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ Exercism Website is a comprehensive Ruby on Rails application with React/TypeScr
44

55
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
66

7+
## Documentation
8+
9+
There is a subdirectory called `docs/llm-support` which contains detailed information that an LLM might find useful on different areas of the application. When working with specific components, always reference the RELEVANT docs in that directory first:
10+
11+
- `API.md` - Detailed API architecture, authentication, and patterns
12+
- `SPI.md` - Service Provider Interface for internal AWS services
13+
14+
These files provide comprehensive context that supplements the workflow guidance in this document.
15+
716
## Working Effectively
817

918
### Prerequisites and Environment Setup
@@ -144,7 +153,7 @@ bundle exec rails test:zeitwerk
144153
- **Bundler 2.6.9**: Locked version in Gemfile.lock
145154

146155
### Known Limitations
147-
- Ruby version managers (rbenv/rvm) recommended for version management
156+
- Ruby version managers (setup-ruby and chruby) recommended for version management
148157
- Some JS packages require private NPM access (will fail in some environments)
149158
- Docker services must be running before Rails server starts
150159
- Database must be properly configured with utf8mb4 collation
@@ -239,62 +248,24 @@ cmd.on_failure { |errors| render_400(:failed_validations, errors: errors) }
239248

240249
### API, SPI and Route Architecture
241250

242-
#### API Routes (`/api`)
243-
The API namespace provides public endpoints for authenticated users, primarily consumed by:
244-
- Exercism Command Line Interface (CLI)
245-
- Exercism website frontend
246-
- Third-party integrations with proper authentication
251+
For detailed information about API and SPI architectures, see:
252+
- [`docs/llm-support/API.md`](../docs/llm-support/API.md) - API endpoints, authentication, and patterns
253+
- [`docs/llm-support/SPI.md`](../docs/llm-support/SPI.md) - Internal service endpoints and AWS integration
247254

248-
API controllers delegate business logic to Mandate commands:
255+
#### Quick Reference
249256

250-
```ruby
251-
class API::SettingsController < API::BaseController
252-
def update
253-
cmd = User::Update.(current_user, params)
254-
255-
cmd.on_success { render json: {} }
256-
cmd.on_failure { |errors| render_400(:failed_validations, errors: errors) }
257-
end
258-
end
259-
```
260-
261-
Key characteristics:
262-
- Requires authentication via Bearer tokens (`Authorization: Bearer <token>`)
263-
- Returns JSON responses
264-
- Handles errors consistently via `render_400`, `render_403`, etc.
257+
**API Routes (`/api`)**: Public endpoints for authenticated users (CLI, frontend, third-party integrations)
258+
- Require Bearer token authentication
259+
- Delegate business logic to Mandate commands
260+
- Consistent JSON error responses
265261
- Routes defined in `config/routes/api.rb`
266262

267-
#### SPI Routes (`/spi`)
268-
The Service Provider Interface (SPI) provides internal endpoints for:
269-
- AWS Lambda functions
270-
- Internal microservices
271-
- Exercism infrastructure components
272-
273-
**Security Model**: SPI endpoints are secured at the AWS infrastructure level rather than application-level authentication, allowing trusted internal services to post data arbitrarily.
274-
275-
```ruby
276-
# Example SPI endpoints
277-
namespace :spi do
278-
resources :tooling_jobs, only: :update # Tooling service updates
279-
resources :chatgpt_responses, only: :create # AI service responses
280-
get "solution_image_data/:track_slug/:exercise_slug/:user_handle" => "solution_image_data#show"
281-
end
282-
```
283-
284-
Key characteristics:
285-
- No application-level authentication required
286-
- AWS-level security controls access
263+
**SPI Routes (`/spi`)**: Internal endpoints for AWS Lambda functions and microservices
264+
- No application-level authentication (secured at AWS infrastructure level)
287265
- Used by Lambda functions to post results back to main application
288266
- Routes defined in `config/routes/spi.rb`
289267

290-
#### Standard Routes
291-
Regular Rails routes handle:
292-
- User-facing web pages
293-
- Authentication flows (Devise)
294-
- Webhooks (GitHub, Stripe, PayPal)
295-
- Admin interfaces
296-
297-
Routes are organized in the main `config/routes.rb` with additional route files for specific features like bootcamp functionality.
268+
**Standard Routes**: Regular Rails routes for user-facing web pages, authentication flows, webhooks, and admin interfaces.
298269

299270
### Configuration
300271
- `config/database.yml` - Database configuration
@@ -333,6 +304,23 @@ This setup is complex but necessary for the full Exercism platform. When in doub
333304

334305
## Testing Patterns
335306

307+
Exercism uses **Minitest** as the testing framework with **FactoryBot** for test data generation. Tests are organized by type with comprehensive helper methods to support different testing scenarios.
308+
309+
### Testing Tools and Setup
310+
311+
**Core Testing Stack:**
312+
- **Minitest**: Ruby's standard testing framework with assertions and test structure
313+
- **FactoryBot**: Flexible test data generation with realistic factory definitions
314+
- **Mocha**: Mocking and stubbing framework for isolating tests
315+
- **Capybara**: Browser automation for system tests
316+
- **WebMock**: HTTP request stubbing for external service integration
317+
318+
**Test Data Management:**
319+
- Factories defined in `test/factories/` directory
320+
- Use `create :user` for persisted records, `build :user` for unsaved objects
321+
- Factory traits available for common variations: `create :user, :admin`
322+
- Consistent data patterns ensure realistic test scenarios
323+
336324
### Model Tests
337325
Model tests focus on testing every public method with small, focused tests. Tests should cover:
338326
- **Happy path behavior**: Normal usage scenarios
@@ -401,6 +389,48 @@ class Solution::CreateTest < ActiveSupport::TestCase
401389
end
402390
```
403391

392+
### Controller Tests
393+
Controller tests verify HTTP request handling and integration with command objects. They focus on authentication, parameter validation, and response formatting.
394+
395+
**API Controller Tests:**
396+
- Inherit from `API::BaseTestCase` which provides authentication helpers
397+
- Use `setup_user` to create authenticated test user with auth token
398+
- Test authentication guards with `guard_incorrect_token!` class method
399+
- Mock command objects to isolate controller logic from business logic
400+
401+
```ruby
402+
class API::SolutionsControllerTest < API::BaseTestCase
403+
# Test authentication requirements for all endpoints
404+
guard_incorrect_token! :api_solutions_path
405+
guard_incorrect_token! :api_solution_path, args: 1, method: :patch
406+
407+
test "create solution successfully" do
408+
setup_user
409+
exercise = create :exercise
410+
mock_solution = mock('solution')
411+
412+
Solution::Create.expects(:call).with(@current_user, exercise).returns(mock_solution)
413+
414+
post api_solutions_path,
415+
params: { exercise_id: exercise.id },
416+
headers: @headers,
417+
as: :json
418+
419+
assert_response :created
420+
end
421+
end
422+
```
423+
424+
**Available Helper Methods (API::BaseTestCase):**
425+
- `setup_user(user = nil)`: Creates authenticated user with auth token, sets `@current_user` and `@headers`
426+
- `guard_incorrect_token!(path, args: 0, method: :get)`: Class method that generates authentication test
427+
- `assert_json_response(expected)`: Compares JSON response with expected hash
428+
429+
**Standard Controller Tests:**
430+
- Inherit from `ActionDispatch::IntegrationTest` for web controllers
431+
- Test user flows, form submissions, and page rendering
432+
- Use Devise test helpers for authentication
433+
404434
### System Tests
405435
System tests verify end-to-end user workflows using browser automation. They should:
406436
- **Test complete user journeys**: From login to task completion
@@ -432,8 +462,24 @@ class UserRegistrationTest < ApplicationSystemTestCase
432462
end
433463
```
434464

465+
**Available Helper Methods (ApplicationSystemTestCase):**
466+
- `sign_in!(user = nil)`: Creates and signs in user, confirms account, sets `@current_user`
467+
- `assert_page(page)`: Verifies current page by checking for `#page-{page}` element
468+
- `assert_html(html, within: "body")`: Compares HTML structure within specified element
469+
- `assert_text(text, **options)`: Enhanced text assertion with normalized whitespace
470+
- `assert_no_text(text, **options)`: Text absence assertion with React loading delay handling
471+
- `url_to_path(url)`: Converts full URL to path for route comparisons
472+
- `expecting_errors { ... }`: Disables JavaScript error checking for tests that expect errors
473+
474+
**Capybara Integration:**
475+
- Access to all Capybara helpers: `visit`, `fill_in`, `click_on`, `find`, etc.
476+
- WebSocket testing support through `WebsocketsHelpers` module
477+
- Custom browser configuration for headless Chrome with download directory setup
478+
- Automatic JavaScript error detection and test failure on unexpected errors
479+
435480
**System Test Guidelines:**
436481
- Use descriptive test names that explain the user action
437-
- Include both success and failure scenarios
482+
- Include both success and failure scenarios
438483
- Use `wait` parameters for dynamic content loading
439-
- Test accessibility and responsive behavior when relevant
484+
- Test accessibility and responsive behavior when relevant
485+
- Use data attributes like `class: "test-sign-up-btn"` for reliable element selection

0 commit comments

Comments
 (0)