Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
96 lines
4.5 KiB
Markdown
96 lines
4.5 KiB
Markdown
---
|
|
phase: 07-custom-rules-and-print-config
|
|
plan: "02"
|
|
subsystem: config, cmd/netsynth
|
|
tags: [config, cli, print-config, rules, wiring, CFG-06, RULE-02]
|
|
dependency_graph:
|
|
requires: [LoadResult, UserRules, AutoClasses, PrintConfig]
|
|
provides: [--print-config flag, runPrintConfig, user-rule-prepend, PrintConfig-output]
|
|
affects: [cmd/netsynth/main.go, config/config.go]
|
|
tech_stack:
|
|
added: ["sort", "time", "strings.Builder"]
|
|
patterns: [LoadResult-propagation, user-rule-prepend, annotated-TOML-output]
|
|
key_files:
|
|
created: []
|
|
modified:
|
|
- cmd/netsynth/main.go
|
|
- cmd/netsynth/main_test.go
|
|
- config/config.go
|
|
- config/config_test.go
|
|
decisions:
|
|
- "--print-config check placed after --list-interfaces but before interface-required validation so it works without -i"
|
|
- "AutoClasses map added to LoadResult to track which classes were auto-assigned by FNV-32a"
|
|
- "PrintConfig returns a string (not writes to io.Writer) for testability; caller prints to stdout"
|
|
- "waveformString returns custom for WaveformCustom (zero value used by hand-tuned built-in classes)"
|
|
- "classAnnotation: built-in classes compared on both BaseHz and WaveformType for override detection"
|
|
metrics:
|
|
duration: 8min
|
|
completed: "2026-03-26T20:55:00Z"
|
|
tasks_completed: 2
|
|
files_modified: 4
|
|
---
|
|
|
|
# Phase 7 Plan 02: CLI Wiring and PrintConfig Output Summary
|
|
|
|
Wire the LoadResult into main.go (user rules prepend, --print-config flag), implement the PrintConfig output function in the config package, and add comprehensive tests for both. Completes RULE-02 and CFG-06 — the final plan for Phase 7 and the v1.1 milestone.
|
|
|
|
## What Was Built
|
|
|
|
**cmd/netsynth/main.go:**
|
|
- Added `printConfig bool` var and `--print-config` flag registration
|
|
- `runPrintConfig()`: calls `config.Load(configPath)` then `config.PrintConfig(result)`, prints to stdout, exits clean
|
|
- --print-config check fires before interface-required validation (no -i needed)
|
|
- `runLiveMode` and `runPcapMode` now accept `config.LoadResult` instead of bare `map[TrafficClass]FreqConfig`
|
|
- User rules prepend in both modes: `append(result.UserRules, classify.DefaultRules...)` (RULE-02)
|
|
- Removed unused `synth` import
|
|
|
|
**config/config.go:**
|
|
- `LoadResult` gains `AutoClasses map[classify.TrafficClass]bool` field
|
|
- `addAutoFreqEntries` updated to accept and populate `autoClasses` map
|
|
- `Load()` initializes `AutoClasses` map and returns it in `LoadResult`
|
|
- `PrintConfig(result LoadResult) string`: generates commented TOML output with:
|
|
- Header: `# NetSynth effective configuration`, `# Config source: <path or "none (using defaults)">`, `# Generated: <UTC timestamp>`
|
|
- `[[rules]]` section for each user rule (port omitted when DstPort==0)
|
|
- `[sounds.*]` section for all classes in deterministic order (14 built-ins in AllClasses() order, then user-defined sorted alphabetically)
|
|
- Per-class annotation: `(default)`, `(override)`, or `(auto-assigned)`
|
|
- `waveformString()`: converts WaveformType to TOML string
|
|
- `classAnnotation()`: determines annotation based on AutoClasses membership and comparison with defaults
|
|
|
|
## Tasks Completed
|
|
|
|
| Task | Name | Commit | Files |
|
|
|------|------|--------|-------|
|
|
| 1 | Wire LoadResult into main.go and add --print-config flag | d43914f | cmd/netsynth/main.go, cmd/netsynth/main_test.go |
|
|
| 2 | Implement PrintConfig output function with comment annotations | b52e36b | config/config.go, config/config_test.go |
|
|
|
|
## Deviations from Plan
|
|
|
|
None - plan executed exactly as written.
|
|
|
|
## Test Coverage
|
|
|
|
New tests added (8 PrintConfig tests in config_test.go, 3 print-config tests in main_test.go):
|
|
|
|
**config/config_test.go:**
|
|
- `TestPrintConfigContainsAllClasses` - all 14 class names in output
|
|
- `TestPrintConfigSourcePath` - `# Config source: <path>` in header
|
|
- `TestPrintConfigNoSourcePath` - `# Config source: none` when no config
|
|
- `TestPrintConfigContainsRules` - `[[rules]]` section with port/protocol/class
|
|
- `TestPrintConfigRuleNoPort` - port line omitted when DstPort==0
|
|
- `TestPrintConfigDefaultAnnotation` - `(default)` for unmodified built-in class
|
|
- `TestPrintConfigOverrideAnnotation` - `(override)` for modified built-in class
|
|
- `TestPrintConfigAutoAssignedAnnotation` - `(auto-assigned)` for FNV-hash assigned class
|
|
|
|
**cmd/netsynth/main_test.go:**
|
|
- `TestPrintConfigFlagRegistered` - flag exists on command
|
|
- `TestPrintConfigNoInterface` - --print-config works without -i
|
|
- `TestPrintConfigWithConfigFile` - --print-config with --config succeeds
|
|
|
|
Full suite: `go test ./... -count=1` all 7 packages pass.
|
|
|
|
## Known Stubs
|
|
|
|
None. All functionality is fully implemented and wired.
|
|
|
|
## Self-Check: PASSED
|