mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-16 19:59:26 +00:00
Add a [harnessx] config block so the agentic plane can be steered from
openultrasast.toml, and make the LLM provider selectable (the hunter and verifier
previously hardcoded AnthropicProvider).
- config.HarnessxConfig: provider ("anthropic"|"openai"|"litellm", default
anthropic), max_cost_usd (2.0), token_threshold (120000); parsed from [harnessx].
- harness_ext.build_provider: single lazy, capability-guarded provider factory.
The provider name is validated before any import, so an unknown choice fails with
a clear ValueError even when the extra is absent; each provider reads its own
standard key env var (openai -> OPENAI_API_KEY, anthropic -> ANTHROPIC_API_KEY).
- HxScanOrchestrator and verify_findings_dispatch take a provider and route through
build_provider; cli threads config.harnessx.{provider,max_cost_usd,token_threshold}
into both the hunter and the verifier.
- README: "Configuring the HarnessX agentic plane" section (install, models,
provider, budgets, fallback/degradation).
Test isolation: convert the "harnessx not in sys.modules" import-guards to a
hermetic subprocess fixture (tests/conftest.py assert_cold_of_harnessx) and
simulate extra-absent in the CLI dispatch tests, so the suite is deterministic
whether or not the optional extra is installed (it now is, locally). Verified the
OpenAI path constructs end-to-end (build_provider -> OpenAIProvider; orchestrator
-> Harness) with the budget threaded through.
137 passed, 3 skipped; ruff + mypy clean; detection gate PASS.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
from pathlib import Path
|
|
|
|
from openultrasast.config import load_config, write_resolved_config
|
|
|
|
|
|
def test_load_config_reads_toml(tmp_path: Path) -> None:
|
|
config_path = tmp_path / "openultrasast.toml"
|
|
config_path.write_text(
|
|
"\n".join(
|
|
[
|
|
"[models]",
|
|
'ranker = "openrouter/test-ranker"',
|
|
"[sandbox]",
|
|
"memory_mb = 1024",
|
|
"[dynamic]",
|
|
"enabled = true",
|
|
'network_scope = ["127.0.0.1:8080"]',
|
|
]
|
|
)
|
|
)
|
|
|
|
config = load_config(config_path)
|
|
|
|
assert config.models.ranker == "openrouter/test-ranker"
|
|
assert config.embeddings.store == "json-local"
|
|
assert config.sandbox.memory_mb == 1024
|
|
assert config.dynamic.enabled is True
|
|
assert config.dynamic.network_scope == ("127.0.0.1:8080",)
|
|
|
|
|
|
def test_harnessx_defaults_when_section_absent() -> None:
|
|
config = load_config(None)
|
|
assert config.harnessx.provider == "anthropic"
|
|
assert config.harnessx.max_cost_usd == 2.0
|
|
assert config.harnessx.token_threshold == 120_000
|
|
|
|
|
|
def test_load_config_reads_harnessx_section(tmp_path: Path) -> None:
|
|
config_path = tmp_path / "openultrasast.toml"
|
|
config_path.write_text(
|
|
"\n".join(
|
|
[
|
|
"[harnessx]",
|
|
'provider = "openai"',
|
|
"max_cost_usd = 5.0",
|
|
"token_threshold = 200000",
|
|
]
|
|
)
|
|
)
|
|
|
|
config = load_config(config_path)
|
|
|
|
assert config.harnessx.provider == "openai"
|
|
assert config.harnessx.max_cost_usd == 5.0
|
|
assert config.harnessx.token_threshold == 200_000
|
|
|
|
|
|
def test_write_resolved_config_creates_json(tmp_path: Path) -> None:
|
|
output = tmp_path / "run" / "resolved_config.json"
|
|
|
|
write_resolved_config(load_config(None), output)
|
|
|
|
assert output.exists()
|
|
assert '"minimum_report_verified": "static_corroboration"' in output.read_text()
|