Skip to content

test: enforce router-axi agent rules with automated checks - #56

Merged
Azd325 merged 3 commits into
mainfrom
fm/router-axi-rule-checks
Oct 20, 2026
Merged

Azd325 merged 3 commits into
mainfrom
fm/router-axi-rule-checks

Conversation

@Azd325

@Azd325 Azd325 commented Oct 20, 2026

Copy link
Copy Markdown
Owner

What Changed

  • Added an action allowlist in internal/tr064/actions.go. postOnce, actionOnService, ConfigExport and EventLog now call checkAction before they send a SOAP request. Read actions (Get, X_Get, X_AVM-DE_Get and similar) and the five approved mutations (SetEnable, Reboot, ForceTermination, Wake-on-LAN, firmware check) pass. Any other action returns an internal error and sends nothing.
  • Added internal/nettest. Each test package (cmd/router-axi, internal/app, internal/tr064) calls it from TestMain. It replaces http.DefaultTransport with one that dials loopback only and ignores proxies. Live tests use nettest.LiveClient to reach a router. The branch also adds tests for the allowlist, the guard and a fixture privacy check, and updates existing tests.
  • Fixed docs drift in internal/skill/SKILL.md. The skill description and command list now include event-log, and the status entry is reworded. skill_test.go now checks the skill text against the command surface. README.md adds router-axi session dashboard to 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.

  • Live validation: ⚠️ inconclusive - 0 of 4 scenarios driven live against the product
Scenario Result Live Evidence
An unlisted Set* or X_AVM-DE_Set* action is refused before any request is sent, and approved mutations still pass ⏸️ untested no The prior payload recorded only unit and fixture-server tests (live=false). It did not establish a live result. No router was reachable.
A private, link-local, CGNAT or factory-default address in tests, testdata or docs fails the scan ⏸️ untested no The prior payload recorded only the repository-scan unit test (live=false). It did not establish a live result.
An ordinary test cannot dial a non-loopback address, including via a proxy ⏸️ untested no The prior payload recorded only unit tests of the network guard (live=false). It did not establish a live result.
Every command in commandFlags, including event-log, account and wake, appears in SKILL.md and README ⏸️ untested no The prior payload recorded only the docs drift and help-sweep unit tests (live=false). It did not establish a live result.
  • Outcome: ⚠️ 1 warning across 1 run (11m48s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ 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: add transport.Proxy = nil in Main. LiveClient keeps the original live transport, 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 &#34;## Command surface&#34; 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 with if 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 with if 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.
⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (0 of 4 scenarios were driven live against the product); untested: An unlisted Set* or X_AVM-DE_Set* action is refused before any request is sent, and approved mutations still pass, A private, link-local, CGNAT or factory-default address in tests, testdata or docs fails the scan, An ordinary test cannot dial a non-loopback address, including via a proxy, Every command in commandFlags, including event-log, account and wake, appears in SKILL.md and README
  • Live validation: ⚠️ inconclusive - 0 of 4 scenarios driven live against the product
Scenario Result Live Evidence
An unlisted Set* or X_AVM-DE_Set* action is refused before any request is sent, and approved mutations still pass ⏸️ untested no The prior payload recorded only unit and fixture-server tests (live=false). It did not establish a live result. No router was reachable.
A private, link-local, CGNAT or factory-default address in tests, testdata or docs fails the scan ⏸️ untested no The prior payload recorded only the repository-scan unit test (live=false). It did not establish a live result.
An ordinary test cannot dial a non-loopback address, including via a proxy ⏸️ untested no The prior payload recorded only unit tests of the network guard (live=false). It did not establish a live result.
Every command in commandFlags, including event-log, account and wake, appears in SKILL.md and README ⏸️ untested no The prior payload recorded only the docs drift and help-sweep unit tests (live=false). It did not establish a live result.
  • 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 tests
  • go test ./internal/tr064 -run 'Scan|Addresses|Testdata|Docs|Doc'
  • baseline go test ./...
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

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.
@Azd325
Azd325 merged commit 6d553b8 into main Oct 20, 2026
5 checks passed
@Azd325
Azd325 deleted the fm/router-axi-rule-checks branch October 20, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant