This commit is contained in:
Samir Hanna Verza 2026-10-14 13:04:11 +00:00 • committed by GitHub
commit 9395a8dbf6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 122 additions and 7 deletions

View file

@ -45,6 +45,7 @@ from strix.core.inputs import (
)
from strix.core.paths import run_dir_for, runtime_state_dir
from strix.core.sessions import open_agent_session
from strix.core.targets import is_whitebox_scan
from strix.report.state import get_global_report_state
from strix.runtime import session_manager
from strix.telemetry import set_scan_phase
@ -389,7 +390,7 @@ async def run_strix_scan(
try:
targets = scan_config.get("targets") or []
scan_mode = str(scan_config.get("scan_mode") or "deep")
is_whitebox = any(t.get("type") == "local_code" for t in targets)
is_whitebox = is_whitebox_scan(targets)
diff_scope = scan_config.get("diff_scope")
is_diff_scoped = bool(isinstance(diff_scope, dict) and diff_scope.get("active"))
skills = list(scan_config.get("skills") or [])

26
strix/core/targets.py Normal file
View file

@ -0,0 +1,26 @@
"""Helpers that read the resolved scan targets.
Kept free of heavy imports on purpose: the interface layer needs them before the
agents SDK may be imported.
"""
from __future__ import annotations
from typing import Any
def is_whitebox_scan(targets_info: list[dict[str, Any]] | None) -> bool:
"""True when any target puts source code in front of the agent (a source-aware scan).
That is a local directory, and also a repository that was cloned for the scan: both
end up in the sandbox workspace, as ``collect_local_sources`` in
``strix.interface.utils`` collects them. A repository that was not cloned has no
source to read, so it does not count.
"""
for target in targets_info or []:
target_type = target.get("type")
if target_type == "local_code":
return True
if target_type == "repository" and (target.get("details") or {}).get("cloned_repo_path"):
return True
return False

View file

@ -17,6 +17,7 @@ from typing import TYPE_CHECKING, Any
from strix.config import Settings, codex, load_settings
from strix.core.paths import run_dir_for
from strix.core.targets import is_whitebox_scan
from strix.interface.utils import (
assign_workspace_subdirs,
clone_repository,
@ -25,7 +26,6 @@ from strix.interface.utils import (
derive_local_base_name,
generate_run_name,
infer_target_type,
is_whitebox_scan,
read_target_list_file,
resolve_diff_scope_context,
rewrite_localhost_targets,

View file

@ -1305,11 +1305,6 @@ def assign_workspace_subdirs(targets_info: list[dict[str, Any]]) -> None:
details["workspace_subdir"] = workspace_subdir
def is_whitebox_scan(targets_info: list[dict[str, Any]]) -> bool:
"""True iff any target is a local source tree (whitebox / source-aware)."""
return any(t.get("type") == "local_code" for t in targets_info or [])
def collect_local_sources(targets_info: list[dict[str, Any]]) -> list[dict[str, Any]]:
local_sources: list[dict[str, Any]] = []

View file

@ -200,6 +200,52 @@ async def test_root_prompt_options_default_to_none(
assert kwargs["system_prompt_context"] == {"scope": "built-in"}
@pytest.mark.asyncio
@pytest.mark.parametrize(
("targets", "expected"),
[
pytest.param(
[{"type": "repository", "details": {"cloned_repo_path": "/work/clones/repo"}}],
True,
id="cloned-repository",
),
pytest.param(
[
{"type": "web_application", "details": {}},
{"type": "repository", "details": {"cloned_repo_path": "/work/clones/repo"}},
],
True,
id="repository-beside-a-domain",
),
pytest.param(
[{"type": "local_code", "details": {"target_path": "/src/app"}}],
True,
id="local-directory",
),
pytest.param([{"type": "web_application", "details": {}}], False, id="web-only"),
],
)
async def test_root_agent_is_whitebox_when_source_is_in_the_workspace(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Any,
targets: list[dict[str, Any]],
*,
expected: bool,
) -> None:
"""A cloned repository is source-aware like a local directory, so the root agent gets
the source-aware skills; the runner used to look at ``local_code`` targets only."""
captured = _patch_engine_scaffold(monkeypatch, tmp_path, {"scope": "built-in"})
await runner.run_strix_scan(
scan_config={"targets": targets, "scan_mode": "deep"},
scan_id="scan-whitebox",
image="img",
coordinator=AgentCoordinator(),
)
assert captured["kwargs"]["is_whitebox"] is expected
@pytest.mark.asyncio
async def test_mcp_available_flag_set_when_a_connection_attaches(
monkeypatch: pytest.MonkeyPatch,

View file

@ -0,0 +1,47 @@
"""Which scans count as source-aware (white-box)."""
from __future__ import annotations
from typing import Any
import pytest
from strix.core.targets import is_whitebox_scan
def _web() -> dict[str, Any]:
return {"type": "web_application", "details": {"target_url": "https://app.example"}}
def _local() -> dict[str, Any]:
return {"type": "local_code", "details": {"target_path": "/src/app"}}
def _repo(*, cloned: bool = True) -> dict[str, Any]:
details: dict[str, Any] = {"target_repo": "https://github.com/org/repo"}
if cloned:
details["cloned_repo_path"] = "/work/clones/repo"
return {"type": "repository", "details": details}
@pytest.mark.parametrize(
("targets", "expected"),
[
pytest.param([], False, id="no-targets"),
pytest.param(None, False, id="targets-missing"),
pytest.param([_web()], False, id="web-only"),
pytest.param([_local()], True, id="local-directory"),
pytest.param([_repo()], True, id="cloned-repository"),
pytest.param([_repo(cloned=False)], False, id="repository-that-was-not-cloned"),
pytest.param([_repo(), _web()], True, id="repository-beside-a-domain"),
pytest.param([_web(), _repo()], True, id="domain-before-repository"),
],
)
def test_source_in_front_of_the_agent_makes_the_scan_whitebox(
targets: list[dict[str, Any]] | None, *, expected: bool
) -> None:
assert is_whitebox_scan(targets) is expected
def test_a_target_without_details_does_not_break_the_check() -> None:
assert is_whitebox_scan([{"type": "repository"}]) is False