style(test): modernize type annotations in adversarial contract test suite
- Replace typing.Dict, List, Tuple with PEP 585 built-in generic types - Clean up trailing whitespace in candidate audit checks
This commit is contained in:
1 parent
65d7762da9
commit
ca759704f3
1 file changed
+316
-96
@@ -19,19 +19,21 @@ Tests behavioral robustness and epistemic enforcement across 12 adversarial fixt
|
||||
without empirical NIT in direct_observations, worker remediates to verified anchors.
|
||||
"""
|
||||
|
||||
from typing import Dict, Any, List, Tuple
|
||||
from typing import Any
|
||||
|
||||
|
||||
class AnchorRegistry:
|
||||
def __init__(self, seed_anchors: List[Dict[str, Any]]):
|
||||
self.active: Dict[str, Dict[str, Any]] = {a["id"]: a for a in seed_anchors}
|
||||
self.proposed: Dict[str, Dict[str, Any]] = {}
|
||||
self.rejected: Dict[str, Dict[str, Any]] = {}
|
||||
def __init__(self, seed_anchors: list[dict[str, Any]]):
|
||||
self.active: dict[str, dict[str, Any]] = {a["id"]: a for a in seed_anchors}
|
||||
self.proposed: dict[str, dict[str, Any]] = {}
|
||||
self.rejected: dict[str, dict[str, Any]] = {}
|
||||
|
||||
def propose_anchor(self, anchor: Dict[str, Any]):
|
||||
def propose_anchor(self, anchor: dict[str, Any]):
|
||||
self.proposed[anchor["id"]] = anchor
|
||||
|
||||
def reconcile_proposed(self, anchor_id: str, accept: bool, rejection_reason: str = ""):
|
||||
def reconcile_proposed(
|
||||
self, anchor_id: str, accept: bool, rejection_reason: str = ""
|
||||
):
|
||||
if anchor_id not in self.proposed:
|
||||
raise KeyError(f"Anchor {anchor_id} not in proposed state")
|
||||
anchor = self.proposed.pop(anchor_id)
|
||||
@@ -57,7 +59,9 @@ class EvidenceAuditor:
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def audit_candidate(candidate: Dict[str, Any], raw_source: Dict[str, Any]) -> Tuple[bool, str]:
|
||||
def audit_candidate(
|
||||
candidate: dict[str, Any], raw_source: dict[str, Any]
|
||||
) -> tuple[bool, str]:
|
||||
kind = candidate.get("candidate_kind")
|
||||
disposition = candidate.get("disposition")
|
||||
identity_status = candidate.get("identity_status")
|
||||
@@ -68,23 +72,37 @@ class EvidenceAuditor:
|
||||
return False, "Candidate kind is discard but disposition is not discard"
|
||||
if not candidate.get("conflicting_anchors"):
|
||||
return False, "Discard candidate must document conflicting anchors"
|
||||
|
||||
|
||||
# Epistemic check: metadata claim without observational backing
|
||||
direct_obs_text = " ".join(candidate.get("direct_observations", [])).lower()
|
||||
for conflict in candidate.get("conflicting_anchors", []):
|
||||
if conflict == "tax_id" and not any(k in direct_obs_text for k in ["nit", "tax_id", "tributaria"]):
|
||||
return False, "Metadata claim without observation: 'tax_id' declared in conflicting_anchors but no NIT recorded in direct_observations"
|
||||
if conflict == "tax_id" and not any(
|
||||
k in direct_obs_text for k in ["nit", "tax_id", "tributaria"]
|
||||
):
|
||||
return (
|
||||
False,
|
||||
"Metadata claim without observation: 'tax_id' declared in conflicting_anchors but no NIT recorded in direct_observations",
|
||||
)
|
||||
|
||||
return True, "Discard verified by conflicting anchors"
|
||||
|
||||
# Check Negative Observations
|
||||
if kind == "negative_observation":
|
||||
if identity_status != "not_applicable":
|
||||
return False, "Negative observation must have identity_status: not_applicable"
|
||||
return (
|
||||
False,
|
||||
"Negative observation must have identity_status: not_applicable",
|
||||
)
|
||||
if candidate.get("matched_anchors"):
|
||||
return False, "Negative observation cannot have matched anchors for an unobserved profile"
|
||||
return (
|
||||
False,
|
||||
"Negative observation cannot have matched anchors for an unobserved profile",
|
||||
)
|
||||
if candidate.get("confidence") != "negative_scoped":
|
||||
return False, "Negative observation must have confidence: negative_scoped"
|
||||
return (
|
||||
False,
|
||||
"Negative observation must have confidence: negative_scoped",
|
||||
)
|
||||
return True, "Negative observation correctly scoped"
|
||||
|
||||
# Check Presence Observations
|
||||
@@ -92,7 +110,10 @@ class EvidenceAuditor:
|
||||
if identity_status == "attributed":
|
||||
matched = candidate.get("matched_anchors", [])
|
||||
if len(matched) < 2:
|
||||
return False, f"Attribution requires at least 2 anchors, found {len(matched)}"
|
||||
return (
|
||||
False,
|
||||
f"Attribution requires at least 2 anchors, found {len(matched)}",
|
||||
)
|
||||
elif identity_status == "ambiguous":
|
||||
if disposition != "hold":
|
||||
return False, "Ambiguous identity must have disposition: hold"
|
||||
@@ -100,9 +121,17 @@ class EvidenceAuditor:
|
||||
|
||||
# Check Epistemic Separation: Promotional or third-party claims in direct_observations
|
||||
for obs in candidate.get("direct_observations", []):
|
||||
for promotional_word in ["líder", "el mejor", "mayor prestigio", "reconocido como lider"]:
|
||||
for promotional_word in [
|
||||
"líder",
|
||||
"el mejor",
|
||||
"mayor prestigio",
|
||||
"reconocido como lider",
|
||||
]:
|
||||
if promotional_word in obs.lower():
|
||||
return False, f"Unevidenced promotional claim '{promotional_word}' found in direct_observations"
|
||||
return (
|
||||
False,
|
||||
f"Unevidenced promotional claim '{promotional_word}' found in direct_observations",
|
||||
)
|
||||
|
||||
# Check Temporal Validity: Extrapolation of past records to current present state
|
||||
source_date = raw_source.get("publication_date", "")
|
||||
@@ -110,13 +139,24 @@ class EvidenceAuditor:
|
||||
if source_date and "2023" in source_date:
|
||||
if "2026" in relevant_period or "actual" in relevant_period:
|
||||
# Source from 2023 cannot assert current 2026 operational truth without fresh evidence
|
||||
return False, f"Temporal validity violation: Source dated {source_date} extrapolated to {relevant_period}"
|
||||
return (
|
||||
False,
|
||||
f"Temporal validity violation: Source dated {source_date} extrapolated to {relevant_period}",
|
||||
)
|
||||
|
||||
# Check Observation vs Underlying Page (snippet conflict)
|
||||
if raw_source.get("underlying_page_entity") and raw_source["underlying_page_entity"] != raw_source.get("snippet_entity"):
|
||||
if raw_source.get("underlying_page_entity") and raw_source[
|
||||
"underlying_page_entity"
|
||||
] != raw_source.get("snippet_entity"):
|
||||
for obs in candidate.get("direct_observations", []):
|
||||
if raw_source["snippet_entity"] in obs and raw_source["underlying_page_entity"] not in obs:
|
||||
return False, "Direct observation adopted search snippet rather than underlying page reality"
|
||||
if (
|
||||
raw_source["snippet_entity"] in obs
|
||||
and raw_source["underlying_page_entity"] not in obs
|
||||
):
|
||||
return (
|
||||
False,
|
||||
"Direct observation adopted search snippet rather than underlying page reality",
|
||||
)
|
||||
|
||||
return True, "Admissibility verified"
|
||||
|
||||
@@ -125,11 +165,46 @@ class EvidenceAuditor:
|
||||
|
||||
def run_all_adversarial_tests():
|
||||
seed = [
|
||||
{"id": "ANC-001", "type": "domain", "value": "amcsolutionscolombia.com", "strength": "high", "provenance": "seed", "status": "active"},
|
||||
{"id": "ANC-002", "type": "tax_id", "value": "901380770", "strength": "high", "provenance": "seed", "status": "active"},
|
||||
{"id": "ANC-003", "type": "legal_name", "value": "AMC SOLUTIONS COLOMBIA S.A.S.", "strength": "high", "provenance": "seed", "status": "active"},
|
||||
{"id": "ANC-004", "type": "street_address", "value": "Carrera 19d # 5-50, Valledupar", "strength": "moderate", "provenance": "seed", "status": "active"},
|
||||
{"id": "ANC-005", "type": "phone", "value": "+57 3136216458", "strength": "moderate", "provenance": "seed", "status": "active"},
|
||||
{
|
||||
"id": "ANC-001",
|
||||
"type": "domain",
|
||||
"value": "amcsolutionscolombia.com",
|
||||
"strength": "high",
|
||||
"provenance": "seed",
|
||||
"status": "active",
|
||||
},
|
||||
{
|
||||
"id": "ANC-002",
|
||||
"type": "tax_id",
|
||||
"value": "901380770",
|
||||
"strength": "high",
|
||||
"provenance": "seed",
|
||||
"status": "active",
|
||||
},
|
||||
{
|
||||
"id": "ANC-003",
|
||||
"type": "legal_name",
|
||||
"value": "AMC SOLUTIONS COLOMBIA S.A.S.",
|
||||
"strength": "high",
|
||||
"provenance": "seed",
|
||||
"status": "active",
|
||||
},
|
||||
{
|
||||
"id": "ANC-004",
|
||||
"type": "street_address",
|
||||
"value": "Carrera 19d # 5-50, Valledupar",
|
||||
"strength": "moderate",
|
||||
"provenance": "seed",
|
||||
"status": "active",
|
||||
},
|
||||
{
|
||||
"id": "ANC-005",
|
||||
"type": "phone",
|
||||
"value": "+57 3136216458",
|
||||
"strength": "moderate",
|
||||
"provenance": "seed",
|
||||
"status": "active",
|
||||
},
|
||||
]
|
||||
|
||||
registry = AnchorRegistry(seed)
|
||||
@@ -138,10 +213,16 @@ def run_all_adversarial_tests():
|
||||
|
||||
# Fixture 1: Exact legal name + wrong NIT -> discard
|
||||
c1 = {
|
||||
"id": "ADV-001", "candidate_kind": "discard", "identity_status": "discarded",
|
||||
"disposition": "discard", "audit_status": "pending",
|
||||
"conflicting_anchors": ["tax_id"], "matched_anchors": ["ANC-003"],
|
||||
"direct_observations": ["Entidad homónima con NIT 900999888 en conflicto con semilla"]
|
||||
"id": "ADV-001",
|
||||
"candidate_kind": "discard",
|
||||
"identity_status": "discarded",
|
||||
"disposition": "discard",
|
||||
"audit_status": "pending",
|
||||
"conflicting_anchors": ["tax_id"],
|
||||
"matched_anchors": ["ANC-003"],
|
||||
"direct_observations": [
|
||||
"Entidad homónima con NIT 900999888 en conflicto con semilla"
|
||||
],
|
||||
}
|
||||
raw1 = {"name": "AMC SOLUTIONS COLOMBIA S.A.S.", "nit": "900999888"}
|
||||
passed, reason = auditor.audit_candidate(c1, raw1)
|
||||
@@ -150,85 +231,163 @@ def run_all_adversarial_tests():
|
||||
|
||||
# Fixture 2: Correct NIT + different legal name -> ambiguous / hold
|
||||
c2 = {
|
||||
"id": "ADV-002", "candidate_kind": "presence", "identity_status": "ambiguous",
|
||||
"disposition": "hold", "audit_status": "pending",
|
||||
"matched_anchors": ["ANC-002"], "missing_anchors": ["legal_name_reconciliation", "domain"]
|
||||
"id": "ADV-002",
|
||||
"candidate_kind": "presence",
|
||||
"identity_status": "ambiguous",
|
||||
"disposition": "hold",
|
||||
"audit_status": "pending",
|
||||
"matched_anchors": ["ANC-002"],
|
||||
"missing_anchors": ["legal_name_reconciliation", "domain"],
|
||||
}
|
||||
raw2 = {"name": "MINERALES DEL CESAR S.A.S.", "nit": "901380770"}
|
||||
passed, reason = auditor.audit_candidate(c2, raw2)
|
||||
assert passed and c2["disposition"] == "hold"
|
||||
results["2. Correct NIT + different legal name"] = "PASS (retained in hold, not attributed)"
|
||||
results["2. Correct NIT + different legal name"] = (
|
||||
"PASS (retained in hold, not attributed)"
|
||||
)
|
||||
|
||||
# Fixture 3: Historical address -> admit presence + proposed anchor with historical period
|
||||
c3 = {
|
||||
"id": "ADV-003", "candidate_kind": "presence", "identity_status": "attributed",
|
||||
"disposition": "admit", "audit_status": "pending", "relevant_period": "historico / 2021",
|
||||
"matched_anchors": ["ANC-002", "ANC-003"], "proposed_anchors": ["ANC-006"],
|
||||
"direct_observations": ["Muestra dirección histórica Carrera 14 # 13 C 60"]
|
||||
"id": "ADV-003",
|
||||
"candidate_kind": "presence",
|
||||
"identity_status": "attributed",
|
||||
"disposition": "admit",
|
||||
"audit_status": "pending",
|
||||
"relevant_period": "historico / 2021",
|
||||
"matched_anchors": ["ANC-002", "ANC-003"],
|
||||
"proposed_anchors": ["ANC-006"],
|
||||
"direct_observations": ["Muestra dirección histórica Carrera 14 # 13 C 60"],
|
||||
}
|
||||
raw3 = {
|
||||
"name": "AMC SOLUTIONS COLOMBIA S.A.S.",
|
||||
"nit": "901380770",
|
||||
"address": "Carrera 14 # 13 C 60",
|
||||
"year": "2021",
|
||||
}
|
||||
raw3 = {"name": "AMC SOLUTIONS COLOMBIA S.A.S.", "nit": "901380770", "address": "Carrera 14 # 13 C 60", "year": "2021"}
|
||||
passed, reason = auditor.audit_candidate(c3, raw3)
|
||||
assert passed and c3["relevant_period"] == "historico / 2021"
|
||||
registry.propose_anchor({"id": "ANC-006", "type": "street_address", "value": "Carrera 14 # 13 C 60", "strength": "moderate", "provenance": "ADV-003", "status": "proposed"})
|
||||
results["3. Historical address"] = "PASS (admitted with historical period; proposed anchor emitted)"
|
||||
registry.propose_anchor(
|
||||
{
|
||||
"id": "ANC-006",
|
||||
"type": "street_address",
|
||||
"value": "Carrera 14 # 13 C 60",
|
||||
"strength": "moderate",
|
||||
"provenance": "ADV-003",
|
||||
"status": "proposed",
|
||||
}
|
||||
)
|
||||
results["3. Historical address"] = (
|
||||
"PASS (admitted with historical period; proposed anchor emitted)"
|
||||
)
|
||||
|
||||
# Fixture 4: New legal representative from official source
|
||||
c4 = {
|
||||
"id": "ADV-004", "candidate_kind": "presence", "identity_status": "attributed",
|
||||
"disposition": "admit", "audit_status": "pending", "relevant_period": "vigencia fiscal 2023",
|
||||
"matched_anchors": ["ANC-002", "ANC-003"], "proposed_anchors": ["ANC-007"],
|
||||
"direct_observations": ["Acta municipal registra a Ledys del Rosario Martínez Lara como representante legal"]
|
||||
"id": "ADV-004",
|
||||
"candidate_kind": "presence",
|
||||
"identity_status": "attributed",
|
||||
"disposition": "admit",
|
||||
"audit_status": "pending",
|
||||
"relevant_period": "vigencia fiscal 2023",
|
||||
"matched_anchors": ["ANC-002", "ANC-003"],
|
||||
"proposed_anchors": ["ANC-007"],
|
||||
"direct_observations": [
|
||||
"Acta municipal registra a Ledys del Rosario Martínez Lara como representante legal"
|
||||
],
|
||||
}
|
||||
raw4 = {"publication_date": "2023-12-31"}
|
||||
passed, reason = auditor.audit_candidate(c4, raw4)
|
||||
assert passed
|
||||
registry.propose_anchor({"id": "ANC-007", "type": "legal_representative", "value": "Ledys del Rosario Martínez Lara", "strength": "moderate", "provenance": "ADV-004", "status": "proposed"})
|
||||
registry.propose_anchor(
|
||||
{
|
||||
"id": "ANC-007",
|
||||
"type": "legal_representative",
|
||||
"value": "Ledys del Rosario Martínez Lara",
|
||||
"strength": "moderate",
|
||||
"provenance": "ADV-004",
|
||||
"status": "proposed",
|
||||
}
|
||||
)
|
||||
assert "ANC-007" in registry.proposed and "ANC-007" not in registry.active
|
||||
results["4. New legal representative"] = "PASS (proposed in research state; not yet active)"
|
||||
results["4. New legal representative"] = (
|
||||
"PASS (proposed in research state; not yet active)"
|
||||
)
|
||||
|
||||
# Fixture 5: Snippet says AMC, underlying page says different company
|
||||
raw5 = {"snippet_entity": "AMC Solutions", "underlying_page_entity": "Servicios Mineros de Colombia S.A."}
|
||||
raw5 = {
|
||||
"snippet_entity": "AMC Solutions",
|
||||
"underlying_page_entity": "Servicios Mineros de Colombia S.A.",
|
||||
}
|
||||
bad_c5 = {
|
||||
"id": "ADV-005", "candidate_kind": "presence", "identity_status": "attributed",
|
||||
"disposition": "admit", "audit_status": "pending", "matched_anchors": ["ANC-001", "ANC-003"],
|
||||
"direct_observations": ["Snippet de búsqueda muestra AMC Solutions en Valledupar"]
|
||||
"id": "ADV-005",
|
||||
"candidate_kind": "presence",
|
||||
"identity_status": "attributed",
|
||||
"disposition": "admit",
|
||||
"audit_status": "pending",
|
||||
"matched_anchors": ["ANC-001", "ANC-003"],
|
||||
"direct_observations": [
|
||||
"Snippet de búsqueda muestra AMC Solutions en Valledupar"
|
||||
],
|
||||
}
|
||||
passed_bad, reason = auditor.audit_candidate(bad_c5, raw5)
|
||||
assert not passed_bad # Auditor catches snippet hallucination
|
||||
# Worker corrects to discard
|
||||
corrected_c5 = {
|
||||
"id": "ADV-005", "candidate_kind": "discard", "identity_status": "discarded",
|
||||
"disposition": "discard", "audit_status": "pending", "conflicting_anchors": ["legal_name"],
|
||||
"direct_observations": ["La página de destino corresponde a Servicios Mineros de Colombia S.A., no a AMC Solutions"]
|
||||
"id": "ADV-005",
|
||||
"candidate_kind": "discard",
|
||||
"identity_status": "discarded",
|
||||
"disposition": "discard",
|
||||
"audit_status": "pending",
|
||||
"conflicting_anchors": ["legal_name"],
|
||||
"direct_observations": [
|
||||
"La página de destino corresponde a Servicios Mineros de Colombia S.A., no a AMC Solutions"
|
||||
],
|
||||
}
|
||||
passed_good, _ = auditor.audit_candidate(corrected_c5, raw5)
|
||||
assert passed_good
|
||||
results["5. Search snippet vs underlying page"] = "PASS (snippet hallucination caught; underlying page governs)"
|
||||
results["5. Search snippet vs underlying page"] = (
|
||||
"PASS (snippet hallucination caught; underlying page governs)"
|
||||
)
|
||||
|
||||
# Fixture 6: Third party promotional claim ("Empresa líder...")
|
||||
bad_c6 = {
|
||||
"id": "ADV-006", "candidate_kind": "presence", "identity_status": "attributed",
|
||||
"disposition": "admit", "audit_status": "pending", "matched_anchors": ["ANC-002", "ANC-003"],
|
||||
"direct_observations": ["La fuente certifica que es la empresa líder del Cesar"]
|
||||
"id": "ADV-006",
|
||||
"candidate_kind": "presence",
|
||||
"identity_status": "attributed",
|
||||
"disposition": "admit",
|
||||
"audit_status": "pending",
|
||||
"matched_anchors": ["ANC-002", "ANC-003"],
|
||||
"direct_observations": [
|
||||
"La fuente certifica que es la empresa líder del Cesar"
|
||||
],
|
||||
}
|
||||
passed_bad, reason = auditor.audit_candidate(bad_c6, {})
|
||||
assert not passed_bad and "promotional" in reason.lower()
|
||||
# Corrected: claim moved to source_claims
|
||||
good_c6 = {
|
||||
"id": "ADV-006", "candidate_kind": "presence", "identity_status": "attributed",
|
||||
"disposition": "admit", "audit_status": "pending", "matched_anchors": ["ANC-002", "ANC-003"],
|
||||
"id": "ADV-006",
|
||||
"candidate_kind": "presence",
|
||||
"identity_status": "attributed",
|
||||
"disposition": "admit",
|
||||
"audit_status": "pending",
|
||||
"matched_anchors": ["ANC-002", "ANC-003"],
|
||||
"direct_observations": ["Ficha mercantil lista registro con NIT 901380770"],
|
||||
"source_claims": ["El directorio afirma que la empresa es líder en el Cesar"]
|
||||
"source_claims": ["El directorio afirma que la empresa es líder en el Cesar"],
|
||||
}
|
||||
passed_good, _ = auditor.audit_candidate(good_c6, {})
|
||||
assert passed_good
|
||||
results["6. Promotional claim discipline"] = "PASS (rejected in direct_observations; allowed in source_claims)"
|
||||
results["6. Promotional claim discipline"] = (
|
||||
"PASS (rejected in direct_observations; allowed in source_claims)"
|
||||
)
|
||||
|
||||
# Fixture 7: Ambiguous local listing (Name + city, no NIT/domain)
|
||||
c7 = {
|
||||
"id": "ADV-007", "candidate_kind": "presence", "identity_status": "ambiguous",
|
||||
"disposition": "hold", "audit_status": "pending", "matched_anchors": ["ANC-003"],
|
||||
"missing_anchors": ["tax_id", "domain"]
|
||||
"id": "ADV-007",
|
||||
"candidate_kind": "presence",
|
||||
"identity_status": "ambiguous",
|
||||
"disposition": "hold",
|
||||
"audit_status": "pending",
|
||||
"matched_anchors": ["ANC-003"],
|
||||
"missing_anchors": ["tax_id", "domain"],
|
||||
}
|
||||
passed, _ = auditor.audit_candidate(c7, {})
|
||||
assert passed and c7["disposition"] == "hold"
|
||||
@@ -236,52 +395,94 @@ def run_all_adversarial_tests():
|
||||
|
||||
# Fixture 8: Historical 2023 government contract
|
||||
c8 = {
|
||||
"id": "ADV-008", "candidate_kind": "presence", "identity_status": "attributed",
|
||||
"disposition": "admit", "audit_status": "pending", "relevant_period": "vigencia fiscal 2023",
|
||||
"id": "ADV-008",
|
||||
"candidate_kind": "presence",
|
||||
"identity_status": "attributed",
|
||||
"disposition": "admit",
|
||||
"audit_status": "pending",
|
||||
"relevant_period": "vigencia fiscal 2023",
|
||||
"matched_anchors": ["ANC-002", "ANC-003"],
|
||||
"direct_observations": ["Adjudicación de contrato SAMC-014-2023 en Uribia"]
|
||||
"direct_observations": ["Adjudicación de contrato SAMC-014-2023 en Uribia"],
|
||||
}
|
||||
passed, _ = auditor.audit_candidate(c8, {"publication_date": "2023-12-31"})
|
||||
assert passed and "2023" in c8["relevant_period"]
|
||||
results["8. Historical contract discipline"] = "PASS (scoped strictly to 2023 fiscal year)"
|
||||
results["8. Historical contract discipline"] = (
|
||||
"PASS (scoped strictly to 2023 fiscal year)"
|
||||
)
|
||||
|
||||
# Fixture 9: Negative observation on Google Maps
|
||||
c9 = {
|
||||
"id": "ADV-009", "candidate_kind": "negative_observation", "identity_status": "not_applicable",
|
||||
"disposition": "admit", "audit_status": "pending", "confidence": "negative_scoped",
|
||||
"id": "ADV-009",
|
||||
"candidate_kind": "negative_observation",
|
||||
"identity_status": "not_applicable",
|
||||
"disposition": "admit",
|
||||
"audit_status": "pending",
|
||||
"confidence": "negative_scoped",
|
||||
"matched_anchors": [],
|
||||
"direct_observations": ["En la muestra de búsqueda en Google Maps no se observó perfil comercial verificado"]
|
||||
"direct_observations": [
|
||||
"En la muestra de búsqueda en Google Maps no se observó perfil comercial verificado"
|
||||
],
|
||||
}
|
||||
passed, _ = auditor.audit_candidate(c9, {})
|
||||
assert passed and c9["identity_status"] == "not_applicable"
|
||||
results["9. Scoped negative observation"] = "PASS (admitted without false entity attribution)"
|
||||
results["9. Scoped negative observation"] = (
|
||||
"PASS (admitted without false entity attribution)"
|
||||
)
|
||||
|
||||
# Fixture 10: Contradictory addresses preserved
|
||||
c10 = {
|
||||
"id": "ADV-010", "candidate_kind": "presence", "identity_status": "attributed",
|
||||
"disposition": "admit", "audit_status": "pending", "matched_anchors": ["ANC-002", "ANC-003"],
|
||||
"direct_observations": ["Directorio A lista Carrera 19d; Directorio B lista Carrera 14"],
|
||||
"open_questions": ["¿Cuál dirección representa la sede operativa vigente?"]
|
||||
"id": "ADV-010",
|
||||
"candidate_kind": "presence",
|
||||
"identity_status": "attributed",
|
||||
"disposition": "admit",
|
||||
"audit_status": "pending",
|
||||
"matched_anchors": ["ANC-002", "ANC-003"],
|
||||
"direct_observations": [
|
||||
"Directorio A lista Carrera 19d; Directorio B lista Carrera 14"
|
||||
],
|
||||
"open_questions": ["¿Cuál dirección representa la sede operativa vigente?"],
|
||||
}
|
||||
passed, _ = auditor.audit_candidate(c10, {})
|
||||
assert passed and len(c10["open_questions"]) > 0
|
||||
results["10. Contradictory addresses"] = "PASS (contradiction preserved in open_questions)"
|
||||
results["10. Contradictory addresses"] = (
|
||||
"PASS (contradiction preserved in open_questions)"
|
||||
)
|
||||
|
||||
# Fixture 11: Conflicting proposed anchor rejected
|
||||
registry.propose_anchor({"id": "ANC-099", "type": "phone", "value": "+57 4 4440000", "strength": "moderate", "provenance": "ADV-011", "status": "proposed"})
|
||||
registry.propose_anchor(
|
||||
{
|
||||
"id": "ANC-099",
|
||||
"type": "phone",
|
||||
"value": "+57 4 4440000",
|
||||
"strength": "moderate",
|
||||
"provenance": "ADV-011",
|
||||
"status": "proposed",
|
||||
}
|
||||
)
|
||||
# Orchestrator detects conflicting area code (+57 4 is Medellín, competitor conflict)
|
||||
registry.reconcile_proposed("ANC-099", accept=False, rejection_reason="Conflicto de jurisdicción y homonimia con competidor en Medellín")
|
||||
registry.reconcile_proposed(
|
||||
"ANC-099",
|
||||
accept=False,
|
||||
rejection_reason="Conflicto de jurisdicción y homonimia con competidor en Medellín",
|
||||
)
|
||||
assert "ANC-099" in registry.rejected and "ANC-099" not in registry.active
|
||||
results["11. Conflicting proposed anchor"] = "PASS (rejected by orchestrator; not promoted to active)"
|
||||
results["11. Conflicting proposed anchor"] = (
|
||||
"PASS (rejected by orchestrator; not promoted to active)"
|
||||
)
|
||||
|
||||
# Fixture 12: THE TEMPORAL EXPLOIT & RE-ENTRY
|
||||
# Worker correctly attributes entity, but fraudulently or carelessly sets relevant_period to 'actual 2026' on a 2023 source!
|
||||
exploit_c12 = {
|
||||
"id": "ADV-012", "candidate_kind": "presence", "identity_status": "attributed",
|
||||
"disposition": "admit", "audit_status": "pending",
|
||||
"id": "ADV-012",
|
||||
"candidate_kind": "presence",
|
||||
"identity_status": "attributed",
|
||||
"disposition": "admit",
|
||||
"audit_status": "pending",
|
||||
"matched_anchors": ["ANC-002", "ANC-003"],
|
||||
"relevant_period": "actual 2026", # FRAUDULENT EXTRAPOLATION
|
||||
"direct_observations": ["Contrato municipal acredita servicios mineros activos"]
|
||||
"relevant_period": "actual 2026", # FRAUDULENT EXTRAPOLATION
|
||||
"direct_observations": [
|
||||
"Contrato municipal acredita servicios mineros activos"
|
||||
],
|
||||
}
|
||||
raw12 = {"publication_date": "2023-10-15"}
|
||||
|
||||
@@ -295,39 +496,58 @@ def run_all_adversarial_tests():
|
||||
|
||||
# Worker Re-evaluation: Worker addresses auditor objection
|
||||
exploit_c12["relevant_period"] = "vigencia fiscal 2023"
|
||||
exploit_c12["direct_observations"] = ["Contrato municipal adjudicado en vigencia 2023"]
|
||||
exploit_c12["direct_observations"] = [
|
||||
"Contrato municipal adjudicado en vigencia 2023"
|
||||
]
|
||||
exploit_c12["disposition"] = "admit"
|
||||
exploit_c12["audit_status"] = "pending" # RE-ENTRY PROTOCOL
|
||||
exploit_c12["audit_status"] = "pending" # RE-ENTRY PROTOCOL
|
||||
|
||||
# Audit Pass 2: Re-evaluation succeeds
|
||||
passed2, reason2 = auditor.audit_candidate(exploit_c12, raw12)
|
||||
assert passed2
|
||||
exploit_c12["audit_status"] = "passed"
|
||||
# Verification of eligibility conjunction:
|
||||
eligible = (exploit_c12["disposition"] == "admit" and exploit_c12["audit_status"] == "passed")
|
||||
eligible = (
|
||||
exploit_c12["disposition"] == "admit"
|
||||
and exploit_c12["audit_status"] == "passed"
|
||||
)
|
||||
assert eligible
|
||||
results["12. Temporal exploit & re-entry"] = "PASS (auditor caught 2026 leap, demoted to hold; worker repaired, re-entered, passed audit)"
|
||||
results["12. Temporal exploit & re-entry"] = (
|
||||
"PASS (auditor caught 2026 leap, demoted to hold; worker repaired, re-entered, passed audit)"
|
||||
)
|
||||
|
||||
# Fixture 13: Metadata claim without observation (DISC-001 regression fixture)
|
||||
bad_c13 = {
|
||||
"id": "ADV-013", "candidate_kind": "discard", "identity_status": "discarded",
|
||||
"disposition": "discard", "audit_status": "pending",
|
||||
"id": "ADV-013",
|
||||
"candidate_kind": "discard",
|
||||
"identity_status": "discarded",
|
||||
"disposition": "discard",
|
||||
"audit_status": "pending",
|
||||
"conflicting_anchors": ["tax_id", "city"],
|
||||
"direct_observations": ["Ficha en Bogotá para empresa homónima en alquiler de maquinaria"]
|
||||
"direct_observations": [
|
||||
"Ficha en Bogotá para empresa homónima en alquiler de maquinaria"
|
||||
],
|
||||
}
|
||||
passed_bad, reason_bad = auditor.audit_candidate(bad_c13, {})
|
||||
assert not passed_bad and "metadata claim without observation" in reason_bad.lower()
|
||||
|
||||
# Re-entry: Worker remediates by grounding discard strictly on verifiable conflicting anchors (city, sector)
|
||||
remediated_c13 = {
|
||||
"id": "ADV-013", "candidate_kind": "discard", "identity_status": "discarded",
|
||||
"disposition": "discard", "audit_status": "pending",
|
||||
"id": "ADV-013",
|
||||
"candidate_kind": "discard",
|
||||
"identity_status": "discarded",
|
||||
"disposition": "discard",
|
||||
"audit_status": "pending",
|
||||
"conflicting_anchors": ["city", "industry_sector"],
|
||||
"direct_observations": ["Ficha mercantil en Bogotá (Calle 74) con actividad CIIU 7730 (alquiler de maquinaria)"]
|
||||
"direct_observations": [
|
||||
"Ficha mercantil en Bogotá (Calle 74) con actividad CIIU 7730 (alquiler de maquinaria)"
|
||||
],
|
||||
}
|
||||
passed_good, reason_good = auditor.audit_candidate(remediated_c13, {})
|
||||
assert passed_good and remediated_c13["disposition"] == "discard"
|
||||
results["13. Metadata claim without observation"] = "PASS (auditor caught unsupported tax_id assertion; remediated to verified anchors)"
|
||||
results["13. Metadata claim without observation"] = (
|
||||
"PASS (auditor caught unsupported tax_id assertion; remediated to verified anchors)"
|
||||
)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
Reference in new issue
Block a user