added
This commit is contained in:
1 parent
87cc362513
commit
2a0d6aa2bf
1029 files changed
+106050
-14573
No files matched your search
@@ -0,0 +1,85 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
BASE = Path(__file__).resolve().parent.parent
|
||||
PIPELINE = BASE / "scripts" / "future_map_pipeline.py"
|
||||
FIXTURES = BASE / "tests" / "fixtures" / "source"
|
||||
|
||||
|
||||
class PipelineTests(unittest.TestCase):
|
||||
def run_pipeline(self, *args: str) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.run(
|
||||
[sys.executable, str(PIPELINE), *args],
|
||||
text=True,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
def test_sync_sanitizes_and_preserves_source_fields(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
output = Path(temporary)
|
||||
result = self.run_pipeline(
|
||||
"sync",
|
||||
"--source-hrecords", str(FIXTURES / "hrecords"),
|
||||
"--source-files", str(FIXTURES / "files"),
|
||||
"--output-root", str(output),
|
||||
)
|
||||
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
|
||||
self.assertEqual(len(list((output / "hrecords").glob("*.json"))), 2)
|
||||
first = json.loads((output / "hrecords" / "1001.json").read_text(encoding="utf-8"))
|
||||
second = json.loads((output / "hrecords" / "1002.json").read_text(encoding="utf-8"))
|
||||
self.assertEqual(first["source_record"]["summary"], "A source-authored signal summary.")
|
||||
self.assertEqual(first["source_record"]["contact_reference_count"], 1)
|
||||
self.assertEqual(first["reasoning"]["status"], "pending")
|
||||
self.assertNotIn("[email protected]", json.dumps(second))
|
||||
self.assertIn("[email removed]", second["source_record"]["notes"]["text"])
|
||||
self.assertEqual(second["links"][0]["url"], "https://example.com/report")
|
||||
self.assertTrue((output / "files" / "fixture-image.png").exists())
|
||||
digest_lines = (output / "future-map-insights.md").read_text(encoding="utf-8").splitlines()
|
||||
self.assertFalse(any(line != line.rstrip() for line in digest_lines))
|
||||
|
||||
def test_apply_reasoning_and_preserve_it_on_unchanged_sync(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
output = Path(temporary)
|
||||
sync_args = (
|
||||
"sync", "--source-hrecords", str(FIXTURES / "hrecords"),
|
||||
"--source-files", str(FIXTURES / "files"), "--output-root", str(output),
|
||||
)
|
||||
self.assertEqual(self.run_pipeline(*sync_args).returncode, 0)
|
||||
patch = {
|
||||
"record_id": "fm-signal-1001",
|
||||
"analysis": "This signal reinforces a documented Future Map structural transition.",
|
||||
"implications": ["Monitor whether the signal accelerates across related systems."],
|
||||
"claims": [{"text": "The signal may reinforce a transition.", "type": "interpretation", "confidence": "medium"}],
|
||||
"classification": {
|
||||
"signal_types": ["structural-shift"], "topics": ["technology"],
|
||||
"future_map_concepts": ["tipping-point"], "time_horizons": ["near-term"],
|
||||
"geographies": [], "industries": [], "audiences": ["business-leaders"],
|
||||
"direction": "mixed", "maturity": "emerging"
|
||||
},
|
||||
"related_documents": [], "related_signals": [],
|
||||
"confidence": "medium", "novelty": "reinforcing",
|
||||
"corpus_documents_consulted": ["critical-states"], "generated_by": "fixture-agent"
|
||||
}
|
||||
patch_path = output / "patch.json"
|
||||
patch_path.write_text(json.dumps(patch), encoding="utf-8")
|
||||
applied = self.run_pipeline(
|
||||
"apply-reasoning", "--record-id", "fm-signal-1001",
|
||||
"--patch", str(patch_path), "--output-root", str(output),
|
||||
)
|
||||
self.assertEqual(applied.returncode, 0, applied.stdout + applied.stderr)
|
||||
self.assertEqual(self.run_pipeline(*sync_args).returncode, 0)
|
||||
record = json.loads((output / "hrecords" / "1001.json").read_text(encoding="utf-8"))
|
||||
self.assertEqual(record["reasoning"]["status"], "complete")
|
||||
self.assertEqual(record["reasoning"]["related_signals"], [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user