|
| 1 | +# GitHub Copilot Instructions for Faraday |
| 2 | + |
| 3 | +## Essential Reading |
| 4 | +**Before making any code suggestions**, consult `.ai/guidelines.md` for comprehensive Faraday-specific conventions and patterns. |
| 5 | + |
| 6 | +## About This Repository |
| 7 | +Faraday is a Ruby HTTP client library that provides: |
| 8 | +- A middleware-based architecture (similar to Rack) |
| 9 | +- A common interface over various HTTP adapters (Net::HTTP, HTTPClient, etc.) |
| 10 | +- Extensible request/response processing pipeline |
| 11 | + |
| 12 | +## Your Responsibilities |
| 13 | +As GitHub Copilot working on Faraday, you must: |
| 14 | + |
| 15 | +1. **Read & Follow**: Always reference `.ai/guidelines.md` for Faraday conventions |
| 16 | +2. **Stay Current**: Suggest updates to `.ai/guidelines.md` when you notice: |
| 17 | + - New patterns not yet documented |
| 18 | + - Changes to existing conventions |
| 19 | + - Discrepancies between guidelines and actual code |
| 20 | +3. **Focus on Faraday**: Provide Faraday-specific guidance, not generic Ruby/RSpec tips |
| 21 | + |
| 22 | +## Core Architecture Patterns |
| 23 | + |
| 24 | +### Middleware System |
| 25 | +All middleware must: |
| 26 | +- Inherit from `Faraday::Middleware` |
| 27 | +- Define `DEFAULT_OPTIONS` constant if configurable |
| 28 | +- Implement only required hooks: `on_request`, `on_complete`, or `on_error` |
| 29 | +- Register with a unique key via `Faraday::Middleware.register_middleware` |
| 30 | +- Remain stateless (store state in `env` hash only) |
| 31 | + |
| 32 | +Example structure: |
| 33 | +```ruby |
| 34 | +module Faraday |
| 35 | + class Request |
| 36 | + class MyMiddleware < Middleware |
| 37 | + DEFAULT_OPTIONS = { option: 'value' }.freeze |
| 38 | + |
| 39 | + def on_request(env) |
| 40 | + # Modify request |
| 41 | + end |
| 42 | + end |
| 43 | + end |
| 44 | +end |
| 45 | + |
| 46 | +Faraday::Request.register_middleware(my_middleware: Faraday::Request::MyMiddleware) |
| 47 | +``` |
| 48 | + |
| 49 | +### Adapter System |
| 50 | +All adapters must: |
| 51 | +- Extend `Faraday::MiddlewareRegistry` |
| 52 | +- Implement `call(env)` method |
| 53 | +- Implement `build_connection(env)` for connection setup |
| 54 | +- Implement `close` for cleanup |
| 55 | +- Be placed in `lib/faraday/adapter/` |
| 56 | +- Register via `Faraday::Adapter.register_middleware` |
| 57 | + |
| 58 | +For parallel support: |
| 59 | +- Include `Parallelism` module |
| 60 | +- Set `supports_parallel = true` |
| 61 | + |
| 62 | +### Testing Conventions |
| 63 | +- Use RSpec for all tests |
| 64 | +- Leverage shared examples for adapters and middleware (see `spec/support`) |
| 65 | +- Mock HTTP calls; never make real network requests |
| 66 | +- Follow test organization: `spec/faraday/` mirrors `lib/faraday/` |
| 67 | +- Test middleware: use doubles for `app` and verify hook invocations |
| 68 | + |
| 69 | +### Documentation Standards |
| 70 | +- Add YARD comments to all public APIs |
| 71 | +- Update `docs/` for user-facing features |
| 72 | +- Keep README.md and CHANGELOG.md current |
| 73 | +- Document new middleware/adapters in `docs/` folder |
| 74 | + |
| 75 | +## Project Structure |
| 76 | +``` |
| 77 | +lib/faraday/ |
| 78 | +├── adapter/ # HTTP backend adapters |
| 79 | +│ └── test.rb # Test adapter (example) |
| 80 | +├── request/ # Request middleware |
| 81 | +│ ├── json.rb # JSON encoding (example) |
| 82 | +│ └── authorization.rb |
| 83 | +├── response/ # Response middleware |
| 84 | +├── middleware.rb # Base middleware class |
| 85 | +└── adapter.rb # Base adapter class |
| 86 | +
|
| 87 | +spec/faraday/ |
| 88 | +└── (mirrors lib structure) |
| 89 | +``` |
| 90 | + |
| 91 | +## Code Quality Requirements |
| 92 | +- Follow RuboCop style guide (`.rubocop.yml`) |
| 93 | +- Ensure all code passes: `bundle exec rubocop` |
| 94 | +- All features need tests: `bundle exec rspec` |
| 95 | +- Use inclusive language (see `.github/CONTRIBUTING.md`) |
| 96 | + |
| 97 | +## Contribution Process |
| 98 | +1. Check `.github/CONTRIBUTING.md` for workflow |
| 99 | +2. New features require tests and documentation |
| 100 | +3. Adapters/middleware should be separate gems (link from this project) |
| 101 | +4. Follow semantic versioning for breaking changes |
| 102 | + |
| 103 | +## Self-Maintaining Guidelines |
| 104 | +You are responsible for keeping `.ai/guidelines.md` accurate and current. When you identify: |
| 105 | +- Code patterns not reflected in guidelines |
| 106 | +- Convention changes |
| 107 | +- Better practices |
| 108 | + |
| 109 | +Propose updates to `.ai/guidelines.md` to maintain alignment with the actual codebase. |
| 110 | + |
| 111 | +## Reference Files |
| 112 | +- **Complete Guidelines**: `.ai/guidelines.md` (PRIMARY REFERENCE) |
| 113 | +- **Contribution Guide**: `.github/CONTRIBUTING.md` |
| 114 | +- **Middleware Base**: `lib/faraday/middleware.rb` |
| 115 | +- **Middleware Example**: `lib/faraday/request/json.rb` |
| 116 | +- **Adapter Example**: `lib/faraday/adapter/test.rb` |
| 117 | +- **Style Guide**: `.rubocop.yml` |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +**Remember**: The guidelines in `.ai/guidelines.md` are the source of truth for Faraday conventions. Keep them current and refer to them consistently. |
0 commit comments