Co-authored-by: multica <multica@users.noreply.github.com> Co-authored-by: multica-agent <github@multica.ai>
156 lines
5.8 KiB
Python
156 lines
5.8 KiB
Python
"""Publish exclusive audit files, verify the ledger and freeze the full baseline."""
|
|
|
|
import csv
|
|
import hashlib
|
|
import json
|
|
import socket
|
|
import sqlite3
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
HERE = Path(__file__).resolve().parent
|
|
LOCAL = ROOT / ".local-evidence/batch175-closure"
|
|
OUTPUT = LOCAL / "audit-final-expanded"
|
|
NAMES = [
|
|
"existing-library-audit.json",
|
|
"historical-comment-texts.json",
|
|
"current-instruction.json",
|
|
"qualification-records.json",
|
|
"ledger.json",
|
|
"saved-value-proof.json",
|
|
"notes-proof.json",
|
|
"identity-records.json",
|
|
"source-text-records.json",
|
|
"remaining-work.json",
|
|
"summary.json",
|
|
]
|
|
|
|
|
|
def sha(raw):
|
|
return hashlib.sha256(raw).hexdigest()
|
|
|
|
|
|
def publish(path, raw):
|
|
if path.exists():
|
|
assert path.read_bytes() == raw, path
|
|
else:
|
|
with path.open("xb") as f:
|
|
f.write(raw)
|
|
|
|
|
|
def write(name, obj):
|
|
publish(HERE / name, (json.dumps(obj, ensure_ascii=False, indent=2) + "\n").encode())
|
|
|
|
|
|
def main():
|
|
for name in NAMES:
|
|
publish(HERE / name, (OUTPUT / name).read_bytes())
|
|
ledger = json.loads((HERE / "ledger.json").read_bytes())
|
|
# CSV carries every JSON column; structured cells are valid JSON strings.
|
|
with (HERE / "ledger.csv").open("x", encoding="utf-8-sig", newline="") as f:
|
|
writer = csv.DictWriter(f, fieldnames=list(ledger[0]), lineterminator="\n")
|
|
writer.writeheader()
|
|
writer.writerows(
|
|
{
|
|
k: json.dumps(v, ensure_ascii=False) if isinstance(v, (dict, list)) else v
|
|
for k, v in row.items()
|
|
}
|
|
for row in ledger
|
|
)
|
|
with (HERE / "ledger.csv").open(encoding="utf-8-sig", newline="") as f:
|
|
csvrows = list(csv.DictReader(f))
|
|
assert len(csvrows) == len(ledger) == 155
|
|
for c, r in zip(csvrows, ledger):
|
|
assert set(c) == set(r)
|
|
for k, v in r.items():
|
|
if isinstance(v, (dict, list)):
|
|
assert json.loads(c[k]) == v, (r["source_repo_path"], k)
|
|
else:
|
|
assert c[k] == ("" if v is None else str(v))
|
|
readable = (HERE / "逐文件总账与剩余条件.md").read_text()
|
|
assert readable.count("\n## ") == 155
|
|
assert all(readable.count("源:`" + r["source_repo_path"] + "`") == 1 for r in ledger)
|
|
# Independently check actual stored source bytes as JSON, and every actual qualification row.
|
|
with sqlite3.connect(f"file:{LOCAL / 'library.db'}?mode=ro", uri=True) as conn:
|
|
conn.row_factory = sqlite3.Row
|
|
rows = list(conn.execute("SELECT * FROM workflows ORDER BY source_repo_path"))
|
|
assert len(rows) == 155
|
|
for row in rows:
|
|
original = json.loads((ROOT / row["source_repo_path"]).read_bytes().decode("utf-8-sig"))
|
|
stored = json.loads(row["raw_source_json"])
|
|
# Compare canonical text here; audit.py separately checks recursive primitive JSON types.
|
|
assert json.dumps(original, sort_keys=True) == json.dumps(stored, sort_keys=True)
|
|
assert row["is_enabled"] == 0
|
|
assert row["doc_completed_at"] is None and row["exec_verified_at"] is None
|
|
doc = json.loads(row["doc_json"])
|
|
assert doc["draft"] is True and doc["fixed_version"]["matched"] is True
|
|
assert doc["dependencies"]["check_state"] == "unchecked"
|
|
frozen = json.loads((LOCAL / "baseline-files.json").read_bytes())
|
|
for row in frozen["files"]:
|
|
assert sha((ROOT / row["path"]).read_bytes()) == row["sha256"], row["path"]
|
|
publish(HERE / "baseline-files.json", (LOCAL / "baseline-files.json").read_bytes())
|
|
publish(HERE / "preflight.json", (LOCAL / "preflight.json").read_bytes())
|
|
publish(HERE / "startup-limitations.md", (LOCAL / "startup-limitations.md").read_bytes())
|
|
# Preserve actual historical context inputs, without the unrelated attachment envelope.
|
|
publish(HERE / "instruction-snapshot.json", (LOCAL / "instruction.json").read_bytes())
|
|
publish(
|
|
HERE / "thread-scan.json",
|
|
(ROOT / ".local-evidence/resume174-check/threads.json").read_bytes(),
|
|
)
|
|
inherited = []
|
|
old = ROOT / "docs/hel-892/minimax-extend-api-document-evidence"
|
|
for name in [
|
|
"validation-results.json",
|
|
"browser-results.json",
|
|
"package-check.json",
|
|
"import-protection.json",
|
|
"repeatability.json",
|
|
"frozen-baseline.json",
|
|
"audit-summary.json",
|
|
"completed-log-records.json",
|
|
]:
|
|
p = old / name
|
|
inherited.append(
|
|
dict(
|
|
path=p.relative_to(ROOT).as_posix(),
|
|
sha256=sha(p.read_bytes()),
|
|
original_commit=frozen["base"],
|
|
rerun_this_batch=False,
|
|
)
|
|
)
|
|
write("inherited-evidence.json", inherited)
|
|
ports = []
|
|
for port in (8247, 5173):
|
|
with socket.socket() as s:
|
|
s.settimeout(1)
|
|
assert s.connect_ex(("127.0.0.1", port)) != 0
|
|
with socket.socket() as s:
|
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
s.bind(("127.0.0.1", port))
|
|
ports.append(dict(port=port, connection_refused=True, bindable=True))
|
|
write(
|
|
"final-verification.json",
|
|
dict(
|
|
base=frozen["base"],
|
|
baseline_files=len(frozen["files"]),
|
|
baseline_unchanged=True,
|
|
allowed_product_changes=[],
|
|
csv_all_columns_equal=True,
|
|
chinese_sections=155,
|
|
actual_fresh_library_rows=155,
|
|
raw_source_json_equal=True,
|
|
isolated_only=True,
|
|
ports=ports,
|
|
new_browser_or_build_run=False,
|
|
),
|
|
)
|
|
print(
|
|
"PASS all CSV columns/155 Chinese sections/source DB/qualifications;",
|
|
len(frozen["files"]),
|
|
"baseline files unchanged; ports refused/bindable",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|