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
3 changes: 2 additions & 1 deletion .github/workflows/defect-pr-hardening-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ jobs:
Per project invariants (`AGENTS.md`), defect fixes must codify root-cause guardrails into at least one declared surface to prevent recurrent regressions.
EOF
sed -i "s/\${PR_NUMBER}/${PR_NUMBER}/g" "$INTAKE_BODY"
uv run devops roadmap intake --title "fix(hardening): defect PR #${PR_NUMBER} missing declared surface hardening" --body-file "$INTAKE_BODY" --confirm
# The runner has no model credential, so the model-based intake command cannot run here. The issue has no priority label, so the next intake round of the Service places it.
uv run devops gh issues create --repo "$GITHUB_REPOSITORY" --title "fix(hardening): defect PR #${PR_NUMBER} missing declared surface hardening" --body "$(cat "$INTAKE_BODY")" --label source/agent
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

Reads: `src/devops_cli/ai/rag/embeddings.py` (lines 160-190, 862-877, 1021-1050), `src/devops_cli/lang/en/errors.py` (lines 284-300), `tests/ai/rag/test_rag_embeddings.py` (lines 1-37, 79-97, 612-625). Changes: `src/devops_cli/ai/rag/embeddings.py`, `src/devops_cli/lang/en/errors.py`, `tests/ai/rag/test_rag_embeddings.py`.

- [ ] 1.1 Write the failing test `test_ollama_provider_with_no_url_raises_embeddings_error_naming_the_setting` in `tests/ai/rag/test_rag_embeddings.py`, after `test_no_provider_configured_raises_and_caches_nothing`, in the same shape. Build `EmbeddingsEngine(AIConfig(provider="ollama", ollama_urls=[]), valkey_client=mock_valkey)` with the `_MockValkey` of the file, and call `embed_texts(["hello world"])`. Assert that it raises `EmbeddingsError` with the message `Embedding model {engine.model} has no Ollama URL: ai.provider is 'ollama' and ai.ollama_urls is empty. Set ai.ollama_urls`, the details `{"model": engine.model, "provider": "ollama"}`, an empty cache (`engine._cache.size == 0`) and an empty `mock_valkey.store`. And verify that `uv run devops ci test tests/ai/rag/test_rag_embeddings.py -k no_url_raises_embeddings_error` fails on the base: the call raises `ZeroDivisionError`, which `pytest.raises(EmbeddingsError)` does not catch
- [ ] 1.2 Add `embedding_no_ollama_urls` to `RAGErrorMessages` in `src/devops_cli/lang/en/errors.py`, after `embedding_no_provider`, with the text of 1.1. In `_embed_ollama` of `src/devops_cli/ai/rag/embeddings.py`, after `urls = self._get_ollama_urls()`, raise `EmbeddingsError(ERRORS.rag.embedding_no_ollama_urls.format(model=self.model, provider=self.ai_config.provider), details={"model": self.model, "provider": self.ai_config.provider})` when `urls` is empty, before any batch work. Leave `_dispatch_embed` and `embedding_no_provider` as they are. And verify that `uv run devops ci test tests/ai/rag/test_rag_embeddings.py tests/lang/test_language_catalogs.py` passes, with the other tests of the file that use `ollama_urls=[]` still green because they replace `_dispatch_embed`
- [x] 1.1 Write the failing test `test_ollama_provider_with_no_url_raises_embeddings_error_naming_the_setting` in `tests/ai/rag/test_rag_embeddings.py`, after `test_no_provider_configured_raises_and_caches_nothing`, in the same shape. Build `EmbeddingsEngine(AIConfig(provider="ollama", ollama_urls=[]), valkey_client=mock_valkey)` with the `_MockValkey` of the file, and call `embed_texts(["hello world"])`. Assert that it raises `EmbeddingsError` with the message `Embedding model {engine.model} has no Ollama URL: ai.provider is 'ollama' and ai.ollama_urls is empty. Set ai.ollama_urls`, the details `{"model": engine.model, "provider": "ollama"}`, an empty cache (`engine._cache.size == 0`) and an empty `mock_valkey.store`. And verify that `uv run devops ci test tests/ai/rag/test_rag_embeddings.py -k no_url_raises_embeddings_error` fails on the base: the call raises `ZeroDivisionError`, which `pytest.raises(EmbeddingsError)` does not catch
- [x] 1.2 Add `embedding_no_ollama_urls` to `RAGErrorMessages` in `src/devops_cli/lang/en/errors.py`, after `embedding_no_provider`, with the text of 1.1. In `_embed_ollama` of `src/devops_cli/ai/rag/embeddings.py`, after `urls = self._get_ollama_urls()`, raise `EmbeddingsError(ERRORS.rag.embedding_no_ollama_urls.format(model=self.model, provider=self.ai_config.provider), details={"model": self.model, "provider": self.ai_config.provider})` when `urls` is empty, before any batch work. Leave `_dispatch_embed` and `embedding_no_provider` as they are. And verify that `uv run devops ci test tests/ai/rag/test_rag_embeddings.py tests/lang/test_language_catalogs.py` passes, with the other tests of the file that use `ollama_urls=[]` still green because they replace `_dispatch_embed`

## 2. The hardening audit files its finding without a model

Reads: `.github/workflows/defect-pr-hardening-audit.yml`, `tests/invariants/test_workflow_contracts.py` (lines 1-45, 374-456). Changes: `.github/workflows/defect-pr-hardening-audit.yml`, `tests/invariants/test_workflow_contracts.py`.

- [ ] 2.1 The verification of the group is `uv run devops ci test tests/invariants/test_workflow_contracts.py` and `uv run devops ci actionlint`. Both must pass after the group. A third check, `! git grep -n "roadmap intake" -- .github/workflows/defect-pr-hardening-audit.yml`, must print nothing. Make 2.2 and 2.3 in one commit, because the contract test fails between them
- [ ] 2.2 In the step "Hand unhardened defect finding to intake" of `.github/workflows/defect-pr-hardening-audit.yml`, replace the last line (`uv run devops roadmap intake ... --confirm`) with `uv run devops gh issues create --repo "$GITHUB_REPOSITORY" --title "fix(hardening): defect PR #${PR_NUMBER} missing declared surface hardening" --body "$(cat "$INTAKE_BODY")" --label source/agent`. Keep the heredoc and the `sed` line. Add a comment above the command, in these words: `# The runner has no model credential, so the model-based intake command cannot run here. The issue has no priority label, so the next intake round of the Service places it.` The comment must not contain the text `roadmap intake`, because 2.1 and the contract test of 2.3 search the run text for it. Set no priority and no milestone
- [ ] 2.3 In `tests/invariants/test_workflow_contracts.py`, change `assert_audit_workflow_contract`: the failure path must run `devops gh issues create` with `source/agent`, and must not run `devops roadmap intake` or pass a `priority/` label. In the function, replace the `has_intake` check and its message with two checks. The first check needs `devops gh issues create` and `source/agent` in one step run. Its message is `Workflow failure path must file the finding with 'devops gh issues create' and the 'source/agent' label`. The second check needs that no step run contains `devops roadmap intake` or `priority/`. Its message is `Workflow failure path must not run 'devops roadmap intake' or set a priority/ label: the runner has no model`. Change `mutated3` of `test_defect_pr_hardening_audit_workflow_mutation` to replace `gh issues create` with `create_repository_issue` in the step that holds it, and use `match="gh issues create"`. Add a `mutated4` that appends the line `devops roadmap intake` to the run text of that step and use `match="no model"`
- [ ] 2.4 Run the three checks of 2.1 and confirm that they pass
- [x] 2.1 The verification of the group is `uv run devops ci test tests/invariants/test_workflow_contracts.py` and `uv run devops ci actionlint`. Both must pass after the group. A third check, `! git grep -n "roadmap intake" -- .github/workflows/defect-pr-hardening-audit.yml`, must print nothing. Make 2.2 and 2.3 in one commit, because the contract test fails between them
- [x] 2.2 In the step "Hand unhardened defect finding to intake" of `.github/workflows/defect-pr-hardening-audit.yml`, replace the last line (`uv run devops roadmap intake ... --confirm`) with `uv run devops gh issues create --repo "$GITHUB_REPOSITORY" --title "fix(hardening): defect PR #${PR_NUMBER} missing declared surface hardening" --body "$(cat "$INTAKE_BODY")" --label source/agent`. Keep the heredoc and the `sed` line. Add a comment above the command, in these words: `# The runner has no model credential, so the model-based intake command cannot run here. The issue has no priority label, so the next intake round of the Service places it.` The comment must not contain the text `roadmap intake`, because 2.1 and the contract test of 2.3 search the run text for it. Set no priority and no milestone
- [x] 2.3 In `tests/invariants/test_workflow_contracts.py`, change `assert_audit_workflow_contract`: the failure path must run `devops gh issues create` with `source/agent`, and must not run `devops roadmap intake` or pass a `priority/` label. In the function, replace the `has_intake` check and its message with two checks. The first check needs `devops gh issues create` and `source/agent` in one step run. Its message is `Workflow failure path must file the finding with 'devops gh issues create' and the 'source/agent' label`. The second check needs that no step run contains `devops roadmap intake` or `priority/`. Its message is `Workflow failure path must not run 'devops roadmap intake' or set a priority/ label: the runner has no model`. Change `mutated3` of `test_defect_pr_hardening_audit_workflow_mutation` to replace `gh issues create` with `create_repository_issue` in the step that holds it, and use `match="gh issues create"`. Add a `mutated4` that appends the line `devops roadmap intake` to the run text of that step and use `match="no model"`
- [x] 2.4 Run the three checks of 2.1 and confirm that they pass

## Workflow follow-up

Expand Down
7 changes: 7 additions & 0 deletions openspec/specs/configured-service-urls/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,10 @@ The `devops config init` wizard SHALL check typed service URLs at `configured` l
#### Scenario: Config init wizard allows loopback URL without flag
- **WHEN** a user enters a loopback URL in the config init wizard and `ai.allow_private_network` is false
- **THEN** the URL is accepted without error

### Requirement: The embeddings engine stops on a missing Ollama URL
When `ai.provider` is `ollama` and no Ollama URL is configured (`ai.ollama_urls` is empty and `ai.api_base_url` is not set), the embeddings engine SHALL raise an `EmbeddingsError` that names `ai.ollama_urls`. It SHALL NOT raise a `ZeroDivisionError`.

#### Scenario: The Ollama provider with an empty URL list
- **WHEN** `ai.provider` is `ollama`, `ai.ollama_urls` is empty, `ai.api_base_url` is not set, and `embed_texts` gets one text
- **THEN** it raises an `EmbeddingsError` whose message names `ai.ollama_urls`, and it stores no vector in the cache
7 changes: 7 additions & 0 deletions src/devops_cli/ai/rag/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,13 @@ def _embed_batch_with_subdivision(
def _embed_ollama(self, texts: list[str]) -> list[list[float]]:
"""Compute Ollama embeddings with dynamic batch sizing and multi-node distribution."""
urls = self._get_ollama_urls()
if not urls:
raise EmbeddingsError(
ERRORS.rag.embedding_no_ollama_urls.format(
model=self.model, provider=self.ai_config.provider
),
details={"model": self.model, "provider": self.ai_config.provider},
)
chunk_batch_size = max(
DEFAULT_RAG_EMBEDDING_MIN_BATCH_SIZE,
self._current_batch_size,
Expand Down
4 changes: 4 additions & 0 deletions src/devops_cli/lang/en/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ class RAGErrorMessages:
"is not ollama, openai, copilot or gateway, and no Ollama URLs are set. "
"Set ai.tasks.embedding.provider"
)
embedding_no_ollama_urls: str = (
"Embedding model {model} has no Ollama URL: ai.provider is '{provider}' and "
"ai.ollama_urls is empty. Set ai.ollama_urls"
)
batch_failed: str = "Failed to embed batch from '{first_file}' to '{last_file}': {error}"


Expand Down
19 changes: 19 additions & 0 deletions tests/ai/rag/test_rag_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,25 @@ def test_no_provider_configured_raises_and_caches_nothing() -> None:
)


def test_ollama_provider_with_no_url_raises_embeddings_error_naming_the_setting() -> None:
"""With the Ollama provider and no Ollama URL, embedding raises an error that names the setting."""
mock_valkey = _MockValkey()
engine = EmbeddingsEngine(
AIConfig(provider="ollama", ollama_urls=[]), valkey_client=mock_valkey
)

with pytest.raises(EmbeddingsError) as raised:
engine.embed_texts(["hello world"])

assert (raised.value.message, raised.value.details, engine._cache.size, mock_valkey.store) == (
f"Embedding model {engine.model} has no Ollama URL: ai.provider is 'ollama' and "
"ai.ollama_urls is empty. Set ai.ollama_urls",
{"model": engine.model, "provider": "ollama"},
0,
{},
)


def _ollama_engine(monkeypatch: pytest.MonkeyPatch, nodes: list[str]) -> EmbeddingsEngine:
"""An Ollama engine over `nodes`."""
ai_cfg = AIConfig(provider="ollama", ollama_urls=nodes, allow_private_network=True)
Expand Down
24 changes: 17 additions & 7 deletions tests/invariants/test_workflow_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,14 @@ def assert_audit_workflow_contract(workflow: dict[str, Any]) -> None:
"Workflow must execute 'devops pr hardening-report' with '--fail-on-missing'"
)

has_intake = any(
"devops roadmap intake" in run and "create_repository_issue" not in run for run in step_runs
files_issue = any(
"devops gh issues create" in run and "source/agent" in run for run in step_runs
)
assert has_intake, (
"Workflow failure path must hand findings to intake via 'devops roadmap intake' (not create_repository_issue)"
assert files_issue, (
"Workflow failure path must file the finding with 'devops gh issues create' and the 'source/agent' label"
)
assert not any("devops roadmap intake" in run or "priority/" in run for run in step_runs), (
"Workflow failure path must not run 'devops roadmap intake' or set a priority/ label: the runner has no model"
)


Expand Down Expand Up @@ -449,11 +452,18 @@ def test_defect_pr_hardening_audit_workflow_mutation() -> None:

mutated3 = copy.deepcopy(workflow)
for step in mutated3["jobs"]["audit-hardening"]["steps"]:
if "roadmap intake" in step.get("run", ""):
step["run"] = step["run"].replace("roadmap intake", "create_repository_issue")
with pytest.raises(AssertionError, match="intake"):
if "gh issues create" in step.get("run", ""):
step["run"] = step["run"].replace("gh issues create", "create_repository_issue")
with pytest.raises(AssertionError, match="gh issues create"):
assert_audit_workflow_contract(mutated3)

mutated4 = copy.deepcopy(workflow)
for step in mutated4["jobs"]["audit-hardening"]["steps"]:
if "gh issues create" in step.get("run", ""):
step["run"] += "devops roadmap intake\n"
with pytest.raises(AssertionError, match="no model"):
assert_audit_workflow_contract(mutated4)


# ── Every `devops` command the automation runs (#861) ─────────────────────────

Expand Down
Loading