|
| 1 | +--- |
| 2 | +name: netgraph-dev-workflow |
| 3 | +description: > |
| 4 | + NetGraph development workflow and CLI reference. Use when: setting up dev environment, |
| 5 | + running tests or lint, fixing CI failures, using the ngraph CLI (inspect, run commands), |
| 6 | + troubleshooting venv issues, or asking about make targets. |
| 7 | +--- |
| 8 | + |
| 9 | +# NetGraph Development Workflow |
| 10 | + |
| 11 | +## Command Discovery |
| 12 | + |
| 13 | +Run `make help` to see all available targets with descriptions. The Makefile is the authoritative source. |
| 14 | + |
| 15 | +## Initial Setup |
| 16 | + |
| 17 | +```bash |
| 18 | +make dev # Creates venv, installs package + dev deps, sets up pre-commit hooks |
| 19 | +``` |
| 20 | + |
| 21 | +Requires Python 3.11+. The setup auto-detects the best available Python version. |
| 22 | + |
| 23 | +## Workflow Patterns |
| 24 | + |
| 25 | +### Iterating on Code |
| 26 | + |
| 27 | +| Scenario | Command | Notes | |
| 28 | +|----------|---------|-------| |
| 29 | +| Quick feedback loop | `make qt` | Fast: skips slow tests, no coverage | |
| 30 | +| Before committing | `make check` | **Mandatory.** Runs pre-commit + tests + lint | |
| 31 | +| Full test suite | `make test` | Includes slow tests, generates coverage | |
| 32 | +| After changing APIs | `make docs` | **Mandatory.** Regenerates API documentation | |
| 33 | + |
| 34 | +### When to Run `make docs` |
| 35 | + |
| 36 | +Run `make docs` when modifying: |
| 37 | +- Public function/class signatures |
| 38 | +- Docstrings |
| 39 | +- Module-level documentation |
| 40 | +- Adding new public modules |
| 41 | + |
| 42 | +The generated `docs/reference/api-full.md` should be committed with your changes. |
| 43 | + |
| 44 | +### Fixing Lint Failures |
| 45 | + |
| 46 | +When `make lint` fails: |
| 47 | + |
| 48 | +1. Run `make format` first (auto-fixes formatting issues) |
| 49 | +2. Run `make lint` again to check remaining issues |
| 50 | +3. Fix any type errors or code quality issues manually |
| 51 | + |
| 52 | +### Pre-commit vs CI |
| 53 | + |
| 54 | +| Command | Behavior | Use case | |
| 55 | +|---------|----------|----------| |
| 56 | +| `make check` | Auto-fixes via pre-commit, then tests + lint | Local development | |
| 57 | +| `make check-ci` | Read-only lint + validate + test (no mutations) | CI pipelines | |
| 58 | + |
| 59 | +### Validating Scenarios |
| 60 | + |
| 61 | +```bash |
| 62 | +make validate # Validates all YAML files in scenarios/ and tests/integration/ |
| 63 | +``` |
| 64 | + |
| 65 | +## CLI Reference |
| 66 | + |
| 67 | +The `ngraph` CLI runs and inspects network scenarios. Use `ngraph --help` or `ngraph <command> --help` for full option details. |
| 68 | + |
| 69 | +### Commands |
| 70 | + |
| 71 | +| Command | Purpose | |
| 72 | +|---------|---------| |
| 73 | +| `ngraph inspect <scenario.yaml>` | Validate scenario and show structure summary | |
| 74 | +| `ngraph run <scenario.yaml>` | Execute workflow steps and export results | |
| 75 | + |
| 76 | +### Common Usage Patterns |
| 77 | + |
| 78 | +**Validate before running:** |
| 79 | + |
| 80 | +```bash |
| 81 | +./venv/bin/ngraph inspect scenario.yaml |
| 82 | +./venv/bin/ngraph run scenario.yaml |
| 83 | +``` |
| 84 | + |
| 85 | +**Detailed inspection (node/link tables, step parameters):** |
| 86 | + |
| 87 | +```bash |
| 88 | +./venv/bin/ngraph inspect --detail scenario.yaml |
| 89 | +``` |
| 90 | + |
| 91 | +**Run with profiling (CPU analysis, bottleneck detection):** |
| 92 | + |
| 93 | +```bash |
| 94 | +./venv/bin/ngraph run --profile scenario.yaml |
| 95 | +./venv/bin/ngraph run --profile --profile-memory scenario.yaml # Include memory tracking |
| 96 | +``` |
| 97 | + |
| 98 | +**Control output:** |
| 99 | + |
| 100 | +```bash |
| 101 | +./venv/bin/ngraph run scenario.yaml # Default: writes <scenario>.results.json |
| 102 | +./venv/bin/ngraph run scenario.yaml --results out.json # Custom results path |
| 103 | +./venv/bin/ngraph run scenario.yaml --output ./results/ # All artifacts to directory |
| 104 | +./venv/bin/ngraph run scenario.yaml --no-results --stdout # Print to stdout only |
| 105 | +./venv/bin/ngraph run scenario.yaml --keys msd placement # Filter to specific workflow steps |
| 106 | +``` |
| 107 | + |
| 108 | +**Debug logging:** |
| 109 | + |
| 110 | +```bash |
| 111 | +./venv/bin/ngraph -v inspect scenario.yaml # Verbose (debug level) |
| 112 | +./venv/bin/ngraph --quiet run scenario.yaml # Suppress info, show warnings only |
| 113 | +``` |
| 114 | + |
| 115 | +### Key Options |
| 116 | + |
| 117 | +**Global:** |
| 118 | +- `-v, --verbose` - Enable debug logging |
| 119 | +- `--quiet` - Suppress console output (warnings only) |
| 120 | + |
| 121 | +**inspect:** |
| 122 | +- `-d, --detail` - Show complete node/link tables and step parameters |
| 123 | +- `-o, --output DIR` - Output directory for artifacts |
| 124 | + |
| 125 | +**run:** |
| 126 | +- `-r, --results FILE` - Custom results JSON path |
| 127 | +- `--no-results` - Skip writing results file |
| 128 | +- `--stdout` - Print results to stdout |
| 129 | +- `-k, --keys STEP [STEP...]` - Filter output to specific workflow step names |
| 130 | +- `--profile` - Enable CPU profiling with analysis |
| 131 | +- `--profile-memory` - Add memory tracking (requires `--profile`) |
| 132 | +- `-o, --output DIR` - Output directory for results and profiles |
| 133 | + |
| 134 | +### Output Interpretation |
| 135 | + |
| 136 | +**inspect output sections:** |
| 137 | +1. **OVERVIEW** - Quick metrics: nodes, links, capacity, demand, utilization |
| 138 | +2. **NETWORK STRUCTURE** - Hierarchy tree, capacity statistics, validation warnings |
| 139 | +3. **RISK GROUPS** - Failure correlation groups defined |
| 140 | +4. **COMPONENTS LIBRARY** - Hardware definitions for cost/power modeling |
| 141 | +5. **FAILURE POLICIES** - Failure simulation rules and modes |
| 142 | +6. **DEMAND SETS** - Traffic demands with pattern matching summary |
| 143 | +7. **WORKFLOW STEPS** - Execution plan with node selection preview |
| 144 | + |
| 145 | +**run output:** |
| 146 | +- Results JSON contains `steps.<step_name>.data` for each workflow step |
| 147 | +- With `--profile`: performance report shows timing breakdown and bottlenecks |
| 148 | + |
| 149 | +## Running Commands |
| 150 | + |
| 151 | +### Prefer Direct Venv Paths |
| 152 | + |
| 153 | +Use direct paths instead of `source venv/bin/activate`: |
| 154 | + |
| 155 | +```bash |
| 156 | +./venv/bin/python -m pytest tests/dsl/ # Run specific tests |
| 157 | +./venv/bin/ngraph inspect scenario.yaml # Validate a scenario |
| 158 | +./venv/bin/ngraph run scenario.yaml # Execute a scenario |
| 159 | +``` |
| 160 | + |
| 161 | +This avoids shell state issues that agents may not maintain between commands. |
| 162 | + |
| 163 | +### Make Targets (Alternative) |
| 164 | + |
| 165 | +Make targets auto-detect the venv and work without activation: |
| 166 | + |
| 167 | +```bash |
| 168 | +make qt # Quick tests |
| 169 | +make lint # Linting checks |
| 170 | +``` |
| 171 | + |
| 172 | +## Troubleshooting |
| 173 | + |
| 174 | +### Venv Missing or Broken |
| 175 | + |
| 176 | +**Symptom**: Commands fail with "No module named..." or venv/bin/python not found |
| 177 | + |
| 178 | +**Fix**: |
| 179 | + |
| 180 | +```bash |
| 181 | +make dev # Recreates venv if missing, installs all deps |
| 182 | +``` |
| 183 | + |
| 184 | +Or to fully reset: |
| 185 | + |
| 186 | +```bash |
| 187 | +make clean-venv && make dev |
| 188 | +``` |
| 189 | + |
| 190 | +### Python Version Mismatch |
| 191 | + |
| 192 | +**Symptom**: `make dev` warns about venv Python version != best available |
| 193 | + |
| 194 | +**Fix**: Recreate venv with latest Python: |
| 195 | + |
| 196 | +```bash |
| 197 | +make clean-venv && make dev |
| 198 | +``` |
| 199 | + |
| 200 | +### Import Errors After Pulling Changes |
| 201 | + |
| 202 | +**Symptom**: New imports fail after git pull |
| 203 | + |
| 204 | +**Fix**: Reinstall the package: |
| 205 | + |
| 206 | +```bash |
| 207 | +./venv/bin/pip install -e '.[dev]' |
| 208 | +``` |
| 209 | + |
| 210 | +Or run `make dev` which handles this. |
| 211 | + |
| 212 | +### Pre-commit Hook Failures |
| 213 | + |
| 214 | +**Symptom**: Commit blocked by pre-commit hooks |
| 215 | + |
| 216 | +**Fix**: |
| 217 | + |
| 218 | +1. Run `make format` to auto-fix formatting |
| 219 | +2. Run `make check` to see remaining issues |
| 220 | +3. Fix manually and commit again |
| 221 | + |
| 222 | +### Tests Pass Locally but Fail in CI |
| 223 | + |
| 224 | +**Symptom**: `make qt` passes but CI fails |
| 225 | + |
| 226 | +**Cause**: `make qt` skips slow tests; CI runs full suite |
| 227 | + |
| 228 | +**Fix**: Run `make test` locally to match CI behavior. |
0 commit comments