Contributing to cyber-trackr-live โ
Thank you for your interest in contributing to cyber-trackr-live! This project provides an OpenAPI specification and Ruby client for the cyber.trackr.live API.
๐ Quick Start โ
# Fork and clone
git clone https://github.com/YOUR_USERNAME/cyber-trackr-live.git
cd cyber-trackr-live
# Install dependencies
bundle install # Ruby dependencies
npm install # Node dependencies (optional - for docs)
# Run tests
bundle exec rake test # Unit tests
bundle exec rake test:all # All tests including integration
๐ ๏ธ Development Setup โ
Prerequisites โ
- Ruby 3.2+ (check
.ruby-version
) - Node.js 22+ (check
.nvmrc
) - optional, only for OpenAPI docs - Docker (for client generation)
Environment Setup โ
# Using rbenv
rbenv install 3.3.0
rbenv local 3.3.0
# Using nvm (for docs development)
nvm install
nvm use
# Or using asdf
asdf install
๐ Development Workflows โ
Working on the OpenAPI Specification โ
The OpenAPI spec is the source of truth for the API documentation and client generation.
# 1. Edit the spec
vi openapi/openapi.yaml
# 2. Validate your changes
npm run docs:validate
# 3. Preview the docs
npm run docs:dev
# Opens at http://localhost:4000
# 4. Regenerate the Ruby client (if needed)
./scripts/generate_client.sh
# 5. Run tests to ensure compatibility
bundle exec rake test
OpenAPI Best Practices โ
- Use OpenAPI 3.1.1 features (proper null handling with
anyOf
) - Include examples for all schemas
- Add operation IDs for clean client generation
- Document all error responses
- Keep descriptions clear and concise
Ruby Client Development โ
Generated Code โ
The Ruby client in lib/cyber_trackr_client/
is generated from the OpenAPI spec. Do not edit these files directly.
To fix issues in generated code:
- Update the OpenAPI spec if the issue is in the API definition
- Use RuboCop cops in
lib/rubocop/cop/
for post-generation fixes - Add helper methods in
lib/cyber_trackr_helper/
Helper Development โ
# Work on helper methods
vi lib/cyber_trackr_helper.rb
# Run tests
bundle exec ruby test/cyber_trackr_helper_test.rb
# Test interactively
bundle exec irb -I lib -r cyber_trackr_helper
client = CyberTrackrHelper::Client.new
client.list_stigs
Testing โ
# OpenAPI validation (Node.js/Spectral)
npm run docs:validate
# Ruby testing
bundle exec rake test # Core gem tests (fast - default)
bundle exec rake test:all # All tests including live API
bundle exec rake test:stage2b # Live API integration only
# Run specific test file
bundle exec ruby test/cyber_trackr_helper_test.rb
Documentation Development โ
API Documentation (Scalar) โ
# Start local docs server
npm run docs:dev
# Build static docs
npm run docs:build
# Update Scalar configuration
vi scalar.config.json
Ruby Documentation (YARD) โ
# Generate YARD docs
bundle exec yard doc
# Preview at http://localhost:8808
bundle exec yard server
# Update documentation
vi lib/cyber_trackr_helper.rb # Add YARD comments
๐งช Testing Guidelines โ
Test Architecture โ
We use a two-tier testing approach with clear separation of concerns:
Test Structure โ
test/
โโโ cyber_trackr_helper_test.rb # Core gem functionality
โโโ live_api_validation_test.rb # Live API integration
Writing Tests โ
# Unit test example
class HelperTest < Minitest::Test
def test_list_stigs_filters_srgs
mock_documents_list # Use test helpers
stigs = @client.list_stigs
assert_equal 2, stigs.size
refute stigs.key?(:Application_Security_Requirements_Guide)
end
end
Mocking API Responses โ
Always use the test helpers from test/test_helper.rb
:
# Good - uses proper mock structure
mock_documents_list(sample_document_list)
# Bad - incomplete mock missing required fields
stub_request(:get, url).to_return(body: {}.to_json)
๐ Contribution Types โ
Bug Reports ๐ โ
Use GitHub Issues with:
- Clear reproduction steps
- Version information (Ruby, gem version)
- Error messages and stack traces
- Minimal code example
Feature Requests ๐ก โ
- Open an issue first to discuss
- Explain the use case
- Consider API compatibility
- Propose implementation approach
Pull Requests ๐ โ
- Fork and branch from
main
- Make focused changes - one feature/fix per PR
- Add tests for new functionality
- Update docs as needed
- Run all checks:bash
npm run docs:validate # OpenAPI validation bundle exec rake test # Ruby tests bundle exec rubocop # Code style
- Update changelogs:
CHANGELOG-GEM.md
for Ruby changesCHANGELOG-OPENAPI.md
for spec changes
- Version updates (maintainers only):
- Do NOT bump version in PRs
- Versions are bumped during release process
- If you modified
openapi/openapi.yaml
, regenerate client
๐ Cross-Platform Development โ
This gem supports multiple platforms and architectures:
Supported Platforms โ
- Linux: x86_64, aarch64 (ARM), musl (Alpine)
- macOS: Intel (x86_64), ARM (arm64)
- Windows: x64 (mingw-ucrt)
- Ruby: Generic Ruby platform
Adding Platform Support โ
When adding new dependencies that have native extensions, update Gemfile.lock
for all platforms:
# Add common platforms
bundle lock --add-platform x86_64-linux
bundle lock --add-platform x86_64-darwin
bundle lock --add-platform arm64-darwin-24
bundle lock --add-platform x64-mingw-ucrt
bundle lock --add-platform aarch64-linux
bundle lock --add-platform x86_64-linux-musl
bundle lock --add-platform ruby
# Verify all platforms are present
grep -A 10 "PLATFORMS" Gemfile.lock
CI/CD Testing Matrix โ
Our CI tests across multiple platforms and Ruby versions:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
ruby-version: ['3.2', '3.3', '3.4']
This ensures the gem works correctly across all supported environments.
Platform-Specific Issues โ
Common issues and solutions:
Bundle installation fails on CI:
# Error: "Your bundle only supports platforms ['arm64-darwin-24'] but your local platform is x86_64-linux"
# Solution: Add the missing platform to Gemfile.lock
bundle lock --add-platform x86_64-linux
Native extension compilation fails:
- Check if the gem has platform-specific versions
- Ensure all required platforms are in Gemfile.lock
- Update gem to a version that supports the target platform
HTTP Client Architecture โ
This project uses Faraday as the HTTP client for maximum compatibility:
# โ
Good - Uses Faraday (built into Ruby)
gem 'faraday', '~> 2.0'
gem 'faraday-multipart', '~> 1.0'
# โ Avoided - typhoeus (requires libcurl.dll on Windows)
# gem 'typhoeus'
Benefits of Faraday:
- No external dependencies - Pure Ruby using Net::HTTP
- Windows compatible - No libcurl.dll required
- Widely adopted - More stable and mature
- Consistent - Same HTTP client used in tests and generated client
OpenAPI Client Generation: The generated client uses Faraday via the --library=faraday
flag:
./scripts/generate_client.sh # Automatically uses Faraday
๐ฆ CI/CD Pipeline โ
All PRs must pass:
- Unit Tests - Ruby tests must pass on Linux, macOS, and Windows
- Linting - RuboCop with no violations
- OpenAPI Validation - Spec must be valid
- Security Checks - No vulnerable dependencies
- Documentation - Must build successfully
๐ฆ Release Process โ
Maintainers handle releases:
Version Bump
- Use rake tasks to bump version:
bundle exec rake version:major
- For breaking changes (2.0.0)bundle exec rake version:minor
- For new features (1.1.0)bundle exec rake version:patch
- For bug fixes (1.0.1)
- Regenerate client:
make generate
- This updates
lib/cyber_trackr_client/version.rb
automatically - Commit all changes together
- Use rake tasks to bump version:
Update Changelogs
- Add entries to
CHANGELOG-GEM.md
for Ruby/gem changes - Add entries to
CHANGELOG-OPENAPI.md
for API spec changes - Follow Keep a Changelog format
- Add entries to
Create Release
- Run:
bundle exec rake prepare_release
- This checks version consistency and creates a tag
- Push the tag:
git push origin v{version}
- GitHub Actions automatically:
- Publishes gem to RubyGems.org
- Deploys docs to GitHub Pages
- Creates GitHub release
- Run:
Version Management โ
IMPORTANT: The version in openapi/openapi.yaml
is the single source of truth.
# openapi/openapi.yaml
info:
version: 1.0.0 # Update this version
Never manually edit lib/cyber_trackr_client/version.rb
- it's generated!
๐ Security โ
- Never commit credentials or tokens
- Report security issues to saf-security@mitre.org
- Run
bundle audit
before submitting PRs - Be cautious with user input handling
๐ Resources โ
๐ค Code of Conduct โ
Please follow our Code of Conduct in all interactions.
๐ License โ
By contributing, you agree that your contributions will be licensed under the Apache-2.0 license.