|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file contains guidelines and commands for agentic coding agents working in the ActiveRecord SQL Server Adapter repository. |
| 4 | + |
| 5 | +## Build, Lint & Test Commands |
| 6 | + |
| 7 | +### Core Commands |
| 8 | +```bash |
| 9 | +# Install dependencies |
| 10 | +bundle install |
| 11 | + |
| 12 | +# Run all tests |
| 13 | +bundle exec rake test |
| 14 | + |
| 15 | +# Run specific test files |
| 16 | +bundle exec ruby -Ilib:test test/cases/adapter_test_sqlserver.rb |
| 17 | + |
| 18 | +# Run tests with environment variables |
| 19 | +ONLY_SQLSERVER=1 bundle exec rake test |
| 20 | +ONLY_ACTIVERECORD=1 bundle exec rake test |
| 21 | + |
| 22 | +# Run specific tests using TEST_FILES environment variable |
| 23 | +TEST_FILES=test/cases/adapter_test_sqlserver.rb,test/cases/schema_test_sqlserver.rb bundle exec rake test:dblib |
| 24 | + |
| 25 | +# Run specific ActiveRecord tests using TEST_FILES_AR |
| 26 | +TEST_FILES_AR=test/cases/adapters/mysql2/schema_test.rb bundle exec rake test:dblib |
| 27 | + |
| 28 | +# Enable warnings during testing |
| 29 | +WARNING=1 bundle exec rake test:dblib |
| 30 | + |
| 31 | +# Run performance profiling |
| 32 | +bundle exec rake profile:dblib:[profile_case_name] |
| 33 | +``` |
| 34 | + |
| 35 | +### Code Quality |
| 36 | +```bash |
| 37 | +# Run Standard Ruby formatter/linter |
| 38 | +bundle exec standardrb |
| 39 | + |
| 40 | +# Run Standard with fix |
| 41 | +bundle exec standardrb --fix |
| 42 | + |
| 43 | +# Check only (no modifications) |
| 44 | +bundle exec standardrb --format progress |
| 45 | +``` |
| 46 | + |
| 47 | +## Code Style Guidelines |
| 48 | + |
| 49 | +### General Standards |
| 50 | +- **Ruby Version**: Target Ruby 3.2.0+ (uses frozen_string_literal: true) |
| 51 | +- **Code Style**: Uses Standard Ruby formatter |
| 52 | +- **Line Length**: 120 characters max |
| 53 | +- **String Literals**: Double quotes preferred (enforced by RuboCop) |
| 54 | +- **Encoding**: Always include `# frozen_string_literal: true` at top of files |
| 55 | + |
| 56 | +### Import/Require Organization |
| 57 | +```ruby |
| 58 | +# frozen_string_literal: true |
| 59 | + |
| 60 | +# External libraries first |
| 61 | +require "tiny_tds" |
| 62 | +require "base64" |
| 63 | +require "active_record" |
| 64 | + |
| 65 | +# Internal libraries next, grouped by functionality |
| 66 | +require "active_record/connection_adapters/sqlserver/version" |
| 67 | +require "active_record/connection_adapters/sqlserver/type" |
| 68 | +require "active_record/connection_adapters/sqlserver/database_limits" |
| 69 | +# ... etc |
| 70 | + |
| 71 | +# Local requires last |
| 72 | +require_relative "support/paths_sqlserver" |
| 73 | +``` |
| 74 | + |
| 75 | +### Naming Conventions |
| 76 | +- **Files**: snake_case with `_test_sqlserver.rb` suffix for test files |
| 77 | +- **Classes**: PascalCase, test classes end with `SQLServer` suffix |
| 78 | +- **Methods**: snake_case, use descriptive names |
| 79 | +- **Constants**: SCREAMING_SNAKE_CASE |
| 80 | +- **Modules**: PascalCase, logical grouping (e.g., `SQLServer::Type`) |
| 81 | + |
| 82 | +### Module Structure |
| 83 | +```ruby |
| 84 | +module ActiveRecord |
| 85 | + module ConnectionAdapters |
| 86 | + module SQLServer |
| 87 | + module Type |
| 88 | + class Boolean < ActiveRecord::Type::Boolean |
| 89 | + def sqlserver_type |
| 90 | + "bit" |
| 91 | + end |
| 92 | + end |
| 93 | + end |
| 94 | + end |
| 95 | + end |
| 96 | +end |
| 97 | +``` |
| 98 | + |
| 99 | +### Testing Patterns |
| 100 | +- **Test Files**: Follow pattern `*_test_sqlserver.rb` in `test/cases/` |
| 101 | +- **Test Classes**: Inherit from `ActiveRecord::TestCase` |
| 102 | +- **Fixtures**: Use `fixtures :table_name` when needed |
| 103 | +- **Let Blocks**: Use `let` for test setup data |
| 104 | +- **Assertions**: Use custom assertions from `ARTest::SQLServer::QueryAssertions` |
| 105 | + |
| 106 | +### Error Handling |
| 107 | +- Use SQL Server-specific error classes from `ActiveRecord::ConnectionAdapters::SQLServer::Errors` |
| 108 | +- Handle TinyTDS errors appropriately |
| 109 | +- Log database errors with context |
| 110 | + |
| 111 | +### Type System |
| 112 | +- All SQL Server types inherit from corresponding ActiveRecord types |
| 113 | +- Implement `sqlserver_type` method for database type mapping |
| 114 | +- Location: `lib/active_record/connection_adapters/sqlserver/type/` |
| 115 | + |
| 116 | +### Connection Management |
| 117 | +- Use `ActiveRecord::Base.lease_connection` for connection access |
| 118 | +- Handle connection pooling and timeout scenarios |
| 119 | +- Support both dblib modes |
| 120 | + |
| 121 | +### Schema Statements |
| 122 | +- Follow SQL Server-specific SQL syntax |
| 123 | +- Use proper identifier quoting with square brackets: `[table_name]` |
| 124 | +- Handle SQL Server's quirks around primary keys, indexes, and constraints |
| 125 | + |
| 126 | +## File Organization |
| 127 | + |
| 128 | +### Core Structure |
| 129 | +``` |
| 130 | +lib/ |
| 131 | +├── active_record/ |
| 132 | +│ └── connection_adapters/ |
| 133 | +│ └── sqlserver/ # Main adapter implementation |
| 134 | +│ ├── type/ # SQL Server-specific types |
| 135 | +│ └── core_ext/ # ActiveRecord extensions |
| 136 | +test/ |
| 137 | +├── cases/ # Test files (*_test_sqlserver.rb) |
| 138 | +├── support/ # Test utilities and helpers |
| 139 | +└── migrations/ # Test migrations |
| 140 | +``` |
| 141 | + |
| 142 | +### Module Dependencies |
| 143 | +- Core adapter: `lib/active_record/connection_adapters/sqlserver_adapter.rb` |
| 144 | +- Types: `lib/active_record/connection_adapters/sqlserver/type.rb` |
| 145 | +- Core extensions: `lib/active_record/connection_adapters/sqlserver/core_ext/` |
| 146 | + |
| 147 | +## Development Notes |
| 148 | + |
| 149 | +### Environment Variables |
| 150 | +- `ARCONN`: Set to "sqlserver" for testing |
| 151 | +- `ARCONFIG`: Path to database configuration file |
| 152 | +- `TEST_FILES`: Comma-separated test files to run |
| 153 | +- `TEST_FILES_AR`: ActiveRecord test files to run |
| 154 | +- `ONLY_SQLSERVER`: Run only SQL Server-specific tests |
| 155 | +- `ONLY_ACTIVERECORD`: Run only ActiveRecord tests |
| 156 | +- `WARNING`: Enable Ruby warnings during tests |
| 157 | + |
| 158 | +### Dependencies |
| 159 | +- **tiny_tds**: SQL Server connectivity (v3.0+) |
| 160 | +- **activerecord**: Rails ORM (v8.2.0.alpha) |
| 161 | +- **mocha**: Mocking framework for tests |
| 162 | +- **minitest**: Testing framework (v6.0+) |
| 163 | + |
| 164 | +### Database Configuration |
| 165 | +- Tests use configuration from `test/config.yml` |
| 166 | +- Supports SQL Server 2012 and upward |
| 167 | +- Requires proper SQL Server connection setup |
| 168 | + |
| 169 | +## Testing Best Practices |
| 170 | + |
| 171 | +### Running Single Tests |
| 172 | +```bash |
| 173 | +# Run a single test file |
| 174 | +bundle exec ruby -Ilib:test test/cases/adapter_test_sqlserver.rb |
| 175 | + |
| 176 | +# Run specific test method |
| 177 | +bundle exec ruby -Ilib:test test/cases/adapter_test_sqlserver.rb -n test_method_name |
| 178 | +``` |
| 179 | + |
| 180 | +### Test Environment Setup |
| 181 | +- All test helpers are in `test/support/` |
| 182 | +- Use `ARTest::SQLServer` module for test utilities |
| 183 | +- Schema loaded via `support/load_schema_sqlserver.rb` |
| 184 | + |
| 185 | +### Test Data |
| 186 | +- Use fixtures where appropriate |
| 187 | +- Let blocks for test-specific data setup |
| 188 | +- Clean database state between tests |
0 commit comments