Files
nofx/.github/workflows/pr-go-test-coverage.yml
WquGuru c8314cb89b test(trader): add comprehensive unit tests and CI coverage reporting (#823)
* chore(config): add Python and uv support to project

- Add comprehensive Python .gitignore rules (pycache, venv, pytest, etc.)
- Add uv package manager specific ignores (.uv/, uv.lock)
- Initialize pyproject.toml for Python tooling

Co-authored-by: Claude <noreply@anthropic.com>

* chore(deps): add testing dependencies

- Add github.com/stretchr/testify v1.11.1 for test assertions
- Add github.com/agiledragon/gomonkey/v2 v2.13.0 for mocking
- Promote github.com/rs/zerolog to direct dependency

Co-authored-by: Claude <noreply@anthropic.com>

* ci(workflow): add PR test coverage reporting

Add GitHub Actions workflow to run unit tests and report coverage on PRs:
- Run Go tests with race detection and coverage profiling
- Calculate coverage statistics and generate detailed reports
- Post coverage results as PR comments with visual indicators
- Fix Go version to 1.23 (was incorrectly set to 1.25.0)

Coverage guidelines:
- Green (>=80%): excellent
- Yellow (>=60%): good
- Orange (>=40%): fair
- Red (<40%): needs improvement

This workflow is advisory only and does not block PR merging.

Co-authored-by: Claude <noreply@anthropic.com>

* test(trader): add comprehensive unit tests for trader modules

Add unit test suites for multiple trader implementations:
- aster_trader_test.go: AsterTrader functionality tests
- auto_trader_test.go: AutoTrader lifecycle and operations tests
- binance_futures_test.go: Binance futures trader tests
- hyperliquid_trader_test.go: Hyperliquid trader tests
- trader_test_suite.go: Common test suite utilities and helpers

Also fix minor formatting issue in auto_trader.go (trailing whitespace)

Co-authored-by: Claude <noreply@anthropic.com>

* test(trader): preserve existing calculatePnLPercentage unit tests

Merge existing calculatePnLPercentage tests with incoming comprehensive test suite:
- Preserve TestCalculatePnLPercentage with 9 test cases covering edge cases
- Preserve TestCalculatePnLPercentage_RealWorldScenarios with 3 trading scenarios
- Add math package import for floating-point precision comparison
- All tests validate PnL percentage calculation with different leverage scenarios

Co-authored-by: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-09 17:43:28 +08:00

79 lines
2.1 KiB
YAML

name: Go Test Coverage
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- dev
- main
push:
branches:
- dev
- main
permissions:
contents: read
pull-requests: write
jobs:
test-coverage:
name: Go Unit Tests & Coverage
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r .github/workflows/scripts/requirements.txt
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Run tests with coverage
run: |
go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
- name: Calculate coverage and generate report
id: coverage
run: |
chmod +x .github/workflows/scripts/calculate_coverage.py
python .github/workflows/scripts/calculate_coverage.py coverage.out coverage_report.md
- name: Comment PR with coverage
if: github.event_name == 'pull_request'
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
chmod +x .github/workflows/scripts/comment_pr.py
python .github/workflows/scripts/comment_pr.py \
${{ github.event.pull_request.number }} \
"${{ steps.coverage.outputs.coverage }}" \
"${{ steps.coverage.outputs.emoji }}" \
"${{ steps.coverage.outputs.status }}" \
"${{ steps.coverage.outputs.badge_color }}" \
coverage_report.md