Fix short-intent discovery and publish verified browser provider guidance
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a13690-1c84-77a2-aeee-7f517ec60f5d
This commit is contained in:
parent
9042dec5ed
commit
50077c9bea
22 changed files with 736 additions and 87 deletions
|
|
@ -58,6 +58,31 @@ def test_hosted_only_capability_and_provenance_without_local_fallback(monkeypatc
|
|||
assert result["index_source"]["capability_count"] == 1
|
||||
|
||||
|
||||
def test_hosted_browser_discovery_includes_conditional_trial_guidance(monkeypatch, capsys):
|
||||
from reuse_surface.registry import load_index
|
||||
|
||||
browser = next(item for item in load_index()["capabilities"]
|
||||
if item["id"] == "capability.infotech.headless-browser")
|
||||
payload = snapshot()
|
||||
payload["capabilities"] = [
|
||||
{"id": "capability.example.headless", "name": "Headless Knowledge Engine",
|
||||
"summary": "Headless information management", "tags": [],
|
||||
"vector": "D7 / A7 / C6 / R6"},
|
||||
browser,
|
||||
]
|
||||
serve(monkeypatch, payload)
|
||||
assert main(["plan-check", "--intent", "headless browser", "--hub-url",
|
||||
"https://registry.example", "--no-llm", "--format", "json"]) == 0
|
||||
result = json.loads(capsys.readouterr().out)
|
||||
assert result["verdict"] == "reuse"
|
||||
assert result["matches"][0]["id"] == browser["id"]
|
||||
summary = result["matches"][0]["summary"]
|
||||
assert "rapp_playwright.py" in summary
|
||||
assert "preflight" in summary and "trial --out" in summary
|
||||
assert "ephemeral" in summary and "admission is pending" in summary
|
||||
assert "availability gap" in summary
|
||||
|
||||
|
||||
@pytest.mark.parametrize("change", [
|
||||
{"stale": True}, {"stale": None}, {"composed_at": None},
|
||||
{"composed_at": "2020-01-01T00:00:00Z"},
|
||||
|
|
|
|||
|
|
@ -80,6 +80,63 @@ def test_match_query_no_capabilities():
|
|||
assert match_query(query, []) == []
|
||||
|
||||
|
||||
def test_short_browser_intent_outranks_mature_headless_services(monkeypatch):
|
||||
browser = {
|
||||
"id": "capability.infotech.headless-browser",
|
||||
"name": "Headless Browser Automation",
|
||||
"summary": "Playwright Chromium screenshots keyboard " + " ".join(
|
||||
f"detail{i}" for i in range(100)
|
||||
),
|
||||
"vector": "D3 / A2 / C2 / R2",
|
||||
"tags": ["headless", "browser"],
|
||||
}
|
||||
other = {
|
||||
"id": "capability.communication.context-engine",
|
||||
"name": "Context Engine",
|
||||
"summary": "Headless knowledge operations",
|
||||
"vector": "D7 / A7 / C6 / R6",
|
||||
}
|
||||
monkeypatch.setattr(
|
||||
"reuse_surface.plan_check.load_federated_capabilities",
|
||||
lambda: ([other, browser], _recent_date()),
|
||||
)
|
||||
result = run_plan_check(load_query_from_intent("headless browser"), use_llm=False)
|
||||
assert result["verdict"] == "reuse"
|
||||
assert result["matches"][0]["id"] == browser["id"]
|
||||
assert result["matches"][0]["score"] > result["matches"][1]["score"]
|
||||
assert maybe_file_capability_request(
|
||||
result, requesting_domain="infotech", requesting_agent="test"
|
||||
) is None
|
||||
|
||||
# Extra operational documentation must not turn a direct name match into NEW.
|
||||
original_score = result["top_score"]
|
||||
browser["summary"] += " " + " ".join(f"command{i}" for i in range(100))
|
||||
repeated = run_plan_check(load_query_from_intent("headless browser"), use_llm=False)
|
||||
assert repeated["top_score"] == original_score
|
||||
|
||||
|
||||
def test_summary_only_matching_survives_name_scoring():
|
||||
query = load_query_from_intent("responsive screenshots keyboard assertions")
|
||||
matches = match_query(query, [{
|
||||
"id": "capability.infotech.headless-browser",
|
||||
"name": "Browser Automation",
|
||||
"summary": "Responsive screenshots keyboard assertions",
|
||||
}])
|
||||
assert verdict_for_score(matches[0].score) == "reuse"
|
||||
|
||||
|
||||
def test_maturity_still_breaks_equally_relevant_name_ties():
|
||||
candidates = [
|
||||
{"id": "capability.example.early", "name": "Browser Automation",
|
||||
"summary": "Early implementation", "vector": "D2 / A2 / C1 / R1"},
|
||||
{"id": "capability.example.mature", "name": "Browser Automation",
|
||||
"summary": "Documented implementation", "vector": "D4 / A5 / C3 / R3"},
|
||||
]
|
||||
matches = match_query(load_query_from_intent("browser automation"), candidates)
|
||||
assert matches[0].id == "capability.example.mature"
|
||||
assert matches[0].score == matches[1].score
|
||||
|
||||
|
||||
def test_load_query_from_workplan(tmp_path):
|
||||
workplan = tmp_path / "TEST-WP-0001-thing.md"
|
||||
workplan.write_text(
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ from __future__ import annotations
|
|||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from reuse_surface.stats import (
|
||||
collect_roster_stats,
|
||||
collect_stats,
|
||||
|
|
@ -10,19 +12,36 @@ from reuse_surface.stats import (
|
|||
)
|
||||
|
||||
|
||||
def test_collect_stats_on_repo_root():
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
stats = collect_stats(root)
|
||||
@pytest.fixture
|
||||
def stats_repo(tmp_path, monkeypatch):
|
||||
monkeypatch.delenv("REUSE_SURFACE_URL", raising=False)
|
||||
index = tmp_path / "registry/indexes/capabilities.yaml"
|
||||
index.parent.mkdir(parents=True)
|
||||
index.write_text("""version: 1
|
||||
domain: infotech
|
||||
capabilities:
|
||||
- id: capability.example.source
|
||||
vector: D3 / A2 / C2 / R2
|
||||
path: registry/capabilities/source.md
|
||||
- id: capability.example.service
|
||||
vector: D4 / A5 / C3 / R3
|
||||
path: registry/capabilities/service.md
|
||||
""")
|
||||
return tmp_path
|
||||
|
||||
|
||||
def test_collect_stats_on_repo_root(stats_repo):
|
||||
stats = collect_stats(stats_repo)
|
||||
assert stats["capability_count"] == 2
|
||||
assert stats["index_present"] is True
|
||||
assert "discovery" in stats["histograms"]
|
||||
assert stats["histograms"]["discovery"]["D3"] == 1
|
||||
assert stats["histograms"]["discovery"]["D4"] == 1
|
||||
assert stats["reliability"] == {"r0_r2": 1, "r3_plus": 1}
|
||||
|
||||
|
||||
def test_format_stats_markdown_contains_count():
|
||||
root = Path(__file__).resolve().parent.parent
|
||||
text = format_stats_markdown(collect_stats(root))
|
||||
assert "Capabilities:" in text
|
||||
assert "2" in text
|
||||
def test_format_stats_markdown_contains_count(stats_repo):
|
||||
text = format_stats_markdown(collect_stats(stats_repo))
|
||||
assert "**Capabilities:** 2" in text
|
||||
|
||||
|
||||
def test_collect_roster_stats_federation_ready():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue