Description
Background
#67253 (fixes #67250) adds golden tests under pkg/cli/testdata/model_routing_golden/. They contain five trimmed, sanitized routed runs in the downloaded-run layout. Each case has an expected.json and an expected.legacy.json, and logs_expected.json covers the gh aw logs aggregate. pkg/cli/model_routing_golden_test.go checks them all.
@pelikhan asked for an agentic way to maintain these goldens. They need updating whenever audit's routing or token-usage output changes. Today there are only two tools:
- the
UPDATE_MODEL_ROUTING_GOLDENenvironment variable ongo test, which regenerates the expected files; - an out-of-repo script, which produced the input fixtures and can't be reproduced in this repo.
Plan
1. make update-model-routing-golden
Add an update-model-routing-golden target to the Makefile, modeled on update-wasm-golden. It runs the TestModelRoutingGolden* tests in ./pkg/cli with UPDATE_MODEL_ROUTING_GOLDEN=1 to regenerate every expected.json, expected.legacy.json and logs_expected.json. Then it prints a diff summary of pkg/cli/testdata/model_routing_golden/ for review. Add the target to the make help listing next to update-wasm-golden.
2. Fixture-capture command
Add a capture tool: either a hidden gh aw subcommand in pkg/cli or a script under scripts/. It takes a run ID or run URL and a case name, downloads the run the same way gh aw audit does, and writes a new case directory under pkg/cli/testdata/model_routing_golden/. It should:
- Keep only the files that audit's routing and token-usage analysis reads:
- root and agent
aw_info.json, plususage/aw_info.jsonwhen present agent/awf-routing-outcome.jsonagent_usage.jsonandusage/agent_usage.jsonusage/aw_session.jsonlandagent-session.jsonlmodel-routing.jsonlandtoken-usage.jsonlundersandbox/firewall/logs/api-proxy-logs/
- root and agent
- Filter session events. In session files, keep only:
session.*,workflow.info,model_routing.outcome,firewall.model_routing,firewall.token_usage,agent.executionandsubagent.*pi.subagent_*and, for pi,tool.execution_*
- Redact sensitive content:
- prompt, message, task and tool content
cwd, conversation hashes, signatures and encrypted content- org, repo and user names, which it replaces with placeholders
- Preserve what the analysis depends on. Keep AWF credit fields intact, because audit validates them and falls back to price tables when they're missing or invalid. Also keep model IDs, endpoints, efforts, token counts and request IDs.
- Verify the fixture. Run the routing and token-usage analysis on both the full download and the trimmed fixture. Fail without writing the fixture if the two outputs differ.
- Get the fixture committed.
.gitignoreignoreslogs/directories, so the fixture'ssandbox/firewall/logs/files depend on the negation that Add golden coverage for routed model audit analysis #67253 adds underpkg/cli/testdata/model_routing_golden/. The tool should check that the new files aren't ignored, or tell the user to force-add them.
After capturing a case, the user runs the make target from step 1 to generate its expected files.
3. Maintenance skill
Add .github/skills/model-routing-goldens/SKILL.md for agents to follow. It should cover:
- When to refresh: only when audit's routing or token-usage output changed on purpose.
- How to refresh: run
make update-model-routing-goldenand review the diff. Only the fields the change intends to affect may differ, and the PR must explain each changed field. - How to add a case: use the capture command from step 2. Runs from a private sandbox must be captured by a maintainer or by the person who reported the issue, because an agent can't access them.
- What to check before committing: the fixture layout matches the downloaded-run layout, redaction is complete (no prompt, message or tool content and no real org, repo or user names), credit fields are intact, and the logs files are tracked by git.
Also add the skill to the intent routing list in AGENTS.md.
4. pr-finisher step
Add a step to .github/skills/pr-finisher/SKILL.md. When TestModelRoutingGolden* fails because of an intended output change, run make update-model-routing-golden and summarize the golden diff in the PR description. When the change is unintended, fix the code and leave the goldens unchanged.
5. Fixture README
Add a short pkg/cli/testdata/model_routing_golden/README.md. It should describe each of the five cases and the routing scenario it covers, list each case's source run, and describe the refresh workflow. It should point to the make target, the capture command and the skill.
Acceptance criteria
make update-model-routing-goldenregenerates all the goldens, and after a refresh with no code changes,git diffis empty.- The capture command recreates an existing case from its source run, and the analysis output matches that case's committed
expected.json. - The capture command fails when the trimmed fixture's analysis output differs from the full download's output.
- The skill, the
pr-finisherstep and the README are in place and reference each other.
Activity