From 56290d0abfcc3b4bdcd0022baece79ea9cdce276 Mon Sep 17 00:00:00 2001 From: Eirik Botten Nicolaysen Date: Sat, 31 Oct 2026 07:41:49 +0100 Subject: [PATCH] Record a format version in AuditResults.to_dict() RepeatedExperimentResults already writes "version": "1.0"; a single run's export had no version, so a consumer of the saved JSON could not tell which shape it was reading. Add the same key to AuditResults. load() does not read it, so files written before it still load. --- simpleaudit/results.py | 1 + tests/test_audit_flow.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/simpleaudit/results.py b/simpleaudit/results.py index 72012e6..f7e7e37 100644 --- a/simpleaudit/results.py +++ b/simpleaudit/results.py @@ -247,6 +247,7 @@ def summary(self): def to_dict(self) -> Dict: return { + "version": "1.0", "timestamp": self.timestamp, "summary": { "total_scenarios": len(self.results), diff --git a/tests/test_audit_flow.py b/tests/test_audit_flow.py index 988c94b..5ad53f5 100644 --- a/tests/test_audit_flow.py +++ b/tests/test_audit_flow.py @@ -297,6 +297,28 @@ def test_save_produces_valid_json(self): finally: os.unlink(filepath) + def test_saved_json_carries_format_version(self): + """The export names its format version, as RepeatedExperimentResults does.""" + results = AuditResults([_make_audit_result()]) + assert results.to_dict()["version"] == "1.0" + + with tempfile.NamedTemporaryFile(suffix=".json", delete=False) as f: + filepath = f.name + + try: + results.save(filepath) + with open(filepath) as f: + data = json.load(f) + assert data["version"] == "1.0" + + # Files written before the key existed still load. + del data["version"] + with open(filepath, "w") as f: + json.dump(data, f) + assert len(AuditResults.load(filepath)) == 1 + finally: + os.unlink(filepath) + # --- Plot smoke test ---