Files
Jyotisha/tests/test_probe_question_contract.py
T
Jesse_Chen 63b4591aae
Independent Staging Quality Gate / validate (push) Failing after 17m9s
Independent Staging Quality Gate / publish (push) Has been skipped
fix(rectification): surface dropped probes and filter tools by the decision
Silent unrenderable discriminators, a missing question-contract golden, and a always-on tool table were hiding fail-closed drops behind the prompt wall.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 20:31:15 +08:00

74 lines
3.4 KiB
Python

from __future__ import annotations
import unittest
from scripts.rectification.probe_question_contract import (
ANSWER_CLASSES,
EXISTENCE_STYLE_OPTIONS,
QUALITY_STYLE_OPTIONS,
canonical_probe_question_contract_json,
complete_style_options,
is_renderable_probe,
load_probe_question_contract_golden,
)
class ProbeQuestionContractTests(unittest.TestCase):
def test_existence_completes_four_options(self) -> None:
completed = complete_style_options("existence")
self.assertTrue(completed["ok"])
self.assertEqual(completed.get("options"), [dict(item) for item in EXISTENCE_STYLE_OPTIONS])
def test_quality_covers_unsure(self) -> None:
completed = complete_style_options("event_quality")
self.assertTrue(completed["ok"])
self.assertEqual(completed.get("options"), [dict(item) for item in QUALITY_STYLE_OPTIONS])
self.assertEqual({item["answer_class"] for item in completed.get("options") or []}, set(ANSWER_CLASSES))
def test_varga_style_needs_two_scoring_labels(self) -> None:
rejected = complete_style_options("varga_style", [
{"label": "巨蟹相处主动热情", "answer_class": "yes"},
])
self.assertFalse(rejected["ok"])
self.assertEqual(rejected.get("reason"), "varga_insufficient_scoring")
completed = complete_style_options("varga_style", [
{"label": "巨蟹相处主动热情", "answer_class": "yes", "sign": "巨蟹"},
{"label": "狮子独立强势", "answer_class": "weak_yes", "sign": "狮子"},
])
self.assertTrue(completed["ok"])
options = completed.get("options") or []
self.assertEqual(len(options), 4)
self.assertEqual(next(item["label"] for item in options if item["answer_class"] == "no"), "都不是这些特质")
def test_clock_copy_is_dropped_and_catalog_fills_existence(self) -> None:
completed = complete_style_options("existence", [
{"label": "08:12 左右发生", "answer_class": "yes"},
])
self.assertTrue(completed["ok"])
self.assertEqual((completed.get("options") or [])[0]["label"], "明确发生且时间吻合")
def test_unrenderable_varga_probe_is_rejected(self) -> None:
result = is_renderable_probe({
"information_gain": 1.2,
"candidate_ids": ["05:00", "05:04"],
"expected_outcomes": [{}, {}],
"choice_kind": "varga_style",
"style_options": [{"label": "外貌更接近第一种", "answer_class": "yes"}],
})
self.assertFalse(result["ok"])
self.assertEqual(result.get("reason"), "forbidden_copy")
def test_duplicate_labels_uniquify_with_index(self) -> None:
completed = complete_style_options("varga_style", [
{"label": "相处主动热情", "answer_class": "yes"},
{"label": "相处主动热情", "answer_class": "weak_yes"},
])
self.assertTrue(completed["ok"])
labels = [item["label"] for item in completed.get("options") or []]
self.assertIn("相处主动热情·2", labels)
self.assertFalse(any("weak_yes" in item or item.endswith("·yes") for item in labels))
self.assertEqual(len(set(labels)), 4)
def test_golden_json_matches_python_payload_bytes(self) -> None:
self.assertEqual(canonical_probe_question_contract_json(), load_probe_question_contract_golden())