|
| 1 | +# Agent Guidelines |
| 2 | + |
| 3 | +This file provides guidelines for agentic coding agents operating in this repository. |
| 4 | + |
| 5 | +## Quick Reference |
| 6 | + |
| 7 | +### Running Tests |
| 8 | + |
| 9 | +```bash |
| 10 | +# Run all tests (Go + shell scripts + linting) |
| 11 | +make |
| 12 | + |
| 13 | +# Run only Go tests |
| 14 | +make test-go |
| 15 | + |
| 16 | +# Run Go tests with verbose output |
| 17 | +go test -v ./... |
| 18 | + |
| 19 | +# Run a single Go test by name |
| 20 | +go test -v -run TestName ./... |
| 21 | + |
| 22 | +# Run only shell script tests (requires Docker) |
| 23 | +make unit-tests |
| 24 | + |
| 25 | +# Run specific linter |
| 26 | +make test-github # GitHub workflow/action validation |
| 27 | +make test-json # JSON validation |
| 28 | +make test-markdown # Markdown linting |
| 29 | +make test-openapi # OpenAPI spec validation |
| 30 | +make test-shellcheck # Shell script linting |
| 31 | +``` |
| 32 | + |
| 33 | +## Code Style Guidelines |
| 34 | + |
| 35 | +### General |
| 36 | + |
| 37 | +Read `.editorconfig` for formatting rules. |
| 38 | + |
| 39 | +### Go |
| 40 | + |
| 41 | +Use idiomatic go: |
| 42 | + |
| 43 | +- **Testing**: Uses `github.com/stretchr/testify/assert` for assertions |
| 44 | +- **Error handling**: Wrap errors with `errors.Join()` for multiple errors, use sentinel errors defined at package level |
| 45 | +- **JSON**: Use struct tags for serialization (e.g., `json:"euro"`) |
| 46 | +- **Formatting**: Run `go fmt` before committing; `go mod tidy` for dependencies |
| 47 | + |
| 48 | +### Shell Scripts |
| 49 | + |
| 50 | +- Use POSIX-compliant `sh` (not bash) |
| 51 | +- Always use `set -e` for error handling |
| 52 | +- Check required tools with `which` before use |
| 53 | +- Exit codes: 1 = file error, 2 = directory error, 3 = validation error |
| 54 | +- Quote variables: `"$VAR"` not `$VAR` |
| 55 | + |
| 56 | +Example pattern for validation: |
| 57 | + |
| 58 | +```sh |
| 59 | +set -e |
| 60 | + |
| 61 | +FILE=$1 |
| 62 | +[ -f "$FILE" ] || { echo "Not a file: $FILE"; exit 1; } |
| 63 | +``` |
| 64 | + |
| 65 | +## GitHub Workflows |
| 66 | + |
| 67 | +This repository relies on GitHub Actions for CI/CD and data updates. |
| 68 | +Workflows are located in `.github/workflows/`. |
| 69 | + |
| 70 | +### Essential Workflows |
| 71 | + |
| 72 | +| Workflow | Purpose | |
| 73 | +| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | |
| 74 | +| `merge-test.yaml` | Runs `make` on all PRs to main. Auto-merges dependabot and automation bot PRs. | |
| 75 | +| `health-checks.yaml` | Scheduled daily health checks. Calls `health-check-grid.yaml`, `health-check-networks.yaml`, and `health-check-integrity.yaml`. | |
| 76 | +| `health-check-grid.yaml` | Validates grid configuration data | |
| 77 | +| `health-check-networks.yaml` | Validates network configuration data | |
| 78 | +| `health-check-integrity.yaml` | Validates data integrity across datasets | |
| 79 | +| `pull-data.yaml` | Fetches energy price data from Energi Data Service API | |
| 80 | +| `pull-tariff-data.yaml` | Fetches tariff data from Energinet | |
| 81 | +| `update-visualization.yaml` | Updates static visualization files | |
| 82 | +| `update-api-constants.yaml` | Updates API constant definitions | |
| 83 | +| `upgrade-go.yaml` | Automated Go version upgrades | |
| 84 | + |
| 85 | +### Workflow Patterns |
| 86 | + |
| 87 | +- Workflows use `on.schedule` for periodic tasks |
| 88 | +- Most workflows support `workflow_dispatch` for manual runs |
| 89 | +- Health check workflows publish results to `gh-pages` branch |
| 90 | + |
| 91 | +## Docker |
| 92 | + |
| 93 | +Docker and Docker Compose are required for running tests and development: |
| 94 | + |
| 95 | +```bash |
| 96 | +# Install dependencies and run all tests |
| 97 | +make deps |
| 98 | +make |
| 99 | + |
| 100 | +# Run a shell in the runner container |
| 101 | +make shell |
| 102 | +``` |
| 103 | + |
| 104 | +The `compose.yml` defines services for: |
| 105 | + |
| 106 | +- `runner` - Main container for running scripts and tests |
| 107 | +- `builder` - For build operations |
| 108 | +- `swagger` - Local OpenAPI documentation |
| 109 | + |
| 110 | +## Maintenance |
| 111 | + |
| 112 | +When modifying this repository: |
| 113 | + |
| 114 | +1. **Adding new tests**: Add Go tests in `*_test.go` files. Add shell tests in `test/*.sh` and call them from the main Makefile target. |
| 115 | + |
| 116 | +2. **Adding new workflows**: Place in `.github/workflows/` and validate with `make test-github`. |
| 117 | + |
| 118 | +3. **Updating AGENTS.md**: If you add new commands, change code style, or add new workflows, update this file to reflect those changes. Run `make` to ensure all tests pass. |
| 119 | + |
| 120 | +4. **Dependencies**: Use `go mod tidy` for Go dependencies. Shell scripts should use tools available in the runner container (check `compose.yml` for the base image). |
| 121 | + |
| 122 | +## Project Structure |
| 123 | + |
| 124 | +``` |
| 125 | +├── .github/ |
| 126 | +│ ├── workflows/ # GitHub Actions workflows |
| 127 | +│ └── actions/ # Reusable GitHub Actions |
| 128 | +├── build/ # Generated build artifacts (gitignored) |
| 129 | +├── configuration/ # JSON configuration files |
| 130 | +├── resources/ # OpenAPI spec and static HTML |
| 131 | +├── src/ # Shell scripts for data operations |
| 132 | +├── test/ # Shell script tests |
| 133 | +├── test/fixtures/ # Shell test fixtures |
| 134 | +├── testdata/ # Go test fixtures (raw API responses) |
| 135 | +└── Makefile # Build automation |
| 136 | +``` |
0 commit comments