Skip to content

test(ai): the gateway sweep script imports only the standard library #909

Description

@dan-petty

Problem

src/devops_cli/ai/gateway_bench.py does not run in the CLI process. bench_script() (gateway_tune.py:403-405) sends its source over stdin to python - in an ephemeral python:3.14-slim container attached to the gateway pod (gateway_tune.py:584-601), so the module may import only the standard library (module docstring, task-470).

Nothing enforces that. On release PR #905, Copilot asked for _validate_http_url (gateway_bench.py:63) to raise InvalidURLError instead of a bare ValueError, as AGENTS.md's exception taxonomy requires. Applying that would make every devops ai gateway tune sweep fail with ModuleNotFoundError: No module named 'devops_cli', and the current tests would still pass, because they run the script where devops_cli is importable. The ValueError never leaves the script: _get_text turns it into (0, "") (:73) and run_level.one into a last_error string (:132).

Acceptance criteria

  • test_bench_module_imports_only_the_standard_library (tests/test_ai_gateway_tune.py) parses inspect.getsource(gateway_bench) with ast and asserts that every imported top-level module, other than __future__, is in sys.stdlib_module_names. It fails on a copy that adds from devops_cli.exceptions import InvalidURLError.
  • A comment above gateway_bench.py:63 says why the module raises the standard library's ValueError: it runs in a container without devops_cli, and the error is caught at :73 and :132.
  • _validate_http_url's error does not echo the URL. The message reaches run_level(...)["last_error"] and the sweep's JSON, so a URL with userinfo or a query token would print its credentials in benchmark output. Copilot noted this on feat(release): v0.2.24 #905's re-review as a previously missed issue. A test passes ftp://user:s3cr3t@host/x?token=t0k3n and asserts that the error contains neither s3cr3t nor t0k3n.
  • uv run devops ci passes.

Key questions

  • Should AGENTS.md name this exemption? Proposed: no. The comment and the test are enough, and AGENTS.md changes go through devops ai agents.

Activity

  1. added
    type/chore
    scope/ai
    priority/p3-low
    type/test
    and removed
    type/chore
    on Oct 1, 2026
  2. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #796. Both fix the in-pod sweep runner and add tests to tests/test_ai_gateway_tune.py; they land in either order. Found by the 2026-10-08 backlog review.

  3. added a commit that references this issue on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p3-lowscope/aitype/test

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions