-
Notifications
You must be signed in to change notification settings - Fork 16
fix(agent-challenge): stop forwarding operator OpenRouter key after cutoff #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
echobt
wants to merge
1
commit into
main
Choose a base branch
from
fix/stop-operator-openrouter-key-forward-post-cutoff
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
packages/challenges/agent-challenge/tests/test_operator_env_forward_cutoff.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| """Operator harbor_forward_env_vars grandfathering by submission.created_at. | ||
|
|
||
| Pre-cutoff submissions keep receiving the operator-injected OPENROUTER_API_KEY | ||
| (and any other harbor_forward_env_vars). Post-cutoff submissions must supply | ||
| their own key via miner env; the operator key is not forwarded and must not | ||
| shadow the miner value. Missing keys fail with an attributable error. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import UTC, datetime, timedelta | ||
|
|
||
| import pytest | ||
|
|
||
| from agent_challenge.evaluation.runner import _terminal_bench_env | ||
| from agent_challenge.sdk.config import ChallengeSettings | ||
|
|
||
| CUTOFF = datetime(2026, 7, 30, 12, 0, 0, tzinfo=UTC) | ||
| PRE_CUTOFF = CUTOFF - timedelta(hours=1) | ||
| POST_CUTOFF = CUTOFF + timedelta(hours=1) | ||
| OPERATOR_KEY = "sk-or-v1-operator-forward-test-value" | ||
| MINER_KEY = "sk-or-v1-miner-supplied-test-value" | ||
|
|
||
|
|
||
| def _patch_forward_settings(monkeypatch, *, cutoff: datetime | None = CUTOFF) -> None: | ||
| monkeypatch.setattr( | ||
| "agent_challenge.evaluation.runner.settings.harbor_forward_env_vars", | ||
| ("OPENROUTER_API_KEY",), | ||
| ) | ||
| monkeypatch.setattr( | ||
| "agent_challenge.evaluation.runner.settings.operator_env_forward_cutoff_at", | ||
| cutoff, | ||
| ) | ||
| monkeypatch.setenv("OPENROUTER_API_KEY", OPERATOR_KEY) | ||
|
|
||
|
|
||
| def test_pre_cutoff_submission_forwards_operator_key(monkeypatch) -> None: | ||
| """Given: submission created before cutoff, operator has OPENROUTER_API_KEY. | ||
| When: _terminal_bench_env builds job env | ||
| Then: operator key is present (grandfathered). | ||
| """ | ||
| _patch_forward_settings(monkeypatch) | ||
|
|
||
| env = _terminal_bench_env( | ||
| {"LLM_COST_LIMIT": "1.0"}, | ||
| submission_created_at=PRE_CUTOFF, | ||
| ) | ||
|
|
||
| assert env["OPENROUTER_API_KEY"] == OPERATOR_KEY | ||
|
|
||
|
|
||
| def test_post_cutoff_with_miner_key_uses_miner_not_operator(monkeypatch) -> None: | ||
| """Given: post-cutoff submission with miner OPENROUTER_API_KEY | ||
| When: _terminal_bench_env builds job env | ||
| Then: miner key is present, operator key is absent (not shadowed). | ||
| """ | ||
| _patch_forward_settings(monkeypatch) | ||
|
|
||
| env = _terminal_bench_env( | ||
| {"OPENROUTER_API_KEY": MINER_KEY}, | ||
| submission_created_at=POST_CUTOFF, | ||
| ) | ||
|
|
||
| assert env["OPENROUTER_API_KEY"] == MINER_KEY | ||
| assert env["OPENROUTER_API_KEY"] != OPERATOR_KEY | ||
|
|
||
|
|
||
| def test_post_cutoff_without_key_raises_attributable_error(monkeypatch) -> None: | ||
| """Given: post-cutoff submission with no OPENROUTER_API_KEY | ||
| When: _terminal_bench_env builds job env | ||
| Then: ValueError names OPENROUTER_API_KEY (not silent zero / crash elsewhere). | ||
| """ | ||
| _patch_forward_settings(monkeypatch) | ||
|
|
||
| with pytest.raises(ValueError, match="OPENROUTER_API_KEY") as exc_info: | ||
| _terminal_bench_env( | ||
| {"LLM_COST_LIMIT": "1.0"}, | ||
| submission_created_at=POST_CUTOFF, | ||
| ) | ||
|
|
||
| message = str(exc_info.value) | ||
| assert "OPENROUTER_API_KEY" in message | ||
| assert "cutoff" in message.lower() or "operator" in message.lower() | ||
|
|
||
|
|
||
| def test_cutoff_boundary_instant_is_post_cutoff(monkeypatch) -> None: | ||
| """Given: submission.created_at exactly equal to cutoff | ||
| When: _terminal_bench_env builds job env without miner key | ||
| Then: boundary is post-cutoff (operator not forwarded; missing key fails). | ||
| """ | ||
| _patch_forward_settings(monkeypatch) | ||
|
|
||
| with pytest.raises(ValueError, match="OPENROUTER_API_KEY"): | ||
| _terminal_bench_env( | ||
| {}, | ||
| submission_created_at=CUTOFF, | ||
| ) | ||
|
|
||
| env = _terminal_bench_env( | ||
| {"OPENROUTER_API_KEY": MINER_KEY}, | ||
| submission_created_at=CUTOFF, | ||
| ) | ||
| assert env["OPENROUTER_API_KEY"] == MINER_KEY | ||
|
|
||
|
|
||
| def test_no_cutoff_configured_keeps_legacy_operator_forward(monkeypatch) -> None: | ||
| """Given: operator_env_forward_cutoff_at is None (unset) | ||
| When: any submission builds env | ||
| Then: operator key is still forwarded (safe default until ops sets cutoff). | ||
| """ | ||
| _patch_forward_settings(monkeypatch, cutoff=None) | ||
|
|
||
| env = _terminal_bench_env( | ||
| {}, | ||
| submission_created_at=POST_CUTOFF, | ||
| ) | ||
|
|
||
| assert env["OPENROUTER_API_KEY"] == OPERATOR_KEY | ||
|
|
||
|
|
||
| def test_operator_env_forward_cutoff_at_env_override(monkeypatch) -> None: | ||
| """Given: CHALLENGE_OPERATOR_ENV_FORWARD_CUTOFF_AT is set | ||
| When: ChallengeSettings loads | ||
| Then: operator_env_forward_cutoff_at parses as aware UTC datetime. | ||
| """ | ||
| monkeypatch.setenv( | ||
| "CHALLENGE_OPERATOR_ENV_FORWARD_CUTOFF_AT", | ||
| "2026-07-30T12:00:00+00:00", | ||
| ) | ||
| settings = ChallengeSettings() | ||
| assert settings.operator_env_forward_cutoff_at == CUTOFF | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Replace API-key-shaped test literals with non-secret sentinels.
These literals mimic full OpenRouter API tokens, which violates the repository rule even in test evidence. Use clearly non-secret fixture values instead.
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines