Co-authored-by: multica <multica@users.noreply.github.com> Co-authored-by: multica-agent <github@multica.ai>
139 lines
5.6 KiB
Python
139 lines
5.6 KiB
Python
"""Verify provenance-only differences and publish into an exclusively new directory."""
|
|
|
|
import csv
|
|
import json
|
|
import socket
|
|
from pathlib import Path
|
|
|
|
from attribution import CODE, sha
|
|
from rebuild import HISTORY_KEYS
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
HERE = Path(__file__).resolve().parent
|
|
LOCAL = ROOT / ".local-evidence/history-attribution-correction"
|
|
PRIOR = HERE / "prior175"
|
|
NAMES = [
|
|
"ledger.json",
|
|
"ledger.csv",
|
|
"summary.json",
|
|
"remaining-work.json",
|
|
"candidate-matrix.json",
|
|
"row-field-differences.json",
|
|
"comment-role-records.json",
|
|
"git-facts.json",
|
|
"逐文件总账与剩余条件.md",
|
|
"进度说明.md",
|
|
]
|
|
ALLOWED = {
|
|
"docs/hel-892/batch175-closure-evidence/audit.py",
|
|
"docs/hel-892/batch175-closure-evidence/README.md",
|
|
}
|
|
|
|
|
|
def load(path):
|
|
return json.loads(path.read_bytes())
|
|
|
|
|
|
def main():
|
|
source = LOCAL / "final"
|
|
new, old = load(source / "ledger.json"), load(PRIOR / "ledger.json")
|
|
matrix = load(source / "candidate-matrix.json")
|
|
assert len(new) == len(matrix) == 155
|
|
with (source / "ledger.csv").open(encoding="utf-8-sig", newline="") as f:
|
|
csvrows = list(csv.DictReader(f))
|
|
assert len(csvrows) == 155
|
|
for index, (before, after, candidate, csvrow) in enumerate(zip(old, new, matrix, csvrows)):
|
|
assert (
|
|
before["source_repo_path"] == after["source_repo_path"] == candidate["source_repo_path"]
|
|
)
|
|
assert {k: v for k, v in after.items() if k in before and k not in HISTORY_KEYS} == {
|
|
k: v for k, v in before.items() if k not in HISTORY_KEYS
|
|
}
|
|
assert set(after) == set(csvrow)
|
|
for k, v in after.items():
|
|
if isinstance(v, (dict, list)):
|
|
assert json.loads(csvrow[k]) == v
|
|
else:
|
|
assert csvrow[k] == ("" if v is None else str(v))
|
|
assert len(candidate["definition_pin_introductions"]) == 1
|
|
selected = candidate["delivery_comment_id"]
|
|
assert selected == after["delivery_comment_id"]
|
|
if selected != "unknown":
|
|
accepted = [c for c in candidate["candidates"] if c["candidate_accepted"]]
|
|
assert len(accepted) == 1 and accepted[0]["comment_id"] == selected
|
|
for parent in after["review_basis"].get("all_parent_records", []):
|
|
assert parent["parent_id"] == selected
|
|
assert after["historical_attribution_evidence"] == f"candidate-matrix.json#/{index}"
|
|
# All old remaining conditions survive byte-for-byte as parsed JSON, with history appended.
|
|
for before, after in zip(
|
|
load(PRIOR / "remaining-work.json"), load(source / "remaining-work.json")
|
|
):
|
|
assert {k: v for k, v in after.items() if k != "historical_attribution"} == before
|
|
summary = load(source / "summary.json")
|
|
previous = load(PRIOR / "summary.json")
|
|
for key in previous:
|
|
if key not in ("delivery_unresolved", "review_basis_unknown"):
|
|
assert summary[key] == previous[key]
|
|
assert summary["delivery_unresolved"] == sum(r["delivery_comment_id"] == "unknown" for r in new)
|
|
assert summary["review_basis_unknown"] == sum(
|
|
r["review_basis"]["kind"] == "unknown" for r in new
|
|
)
|
|
frozen, changed = [], []
|
|
for row in load(HERE / "baseline-files.json")["files"]:
|
|
raw = (ROOT / row["path"]).read_bytes()
|
|
if row["path"] in ALLOWED:
|
|
if sha(raw) != row["sha256"]:
|
|
changed.append(row["path"])
|
|
else:
|
|
assert sha(raw) == row["sha256"], row["path"]
|
|
frozen.append(row)
|
|
assert set(changed) == ALLOWED
|
|
for row in load(HERE / "prior175-sha256.json")["files"]:
|
|
assert sha((ROOT / row["archive_path"]).read_bytes()) == row["sha256"]
|
|
# Current product allowlist bytes and all original proof files stayed frozen above.
|
|
assert any(r["path"] == CODE for r in frozen)
|
|
readable = (source / "逐文件总账与剩余条件.md").read_text()
|
|
assert readable.count("\n## ") == 155
|
|
for row in new:
|
|
assert readable.count("源:`" + row["source_repo_path"] + "`") == 1
|
|
for name in NAMES:
|
|
with (HERE / name).open("xb") as f:
|
|
f.write((source / name).read_bytes())
|
|
ports = []
|
|
for port in [8247, 5173]:
|
|
with socket.socket() as sock:
|
|
assert sock.connect_ex(("127.0.0.1", port)) != 0
|
|
with socket.socket() as sock:
|
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
sock.bind(("127.0.0.1", port))
|
|
ports.append(dict(port=port, refused=True, bindable=True))
|
|
facts = dict(
|
|
base="0e3e7b071f4c293642900849db8b1ead997417b8",
|
|
original_ledger_sha256=sha((PRIOR / "ledger.json").read_bytes()),
|
|
corrected_ledger_sha256=sha((HERE / "ledger.json").read_bytes()),
|
|
original_csv_sha256=sha((PRIOR / "ledger.csv").read_bytes()),
|
|
corrected_csv_sha256=sha((HERE / "ledger.csv").read_bytes()),
|
|
frozen_baseline_files=len(frozen),
|
|
changed_existing_tools=sorted(changed),
|
|
product_changes=0,
|
|
rows=155,
|
|
non_history_row_fields_unchanged=True,
|
|
remaining_non_history_unchanged=True,
|
|
csv_all_columns_equal=True,
|
|
independent_value_note_qualification_checks_rerun=False,
|
|
ports=ports,
|
|
formal_legacy_rule_removed="Attributor.select replaces full-text SHA/date matching",
|
|
)
|
|
with (HERE / "verification.json").open("x") as f:
|
|
json.dump(facts, f, ensure_ascii=False, indent=2)
|
|
f.write("\n")
|
|
print(
|
|
"PASS 155 rows/full CSV/Chinese; approved data frozen;",
|
|
len(frozen),
|
|
"old files unchanged, only2 existing tools/docs changed; ports refused/bindable",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|