Skip to content

Tests: cross-module model-routing contract tests and measurable harness routing coverage #67251

Closed

Description

@SivaKesava1

Why

On main at 29b5ac2, the routing core modules in actions/setup/js/ are well covered (line coverage):

Module Lines
awf_model_routing.cjs 94%
model_attribution.cjs 97%
parse_token_usage.cjs 91%
pi_models_json.cjs 93%
unified_session_payload.cjs 96%

The harnesses report much lower coverage:

Harness Lines
claude_harness.cjs 37%
copilot_harness.cjs 46%
codex_harness.cjs 55%

Their tests run them with spawnSync, and vitest's v8 coverage doesn't follow child processes. So coverage can't show whether the harness routing paths are exercised.

Good per-module coverage also doesn't catch disagreements between modules. The F5 bug (#67012) was an interaction: the harness applied one endpoint rule (#66956) and attribution applied another (#66963). Each module passed its own tests.

Where one routing decision is evaluated today

At 29b5ac2, the same selection is derived or re-derived in several places:

  • Harness selection.
    • resolveAWFModelRoutingSelection, getAWFModelRoutingPolicy, and mapAWFRoutingEffort in awf_model_routing.cjs.
    • Called from:
      • copilot_harness.cjs: main, applyCopilotRoutingSelection, applyCopilotRoutingArgs
      • claude_harness.cjs: inside main, feeding buildClaudeChildEnv
      • codex_harness.cjs: resolveCodexModelRouting
      • pi: resolvePiModelRouting and resolvePiRoutingEndpoint in pi_models_json.cjs
    • Each records an advisory outcome via recordAWFModelRoutingOutcome in agent/awf-routing-outcome.json.
  • Post-run resolution. resolveModelRoutingOutcome in parse_token_usage.cjs combines the proxy model-routing.jsonl record, agent/awf-reflect.json, and the harness advisory. For endpoint overrides it re-runs resolveAWFModelRoutingSelection. It then writes the aw_info.json model_routing block through recordModelRouting in model_attribution.cjs.
  • Consumers.
    • resolveEffectiveModel and getEffectiveModelLabel in model_attribution.cjs, which drive the footer via messages_footer.cjs and handle_noop_message.cjs.
    • unified_session.cjs emits workflow.info and model_routing.outcome and merges the outcome fields into workflow.info.modelRouting. The payload shapes come from unified_session_payload.cjs.
    • sendJobConclusionSpan in send_otlp_span.cjs emits gen_ai.request.model, gh-aw.model.requested, gh-aw.model.effort, and gh-aw.model_routing.status / .mode / .router_version.

Plan

1. Per-engine contract test

Add actions/setup/js/model_routing_contract.test.cjs, table-driven over copilot, claude, pi, and codex. Each row has one /reflect payload and one proxy model-routing.jsonl log, stored under actions/setup/js/fixtures/. Each row runs in a temp GH_AW_TMP_DIR with the engine ID and routing env set, and feeds the same inputs through every stage in-process:

  1. the harness's routing resolution, which writes the advisory through recordAWFModelRoutingOutcome
  2. resolveModelRoutingOutcome in parse_token_usage.cjs, which writes the aw_info.json model_routing block
  3. the footer label from getEffectiveModelLabel (and the underlying resolveEffectiveModel)
  4. the unified session's workflow.info and model_routing.outcome events
  5. the OTEL routing attributes from send_otlp_span.cjs, with a mocked exporter

Assert that every stage agrees on model, effort, status, effective endpoint, and selected endpoint. Today the OTEL span carries model, effort, and status but no endpoints. Assert those three there, and add endpoint assertions if #67237 adds endpoint attributes. If an engine maps effort (pi maps none to off), assert that applied effort and requested effort stay consistent everywhere they appear.

Rows should include at least:

The goal: changing an endpoint or effort rule in any one module fails this test. That includes a harness, awf_model_routing.cjs, parse_token_usage.cjs, model_attribution.cjs, unified_session.cjs, or send_otlp_span.cjs.

2. Engine effort matrix

Add a table test covering every value of ROUTING_REASONING_EFFORTS (none, minimal, low, medium, high, xhigh, max) for each engine. Each cell is classified as accepted, mapped, or fail-closed. Current mapAWFRoutingEffort behaviour at 29b5ac2:

  • Copilot passes every value through. The SDK driver forwards it via resolveRoutingReasoningEffort in copilot_routing_effort.cjs.
  • Claude accepts low through max and rejects none and minimal.
  • Codex accepts minimal through xhigh and rejects none and max.
  • pi accepts every value and maps none to off.

Check each cell end to end through the harness, not just through mapAWFRoutingEffort:

  • Fail-closed cells: the harness records rejected / unsupported_effort with an error naming both effort and engine. The aw_info.json block, footer, session events, and OTEL then show no routed model.
  • Mapped cells: the applied effort is what reaches the engine and what downstream outputs report.

The test table is the reference for current behaviour. Any intentional change to a cell should be visible in the diff.

3. Non-routed OTEL assertion

send_otlp_span.test.cjs currently only asserts that routing attributes are present on a routed run. Add a case for a non-routed run: no model_routing block in aw_info.json and no GH_AW_MODEL_ROUTING_STATUS. That run must emit no gh-aw.model_routing.* attributes. Under current gating it must also emit no routing-only gh-aw.model.requested / gh-aw.model.effort. Coordinate with #67237 so this assertion matches the attribute set that issue settles on.

4. Make harness routing coverage measurable

Choose one of these approaches, or use both:

  • Export routing helpers for in-process unit tests (preferred, since step 1 needs it anyway).
    • Copilot already exports resolveAWFModelRoutingSelection, applyCopilotRoutingSelection, and applyCopilotRoutingArgs, but the selection call and the failure-path recordAWFModelRoutingOutcome call sit inline in main.
    • Codex already exports resolveCodexModelRouting, applyCodexRoutingEffort, and removeCodexRoutingOverrides.
    • Claude exports only buildClaudeChildEnv and removeClaudeRoutingOverrides. Its routing decision and outcome recording live inside main.
    • Extract each harness's resolve-and-record step out of main into an exported function that main calls, so tests and the contract test exercise exactly the production path.
  • Collect child-process coverage. Run the existing spawnSync harness tests with NODE_V8_COVERAGE and merge that output into the test:js-coverage report. The vitest v8 provider only reports the worker's own process, so this needs an explicit merge step.

Acceptance criteria

  • model_routing_contract.test.cjs covers copilot, claude, pi, and codex in-process, including the negative rows above.
  • The PR describes a mutation check that fails the contract test. Candidate changes:
    • temporarily changing one engine's endpoints in getAWFModelRoutingPolicy
    • changing the endpoint-override branch in resolveModelRoutingOutcome
    • dropping a field from the workflow.info merge in unified_session.cjs
  • The effort matrix covers all 28 engine × effort cells.
  • send_otlp_span.test.cjs asserts that a non-routed run emits no gh-aw.model_routing.* attributes.
  • npm run test:js-coverage shows the harness routing paths as covered. The PR reports before and after line coverage for claude_harness.cjs, copilot_harness.cjs, and codex_harness.cjs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementmodel-routingtesting

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions