## Code Review
### Test Results
- Test suite run: `bundle exec rspec`
- Results: 728 examples, **126 failures**, 7 pending
- **CRITICAL: 126 test failures caused by authentication breaking existing tests**
### Root Cause Analysis
The PR adds `before_action :require_login` to `ApplicationController` with `login_optional?` defaulting to `false`. This means ALL controllers now require authentication, but existing tests were not updated to log in first.
### Failure Categories
1. **Feature specs (67 failures)**: All feature tests redirect to `/login` because they don't authenticate first
- spec/features/approvals_spec.rb
- spec/features/dashboard_spec.rb
- spec/features/debug_dashboard_spec.rb
- spec/features/kanban_board_spec.rb
- spec/features/multi_terminal_page_spec.rb
- spec/features/proposals_spec.rb
- spec/features/sessions_page_spec.rb
- spec/features/terminal_page_spec.rb
- spec/features/ticket_comments_spec.rb
- spec/features/ticket_workflow_spec.rb
2. **Request specs (18 failures)**: All request specs now redirect (302) instead of returning content
3. **New authentication spec issues (2 failures)**:
- spec/requests/sessions_spec.rb:29 - Uses `session` method incorrectly in request spec
- spec/features/sessions_spec.rb:181 - Uses Selenium cookie access incompatible with Cuprite driver
4. **System specs (6 failures)**: Agent session tests also redirect to login
### Files Changed
- app/controllers/application_controller.rb - Added require_login before_action
- app/controllers/sessions_controller.rb - New controller (63 lines)
- app/views/layouts/application.html.haml - Navigation changes
- app/views/sessions/new.html.haml - New login view (55 lines)
- config/routes.rb - Added login/logout routes
- spec/features/sessions_spec.rb - New feature specs (209 lines)
- spec/requests/sessions_spec.rb - New request specs (122 lines)
### Required Fixes
**OPTION 1: Opt-in Authentication (RECOMMENDED)**
Change the default to NOT require login, only require it on specific controllers:
```ruby
before_action :require_login, if: :login_required?
def login_required?
false # Override in controllers that need auth
end
```
**OR OPTION 2: Update All Existing Tests**
Add `before { login_as(agent) }` helper or similar to all 100+ existing feature/request specs.
**ALSO FIX:**
1. spec/requests/sessions_spec.rb:29 - Request specs cannot directly call `session[:key] = value`
2. spec/features/sessions_spec.rb:181 - Use driver-agnostic session check instead of Selenium-specific `manage.cookie`
### Security Notes
- Session fixation protection with `reset_session` is good ✓
- Rate limiting on failed attempts is good ✓
- Password-type input field for API key is good ✓
### Decision
**FAIL - Breaking Changes + Spec Issues**
This PR adds authentication that breaks 126 existing tests. Before this can be approved:
1. Choose opt-in approach OR update all existing tests to authenticate first
2. Fix the 2 broken tests in the new authentication specs
3. Verify the full test suite passes (0 failures)