imbajin commented on code in PR #3271:
URL: https://github.com/apache/hugegraph/pull/3271#discussion_r4190592647


##########
.github/scripts/check-rerun.py:
##########
@@ -0,0 +1,147 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Check the failed run again immediately before an automatic retry."""
+
+import argparse
+import io
+import json
+import zipfile
+import os
+import subprocess
+from urllib.parse import quote, urlencode
+
+
+def api(path, binary=False):
+    result = subprocess.run(
+        ["gh", "api", "--method", "GET", path], check=True,
+        capture_output=True, timeout=30,
+    )
+    return result.stdout if binary else json.loads(result.stdout)
+
+
+def tested_base_matches(repository, run_id, pr, sha, fetch):
+    artifacts = 
fetch(f"repos/{repository}/actions/runs/{run_id}/artifacts?per_page=100")["artifacts"]
+    candidates = [a for a in artifacts if a.get("name") == "ci-plan" and not 
a.get("expired")]
+    for artifact in candidates:
+        payload = 
fetch(f"repos/{repository}/actions/artifacts/{artifact['id']}/zip", binary=True)

Review Comment:
   ⚠️ Blocking: no. Summary: The retry checker buffers the full PR-produced 
ci-plan ZIP before enforcing a size limit. Evidence: this API call loads the 
ZIP into memory, and the 1 MiB check applies only to plan.json after the 
download at lines 42-45; this script runs in the privileged workflow_run job 
with actions: write. Please reject artifacts with missing, invalid, or 
oversized size_in_bytes before fetching, or stream the ZIP through a hard byte 
cap.



##########
.github/scripts/ci-policy.py:
##########
@@ -0,0 +1,573 @@
+#!/usr/bin/env python3
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Conservative CI selection and GitHub-verified test receipt reuse."""
+
+import argparse
+import base64
+import hashlib
+import io
+import json
+import os
+from pathlib import Path
+import subprocess
+import zipfile
+from urllib.parse import urlencode
+
+MODULES = {
+    "server": ["server", "commons", "struct", "pd", "store", "hstore", 
"cluster", "docker", "helm", "dependency_license"],
+    "toolchain": ["client", "loader", "tools", "spark", "hubble", "go"],
+}
+PREFIXES = {
+    "server": {"hugegraph-server/": "server", "hugegraph-commons/": "commons",
+               "hugegraph-struct/": "struct", "hugegraph-pd/": "pd", 
"hugegraph-store/": "store",
+               "hugegraph-cluster-test/": "cluster", "docker/": "docker", 
"helm/": "helm"},
+    "toolchain": {"hugegraph-client/": "client", "hugegraph-client-go/": "go",
+                  "hugegraph-loader/": "loader", "hugegraph-tools/": "tools",
+                  "hugegraph-spark-connector/": "spark", "hugegraph-hubble/": 
"hubble"},
+}
+WORKFLOWS = {
+    "server": {"server-ci.yml": MODULES["server"], "commons-ci.yml": 
["commons"],
+               "pd-store-ci.yml": ["pd", "store", "hstore"], 
"cluster-test-ci.yml": ["cluster"],
+               "docker-build-ci.yml": ["docker"], "helm-chart-ci.yml": 
["helm"],
+               "codeql-analysis.yml": [], "riscv64-ci.yml": ["server"], 
"check-dependencies.yml": ["dependency_license"]},
+    "toolchain": {"client-ci.yml": ["client"], "client-go-ci.yml": ["go"],
+                  "loader-ci.yml": ["loader"], "tools-ci.yml": ["tools"],
+                  "spark-connector-ci.yml": ["spark"], "hubble-ci.yml": 
["hubble"],
+                  "codeql-analysis.yml": []},
+}
+DEPENDENTS = {
+    "server": {"commons": ["server", "pd", "store", "hstore", "cluster"],
+               "struct": ["server", "pd", "store", "hstore", "cluster"],
+               "server": ["pd", "store", "hstore", "cluster"], "pd": ["store", 
"hstore", "cluster"],
+               "store": ["hstore", "cluster"], "hstore": ["cluster"]},
+    "toolchain": {"client": ["loader", "tools", "spark", "hubble"], "loader": 
["hubble"]},
+}
+
+
+def git(*args):
+    return subprocess.check_output(["git", *args], text=True).strip()
+
+
+def api(path, binary=False):
+    result = subprocess.run(["gh", "api", "--method", "GET", path], 
check=True, capture_output=True, timeout=30)
+    return result.stdout if binary else json.loads(result.stdout)
+
+
+def documentation(path, mode="100644"):
+    """Only prose and static documentation assets; never source or config."""
+    if mode != "100644":
+        return False
+    p = Path(path)
+    prose_names = {"README.md", "README_CN.md", "README_ZH.md", "AGENTS.md"}
+    module_roots = {prefix.rstrip("/") for mapping in PREFIXES.values() for 
prefix in mapping}
+    module_roots.update("hugegraph-server/" + module for module in [
+        "hugegraph-api", "hugegraph-core", "hugegraph-dist", 
"hugegraph-example",
+        "hugegraph-hbase", "hugegraph-hstore", "hugegraph-rocksdb", 
"hugegraph-test"])
+    if p.name in prose_names and (str(p.parent) == "." or str(p.parent) in 
module_roots):
+        return True
+    return path.startswith("docs/") and p.suffix.lower() in {".md", ".rst", 
".txt", ".png", ".jpg", ".jpeg", ".svg"}
+
+
+def unsafe_documentation(ref, paths):
+    entries = subprocess.check_output(["git", "ls-tree", "-rz", "--full-tree", 
ref]).split(b"\0")
+    for entry in entries:
+        if not entry:
+            continue
+        metadata, name = entry.split(b"\t", 1)
+        path = name.decode("utf-8", "surrogateescape")
+        if path in paths and documentation(path) and metadata.split(b" ", 
1)[0] != b"100644":
+            return True
+    return False
+
+
+def select(project, paths):
+    selected = set()
+    for path in paths:
+        if documentation(path):
+            continue
+        if project == "server" and (Path(path).name == "pom.xml" or 
path.startswith("install-dist/")):
+            selected.add("dependency_license")
+        if path.startswith(".github/workflows/") and Path(path).name in 
WORKFLOWS[project]:
+            selected.update(WORKFLOWS[project][Path(path).name])
+            continue
+        if path.endswith(".proto"):
+            return set(MODULES[project])
+        if project == "server" and path == 
"hugegraph-commons/hugegraph-common/src/main/resources/version.properties":
+            selected.update(["commons", "docker"])
+            continue
+        if project == "server" and path == 
"hugegraph-store/hg-store-dist/src/assembly/static/bin/util.sh":
+            selected.update(["store", "docker"])
+            continue
+        if project == "toolchain" and 
path.startswith("hugegraph-client/assembly/travis/"):
+            selected.update(["client", "go"])
+            continue
+        if project == "server":
+            if path.startswith("hugegraph-server/hugegraph-hstore/"):
+                selected.update(["server", "hstore"])
+                continue
+            if path.startswith("hugegraph-server/hugegraph-dist/"):
+                selected.update(["server", "pd", "store", "hstore", "docker", 
"cluster"])
+                continue
+            if path.startswith(("hugegraph-server/hugegraph-core/", 
"hugegraph-server/hugegraph-api/",
+                                "hugegraph-server/hugegraph-test/")):
+                selected.update(["server", "hstore"])
+                continue
+        module = next((value for prefix, value in PREFIXES[project].items() if 
path.startswith(prefix)), None)
+        if module is None or path.endswith(".proto"):
+            return set(MODULES[project])
+        selected.add(module)
+        if project == "server" and ("Dockerfile" in Path(path).name or 
"docker-entrypoint" in path):
+            selected.add("docker")
+    changed = True
+    while changed:
+        before = set(selected)
+        for module in before:
+            selected.update(DEPENDENTS[project].get(module, []))
+        changed = before != selected
+    return selected
+
+
+def external_context(inputs, selected):
+    context = dict(inputs or {})
+    if "hubble" not in selected:
+        context.pop("hubble", None)
+    return json.dumps(context, sort_keys=True, separators=(",", ":"))
+
+
+def packaged_readme_state(ref):
+    path = "hugegraph-hubble/README.md"
+    entry = git("ls-tree", ref, "--", path)
+    if not entry:
+        return "missing"
+    mode, kind, blob = entry.split("\t", 1)[0].split()
+    if mode != "100644" or kind != "blob":
+        return "invalid-mode:" + mode + ":" + blob
+    content = subprocess.check_output(["git", "cat-file", "blob", blob])
+    return "valid" if content.strip() else "empty:" + blob
+
+
+def fingerprint(ref, policy=False, project=None):
+    """Hash blob identities, including paths; exclude only the strict prose 
whitelist."""
+    entries = subprocess.check_output(["git", "ls-tree", "-rz", "--full-tree", 
ref]).split(b"\0")

Review Comment:
   ⚠️ Blocking: no. Summary: Local and API receipt fingerprints cover different 
tree shapes, so proof validation rejects valid receipts and reruns suites. 
Evidence: fingerprint() uses git ls-tree -rz without recursive traversal here, 
while remote_fingerprint() hashes recursive leaf entries at lines 185-200; 
validate_proof_run() compares those digests at lines 283-285. Please make both 
paths hash the same recursive entries with the same filters, and add an 
unmocked fingerprint-equivalence check.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to