floop: DATE answer type + deterministic year check (his 22/10 run)
His local run: the term-start question answered '15' — not a date — and the dependent predecessor question became unclear downstream. - AnswerType.DATE joins the enum; the Subquestion desc the model sees now says: DATE for a specific date (day, month and year — '15' alone is NOT a date) - _looks_like_date: deterministic admission bar — a plausible year (1500-2999). '2 June 2018'/'June 2018'/'2018' pass; '15', a month name alone, garbage: refused - _append_checked: a DATE answer without a year becomes UNKNOWN, the question fails honestly, a note lands in the run log — the wrong type never flows silently into dependents VERIFIED: tests/date_type.py 4/4 (enum+desc in the rendered schema, deterministic admission, '15' rejected end-to-end, real date accepted); suite 16/16.
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
"""DATE answer type tests (his 22/10 local run: term-start answered '15').
|
||||
|
||||
Laws under test:
|
||||
1. AnswerType.DATE exists; INIT's enum desc mentions it (the schema the
|
||||
model sees carries the date guidance).
|
||||
2. _looks_like_date is deterministic and strict: a plausible YEAR is the
|
||||
admission bar — '15' alone, a month name alone, garbage: NOT dates.
|
||||
3. The machine refuses a DATE answer without a year: the row becomes
|
||||
UNKNOWN and the question fails (re-buttable honestly, never a silent
|
||||
wrong type flowing downstream into dependents).
|
||||
|
||||
No network. Run: .venv/bin/python tests/date_type.py
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from floop.machine import _looks_like_date
|
||||
from floop.state import AnswerType, Budget, EvidenceRow, OpenQuestion
|
||||
from floop.machine import FloopRun
|
||||
|
||||
|
||||
def test_date_in_enum_and_desc():
|
||||
assert AnswerType.DATE.value == "DATE"
|
||||
from floop.dspy_modules import Subquestion
|
||||
import json
|
||||
schema = json.dumps(Subquestion.model_json_schema(), default=str)
|
||||
assert "DATE for a specific date" in schema, "desc must carry the date guidance"
|
||||
print("ok: AnswerType.DATE exists; the model-visible desc carries it")
|
||||
|
||||
|
||||
def test_looks_like_date():
|
||||
# admission: a plausible year
|
||||
for good in ("2 June 2018", "June 2018", "2018", "17 November 2023",
|
||||
"6–29 December 2023", "sworn in on 1 June 2018"):
|
||||
assert _looks_like_date(good), good
|
||||
# refusal: no year — the exact '15' shape from his run
|
||||
for bad in ("15", "June", "fifteen", "", "the fifteenth",
|
||||
"15 June", "239", "30000"):
|
||||
assert not _looks_like_date(bad), bad
|
||||
print("ok: _looks_like_date deterministic (year required; '15' refused)")
|
||||
|
||||
|
||||
def test_machine_rejects_bare_number_date():
|
||||
b = Budget(max_llm_calls=40, max_depth=2, max_retries=3,
|
||||
missing_extensions=1, min_child_budget=4)
|
||||
|
||||
class DateModules:
|
||||
def init_decompose(self, question):
|
||||
return [{"text": "When did the term begin?",
|
||||
"deps": [], "answer_type": "DATE"}], ""
|
||||
def missing_decompose(self, goal, evidence):
|
||||
return []
|
||||
def route_question(self, question, catalog, evidence):
|
||||
return "knowledge", "date lookup"
|
||||
def expert_draft(self, question, expert_kind, evidence, parent_question=""):
|
||||
return {"value": "15", "source_quote": "",
|
||||
"confidence": "high"}
|
||||
def synthesize(self, goal, evidence, unverified):
|
||||
return "synthesized"
|
||||
|
||||
run = FloopRun("Who was the President before X?", b, modules=DateModules())
|
||||
run._init_decompose() # creates Q1 (DATE) from init_decompose
|
||||
q1 = next(q for q in run.stack.items if q.text == "When did the term begin?")
|
||||
run._route_and_execute(q1)
|
||||
# the expert's '15' must NOT satisfy the DATE question
|
||||
assert q1.status == "failed", q1.status
|
||||
assert any("DATE answer rejected" in n for n in run.notes), run.notes
|
||||
print("ok: '15' rejected for a DATE question — row UNKNOWN, question failed")
|
||||
|
||||
|
||||
def test_machine_accepts_real_date():
|
||||
b = Budget(max_llm_calls=40, max_depth=2, max_retries=3,
|
||||
missing_extensions=1, min_child_budget=4)
|
||||
|
||||
class DateModules:
|
||||
def init_decompose(self, question):
|
||||
return [{"text": "When did the term begin?",
|
||||
"deps": [], "answer_type": "DATE"}], ""
|
||||
def missing_decompose(self, goal, evidence):
|
||||
return []
|
||||
def route_question(self, question, catalog, evidence):
|
||||
return "knowledge", "date lookup"
|
||||
def expert_draft(self, question, expert_kind, evidence, parent_question=""):
|
||||
return {"value": "2 June 2018", "source_quote": "",
|
||||
"confidence": "high"}
|
||||
def synthesize(self, goal, evidence, unverified):
|
||||
return "synthesized"
|
||||
|
||||
run = FloopRun("Who was the President before X?", b, modules=DateModules())
|
||||
run._init_decompose()
|
||||
q1 = next(q for q in run.stack.items if q.text == "When did the term begin?")
|
||||
run._route_and_execute(q1)
|
||||
assert q1.status == "answered", q1.status
|
||||
print("ok: '2 June 2018' accepted for a DATE question")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_date_in_enum_and_desc()
|
||||
test_looks_like_date()
|
||||
test_machine_rejects_bare_number_date()
|
||||
test_machine_accepts_real_date()
|
||||
print("\nDATE type tests passed")
|
||||
Reference in New Issue
Block a user