Просмотр исходного кода

package: bind canonical project and selftest

Codex Resource Selftest 4 месяцев назад
Родитель
Сommit
2084c0ea56
1 измененных файлов с 16 добавлено и 1 удалено
  1. 16 1
      tools/codex_harness.py

+ 16 - 1
tools/codex_harness.py

@@ -540,6 +540,9 @@ def create_unverified_package(
         raise FileNotFoundError(f"project is missing: {project}")
 
     repo = _repo_root()
+    canonical_project = (repo / PROJECT_PATH).resolve()
+    if project.resolve() != canonical_project:
+        raise ValueError("package project must be the canonical project.json")
     if FULL_COMMIT_RE.fullmatch(commit):
         commit_full = commit
     else:
@@ -566,6 +569,17 @@ def create_unverified_package(
         if not source.is_file():
             raise FileNotFoundError(f"package source is missing: {source}")
         shutil.copy2(source, package / name)
+    (package / "selftest.ps1").write_text(
+        "$ErrorActionPreference = 'Stop'\r\n"
+        "$bit = (Get-FileHash (Join-Path $PSScriptRoot 'fw.bit') -Algorithm SHA256).Hash.ToLowerInvariant()\r\n"
+        "$expectedBit = (Get-Content (Join-Path $PSScriptRoot 'bitstream_sha256.txt') -Raw).Trim().ToLowerInvariant()\r\n"
+        "if ($bit -ne $expectedBit) { throw 'bitstream hash mismatch' }\r\n"
+        "$projectHash = (Get-FileHash (Join-Path $PSScriptRoot 'project.json') -Algorithm SHA256).Hash.ToLowerInvariant()\r\n"
+        "$expectedProject = (Get-Content (Join-Path $PSScriptRoot 'project_config_sha256.txt') -Raw).Trim().ToLowerInvariant()\r\n"
+        "if ($projectHash -ne $expectedProject) { throw 'project hash mismatch' }\r\n",
+        encoding="ascii",
+        newline="",
+    )
     project_config_sha256 = sha256_file(package_project)
     source_manifest = build_source_manifest(repo)
     _write_json(package / "source_manifest.json", source_manifest)
@@ -725,7 +739,8 @@ def create_unverified_package(
         "package_class": package_class,
         "run_id": run_id,
         "project_id": PROJECT_ID,
-        "commit": commit,
+        "commit": compatibility_commit,
+        "commit_full": commit_full,
         "production_integration_commit": production_integration_commit,
         "created_at": datetime.now(timezone.utc).isoformat(),
         "bitstream": "fw.bit",