Repository navigation
fix(ci): separate free-pool admission from global discovery #1587
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
Merged
+208
−24
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3b75fc5
fix(ci): bind free-pool admission to credential source
seonghobae caa7318
test(ci): prove OpenAI cannot enter orchestrator free
seonghobae 1c22817
merge main into free-pool credential admission
seonghobae d7e5889
fix(ci): keep discovery counters backward-compatible
seonghobae 1b9b6d6
test(ci): distinguish discovery from free-pool counters
seonghobae 7907f21
test(ci): expose free-pool fallback count drift
seonghobae 211aff9
fix(ci): repair free-pool fallback count enrichment
seonghobae 1cdac1e
fix(ci): make PR 1587 enrichment repair workflow executable
seonghobae 96f5564
fix(ci): preserve free-pool counts across priced fallback
github-actions[bot] 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
89 changes: 89 additions & 0 deletions
89
tests/test_contextual_orchestrator_free_credential_admission.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,89 @@ | ||
| """Free-pool credential-source admission contracts for the review catalog.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from scripts.ci.contextual_orchestrator_review_policy import ( | ||
| PolicyError, | ||
| build_zdr_prioritized_catalog, | ||
| parse_discovery_report, | ||
| ) | ||
| from scripts.ci.zdr_policy import PROVIDER_CREDENTIAL_NAMES | ||
|
|
||
|
|
||
| def _zero_cost_row(provider: str) -> dict[str, object]: | ||
| """Return one complete zero-cost discovery row with authentic source identity.""" | ||
| return { | ||
| "provider": provider, | ||
| "model": f"{provider}-review-model", | ||
| "agent_id": f"{provider}_review_model", | ||
| "is_free": True, | ||
| "prompt_price_per_1k": 0.0, | ||
| "completion_price_per_1k": 0.0, | ||
| "currency_code": "USD", | ||
| "credential_key": PROVIDER_CREDENTIAL_NAMES[provider], | ||
| } | ||
|
|
||
|
|
||
| def test_free_pool_excludes_openai_while_global_discovery_keeps_all_five() -> None: | ||
| """All providers stay discoverable, but OpenAI contributes no free candidate.""" | ||
| providers = ( | ||
| "bytez", | ||
| "nvidia_nim", | ||
| "nvidia_nim_sub", | ||
| "openrouter", | ||
| "openai", | ||
| ) | ||
| rows = parse_discovery_report({"models": [_zero_cost_row(provider) for provider in providers]}) | ||
|
|
||
| result = build_zdr_prioritized_catalog(rows, pool="free", limit=12, account_cap=12) | ||
|
|
||
| selected = result["report"]["selected"] | ||
| assert {entry["provider"] for entry in selected} == { | ||
| "bytez", | ||
| "nvidia_nim", | ||
| "nvidia_nim_sub", | ||
| "openrouter", | ||
| } | ||
| assert all(agent["credential_key"] != "OPENAI_API_KEY" for agent in result["agents"]) | ||
| # Discovery-wide counters keep their established meaning; narrower pool | ||
| # admission gets separate fields so runtime enrichment cannot relabel them. | ||
| assert result["report"]["total_free_routes"] == 5 | ||
| assert result["report"]["free_account_diversity"] == 5 | ||
| assert result["report"]["free_pool_admitted_routes"] == 4 | ||
| assert result["report"]["free_pool_excluded_source_count"] == 1 | ||
| assert result["report"]["free_pool_account_diversity"] == 4 | ||
|
|
||
|
|
||
| def test_auto_pool_may_retain_globally_discovered_openai() -> None: | ||
| """The free-source rule does not delete OpenAI from non-free/global routing.""" | ||
| rows = parse_discovery_report( | ||
| {"models": [_zero_cost_row("openrouter"), _zero_cost_row("openai")]} | ||
| ) | ||
|
|
||
| result = build_zdr_prioritized_catalog(rows, pool="auto", limit=12, account_cap=12) | ||
|
|
||
| assert {entry["provider"] for entry in result["report"]["selected"]} == { | ||
| "openrouter", | ||
| "openai", | ||
| } | ||
| assert result["report"]["free_pool_admitted_routes"] == 1 | ||
| assert result["report"]["free_pool_excluded_source_count"] == 1 | ||
|
|
||
|
|
||
| def test_openai_only_zero_cost_discovery_fails_closed_for_free_pool() -> None: | ||
| """A globally discovered OpenAI route cannot become the sole free fallback.""" | ||
| rows = parse_discovery_report({"models": [_zero_cost_row("openai")]}) | ||
|
|
||
| with pytest.raises(PolicyError, match="orchestrator/free would fail closed"): | ||
| build_zdr_prioritized_catalog(rows, pool="free", limit=12, account_cap=12) | ||
|
|
||
|
|
||
| def test_provider_credential_source_mismatch_is_rejected() -> None: | ||
| """A row cannot spoof an eligible provider while using the OpenAI credential.""" | ||
| row = _zero_cost_row("openrouter") | ||
| row["credential_key"] = "OPENAI_API_KEY" | ||
|
|
||
| with pytest.raises(PolicyError, match="credential source does not match provider evidence"): | ||
| parse_discovery_report({"models": [row]}) |
42 changes: 42 additions & 0 deletions
42
tests/test_contextual_orchestrator_free_pool_enrichment.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,42 @@ | ||
| """Runtime report enrichment contracts for free-pool source admission.""" | ||
|
|
||
| from scripts.ci.contextual_orchestrator_review_launcher import _with_discovery_counts | ||
|
|
||
|
|
||
| def test_discovery_enrichment_recomputes_free_pool_counts_from_full_rows() -> None: | ||
| """Priced fallback reports retain full discovered authorized free capacity.""" | ||
| stage_report = { | ||
| "free_pool_admitted_routes": 0, | ||
| "free_pool_excluded_source_count": 0, | ||
| "free_pool_account_diversity": 0, | ||
| } | ||
| rows = [ | ||
| { | ||
| "provider": "openrouter", | ||
| "credential_key": "OPENROUTER_API_KEY", | ||
| "cost_evidence": "free", | ||
| }, | ||
| { | ||
| "provider": "openai", | ||
| "credential_key": "OPENAI_API_KEY", | ||
| "cost_evidence": "free", | ||
| }, | ||
| { | ||
| "provider": "openai", | ||
| "credential_key": "OPENAI_API_KEY", | ||
| "cost_evidence": "priced", | ||
| }, | ||
| ] | ||
|
|
||
| enriched = _with_discovery_counts( | ||
| stage_report, | ||
| rows, | ||
| provider_account=lambda provider: provider, | ||
| ) | ||
|
|
||
| assert enriched["total_routes"] == 3 | ||
| assert enriched["total_free_routes"] == 2 | ||
| assert enriched["free_account_diversity"] == 2 | ||
| assert enriched["free_pool_admitted_routes"] == 1 | ||
| assert enriched["free_pool_excluded_source_count"] == 1 | ||
| assert enriched["free_pool_account_diversity"] == 1 |
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.
Uh oh!
There was an error while loading. Please reload this page.