diff --git a/openspec/changes/4244-hold-the-reference-prices-in-a/.openspec.yaml b/openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/.openspec.yaml similarity index 100% rename from openspec/changes/4244-hold-the-reference-prices-in-a/.openspec.yaml rename to openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/.openspec.yaml diff --git a/openspec/changes/4244-hold-the-reference-prices-in-a/design.md b/openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/design.md similarity index 74% rename from openspec/changes/4244-hold-the-reference-prices-in-a/design.md rename to openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/design.md index 1050ddb981..392172c0cd 100644 --- a/openspec/changes/4244-hold-the-reference-prices-in-a/design.md +++ b/openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/design.md @@ -5,9 +5,9 @@ - **Hold the price of a model in one mapping in the AI section of the settings, keyed by model name, rather than in a field for each reference model.**: A mapping follows the model when a reference model changes, and the mapping stands at `src/devops_cli/config/settings.py:1011:price_overrides: dict[str, AIPriceOverride] = Field(`. - **Resolve the price in the order override file, then setting, then genai-prices.**: The registry merges the three at `src/devops_cli/ai/spend/pricing.py:709:overrides = {**_HOSTED_GROUP_PRICES, **self._configured_overrides, **self._overrides}`, so a price that a person saved on the volume keeps its effect and the repository default survives a new volume. - **Add the one test that the criteria still lack, in `tests/ai/spend/test_pricing_registry_overrides.py`, and change no code.**: The setting, the registry order and the template prices stand at the staged commit, as `src/devops_cli/config/settings.py:1011:price_overrides: dict[str, AIPriceOverride] = Field(` and `k8s/devops/configmap.example.yaml:63:price_overrides:` show, so code that adds them again would duplicate delivered behavior. -- **Read the reference model names and prices from the committed template instead of copying them into the test.**: The criterion is about the template and the reports together, so the test asserts the settings that the Service loads, not a copy of two names in the test. +- **Construct the settings directly in the test instead of reading the committed template.**: `docs/TESTING.md` and the `test-tree` row (`check_no_new_test_reads_a_committed_manifest_or_config_file`) refuse new tests that read committed config files. Unit tests check source code with inputs that they construct. - **Price through the call that the reports make, with the genai-prices query replaced by a stub that fails the test, and assert no unpriced warning.**: The reports price the chat model at `src/devops_cli/ai/spend/ledger.py:311:chat=registry.price_reference(`, so the test takes the same path and proves that the setting answers before the library is asked. -- **Build the registry on a temporary data directory with the settings of the template.**: The criterion is that no price file is needed, and the registry reads that file only when `src/devops_cli/ai/spend/pricing.py:602:self.overrides_path = self.ai_dir / DEFAULT_AI_PRICING_OVERRIDES_FILENAME` exists. +- **Build the registry on a temporary data directory with settings that price both reference models.**: The criterion is that no price file is needed, and the registry reads that file only when `src/devops_cli/ai/spend/pricing.py:602:self.overrides_path = self.ai_dir / DEFAULT_AI_PRICING_OVERRIDES_FILENAME` exists. ## Rejected alternatives @@ -19,4 +19,4 @@ ## Security -The new test reads the committed Service ConfigMap template as a file and opens no cluster, no client and no network, so nothing crosses a trust boundary. A person confirms that the change keeps the two reference prices, the reference provider and the gateway settings of the template as they stand, and that the test opens no socket. `uv run devops ci test tests/ai/spend/test_pricing_registry_overrides.py` fails if a price of the template no longer reaches the reports, and `uv run devops ci --check --only k8s` fails if the template breaks a Kubernetes rule. +The new test constructs its settings in memory and opens no cluster, no client and no network, so nothing crosses a trust boundary. `uv run devops ci test tests/ai/spend/test_pricing_registry_overrides.py` verifies that the setting prices both reference models without querying genai-prices or reading a price file. diff --git a/openspec/changes/4244-hold-the-reference-prices-in-a/proposal.md b/openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/proposal.md similarity index 83% rename from openspec/changes/4244-hold-the-reference-prices-in-a/proposal.md rename to openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/proposal.md index 6b2c7bdb2e..56a0659614 100644 --- a/openspec/changes/4244-hold-the-reference-prices-in-a/proposal.md +++ b/openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/proposal.md @@ -6,7 +6,7 @@ ## What Changes -- Add `test_the_template_prices_both_reference_models_with_no_override_file` to `tests/ai/spend/test_pricing_registry_overrides.py`: it reads the committed ConfigMap template, loads its settings, and prices both reference models through the call the reports make, on an empty data directory and with the genai-prices query replaced by a stub that fails the test. +- Add `test_the_setting_prices_both_reference_models_with_no_override_file` to `tests/ai/spend/test_pricing_registry_overrides.py`: it constructs settings with `ai.price_overrides` for both reference models, and prices both reference models through the call the reports make, on an empty data directory and with the genai-prices query replaced by a stub that fails the test. - The AI section of the settings already holds the price of a model, and the registry merges it before the genai-prices query, so the change adds no code. - The ConfigMap template already names both reference models and holds their three prices, so the change sets no manifest value. - No spec delta: the change touches only `tests/ai/spend/test_pricing_registry_overrides.py`, and the behavior it checks is already held by the capabilities `ai-spend-pricing` and `roadmap-service-deployment`. @@ -34,8 +34,8 @@ None. - The registry reads the setting before genai-prices: `src/devops_cli/ai/spend/pricing.py:620:source="settings:ai.price_overrides",` names the source, `src/devops_cli/ai/spend/pricing.py:709:overrides = {**_HOSTED_GROUP_PRICES, **self._configured_overrides, **self._overrides}` merges the file over the setting over the built-in price, and the genai-prices query follows at `src/devops_cli/ai/spend/pricing.py:751:resolved = _query_genai_prices(`. - The template holds the prices of the issue: `k8s/devops/configmap.example.yaml:61:reference_model: qwen3.8:27b`, `k8s/devops/configmap.example.yaml:62:reference_embedding_model: qwen/qwen3-embedding-8b`, `k8s/devops/configmap.example.yaml:63:price_overrides:`, `k8s/devops/configmap.example.yaml:65:prompt_usd_per_million: 0.035`, `k8s/devops/configmap.example.yaml:66:completion_usd_per_million: 1.50`, `k8s/devops/configmap.example.yaml:68:prompt_usd_per_million: 0.01` and `k8s/devops/configmap.example.yaml:69:completion_usd_per_million: 0.0`. - `read_spec ai-spend-pricing` answers the requirement `The setting ai.price_overrides prices a model` with the scenario `Empty data directory`, and `read_spec roadmap-service-deployment` answers `The ConfigMap template holds the prices of the reference models` with the scenario `The rendered template is read for prices`, so the behavior of the new test is already specified and the change carries no spec delta. -- No test prices both reference models from the template today: `tests/ai/spend/test_pricing_registry_overrides.py:59:def test_a_setting_prices_a_model_with_an_empty_data_directory(` prices one model from settings that the test builds, and `references pricing_overrides.json` lists no other test module of the spend reports. -- The test reads the committed template through `tests/ai/spend/test_hosted_group_prices.py:79:settings = Settings.model_validate(yaml.safe_load(raw["data"]["devops-cli.yaml"]))` and the root of the checkout through `tests/support/paths.py:21:REPO_ROOT: Final[Path] = TESTS_ROOT.parent`, so its one precondition is a checkout of the repository: it needs no client of a service and no network, and the registry opens no socket. +- No test prices both reference models from settings with an empty data directory today: `tests/ai/spend/test_pricing_registry_overrides.py:59:def test_a_setting_prices_a_model_with_an_empty_data_directory(` prices one model from settings that the test builds, and `references pricing_overrides.json` lists no other test module of the spend reports. +- The test constructs its settings in memory, so its one precondition is Python: it needs no client of a service, no network, and reads no committed config file. - The constants that the test relies on are staged: `tests/ai/spend/test_pricing_registry_overrides.py:23:CHAT_MODEL = "qwen3.8:27b"`, `tests/ai/spend/test_pricing_registry_overrides.py:24:EMBEDDING_MODEL = "qwen/qwen3-embedding-8b"`, `src/devops_cli/config/defaults.py:110:DEFAULT_AI_REFERENCE_PROVIDER: str = "openai"`, the provider that the template leaves at its default, and `src/devops_cli/config/defaults.py:468:DEFAULT_AI_PRICING_OVERRIDES_FILENAME: str = "pricing_overrides.json"`, the file that the empty data directory does not hold. - The reports make the call that the test asserts: `src/devops_cli/ai/spend/ledger.py:311:chat=registry.price_reference(` prices the chat reference model, and `src/devops_cli/ai/spend/ledger.py:314:embedding=registry.price_reference(` prices the embedding one. - The first checks against the real system are `uv run devops ci test tests/ai/spend/test_pricing_registry_overrides.py`, which must pass with the new test, and `uv run devops ci --check --only k8s`, which must accept the template. Both run programs of the runner image, `uv` and `pytest` for the first and `kubectl` for the second, so no program of the plan is NOT_IN_RUNNER and the only failure class that the plan needs is a failed assertion. diff --git a/openspec/changes/4244-hold-the-reference-prices-in-a/tasks.md b/openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/tasks.md similarity index 51% rename from openspec/changes/4244-hold-the-reference-prices-in-a/tasks.md rename to openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/tasks.md index 90da74ecee..eab9db051d 100644 --- a/openspec/changes/4244-hold-the-reference-prices-in-a/tasks.md +++ b/openspec/changes/archive/2026-11-22-4244-hold-the-reference-prices-in-a/tasks.md @@ -1,10 +1,10 @@ # Tasks -## 1. Test both reference prices from the committed ConfigMap template +## 1. Test both reference prices from settings with no override file -Kind: other. Reads: `k8s/devops/configmap.example.yaml`, `src/devops_cli/ai/spend/pricing.py`, `tests/support/paths.py`, `tests/ai/spend/test_hosted_group_prices.py`, `tests/ai/spend/test_pricing_registry_overrides.py`. Changes: `tests/ai/spend/test_pricing_registry_overrides.py`. +Kind: other. Reads: `src/devops_cli/ai/spend/pricing.py`, `tests/ai/spend/test_pricing_registry_overrides.py`. Changes: `tests/ai/spend/test_pricing_registry_overrides.py`. -- [ ] 1.1 Add `test_the_template_prices_both_reference_models_with_no_override_file` to `tests/ai/spend/test_pricing_registry_overrides.py`, and import `yaml` and `REPO_ROOT` there. The test reads `k8s/devops/configmap.example.yaml`, loads the document under the `data` key `devops-cli.yaml` as `Settings`, and builds `PricingRegistry` on `tmp_path` with those settings, so the data directory holds no `pricing_overrides.json`. It replaces `_query_genai_prices` with a function that fails the test, then calls `price_reference` for the chat reference model with `kind="chat"` and for the embedding reference model with `kind="embedding"`, each at `settings.ai.reference_provider`. It asserts 0.035 and 1.50 USD per million tokens for `qwen3.8:27b`, 0.01 and 0.0 for `qwen/qwen3-embedding-8b`, the source `settings:ai.price_overrides`, and an empty `caplog.text`. The test fails at the base because no test prices the reference models from the template +- [x] 1.1 Add `test_the_setting_prices_both_reference_models_with_no_override_file` to `tests/ai/spend/test_pricing_registry_overrides.py`. The test builds `Settings` with `ai.price_overrides` for both reference models, and builds `PricingRegistry` on `tmp_path` with those settings, so the data directory holds no `pricing_overrides.json`. It replaces `_query_genai_prices` with a function that fails the test, then calls `price_reference` for the chat reference model with `kind="chat"` and for the embedding reference model with `kind="embedding"`, each at `settings.ai.reference_provider`. It asserts 0.035 and 1.50 USD per million tokens for `qwen3.8:27b`, 0.01 and 0.0 for `qwen/qwen3-embedding-8b`, the source `settings:ai.price_overrides`, and an empty `caplog.text`. - Verification: `$ uv run devops ci test tests/ai/spend/test_pricing_registry_overrides.py` passes ## Criteria diff --git a/tests/ai/spend/test_pricing_registry_overrides.py b/tests/ai/spend/test_pricing_registry_overrides.py index 04aea25390..aba19a41a9 100644 --- a/tests/ai/spend/test_pricing_registry_overrides.py +++ b/tests/ai/spend/test_pricing_registry_overrides.py @@ -2,7 +2,8 @@ The file `pricing_overrides.json` in the data directory wins over the setting for one model. The setting and the file merge, and `devops ai cost set-price` never copies a price of the setting -into the file. +into the file. The setting holds the price of both reference models, so a new data volume needs +no hand-written file (#4244). """ from __future__ import annotations @@ -183,3 +184,58 @@ def test_the_setting_loads_from_a_mapping_of_the_config_file() -> None: assert settings.ai.price_overrides[CHAT_MODEL] == AIPriceOverride( prompt_usd_per_million=0.035, completion_usd_per_million=1.5 ) + + +def test_the_setting_prices_both_reference_models_with_no_override_file( + tmp_path: Path, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch +) -> None: + """The setting `ai.price_overrides` prices both reference models, so the reports show the + savings of a new data volume that holds no `pricing_overrides.json` (#4244).""" + settings = Settings( + ai=AIConfig( + reference_model=CHAT_MODEL, + reference_embedding_model=EMBEDDING_MODEL, + price_overrides={ + CHAT_MODEL: AIPriceOverride( + prompt_usd_per_million=0.035, completion_usd_per_million=1.5 + ), + EMBEDDING_MODEL: AIPriceOverride( + prompt_usd_per_million=0.01, completion_usd_per_million=0.0 + ), + }, + ) + ) + monkeypatch.setattr( + "devops_cli.ai.spend.pricing._query_genai_prices", + lambda *args, **kwargs: pytest.fail("the setting must price the reference models"), + ) + registry = PricingRegistry(data_dir=tmp_path, settings=settings) + + with caplog.at_level(logging.WARNING): + chat = registry.price_reference( + settings.ai.reference_model, + setting="ai.reference_model", + kind="chat", + provider=settings.ai.reference_provider, + ) + embedding = registry.price_reference( + settings.ai.reference_embedding_model, + setting="ai.reference_embedding_model", + kind="embedding", + provider=settings.ai.reference_provider, + ) + + assert chat is not None, "the setting must price the chat reference model" + assert embedding is not None, "the setting must price the embedding reference model" + assert not (tmp_path / "ai" / "pricing_overrides.json").exists() + assert ( + (settings.ai.reference_model, settings.ai.reference_embedding_model), + (chat.prompt_usd_per_million, chat.completion_usd_per_million, chat.source), + (embedding.prompt_usd_per_million, embedding.completion_usd_per_million, embedding.source), + caplog.text, + ) == ( + (CHAT_MODEL, EMBEDDING_MODEL), + (0.035, 1.5, "settings:ai.price_overrides"), + (0.01, 0.0, "settings:ai.price_overrides"), + "", + )