Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-28
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Proposal

## Why

Issue #909: `src/devops_cli/ai/gateway_bench.py` runs in an ephemeral `python:3.14-slim` container attached to the gateway pod, so it may import only the standard library. The issue asks for three things:

- A test that fails when the module imports a module outside the standard library.
- A comment that says why `_validate_http_url` raises the standard library's `ValueError` and not `InvalidURLError`.
- An error text that does not echo the URL. `run_level` writes `f"{type(exc).__name__}: {exc}"` into `last_error`, and the sweep's JSON and the stored run hold that text. A URL with userinfo or a query token thus put its credential into the benchmark output.

## What Changes

- `_validate_http_url` raises `ValueError("Backend URL is not an http or https URL with a host.")`. The text names no part of the URL. The scheme is not named either: `urllib.parse.urlparse("user:pass@host")` returns `user` as the scheme.
- A comment above the `raise` says why the error is the standard library's `ValueError`: the module runs without `devops_cli`, and `_get_text` and `run_level` catch the error.
- A new test sends a URL with a password and a query token to `run_level` and asserts that `last_error` holds neither.
- The error text reaches the output of `devops ai gateway tune`, so the change carries a spec delta: an ADDED requirement in `gateway-tuning`.
- This change fits one pull request.

## Capabilities

### Modified Capabilities

- `gateway-tuning`: a refused backend URL reaches the sweep's output without its credentials.

## Impact

- `src/devops_cli/ai/gateway_bench.py`.
- `tests/test_ai_gateway_tune.py`.

## Feasibility

- On `origin/main` bb46660c, `_validate_http_url` raised `ValueError(f"Invalid HTTP URL scheme or destination: {url!r}")`, and `run_level` put the text of a `ValueError` from `_post_json` into `last_error`. The new test failed on that code: `last_error` held both `s3cr3t` and `t0k3n`.
- The first criterion of the issue is already met. `test_gateway_bench_imports_only_standard_library` in `tests/test_ai_gateway_tune.py` parses the module with `ast` and compares its imports with `sys.stdlib_module_names`. A copy of the module with `from devops_cli.exceptions import InvalidURLError` made it fail with `assert ['devops_cli'] == []`. The change adds no second test for the same rule.

## Existing Tool Considered

`devops_cli.security.sanitizer.mask_uri_credentials` removes the userinfo of a URL, but the container has no `devops_cli`, so the module cannot import it. The standard library has no function that removes the credentials of a URL. A fixed text with no part of the URL needs no tool. The change deletes the URL from the error text and adds no code.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## ADDED Requirements

### Requirement: A refused backend URL keeps its credentials out of the sweep
When the throughput sweep refuses a backend URL that is not an http or https URL with a host, the error text that the sweep records SHALL name no part of the URL.

#### Scenario: A URL with a password and a query token
- **WHEN** `run_level` gets the URL `ftp://user:s3cr3t@example.com/x?token=t0k3n`
- **THEN** the level counts one error, and its `last_error` starts with `ValueError: ` and holds neither `s3cr3t` nor `t0k3n`
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Tasks

## 1. A refused backend URL keeps its credentials out of the sweep

- [x] Add a failing test: `run_level` with `ftp://user:s3cr3t@example.com/x?token=t0k3n` records a `ValueError` whose text holds neither `s3cr3t` nor `t0k3n`
- Verification: `uv run devops ci test tests/test_ai_gateway_tune.py`
- [x] Raise a fixed `ValueError` text in `_validate_http_url`, with a comment that says why the module raises the standard library's `ValueError`
- Verification: `uv run devops ci test tests/test_ai_gateway_tune.py`
- [x] Regenerate the documentation
- Verification: `uv run devops docs generate --sync-readme`

## 2. Archive

- [x] Archive the change
- Verification: `uv run devops openspec archive 909-gateway-bench-stdlib`
- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).
7 changes: 7 additions & 0 deletions openspec/specs/gateway-tuning/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ The system SHALL persist probe results per deployment in the run store and repor
#### Scenario: Measured capabilities persisted and reported
- **WHEN** gateway tuning completes
- **THEN** run records persist capability probe results per deployment id and reports show measured pass rates or unmeasured status

### Requirement: A refused backend URL keeps its credentials out of the sweep
When the throughput sweep refuses a backend URL that is not an http or https URL with a host, the error text that the sweep records SHALL name no part of the URL.

#### Scenario: A URL with a password and a query token
- **WHEN** `run_level` gets the URL `ftp://user:s3cr3t@example.com/x?token=t0k3n`
- **THEN** the level counts one error, and its `last_error` starts with `ValueError: ` and holds neither `s3cr3t` nor `t0k3n`
6 changes: 5 additions & 1 deletion src/devops_cli/ai/gateway_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ def _validate_http_url(url: str) -> None:
"""Validate that url is a well-formed http or https endpoint."""
parsed = urllib.parse.urlparse(url)
if parsed.scheme not in ("http", "https") or not parsed.netloc:
raise ValueError(f"Invalid HTTP URL scheme or destination: {url!r}")
# The standard library's ValueError, not InvalidURLError: this module runs in a container
# without devops_cli, and `_get_text` and `run_level` catch the error. Its text goes into
# the sweep's `last_error`, so it does not name the URL, whose userinfo or query can hold
# a credential.
raise ValueError("Backend URL is not an http or https URL with a host.")


def _get_text(url: str, timeout: float) -> tuple[int, str]:
Expand Down
25 changes: 25 additions & 0 deletions tests/test_ai_gateway_tune.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,31 @@ def test_gateway_bench_imports_only_standard_library(self) -> None:
}
assert sorted(imported - sys.stdlib_module_names) == []

def test_refused_backend_url_reaches_the_sweep_without_its_credentials(self) -> None:
"""Verify a refused backend URL's error names neither its userinfo nor its query (#909)."""
level = bench.run_level(
"ftp://user:s3cr3t@example.com/x?token=t0k3n",
"m",
"prompt",
5,
concurrency=1,
total=1,
timeout=1.0,
)

error = level["last_error"]
assert (
level["errors"],
error.startswith("ValueError: "),
"s3cr3t" in error,
"t0k3n" in error,
) == (
1,
True,
False,
False,
)

def test_measure_runs_fixed_length_capacity_levels_then_a_natural_cost_pass(self) -> None:
"""Verify capacity levels send concurrency x rounds fixed-length requests, then cost."""
sent: list[bool] = []
Expand Down