Files
Jyotisha/tests/test_probe_question_contract.py
T
Jesse_Chen b43808b016
Independent Staging Quality Gate / validate (push) Successful in 9m10s
Independent Staging Quality Gate / publish (push) Successful in 8m43s
fix(rectification): stop yearless ungrounded varga contrast from minting cards
Only sign-bound varga_style questions may omit a concrete period. Remaining-layer existence and quality probes now drop as yearless_ungrounded_contrast instead of scoring by group order.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-30 10:55:11 +08:00

129 lines
5.8 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"), "都不太像我")
self.assertEqual(next(item["label"] for item in options if item["answer_class"] == "unsure"), "一时说不好")
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_yearless_ungrounded_contrast_is_rejected(self) -> None:
existence = is_renderable_probe({
"information_gain": 1.2,
"candidate_ids": ["05:00", "05:04"],
"expected_outcomes": [{}, {}],
"choice_kind": "existence",
"year": 0,
})
self.assertFalse(existence["ok"])
self.assertEqual(existence.get("reason"), "yearless_ungrounded_contrast")
quality = is_renderable_probe({
"information_gain": 1.2,
"candidate_ids": ["05:00", "05:04"],
"expected_outcomes": [{}, {}],
"choice_kind": "event_quality",
"year": 0,
})
self.assertFalse(quality["ok"])
self.assertEqual(quality.get("reason"), "yearless_ungrounded_contrast")
signed = is_renderable_probe({
"information_gain": 1.2,
"candidate_ids": ["05:00", "05:04"],
"expected_outcomes": [{}, {}],
"choice_kind": "varga_style",
"year": 0,
"style_options": [
{"label": "做事以照顾人为主,在意团队里的感受", "answer_class": "yes", "sign": "巨蟹座"},
{"label": "习惯带头,也不排斥站到台前", "answer_class": "weak_yes", "sign": "狮子座"},
],
})
self.assertTrue(signed["ok"])
unsigned = is_renderable_probe({
"information_gain": 1.2,
"candidate_ids": ["05:00", "05:04"],
"expected_outcomes": [{}, {}],
"choice_kind": "varga_style",
"year": 0,
"style_options": [
{"label": "做事以照顾人为主,在意团队里的感受", "answer_class": "yes"},
{"label": "习惯带头,也不排斥站到台前", "answer_class": "weak_yes"},
],
})
self.assertFalse(unsigned["ok"])
self.assertEqual(unsigned.get("reason"), "yearless_ungrounded_contrast")
dated = is_renderable_probe({
"information_gain": 1.2,
"candidate_ids": ["05:00", "05:04"],
"expected_outcomes": [{}, {}],
"choice_kind": "existence",
"year": 2016,
"year_label": "2016 年前后",
})
self.assertTrue(dated["ok"])
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())