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
Expand Up @@ -4,30 +4,30 @@

Reads: none. Changes: `src/devops_cli/models/vulnerability.py`, `tests/models/test_resource_schemas.py`, `tests/review/test_report.py`, `tests/security/test_osv_scanner.py`, `tests/security/test_reference_report_order.py`, `tests/security/test_vulnerability_lookup.py`, `tests/ai/test_review_finding_losses.py`, `tests/ai/review/test_review_report_summary.py`, `tests/ai/review/test_review_pipeline.py`.

- [ ] 1.1 Write a test in `tests/models/test_resource_schemas.py` that constructs NetworkReference(target='203.0.113.7') without security_status and asserts a pydantic ValidationError is raised. Write a test that constructs PackageLookupResult() without status and asserts a pydantic ValidationError is raised, and verify that `uv run devops ci test tests/models/test_resource_schemas.py` fails on the base
- [ ] 1.2 In `src/devops_cli/models/vulnerability.py`, remove the default from the annotation `security_status: str = "✓ Safe"` of NetworkReference, so that it reads `security_status: str`. Remove the default from the annotation `status: str = "ok" # "ok" | "failed"` of PackageLookupResult in the same file, so that it reads `status: str # "ok" | "failed"`. Both fields are plain annotations, not `Field` calls, so a field with no default is required. Verify that `uv run devops ci test tests/models/test_resource_schemas.py` passes
- [ ] 1.3 Set `security_status="✓ Safe"` (the value that the removed default gave) at each NetworkReference call in these test files that omits it: `tests/review/test_report.py` line 160, `tests/security/test_osv_scanner.py` line 349, `tests/security/test_reference_report_order.py` line 28, `tests/security/test_vulnerability_lookup.py` line 593, `tests/ai/test_review_finding_losses.py` line 47, `tests/ai/review/test_review_report_summary.py` lines 231 and 232, `tests/ai/review/test_review_pipeline.py` lines 782 and 783. These are 9 calls in 7 files. Verify that `uv run devops ci test tests/review/test_report.py tests/security/test_osv_scanner.py tests/security/test_reference_report_order.py tests/ai/test_review_finding_losses.py tests/ai/review/test_review_report_summary.py tests/ai/review/test_review_pipeline.py` passes
- [ ] 1.4 Rewrite `test_package_lookup_result_defaults` in `tests/security/test_vulnerability_lookup.py`. Its call at line 717 omits status, and the test asserts the removed default "ok". Build `PackageLookupResult(status="ok")` and assert that vulnerabilities is `[]` and reason is `""`. Rename the test to `test_package_lookup_result_list_and_reason_defaults`. Verify that `uv run devops ci test tests/security/test_vulnerability_lookup.py` passes
- [ ] 1.5 Run `grep -rlE "NetworkReference\(|PackageLookupResult\(" tests` and check that every test file it lists is in the next command. A test call that still omits a required field fails with a ValidationError. Verify that `uv run devops ci test tests/models/test_resource_schemas.py tests/review/test_report.py tests/security/test_osv_scanner.py tests/security/test_reference_report_order.py tests/security/test_vulnerability_lookup.py tests/security/test_builtin_tools.py tests/ai/test_review_finding_losses.py tests/ai/review/test_review_report_summary.py tests/ai/review/test_review_pipeline.py tests/ai/review/test_review_runner.py tests/ai/review/test_review_admission.py tests/ai/review/test_review_console_report.py` passes
- [x] 1.1 Write a test in `tests/models/test_resource_schemas.py` that constructs NetworkReference(target='203.0.113.7') without security_status and asserts a pydantic ValidationError is raised. Write a test that constructs PackageLookupResult() without status and asserts a pydantic ValidationError is raised, and verify that `uv run devops ci test tests/models/test_resource_schemas.py` fails on the base
- [x] 1.2 In `src/devops_cli/models/vulnerability.py`, remove the default from the annotation `security_status: str = "✓ Safe"` of NetworkReference, so that it reads `security_status: str`. Remove the default from the annotation `status: str = "ok" # "ok" | "failed"` of PackageLookupResult in the same file, so that it reads `status: str # "ok" | "failed"`. Both fields are plain annotations, not `Field` calls, so a field with no default is required. Verify that `uv run devops ci test tests/models/test_resource_schemas.py` passes
- [x] 1.3 Set `security_status="✓ Safe"` (the value that the removed default gave) at each NetworkReference call in these test files that omits it: `tests/review/test_report.py` line 160, `tests/security/test_osv_scanner.py` line 349, `tests/security/test_reference_report_order.py` line 28, `tests/security/test_vulnerability_lookup.py` line 593, `tests/ai/test_review_finding_losses.py` line 47, `tests/ai/review/test_review_report_summary.py` lines 231 and 232, `tests/ai/review/test_review_pipeline.py` lines 782 and 783. These are 9 calls in 7 files. Verify that `uv run devops ci test tests/review/test_report.py tests/security/test_osv_scanner.py tests/security/test_reference_report_order.py tests/ai/test_review_finding_losses.py tests/ai/review/test_review_report_summary.py tests/ai/review/test_review_pipeline.py` passes
- [x] 1.4 Rewrite `test_package_lookup_result_defaults` in `tests/security/test_vulnerability_lookup.py`. Its call at line 717 omits status, and the test asserts the removed default "ok". Build `PackageLookupResult(status="ok")` and assert that vulnerabilities is `[]` and reason is `""`. Rename the test to `test_package_lookup_result_list_and_reason_defaults`. Verify that `uv run devops ci test tests/security/test_vulnerability_lookup.py` passes
- [x] 1.5 Run `grep -rlE "NetworkReference\(|PackageLookupResult\(" tests` and check that every test file it lists is in the next command. A test call that still omits a required field fails with a ValidationError. Verify that `uv run devops ci test tests/models/test_resource_schemas.py tests/review/test_report.py tests/security/test_osv_scanner.py tests/security/test_reference_report_order.py tests/security/test_vulnerability_lookup.py tests/security/test_builtin_tools.py tests/ai/test_review_finding_losses.py tests/ai/review/test_review_report_summary.py tests/ai/review/test_review_pipeline.py tests/ai/review/test_review_runner.py tests/ai/review/test_review_admission.py tests/ai/review/test_review_console_report.py` passes

## 2. Remove test references to deleted models

Reads: none. Changes: `tests/models/test_resource_schemas.py`.

- [ ] 2.1 In `tests/models/test_resource_schemas.py`, remove `NetworkIntelResult` and `PackageIntelResult` from the import list of `devops_cli.models.security` (lines 80 and 82 on `main`). In `test_security_resource_models_roundtrip`, remove the statement `pkg_res = PackageIntelResult(...)` and the line `assert pkg_res.is_vulnerable is False` after it (lines 270 to 277). Remove the statement `net_res = NetworkIntelResult(...)` and the line `assert net_res.is_malicious is False` after it (lines 281 to 289). Keep every other line of the test, including the `PackageIntelRequest` and `NetworkIntelRequest` checks. Verify that `uv run devops ci test tests/models/test_resource_schemas.py` passes
- [x] 2.1 In `tests/models/test_resource_schemas.py`, remove `NetworkIntelResult` and `PackageIntelResult` from the import list of `devops_cli.models.security` (lines 80 and 82 on `main`). In `test_security_resource_models_roundtrip`, remove the statement `pkg_res = PackageIntelResult(...)` and the line `assert pkg_res.is_vulnerable is False` after it (lines 270 to 277). Remove the statement `net_res = NetworkIntelResult(...)` and the line `assert net_res.is_malicious is False` after it (lines 281 to 289). Keep every other line of the test, including the `PackageIntelRequest` and `NetworkIntelRequest` checks. Verify that `uv run devops ci test tests/models/test_resource_schemas.py` passes

## 3. Remove NetworkIntelResult and PackageIntelResult

Reads: none. Changes: `src/devops_cli/models/security.py`, `src/devops_cli/models/__init__.py`.

- [ ] 3.1 Write a test in `tests/models/test_resource_schemas.py` that asserts importing NetworkIntelResult from devops_cli.models raises ImportError. Write a test that asserts importing PackageIntelResult from devops_cli.models raises ImportError. Write a test that asserts neither name is in `devops_cli.models.__all__`, and verify that `uv run devops ci test tests/models/test_resource_schemas.py` fails on the base
- [ ] 3.2 Delete the NetworkIntelResult class from `src/devops_cli/models/security.py`. Delete the PackageIntelResult class from `src/devops_cli/models/security.py`. Remove both names from the import list in `src/devops_cli/models/__init__.py`. Remove both names from the __all__ list in `src/devops_cli/models/__init__.py` (lines 247 and 251 on `main`), and verify that `uv run devops ci test tests/models/test_resource_schemas.py` passes
- [x] 3.1 Write a test in `tests/models/test_resource_schemas.py` that asserts importing NetworkIntelResult from devops_cli.models raises ImportError. Write a test that asserts importing PackageIntelResult from devops_cli.models raises ImportError. Write a test that asserts neither name is in `devops_cli.models.__all__`, and verify that `uv run devops ci test tests/models/test_resource_schemas.py` fails on the base
- [x] 3.2 Delete the NetworkIntelResult class from `src/devops_cli/models/security.py`. Delete the PackageIntelResult class from `src/devops_cli/models/security.py`. Remove both names from the import list in `src/devops_cli/models/__init__.py`. Remove both names from the __all__ list in `src/devops_cli/models/__init__.py` (lines 247 and 251 on `main`), and verify that `uv run devops ci test tests/models/test_resource_schemas.py` passes

## 4. Archive

Reads: none. Changes: `openspec/changes/`.

- [ ] 4.1 In the last commit, archive the change with `uv run devops openspec archive 2636-a-result-that-no-lookup-marked`, and verify that `uv run devops openspec check` passes
- [x] 4.1 In the last commit, archive the change with `uv run devops openspec archive 2636-a-result-that-no-lookup-marked`, and verify that `uv run devops openspec check` passes

## Workflow follow-up

Expand Down
25 changes: 25 additions & 0 deletions openspec/specs/threat-intel-lookup-outcome/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,28 @@ The table of network references SHALL color a status red when it holds the warni
#### Scenario: A flagged reference
- **WHEN** the table is built for a reference with the status "⚠️ Flagged (known botnet)" and for one with the status "High Risk"
- **THEN** both status cells are wrapped in "[red]" and "[/red]"

### Requirement: NetworkReference security_status is required
NetworkReference.security_status SHALL have no default value.

#### Scenario: Construct without security_status
- **WHEN** A producer constructs NetworkReference without setting security_status
- **THEN** Pydantic raises a ValidationError

### Requirement: PackageLookupResult status is required
PackageLookupResult.status SHALL have no default value.

#### Scenario: Construct without status
- **WHEN** A producer constructs PackageLookupResult without setting status
- **THEN** Pydantic raises a ValidationError

### Requirement: No intel result model defaults to a clean status
The models package SHALL NOT offer a result model whose fields default to a clean security status. NetworkIntelResult and PackageIntelResult SHALL NOT be importable from devops_cli.models and SHALL NOT be listed in devops_cli.models.__all__.

#### Scenario: Import a removed intel result model
- **WHEN** A consumer attempts to import NetworkIntelResult or PackageIntelResult from devops_cli.models
- **THEN** The import raises ImportError

#### Scenario: Read the exports
- **WHEN** A consumer reads devops_cli.models.__all__
- **THEN** The list contains neither NetworkIntelResult nor PackageIntelResult
4 changes: 0 additions & 4 deletions src/devops_cli/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@
from devops_cli.models.prometheus import PrometheusQueryResult, PrometheusSeries
from devops_cli.models.security import (
NetworkIntelRequest,
NetworkIntelResult,
PackageIntelRequest,
PackageIntelResult,
SecurityScanRequest,
SecurityScanResult,
SSHKeyAuditRequest,
Expand Down Expand Up @@ -244,11 +242,9 @@
"ManagedSSHKey",
"ModelBenchmarkSummary",
"NetworkIntelRequest",
"NetworkIntelResult",
"NetworkReference",
"NetworkReputationRecord",
"PackageIntelRequest",
"PackageIntelResult",
"PackageLookupResult",
"PeerGrade",
"PodInfo",
Expand Down
29 changes: 0 additions & 29 deletions src/devops_cli/models/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from __future__ import annotations

from typing import Any

from pydantic import BaseModel, Field


Expand Down Expand Up @@ -57,39 +55,12 @@ class PackageIntelRequest(BaseModel):
ecosystem: str = Field(default="PyPI", description="Package ecosystem (PyPI, npm, Go, Maven)")


class PackageIntelResult(BaseModel):
"""Vulnerability and threat intelligence lookup result for a package."""

package_name: str = Field(..., description="Queried package name")
version: str = Field(default="", description="Queried package version")
ecosystem: str = Field(default="PyPI", description="Package ecosystem")
is_vulnerable: bool = Field(default=False, description="Whether known CVEs or advisories exist")
vulnerabilities_count: int = Field(default=0, description="Total count of matching advisories")
advisories: list[dict[str, Any]] = Field(
default_factory=list, description="Detailed advisory records from OSV"
)
security_status: str = Field(default="Clean", description="High-level security evaluation")


class NetworkIntelRequest(BaseModel):
"""Request parameters for querying network target threat intelligence."""

target: str = Field(..., description="IP address, domain name, or URL endpoint")


class NetworkIntelResult(BaseModel):
"""Threat intelligence and reputation report for a network target."""

target: str = Field(..., description="Target IP or hostname queried")
target_type: str = Field(default="domain", description="Target classification (ip | domain)")
is_malicious: bool = Field(default=False, description="Whether target is flagged as malicious")
risk_level: str = Field(default="LOW", description="Evaluated risk level")
open_ports: list[int] = Field(default_factory=list, description="Discovered open ports")
reputation_summary: str = Field(
default="Safe", description="High-level reputation summary from Shodan/Cloudflare"
)


class UvAuditRequest(BaseModel):
"""Request parameters for running uv package dependency audit."""

Expand Down
6 changes: 4 additions & 2 deletions src/devops_cli/models/vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def location(self) -> str:


class PackageLookupResult(BaseModel):
status: str = "ok" # "ok" | "failed"
# No default: a lookup result nobody marked must never read as ok (#2636).
status: str # "ok" | "failed"
vulnerabilities: list[VulnerabilityRecord] = Field(default_factory=list)
# Why a failed lookup failed: OSV's status code or the request's error.
reason: str = ""
Expand All @@ -76,7 +77,8 @@ class NetworkReference(BaseModel):
reference_type: str = "url" # url | ip
source_file: str = ""
line_number: int | None = None
security_status: str = "✓ Safe"
# No default: a reference nobody checked must never read as safe (#2636).
security_status: str
is_local: bool = False
is_example: bool = False
scope: str = "external" # external | local
Expand Down
9 changes: 7 additions & 2 deletions tests/ai/review/test_review_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,14 @@ def test_review_pipeline_dependency_and_network_auditing() -> None:
)

# 3. Audit network references
net_clean = NetworkReference(target="127.0.0.1", reference_type="ip", is_local=True)
net_clean = NetworkReference(
target="127.0.0.1", reference_type="ip", is_local=True, security_status="✓ Safe"
)
net_mal = NetworkReference(
target="https://malicious-site.cc", reference_type="url", is_local=False
target="https://malicious-site.cc",
reference_type="url",
is_local=False,
security_status="✓ Safe",
)
net_cache = {
"https://malicious-site.cc": NetworkReputationRecord(
Expand Down
11 changes: 9 additions & 2 deletions tests/ai/review/test_review_report_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,15 @@ def test_network_references_states_counts() -> None:
from devops_cli.models.vulnerability import NetworkReference

nets = [
NetworkReference(target="127.0.0.1", reference_type="ip", is_local=True),
NetworkReference(target="https://example.com", reference_type="url", is_local=False),
NetworkReference(
target="127.0.0.1", reference_type="ip", is_local=True, security_status="✓ Safe"
),
NetworkReference(
target="https://example.com",
reference_type="url",
is_local=False,
security_status="✓ Safe",
),
]
report_md = render_markdown(
make_report_input(
Expand Down
4 changes: 3 additions & 1 deletion tests/ai/test_review_finding_losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def test_threat_intel_network_findings_start_unverified() -> None:
"""Verify a host with published CVEs is left for verification, not reported as verified."""
finding = _build_malicious_network_finding(
"README.md",
NetworkReference(target="203.0.113.7", reference_type="ip", line_number=4),
NetworkReference(
target="203.0.113.7", reference_type="ip", line_number=4, security_status="✓ Safe"
),
NetworkReputationRecord(
target="203.0.113.7", ip="203.0.113.7", is_malicious=True, outcome="ok"
),
Expand Down
50 changes: 31 additions & 19 deletions tests/models/test_resource_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

from __future__ import annotations

import pytest
from pydantic import ValidationError

from devops_cli import models
from devops_cli.models.ai import (
ExportFeedbackRequest,
Expand Down Expand Up @@ -77,9 +80,7 @@
)
from devops_cli.models.security import (
NetworkIntelRequest,
NetworkIntelResult,
PackageIntelRequest,
PackageIntelResult,
SecurityScanRequest,
SecurityScanResult,
SSHKeyAuditRequest,
Expand All @@ -99,6 +100,10 @@
TFPlanRequest,
TFPlanResult,
)
from devops_cli.models.vulnerability import (
NetworkReference,
PackageLookupResult,
)
from devops_cli.models.workspace import (
WorkspaceCleanRequest,
WorkspaceCleanResult,
Expand Down Expand Up @@ -267,26 +272,9 @@ def test_security_resource_models_roundtrip() -> None:

pkg_req = PackageIntelRequest(package_name="requests", version="2.25.0")
assert pkg_req.package_name == "requests"
pkg_res = PackageIntelResult(
package_name="requests",
version="2.25.0",
ecosystem="PyPI",
is_vulnerable=False,
security_status="Clean",
)
assert pkg_res.is_vulnerable is False

net_req = NetworkIntelRequest(target="example.com")
assert net_req.target == "example.com"
net_res = NetworkIntelResult(
target="example.com",
target_type="domain",
is_malicious=False,
risk_level="LOW",
open_ports=[80, 443],
reputation_summary="Clean Domain",
)
assert net_res.is_malicious is False

uv_req = UvAuditRequest(project_dir=".")
assert uv_req.project_dir == "."
Expand Down Expand Up @@ -595,3 +583,27 @@ def test_domain_model_registry_completeness() -> None:
for m in expected_models:
assert m in exported, f"Missing {m} in models.__all__"
assert hasattr(models, m), f"Missing attribute {m} on models package"


def test_vulnerability_result_fields_are_required() -> None:
"""A result that no lookup marked has no clean default, so a missing field raises (#2636)."""
with pytest.raises(ValidationError) as network_raised:
NetworkReference(target="203.0.113.7")
assert "security_status" in str(network_raised.value)

with pytest.raises(ValidationError) as lookup_raised:
PackageLookupResult()
assert "status" in str(lookup_raised.value)


def test_removed_intel_result_models_are_not_exported() -> None:
"""NetworkIntelResult and PackageIntelResult are removed from the models package (#2636)."""
assert "NetworkIntelResult" not in models.__all__
assert "PackageIntelResult" not in models.__all__
with pytest.raises(ImportError) as network_import:
from devops_cli.models import NetworkIntelResult # noqa: F401
assert "NetworkIntelResult" in str(network_import.value)

with pytest.raises(ImportError) as package_import:
from devops_cli.models import PackageIntelResult # noqa: F401
assert "PackageIntelResult" in str(package_import.value)
Loading
Loading