diff --git a/tests/test_current_site_stylesheet_order.py b/tests/test_current_site_stylesheet_order.py
index 1742683c8..594fce6ab 100644
--- a/tests/test_current_site_stylesheet_order.py
+++ b/tests/test_current_site_stylesheet_order.py
@@ -18,6 +18,109 @@ class StylesheetOrder(unittest.TestCase):
def order(self, path):
return LINK.findall(path.read_text(encoding="utf-8"))
+ def live_publication(self, root, *, predecessor):
+ import test_current_site_history as history_controls
+ harness = history_controls.CurrentSiteHistoryTests()
+ harness.setUp()
+ public, payload = harness.prepare(root)
+ manifest = harness.publish(public)
+ files = harness.public_files(public)
+ if predecessor:
+ # Model the complete prior publication, not an archive-only alias.
+ # Its exact HTML differs solely in these two literal head links.
+ for row in manifest["current_observation"]["files"]:
+ name = row["path"]
+ current = files[name]
+ old = current.replace(
+ b' ',
+ b' ', 1)
+ self.assertNotEqual(old, current, name)
+ self.assertEqual(len(old), len(current))
+ files[name] = old
+ row["sha256"] = hashlib.sha256(old).hexdigest()
+ for alias in manifest["aliases"]:
+ alias["sha256"] = hashlib.sha256(files[alias["path"]]).hexdigest()
+ harness.rebind_manifest(files, manifest)
+ return harness, payload, files, manifest
+
+ def test_restore_predecessor_live_publication_then_build_new_style_first(self):
+ import current_site_history as history
+ import test_current_site_history as history_controls
+ with TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ for name in ("public", "runner", "next"):
+ (root / name).mkdir()
+ harness, _, files, manifest = self.live_publication(root / "public", predecessor=True)
+ self.assertEqual(len(manifest["current_observation"]["files"]), 50)
+ archives = {n: b for n, b in files.items()
+ if n.startswith("snapshots/") and n != "snapshots/index.json"}
+ runner, payload = harness.prepare(root / "runner")
+ try:
+ history.restore_history(runner, history_controls.PublicFixtureReader(files),
+ expected_manifest_sha=hashlib.sha256(files["snapshots/index.json"]).hexdigest())
+ except ValueError as error:
+ self.fail(f"exact predecessor live publication must restore: {error}")
+ for row in manifest["current_observation"]["files"]:
+ self.assertEqual((runner / row["path"]).read_bytes(), files[row["path"]])
+ self.assertEqual(self.order(runner / row["path"]), ["brand.css", "style.css", "current.css"])
+ result = harness.build.run_build(runner, payload)
+ self.assertEqual(result.returncode, 0, result.stderr)
+ fresh = harness.publish(runner)
+ for row in fresh["current_observation"]["files"]:
+ self.assertEqual(self.order(runner / row["path"]), ["style.css", "brand.css", "current.css"])
+ for name, raw in archives.items():
+ self.assertEqual((runner / name).read_bytes(), raw, name)
+ next_site, _ = harness.prepare(root / "next")
+ history.restore_history(next_site, history_controls.PublicFixtureReader(harness.public_files(runner)))
+ for row in fresh["current_observation"]["files"]:
+ self.assertEqual((next_site / row["path"]).read_bytes(), (runner / row["path"]).read_bytes())
+ for name, raw in archives.items():
+ self.assertEqual((next_site / name).read_bytes(), raw, name)
+
+ def test_restore_live_compatibility_refuses_forged_or_incomplete_maps_without_writes(self):
+ import current_site_history as history
+ import test_current_site_history as history_controls
+ with TemporaryDirectory() as tmp:
+ root = Path(tmp)
+ (root / "public").mkdir()
+ harness, _, files, manifest = self.live_publication(root / "public", predecessor=True)
+ for case in ("non-style", "mixed", "missing", "unmatched"):
+ with self.subTest(case=case):
+ forged_files = dict(files)
+ forged = copy.deepcopy(manifest)
+ name = "nodes/beta.html"
+ if case == "non-style":
+ changed = files[name].replace(b"HOLD", b"OPEN", 1)
+ self.assertNotEqual(changed, files[name])
+ elif case == "mixed":
+ changed = files[name].replace(
+ b' ',
+ b' ', 1)
+ self.assertNotEqual(changed, files[name])
+ else:
+ changed = files[name]
+ if case == "missing":
+ forged["current_observation"]["files"] = [r for r in forged["current_observation"]["files"] if r["path"] != name]
+ forged["aliases"] = [r for r in forged["aliases"] if r["path"] != name]
+ forged_files.pop(name)
+ else:
+ forged_files[name] = changed
+ checksum = "e" * 64 if case == "unmatched" else hashlib.sha256(changed).hexdigest()
+ for row in forged["current_observation"]["files"] + forged["aliases"]:
+ if row["path"] == name:
+ row.update(bytes=len(changed), sha256=checksum)
+ forged["total_bytes"] = history.history_size(forged["archives"], forged["aliases"], forged["current_observation"])
+ forged["capacity"] = history.capacity_record(forged["archives"], forged["total_bytes"])
+ harness.rebind_manifest(forged_files, forged)
+ (root / case).mkdir()
+ runner, _ = harness.prepare(root / case)
+ before = harness.public_files(runner)
+ reason = "history alias union is incomplete" if case == "missing" else "live static reading does not match the exact observation"
+ with self.assertRaisesRegex(ValueError, reason):
+ history.restore_history(runner, history_controls.PublicFixtureReader(forged_files),
+ expected_manifest_sha=hashlib.sha256(forged_files["snapshots/index.json"]).hexdigest())
+ self.assertEqual(harness.public_files(runner), before)
+
def test_live_node_pages_load_style_before_brand(self):
pages = sorted((SITE / "nodes").glob("*.html"))
self.assertTrue(pages)
diff --git a/tools/current_site_history.py b/tools/current_site_history.py
index e8f5a3623..75a849487 100644
--- a/tools/current_site_history.py
+++ b/tools/current_site_history.py
@@ -1102,6 +1102,10 @@ def restore_history(site, reader=None, expected_manifest_sha=None):
raise ValueError("published current observation has different mathematical material")
ensure_render_budget(data, remote)
live = render_live_current_v2(data, remote)
+ if [descriptor(k, v) for k, v in sorted(live.items())] != manifest["current_observation"]["files"]:
+ # Restore the exact predecessor publication only as a complete map.
+ # New builds/publications keep the style-first renderer default.
+ live = render_live_current_v2(data, remote, style_first=False)
if [descriptor(k, v) for k, v in sorted(live.items())] != manifest["current_observation"]["files"]:
raise ValueError("live static reading does not match the exact observation")
historical = {}
@@ -1500,19 +1504,21 @@ def _live_v2_current_section(data, meta):
'')
-def _live_v2_static_page(data, meta, title, body):
+def _live_v2_static_page(data, meta, title, body, *, style_first=True):
return (f'\n{_V1_GENERATED}\n
\n'
' \n'
' \n'
f'{_v1_escape(title)} · Current research dependency atlas \n'
- ' \n'
- '\n'
+ + (' \n'
+ if style_first else
+ ' \n')
+ + '\n'
'Home · Explore · Research · Library · Current dependencies · Current static graph index \n'
+ _live_v2_current_section(data, meta)
+ '\n' + body + '\n \n').encode("utf-8")
-def render_live_current_v2(data, meta):
+def render_live_current_v2(data, meta, *, style_first=True):
"""Render current static routes from the full fresh schema-1 observation."""
graph = data["graph"]["data"]
pages = {}
@@ -1525,7 +1531,7 @@ def render_live_current_v2(data, meta):
+ '\nOriginal node metadata '
+ _v1_escape(json.dumps(node, ensure_ascii=False, indent=2, sort_keys=True)) + ' \n'
+ _v1_neighbors(data, node_id))
- pages[f"nodes/{node_id}.html"] = _live_v2_static_page(data, meta, node_id, body)
+ pages[f"nodes/{node_id}.html"] = _live_v2_static_page(data, meta, node_id, body, style_first=style_first)
items = "\n".join(f'{_v1_escape(node_id)} · {_v1_escape(node.get("kind", "not_recorded"))} · {_v1_escape(node.get("classification", "not_recorded"))} '
for node_id, node in graph["nodes"].items())
required = sum(edge["required"] for edge in graph["edges"])
@@ -1537,7 +1543,7 @@ def render_live_current_v2(data, meta):
f'{len(data["sources"])} indexed files at the pinned repository commits. Legacy, quarantine, recovery, scratch and operational paths are excluded from this discovery population.
\n\n'
+ _v1_source_list(data["sources"]) + '\n \n'
+ _v2_equation_collection(data))
- pages["nodes/index.html"] = _live_v2_static_page(data, meta, "Current static graph, equation excerpts and source index", body)
+ pages["nodes/index.html"] = _live_v2_static_page(data, meta, "Current static graph, equation excerpts and source index", body, style_first=style_first)
return pages