feat: carry new upstream names and hashes in json

--detect-new-files and --watch-hashes were printed only by the text report and refused with --json, so check_freshness --profiles never saw a name or hash the cited code gained. Both now live on the report, and check_freshness passes them and marks such a profile stale.
This commit is contained in:
Abdessamad Derraz committed 2026-10-21 09:51:14 +02:00
1 parent fd9a9b14f8
commit 6877512af7
5 files changed
+181 -34

No files matched your search

+59 -4
View File
@@ -2023,13 +2023,42 @@ class TestExtrasSurviveARefusingForge(unittest.TestCase):
upstream.fetch_file = refuse
try:
report = _sample_report()
profile_sync._attach_detection(self._args(), self._profile(), report)
buffer = io.StringIO()
with contextlib.redirect_stdout(buffer):
profile_sync._print_extras(self._args(), self._profile(), _sample_report())
profile_sync._print_extras(self._args(), self._profile(), report)
finally:
upstream.fetch_file = original
self.assertEqual(report.detection_skipped, "https://x/y: HTTP 403")
self.assertIn("extras skipped: https://x/y: HTTP 403", buffer.getvalue())
def test_detection_lands_on_the_report(self):
"""A name the pinned file already carried is listed, but only a name
the pin did not carry is new since the pin."""
files = {
"pinsha0000": ['load("old.rom");'],
"headsha000": ['load("old.rom");', 'load("added.rom"); /* 0xdeadbeef */'],
}
original = upstream.fetch_file
upstream.fetch_file = lambda repo, rev, path, *a, **k: files[rev]
args = self._args()
args.watch_hashes = True
report = _sample_report()
try:
profile_sync._attach_detection(args, self._profile(), report)
finally:
upstream.fetch_file = original
by_name = {(i["path"], i["name"]): i["since_pin"] for i in report.new_files}
self.assertEqual(
by_name,
{("a.c", "old.rom"): False, ("a.c", "added.rom"): True,
("b.c", "old.rom"): False, ("b.c", "added.rom"): True},
)
self.assertIn(
{"path": "a.c", "kind": "crc32", "value": "deadbeef"}, report.new_hashes
)
def test_a_quota_signal_still_stops_the_pass(self):
original = upstream.fetch_file
@@ -2039,7 +2068,9 @@ class TestExtrasSurviveARefusingForge(unittest.TestCase):
upstream.fetch_file = quota
try:
with self.assertRaises(upstream.RateLimitError):
profile_sync._print_extras(self._args(), self._profile(), _sample_report())
profile_sync._attach_detection(
self._args(), self._profile(), _sample_report()
)
finally:
upstream.fetch_file = original
@@ -4112,11 +4143,35 @@ class TestOutputModesApplyTheirFlags(unittest.TestCase):
self.assertIn("clean", out)
self.assertIn("prose under an older pin", out)
def test_extras_are_refused_with_json(self):
code, _, err = self._main("--json", "--detect-new-files")
def test_diffs_are_refused_with_json(self):
code, _, err = self._main("--json", "--full-diff")
self.assertEqual(code, 1)
self.assertIn("--full-diff", err)
def test_markdown_refuses_detection(self):
code, _, err = self._main("--markdown", "--detect-new-files")
self.assertEqual(code, 1)
self.assertIn("--detect-new-files", err)
def test_json_carries_detection(self):
"""check_freshness reads --json: a new upstream file or hash printed
only in the text report stayed a human reading."""
from unittest import mock
def detect(args, profile, report):
report.new_files = [
{"path": "a.c", "line": 3, "name": "new.rom", "since_pin": True}
]
report.new_hashes = [{"path": "a.c", "kind": "md5", "value": "0" * 32}]
with mock.patch.object(profile_sync, "_attach_detection", side_effect=detect):
code, out, err = self._main("--json", "--detect-new-files", "--watch-hashes")
self.assertEqual(code, 0, err)
rows = json.loads(out)
self.assertEqual(rows[0]["new_files"][0]["name"], "new.rom")
self.assertTrue(rows[0]["new_files"][0]["since_pin"])
self.assertEqual(rows[0]["new_hashes"][0]["kind"], "md5")
def test_json_carries_the_version_check(self):
"""check_freshness asks for --json --check-version: refused, its
profile row read an empty report as unreadable on every run."""