mvp-ai's picture
download
raw
7.41 kB
from __future__ import annotations
import inspect
import unittest
from aiworkstation_osi.probe import evaluate_probe, run_probe
class PublicContractProbeTests(unittest.TestCase):
def test_live_probe_uses_full_provider_with_selector_task_transport(self) -> None:
source = inspect.getsource(run_probe)
self.assertIn("FullRadarHttpProvider(", source)
self.assertNotIn("AIWorkstationHttpProvider(", source)
def test_complete_sanitized_envelopes_pass(self) -> None:
facts = {
"data": {
"found": True,
"snapshot_id": "snapshot-1",
"project": {"project_id": "owner/repo"},
},
"verified_facts": [{"field": "license"}],
}
license_result = {
"data": {
"license": "Apache-2.0",
"evidence_status": "verified",
"evidence_count": 1,
},
"unknowns": [],
"risks": [{"code": "NOT_LEGAL_ADVICE"}],
}
search = {
"data": {
"evidence_status": "available",
"total": 1,
"snapshot_id": "snapshot-1",
"no_match_reason": "",
"projects": [{"project_id": "owner/repo"}],
"near_matches": [],
"interpreted_constraints": [
{"id": "docker", "value": True, "polarity": "required"},
{"id": "low_code", "value": True, "polarity": "preferred"},
],
"constraint_evaluations": {
"owner/repo": {
"docker": {
"requested_value": True,
"polarity": "required",
"status": "verified-match",
"evidence": [{"source_url": "https://example.test/readme"}],
},
"low_code": {
"requested_value": True,
"polarity": "preferred",
"status": "unknown",
"evidence": [],
},
}
},
}
}
checks = evaluate_probe(facts, license_result, search)
self.assertTrue(all(check["ok"] for check in checks))
def test_formal_candidate_without_verified_hard_constraint_fails(self) -> None:
facts = {
"data": {
"found": True,
"snapshot_id": "snapshot-1",
"project": {"project_id": "owner/repo"},
},
"verified_facts": [{"field": "project_id"}],
}
license_result = {
"data": {"license": None, "evidence_status": "unknown", "evidence_count": 0},
"unknowns": ["Unknown license evidence"],
"risks": [{"code": "NOT_LEGAL_ADVICE"}],
}
search = {
"data": {
"evidence_status": "available",
"total": 1,
"snapshot_id": "snapshot-1",
"no_match_reason": "",
"projects": [{"project_id": "owner/repo"}],
"near_matches": [],
"interpreted_constraints": [
{"id": "docker", "value": True, "polarity": "required"}
],
"constraint_evaluations": {
"owner/repo": {
"docker": {
"requested_value": True,
"polarity": "required",
"status": "partial",
"evidence": [],
}
}
},
}
}
by_id = {check["id"]: check for check in evaluate_probe(facts, license_result, search)}
self.assertFalse(by_id["selector-formal-hard-requirements"]["ok"])
self.assertEqual(
by_id["selector-formal-hard-requirements"]["details"]["violations"],
[{"project_id": "owner/repo", "failed_constraints": ["docker"]}],
)
def test_license_label_without_direct_evidence_fails_probe_boundary(self) -> None:
facts = {
"data": {
"found": True,
"snapshot_id": "snapshot-1",
"project": {"project_id": "owner/repo"},
},
"verified_facts": [{"field": "project_id"}],
}
license_result = {
"data": {
"license": "Apache-2.0",
"evidence_status": "unknown",
"evidence_count": 0,
},
"unknowns": [],
"risks": [{"code": "NOT_LEGAL_ADVICE"}],
}
search = {
"data": {
"evidence_status": "available",
"total": 1,
"snapshot_id": "snapshot-1",
"no_match_reason": "",
}
}
by_id = {check["id"]: check for check in evaluate_probe(facts, license_result, search)}
self.assertFalse(by_id["license-boundary"]["ok"])
self.assertEqual(by_id["license-boundary"]["details"]["evidence_count"], 0)
def test_explicit_unknown_license_is_acceptable_but_missing_search_reason_is_not(self) -> None:
facts = {
"data": {
"found": True,
"snapshot_id": "snapshot-1",
"project": {"project_id": "owner/repo"},
},
"verified_facts": [{"field": "project_id"}],
}
license_result = {
"data": {
"license": None,
"evidence_status": "unknown",
"evidence_count": 0,
},
"unknowns": ["License evidence is unknown."],
"risks": [{"code": "NOT_LEGAL_ADVICE"}, {"code": "LICENSE_UNVERIFIED"}],
}
search = {
"data": {
"evidence_status": "available",
"total": 0,
"snapshot_id": "",
"no_match_reason": "",
}
}
by_id = {check["id"]: check for check in evaluate_probe(facts, license_result, search)}
self.assertTrue(by_id["license-boundary"]["ok"])
self.assertFalse(by_id["selector-honesty"]["ok"])
self.assertTrue(by_id["selector-snapshot"]["ok"])
def test_project_facts_without_snapshot_fail(self) -> None:
facts = {
"data": {"found": True, "snapshot_id": "", "project": {"project_id": "owner/repo"}},
"verified_facts": [],
}
license_result = {
"data": {"license": None, "evidence_status": "unknown", "evidence_count": 0},
"unknowns": ["Unknown license evidence"],
"risks": [{"code": "NOT_LEGAL_ADVICE"}],
}
search = {
"data": {
"evidence_status": "partial",
"notice": "Some sources are unavailable.",
"total": 0,
"no_match_reason": "No complete match.",
}
}
by_id = {check["id"]: check for check in evaluate_probe(facts, license_result, search)}
self.assertFalse(by_id["project-snapshot"]["ok"])
self.assertFalse(by_id["project-evidence"]["ok"])
if __name__ == "__main__":
unittest.main()

Xet Storage Details

Size:
7.41 kB
·
Xet hash:
61d047e7dc36e8a1c2799ddd1fd719fc8dea647e398c93877a821e6d8132dd3e

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.