fix(block-ci): normalize artifact paths from both checker entry points

This commit is contained in:
pingqiu committed 2026-12-05 05:50:09 -08:00
1 parent 0c510646dd
commit c06afc5a26
2 files changed
+26 -4

No files matched your search

+22 -3
View File
@@ -3,6 +3,7 @@ from pathlib import Path
import copy
import importlib.util
import os
import shutil
import re
import subprocess
import tempfile
@@ -173,9 +174,27 @@ class PortTests(unittest.TestCase):
artifact.parent.mkdir(parents=True); artifact.write_text("")
git("add", "."); git("commit", "-m", "artifact")
artifact_head = git("rev-parse", "HEAD").decode().strip()
leak = subprocess.run(["bash", str(HERE / "public-text-check.sh"), pattern_head, artifact_head, str(title), str(body)], cwd=module, capture_output=True, timeout=20)
self.assertEqual(leak.returncode, 1)
self.assertIn(b"artifact path: " + artifact_path.encode(), leak.stdout)
command = ["bash", str(HERE / "public-text-check.sh"), pattern_head, artifact_head, str(title), str(body)]
for cwd in (root, module):
leak = subprocess.run(command, cwd=cwd, capture_output=True, timeout=20)
self.assertEqual(leak.returncode, 1, (cwd, leak.stdout, leak.stderr))
self.assertIn(b"artifact path: " + artifact_path.encode(), leak.stdout)
git("rm", str(artifact.relative_to(root))); git("commit", "-m", "remove artifact")
deleted = git("rev-parse", "HEAD").decode().strip()
removal = ["bash", str(HERE / "public-text-check.sh"), artifact_head, deleted, str(title), str(body)]
for cwd in (root, module):
result = subprocess.run(removal, cwd=cwd, capture_output=True, timeout=20)
self.assertEqual((result.returncode, result.stdout), (0, b"public-text: clean\n"), result.stderr)
fakebin = root / "fakebin"; fakebin.mkdir()
fakegit = fakebin / "git"
fakegit.write_text("#!/bin/sh\nfor arg; do\n if [ \"$arg\" = --diff-filter=ACMT ]; then\n printf 'docs/spec/partial.txt\\0'\n exit 23\n fi\ndone\nexec \"$PUBLIC_TEXT_REAL_GIT\" \"$@\"\n")
fakegit.chmod(0o755)
env = dict(os.environ, PUBLIC_TEXT_REAL_GIT=shutil.which("git"), PATH=str(fakebin) + os.pathsep + os.environ["PATH"])
for cwd in (root, module):
result = subprocess.run(removal, cwd=cwd, env=env, capture_output=True, timeout=20)
self.assertEqual(result.returncode, 2, (cwd, result.stdout, result.stderr))
self.assertIn(b"cannot enumerate artifact paths", result.stderr)
self.assertNotIn(b"public-text: clean", result.stdout)
def test_public_text_adapter_passes_the_module_self_test(self):
module = ROOT / "seaweed-block/.github/scripts"
+4 -1
View File
@@ -30,11 +30,14 @@ report() { # report WHERE < matching lines
}
# Raw run artifacts are not public specs, even with scrubbed contents.
# Allow deletions so existing artifacts can be removed.
if ! git diff --name-only -z --relative --no-renames --diff-filter=ACMT "$mb" "$head" -- docs/spec/ >"$paths"; then
repo_root=$(git rev-parse --show-toplevel)
if ! (cd "$repo_root" && git diff --name-only -z --no-relative --no-renames --diff-filter=ACMT "$mb" "$head" -- docs/spec/ seaweed-block/docs/spec/) >"$paths"; then
echo 'public-text: cannot enumerate artifact paths' >&2
exit 2
fi
while IFS= read -r -d '' path; do
# Match the module's paths the same way from either entry point.
path=${path#seaweed-block/}
if [[ $path =~ ^docs/spec/(.*/)?recorded-[^/]+(/|$) ]]; then
printf '%s\n' "$path" | report "artifact path"
fi