Repository navigation
test: enforce router-axi agent rules with automated checks - #56
Merged
Merged
Conversation
Replace private addresses in tests, add event-log to the shipped skill, derive the help and factory-failure sweeps from commandFlags, and add checks for the SOAP mutation allowlist, fixture address privacy, a loopback-only test network guard and command-surface documentation drift.
…st with fixture-server tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
internal/tr064/actions.go.postOnce,actionOnService,ConfigExportandEventLognow callcheckActionbefore they send a SOAP request. Read actions (Get,X_Get,X_AVM-DE_Getand similar) and the five approved mutations (SetEnable,Reboot,ForceTermination, Wake-on-LAN, firmware check) pass. Any other action returns aninternalerror and sends nothing.internal/nettest. Each test package (cmd/router-axi,internal/app,internal/tr064) calls it fromTestMain. It replaceshttp.DefaultTransportwith one that dials loopback only and ignores proxies. Live tests usenettest.LiveClientto reach a router. The branch also adds tests for the allowlist, the guard and a fixture privacy check, and updates existing tests.internal/skill/SKILL.md. The skill description and command list now includeevent-log, and thestatusentry is reworded.skill_test.gonow checks the skill text against the command surface.README.mdaddsrouter-axi session dashboardto its examples.Risk Assessment
✅ Low: The change is limited to test guards, documentation fixes and a fail-closed SOAP action allowlist. All four SOAP send sites now call checkAction (actionOnService, postOnce, ConfigExport, EventLog). Every action in production code passes the allowlist, the network guard has no bypass through a pre-cloned transport, and both fixes from round 2 match their findings.
Testing
Only Go test-runner and fixture-server tests ran. They are not live product runs. No scenario was driven against a running product or a real router.
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
internal/nettest/nettest.go:22- nettest.Main clones http.DefaultTransport and keeps its Proxy field (http.ProxyFromEnvironment). With HTTP_PROXY/HTTPS_PROXY set to a loopback proxy, a request to http://fritz.box:49000 makes the transport dial the proxy (for example 127.0.0.1:3128). dialLoopback accepts that dial, and the proxy then forwards the request to the real router. So the guard does not stop the network access it exists to stop (candidate 4: 'refuses any dial to a non-loopback address, so an ordinary test can never reach the real router'). In that environment AssertGuarded also fails, because the proxy returns a response or a non-errNonLoopback error. Sandboxed agent shells often export a loopback proxy. Fix: addtransport.Proxy = nilin Main. LiveClient keeps the originallivetransport, so the opt-in live tests keep their proxy behavior.internal/tr064/actions_test.go:91- TestSourceNamesOnlyApprovedMutations (and its helper sourceStringLiterals) parses the non-test .go source and matches string literals against a verb regex. This is a source-content-only assertion, which the test-quality rule forbids. A dead or commented-out literal satisfies it. A behavior-preserving refactor that builds an action name by concatenation (for example "Set"+name) gets past it. Harmless literals that start with a listed verb can make it fail. The second loop ('approvedMutations lists %q, which no command sends') has the same defect: it proves that a literal exists, not that a command sends the action. The runtime guard in checkAction plus TestCheckAction and TestSOAPLayerRefusesUnapprovedActionsBeforeSending already enforce the contract at the SOAP send boundary. AGENTS.md requires fixture-backed tests for every action, so a new Set* command fails its own fixture test through checkAction. Proposed remedy: remove the AST test, or replace it with a behavioral check, for example a test that runs each mutating command against a fixture server and records every SOAPAction header it receives. The intent asks that 'a new Set* action fails a test', so the user must choose whether the runtime guard alone meets that requirement.🔧 Fix applied.
4 issues (3 warnings, 1 info) still open:
internal/tr064/actions_test.go:91- TestSourceNamesOnlyApprovedMutations (and its helper sourceStringLiterals) parses the non-test .go source and matches string literals against a verb regex. This is a source-content-only assertion, which the test-quality rule forbids. A dead or commented-out literal satisfies it. A behavior-preserving refactor that builds an action name by concatenation (for example "Set"+name) gets past it. Harmless literals that start with a listed verb can make it fail. The second loop ('approvedMutations lists %q, which no command sends') has the same defect: it proves that a literal exists, not that a command sends the action. The runtime guard in checkAction plus TestCheckAction and TestSOAPLayerRefusesUnapprovedActionsBeforeSending already enforce the contract at the SOAP send boundary. AGENTS.md requires fixture-backed tests for every action, so a new Set* command fails its own fixture test through checkAction. Proposed remedy: remove the AST test, or replace it with a behavioral check, for example a test that runs each mutating command against a fixture server and records every SOAPAction header it receives. The intent asks that 'a new Set* action fails a test', so the user must choose whether the runtime guard alone meets that requirement.internal/tr064/event_log.go:110- The event-log path is a SOAP send site that the new mutation allowlist does not cover. EventLog builds its own envelope and SOAPAction header for eventLogAction, then posts it through client.request. It never calls checkAction. The change guards the other three SOAP send sites: actionOnService (client.go:3210), postOnce (client.go:2141), and ConfigExport (client.go:2405, which uses the same hand-built-envelope pattern). The event-log site is the one sibling left without the guard. Today eventLogAction is "X_AVM-DE_GetDeviceLogPath", so no wrong action is sent now. But the intent requires that "the SOAP layer only sends read actions … plus the explicitly approved mutations". A new action built in this event-log style would bypass the guard and no test would fail. Fix: call checkAction(eventLogAction) before the request, as ConfigExport does. Alternatively, put one check in the shared boundary: check the SOAPAction header inside Client.request, which covers both ConfigExport and event-log, and keep the postOnce check.internal/app/skill_test.go:47- TestCommandSurfaceIsDocumented matches the bullet regex^- \<command>[ `]against the whole SKILL.md. It does not restrict the match to the "## Command surface" list. SKILL.md also has rule bullets that start with command names:wifi enable|disable(line 53),reboot(58),wan reconnect(62),wake MAC(68),firmware check(72) andbackup --output(77). Concrete case: someone deletes therebootbullet (line 42) from the command list. The test still passes because of thereboot` rule bullet at line 58. The same applies to wifi, wan, wake, firmware and backup. The intent requires that every command "appear in the shipped SKILL.md command list". Fix: slice SKILL.md from "## Command surface" to the next "## " heading, then run the bullet match on that section only.internal/tr064/actions_test.go:61- TestApprovedMutationsPassCheckAction loops over approvedMutations and asserts that checkAction accepts each entry. checkAction starts withif approvedMutations[action] { return nil }, so this test cannot fail, and it has no independent oracle. TestCheckAction already lists the five approved actions explicitly, with AGENTS.md as the oracle. Fix round 1 added this test because the recorded user instruction asked for it. No change is needed.🔧 Fix applied.
1 info still open:
internal/tr064/actions_test.go:61- TestApprovedMutationsPassCheckAction loops over approvedMutations and asserts that checkAction accepts each entry. checkAction starts withif approvedMutations[action] { return nil }, so this test cannot fail, and it has no independent oracle. TestCheckAction already lists the five approved actions explicitly, with AGENTS.md as the oracle. Fix round 1 added this test because the recorded user instruction asked for it. No change is needed.nix develop --no-pure-eval --command go test ./...go test ./internal/tr064 ./internal/app ./internal/nettest ./cmd/...filtered to the new guard, privacy, drift, event-log and help-sweep testsgo test ./internal/tr064 -run 'Scan|Addresses|Testdata|Docs|Doc'baselinego test ./...✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.