feat: make us-cpa questions retrieval-first

This commit is contained in:
Stefano Fiorini
2026-03-15 04:40:57 -05:00
parent b4f9666560
commit b2bb07fa90
6 changed files with 272 additions and 10 deletions

View File

@@ -14,6 +14,12 @@ class QuestionEngineTests(unittest.TestCase):
corpus = TaxYearCorpus(cache_root=Path(temp_dir))
def fake_fetch(url: str) -> bytes:
if "p501" in url:
return (
"A qualifying child may be your dependent if the relationship, age, residency, support, and joint return tests are met. "
"Temporary absences due to education count as time lived with you. "
"To meet the support test, the child must not have provided more than half of their own support for the year."
).encode()
return f"source for {url}".encode()
corpus.download_catalog(2025, bootstrap_irs_catalog(2025), fetcher=fake_fetch)
@@ -93,6 +99,25 @@ class QuestionEngineTests(unittest.TestCase):
self.assertEqual(analysis["conclusion"]["answer"], "$31,500")
self.assertIn("Qualifying Surviving Spouse", analysis["conclusion"]["summary"])
def test_dependency_question_uses_irs_corpus_research_before_primary_law(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
engine = self.build_engine(temp_dir)
analysis = engine.answer(
question=(
"If my daughter went to college in 2025 starting in August, but also worked before that, "
"should she be considered as a dependent?"
),
tax_year=2025,
case_facts={},
)
self.assertEqual(analysis["issue"], "irs_corpus_research")
self.assertFalse(analysis["primaryLawRequired"])
self.assertEqual(analysis["authorities"][0]["slug"], "p501")
self.assertTrue(any(item["slug"] == "p501" for item in analysis["authorities"]))
self.assertTrue(analysis["excerpts"])
def test_complex_question_flags_primary_law_escalation(self) -> None:
with tempfile.TemporaryDirectory() as temp_dir:
engine = self.build_engine(temp_dir)