100 lines
6.7 KiB
Python
100 lines
6.7 KiB
Python
from pathlib import Path
|
|
import difflib
|
|
import hashlib
|
|
import json
|
|
import re
|
|
import shutil
|
|
|
|
base = Path(__file__).resolve().parent
|
|
canonical = Path(r"C:\kefu\admin-web")
|
|
build_root = Path(r"C:\zyt\identity-admin\.test-runtime\kefu-admin-web")
|
|
before = json.loads((base / "before-hashes.json").read_text(encoding="utf-8-sig"))
|
|
known = {row["path"] for row in before}
|
|
for source in sorted((base / "apps").rglob("*")):
|
|
if not source.is_file():
|
|
continue
|
|
relative = source.relative_to(base).as_posix()
|
|
if relative not in known:
|
|
assert not (canonical / relative).exists(), f"Unexpected canonical new file: {relative}"
|
|
before.append({"path": relative, "sha256": None})
|
|
(base / "before-hashes.json").write_text(json.dumps(before, indent=2), encoding="utf-8")
|
|
build = json.loads((base / "build-result.json").read_text(encoding="utf-8-sig"))
|
|
assert build["typecheck_exit"] == build["build_exit"] == build["token_check_exit"] == 0
|
|
assert build["workflow_test_exit"] == build["translation_test_exit"] == 0
|
|
assert all(row["unchanged"] for row in build["protected_files"])
|
|
sha = lambda path: hashlib.sha256(path.read_bytes()).hexdigest().upper()
|
|
entries = []
|
|
patch = []
|
|
for row in before:
|
|
relative = row["path"]
|
|
original = canonical / relative
|
|
source = base / relative
|
|
if row["sha256"] is None:
|
|
assert not original.exists()
|
|
old = []
|
|
else:
|
|
assert sha(original) == row["sha256"], f"Canonical changed: {relative}"
|
|
old = original.read_text(encoding="utf-8-sig").splitlines()
|
|
snapshot = base / "source-before/admin-web" / relative
|
|
snapshot.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(original, snapshot)
|
|
assert sha(source) == sha(build_root / relative), f"Build mismatch: {relative}"
|
|
test_only = relative.endswith(".test.ts")
|
|
payload = None
|
|
if not test_only:
|
|
target = base / "payload/admin-web" / relative
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(source, target)
|
|
payload = target.relative_to(base).as_posix()
|
|
entries.append({"path": relative, "canonical": str(original), "payload": payload,
|
|
"before_sha256": row["sha256"], "after_sha256": sha(source),
|
|
"test_only": test_only, "change_kind": "added" if row["sha256"] is None else "updated",
|
|
"canonical_unchanged": True})
|
|
patch.extend(line + "\n" for line in difflib.unified_diff(old, source.read_text(encoding="utf-8-sig").splitlines(),
|
|
fromfile="a/" + relative if old else "/dev/null", tofile="b/" + relative, lineterm=""))
|
|
(base / "frontend.patch").write_text("".join(patch), encoding="utf-8")
|
|
unstaged_differences = []
|
|
for source in (canonical / "apps/web-antd/src").rglob("*"):
|
|
if not source.is_file():
|
|
continue
|
|
relative = source.relative_to(canonical).as_posix()
|
|
if not (base / relative).exists() and sha(source) != sha(build_root / relative):
|
|
unstaged_differences.append(relative)
|
|
assert not unstaged_differences, unstaged_differences
|
|
config_files = sorted(Path(build["output"]).glob("**/*app-config*.js"))
|
|
config = [{"path": str(path), "sha256": sha(path), "content": path.read_text(encoding="utf-8")}
|
|
for path in config_files]
|
|
manifest = {"canonical_root": str(canonical), "stage_root": str(base), "payload_root": str(base / "payload/admin-web"),
|
|
"build_output": build["output"], "files": entries, "source_count": sum(not row["test_only"] for row in entries),
|
|
"test_file_count": sum(row["test_only"] for row in entries), "canonical_modified": False, "deployed": False,
|
|
"dependencies_installed": False, "unstaged_build_source_differences": unstaged_differences,
|
|
"contract": {"edit_permissions": ["knowledge:write", "im:content:read"],
|
|
"actions": ["approve", "approve_publish"],
|
|
"editor_eligibility": "Successful detail load, matching selected revision, draft status and action permission",
|
|
"save": "PUT draft, replace only the edited row with the returned revision and content, then recompute eligibility",
|
|
"approval": "Explicit confirmation after saving or canceling the edit; use each row's last saved revision",
|
|
"dialog": "Preserve selection and dialog on save; reload parent list without replacing the batch snapshot"},
|
|
"raw_build_runtime_configs": config, "packaging_transform_required": "Freeze /api/v2 in a uniquely content-hashed runtime config in packaged copy; preserve raw build evidence"}
|
|
(base / "frontend-manifest.json").write_text(json.dumps(manifest, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
workflow = (base / "frontend-workflow-tests.log").read_text(encoding="utf-8-sig")
|
|
workflow_files = int(re.search(r"Test Files\s+(\d+) passed", workflow)[1])
|
|
workflow_tests = int(re.search(r"Tests\s+(\d+) passed", workflow)[1])
|
|
commands = [
|
|
{"command": "pnpm.cmd exec vitest run apps/web-antd/src/views/knowledge apps/web-antd/src/api/knowledge-review.test.ts",
|
|
"exit_code": 0, "test_files": workflow_files, "tests_passed": workflow_tests, "log": str(base / "frontend-workflow-tests.log")},
|
|
{"command": "pnpm.cmd exec vitest run apps/web-antd/src/locales/i18n-coverage.test.ts -t 'translates every'",
|
|
"exit_code": 0, "tests_passed": 2, "tests_skipped": 1, "log": str(base / "frontend-translation-tests.log")},
|
|
{"command": "pnpm.cmd --filter @vben/web-antd run typecheck", "exit_code": 0, "log": str(base / "frontend-typecheck.log")},
|
|
{"command": "pnpm.cmd --filter @vben/web-antd exec vite build --mode production --outDir dist-batch-inline-20261105",
|
|
"exit_code": 0, "log": str(base / "frontend-build.log")},
|
|
{"command": "node scripts/verify-token-build.mjs " + build["output"], "exit_code": 0, "log": str(base / "frontend-token-check.log")},
|
|
]
|
|
(base / "commands.json").write_text(json.dumps({"cwd": str(build_root), "commands": commands}, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
result = {"manifest": str(base / "frontend-manifest.json"), "payload": str(base / "payload/admin-web"),
|
|
"report": str(base / "frontend-report.md"), "build": build["output"], "build_index_sha256": build["index_sha256"],
|
|
"source_count": manifest["source_count"], "test_file_count": manifest["test_file_count"], "workflow_tests_passed": workflow_tests,
|
|
"translation_tests_passed": 2, "typecheck_exit": 0, "build_exit": 0, "token_check_exit": 0,
|
|
"canonical_unchanged": True, "protected_files_unchanged": len(build["protected_files"]), "deployed": False}
|
|
(base / "frontend-result.json").write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
print(json.dumps(result, ensure_ascii=False, indent=2))
|