test(grpc-data): pinned pre-H2 SOURCE option (rig.py up --source-revision), wire tap, H05 v1-origin gate (#921); A09 driver-failure ack revert scenario (#927)
This commit is contained in:
@@ -517,26 +517,91 @@ def run_command(argv, *, timeout=120, environment=None):
|
||||
return result.stdout
|
||||
|
||||
|
||||
def _image_input(name):
|
||||
"""Whether repository-relative `name` is an image build input (the filter both tree hashes share)."""
|
||||
suffix = Path(name).suffix
|
||||
return not name.startswith(("docs/", "tests/", ".playwright-mcp/")) and (
|
||||
suffix in {".cs", ".csproj", ".props", ".targets", ".slnx", ".resx", ".razor", ".css", ".js", ".proto"}
|
||||
or name in {"global.json", "NuGet.Config", "nuget.config", "Directory.Build.rsp", ".dockerignore", "scripts/validation/grpc-data/Dockerfile"}
|
||||
or name.startswith("src/") and suffix == ".json")
|
||||
|
||||
|
||||
def _tree_hash(root, names):
|
||||
import hashlib
|
||||
digest = hashlib.sha256()
|
||||
for name in sorted(set(filter(None, names))):
|
||||
path = root / name
|
||||
if not _image_input(name):
|
||||
continue
|
||||
if path.is_file() and not path.is_symlink():
|
||||
digest.update(name.encode() + b"\0")
|
||||
digest.update(hashlib.sha256(path.read_bytes()).digest())
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def source_tree_hash():
|
||||
"""Hash image build inputs, including pending/new code, excluding review evidence.
|
||||
|
||||
Harness Python and test sources have their own evidence and do not enter the
|
||||
Host/seeder/probe binaries. Notes can change without invalidating an image.
|
||||
"""
|
||||
import hashlib
|
||||
paths = run_command(["git", "ls-files", "--cached", "--others", "--exclude-standard", "-z"]).split("\0")
|
||||
digest = hashlib.sha256()
|
||||
for name in sorted(set(filter(None, paths))):
|
||||
path = ROOT / name
|
||||
if (name.startswith(("docs/", "tests/", ".playwright-mcp/")) or
|
||||
not (path.suffix in {".cs", ".csproj", ".props", ".targets", ".slnx", ".resx", ".razor", ".css", ".js", ".proto"}
|
||||
or name in {"global.json", "NuGet.Config", "nuget.config", "Directory.Build.rsp", ".dockerignore", "scripts/validation/grpc-data/Dockerfile"}
|
||||
or name.startswith("src/") and path.suffix == ".json")):
|
||||
continue
|
||||
if path.is_file() and not path.is_symlink():
|
||||
digest.update(name.encode() + b"\0")
|
||||
digest.update(hashlib.sha256(path.read_bytes()).digest())
|
||||
return digest.hexdigest()
|
||||
return _tree_hash(ROOT, paths)
|
||||
|
||||
|
||||
# lmxopcua#921: a pinned pre-H2 SOURCE pair (plan §4.3 mixed versions, row "new consumer → v1 origin"). A pinned revision must
|
||||
# CONTAIN X0 (a pre-X0 node rejects the whole data-connection snapshot once any newer bit is authored, so it is not the v1 origin
|
||||
# the row describes) and must NOT contain H2 (whose merge adds the origin HistoryRead RPC and the `history` feature).
|
||||
X0_MERGE = "a15912539f8a48804c31e74b2558994a50a338e6"
|
||||
H2_MERGE = "ef938b435bbad2862bcd4b8e1f39e0b1ef2089b2"
|
||||
PINNED_DATA_PROTO = "src/Core/ZB.MOM.WW.OtOpcUa.Commons/Protos/data_connection.proto"
|
||||
# The only rig file added to a pinned tree: the self-contained data-listener wire tap (ASP.NET Core only, compiles at any revision).
|
||||
PINNED_OVERLAY_FILES = ("scripts/validation/grpc-data/node-probe/WireTap.cs",)
|
||||
|
||||
|
||||
def resolve_pinned_source_revision(revision, *, git=None):
|
||||
"""The full SHA of `revision` once it is proven a post-X0, pre-H2 commit; RigError otherwise."""
|
||||
git = git or (lambda *arguments: run_command(["git", *arguments]))
|
||||
if not isinstance(revision, str) or not re.fullmatch(r"[0-9a-f]{7,40}", revision):
|
||||
raise RigError("a pinned SOURCE revision must be a hexadecimal commit id")
|
||||
full = git("rev-parse", "--verify", "--quiet", revision + "^{commit}").strip()
|
||||
if not re.fullmatch(r"[0-9a-f]{40}", full):
|
||||
raise RigError("the pinned SOURCE revision does not name a commit")
|
||||
if git("merge-base", X0_MERGE, full).strip() != X0_MERGE:
|
||||
raise RigError("the pinned SOURCE revision predates X0 (tolerant readers); it would reject the whole snapshot")
|
||||
if git("merge-base", H2_MERGE, full).strip() == H2_MERGE:
|
||||
raise RigError("the pinned SOURCE revision contains H2; it is not a v1 (pre-history) origin")
|
||||
if re.search(r"^\s*rpc\s+HistoryRead\b", git("show", f"{full}:{PINNED_DATA_PROTO}"), re.M):
|
||||
raise RigError("the pinned SOURCE revision's data contract already has HistoryRead")
|
||||
return full
|
||||
|
||||
|
||||
def export_pinned_source(revision, directory):
|
||||
"""Extract `revision`'s committed tree into a new restricted `directory` and add the rig's wire tap."""
|
||||
import shutil
|
||||
import subprocess
|
||||
if directory.exists():
|
||||
raise RigError("pinned SOURCE export directory already exists")
|
||||
directory.mkdir(mode=0o700)
|
||||
archive = subprocess.Popen(["git", "archive", "--format=tar", revision], cwd=ROOT, stdout=subprocess.PIPE)
|
||||
try:
|
||||
extract = subprocess.run(["tar", "-x", "-C", str(directory)], stdin=archive.stdout, timeout=600, check=False)
|
||||
finally:
|
||||
archive.stdout.close()
|
||||
if archive.wait(timeout=600) != 0 or extract.returncode != 0:
|
||||
raise RigError("could not export the pinned SOURCE revision")
|
||||
for name in PINNED_OVERLAY_FILES:
|
||||
target = directory / name
|
||||
if target.exists():
|
||||
raise RigError("the pinned SOURCE tree already has a rig overlay file")
|
||||
shutil.copyfile(ROOT / name, target)
|
||||
return pinned_tree_hash(directory)
|
||||
|
||||
|
||||
def pinned_tree_hash(directory):
|
||||
"""The image-input hash of an exported pinned tree (same filter as `source_tree_hash`)."""
|
||||
names = [str(path.relative_to(directory)) for path in directory.rglob("*") if path.is_file() and not path.is_symlink()]
|
||||
return _tree_hash(directory, [name.replace(os.sep, "/") for name in names])
|
||||
|
||||
|
||||
def device_tree_hash():
|
||||
@@ -678,6 +743,8 @@ class LocalRig:
|
||||
files.extend(["--file", str(HERE / "compose.history.questdb.yml")])
|
||||
if self.environment.get("GRPC_DATA_CONDITIONS") == "1":
|
||||
files.extend(["--file", str(HERE / "compose.conditions.yml")])
|
||||
if self.environment.get("GRPC_DATA_SOURCE_PINNED") == "1":
|
||||
files.extend(["--file", str(HERE / "compose.source-pinned.yml")])
|
||||
return files
|
||||
|
||||
def compose(self, *args, timeout=120):
|
||||
@@ -749,10 +816,18 @@ class LocalRig:
|
||||
expected = source_tree_hash()
|
||||
if manifest.get("source_tree_hash") != expected:
|
||||
raise RigError("running manifest does not match current image build inputs")
|
||||
pinned = manifest.get("source_pinned")
|
||||
if pinned is not None:
|
||||
# lmxopcua#921: the SOURCE pair runs the pinned revision; its export must still hash to what was built.
|
||||
if (not isinstance(pinned, dict) or pinned_tree_hash(self.folder / "pinned-source") != pinned.get("tree_hash")
|
||||
or pinned.get("revision") != self.environment.get("GRPC_DATA_SOURCE_PINNED_REVISION")):
|
||||
raise RigError("pinned SOURCE export does not match the recorded pinned build")
|
||||
for node in NODES:
|
||||
raw = self.compose("exec", "--no-TTY", node, "cat", "/app/grpc-data-source.json", timeout=15)
|
||||
stamp = json.loads(raw)
|
||||
if stamp.get("tree_hash") != expected or stamp.get("revision") != manifest.get("source_revision"):
|
||||
want = ((pinned["tree_hash"], pinned["revision"]) if pinned is not None and node.startswith("source-")
|
||||
else (expected, manifest.get("source_revision")))
|
||||
if stamp.get("tree_hash") != want[0] or stamp.get("revision") != want[1]:
|
||||
raise RigError("running Host build stamp does not match the candidate")
|
||||
device_hash = device_tree_hash()
|
||||
if manifest.get("device_source_hash") != device_hash:
|
||||
@@ -848,7 +923,7 @@ class LocalRig:
|
||||
self.save(manifest)
|
||||
return manifest
|
||||
|
||||
def up(self, timeout=600, history=False, history_backend="sqlserver", conditions=False):
|
||||
def up(self, timeout=600, history=False, history_backend="sqlserver", conditions=False, source_revision=None):
|
||||
import secrets
|
||||
import credentials
|
||||
if self.folder.exists():
|
||||
@@ -875,6 +950,16 @@ class LocalRig:
|
||||
settings["GRPC_DATA_HISTORY_BACKEND"] = history_backend
|
||||
if conditions:
|
||||
settings["GRPC_DATA_CONDITIONS"] = "1"
|
||||
pinned = None
|
||||
if source_revision is not None:
|
||||
# lmxopcua#921: the SOURCE pair is built from a pinned post-X0, pre-H2 revision (the "v1 origin"); CONTROL and
|
||||
# CONSUMER stay on this checkout. Only the wire tap is added to the pinned tree.
|
||||
full = resolve_pinned_source_revision(source_revision)
|
||||
pinned = {"revision": full, "tree_hash": export_pinned_source(full, self.folder / "pinned-source"),
|
||||
"x0_merge": X0_MERGE, "h2_merge_absent": H2_MERGE, "overlay_files": list(PINNED_OVERLAY_FILES)}
|
||||
settings.update({"GRPC_DATA_SOURCE_PINNED": "1", "GRPC_DATA_SOURCE_PINNED_REVISION": full,
|
||||
"GRPC_DATA_SOURCE_PINNED_TREE_HASH": pinned["tree_hash"], "GRPC_DATA_SOURCE_PINNED_CONTEXT": str(self.folder / "pinned-source"),
|
||||
"GRPC_DATA_SOURCE_IMAGE": f"otopcua-grpc-data-source-pinned:{self.run_id}"})
|
||||
atomic_write_secret(self.folder / "environment.json", json.dumps(settings))
|
||||
self.environment.update(settings)
|
||||
credentials.provision_tls(self.folder / "security", NODES[2:])
|
||||
@@ -891,12 +976,15 @@ class LocalRig:
|
||||
resolved = json.loads(self.compose("config", "--format", "json"))
|
||||
validate_fixture_endpoints(resolved, local_services=SERVICES)
|
||||
try:
|
||||
self.compose("build", "--pull", "migrator", "device", "control-1", "seeder", timeout=1800)
|
||||
self.compose("build", "--pull", "migrator", "device", "control-1", "seeder", *(["source-1"] if pinned else []),
|
||||
timeout=2400 if pinned else 1800) # a pinned run builds a second Host image
|
||||
self.compose("up", "--detach", "sql", "device", "migrator", *NODES, timeout=timeout)
|
||||
manifest = self.allocate_manifest()
|
||||
manifest["source_revision"] = revision
|
||||
manifest["source_tree_hash"] = tree_hash
|
||||
manifest["device_source_hash"] = settings["DEVICE_TREE_HASH"]
|
||||
if pinned is not None:
|
||||
manifest["source_pinned"] = pinned
|
||||
self.capture(manifest)
|
||||
wait_until(lambda: self.health(manifest, require_catalog=False), timeout=timeout, description="six node health and independent pair roles")
|
||||
manifest["state"] = "up"
|
||||
@@ -1347,6 +1435,8 @@ def main(argv=None):
|
||||
parser.add_argument("action", choices=("preflight", "up", "seed", "deploy", "status", "down"))
|
||||
parser.add_argument("--run-id")
|
||||
parser.add_argument("--timeout", type=float, default=None)
|
||||
parser.add_argument("--source-revision", default=None,
|
||||
help="up only (#921): build the SOURCE pair from this pinned post-X0, pre-H2 commit (a v1 origin), e.g. 0c86edc1")
|
||||
parser.add_argument("--conditions", action="store_true", help="up only: add the A2a conditions overlay (AlarmSubscribe exports + one scripted alarm)")
|
||||
parser.add_argument("--history", action="store_true", help="up only: add the H2 history overlay (SOURCE historian + history seed profile)")
|
||||
parser.add_argument("--history-backend", choices=HISTORY_BACKENDS, default=None,
|
||||
@@ -1381,6 +1471,10 @@ def main(argv=None):
|
||||
if arguments.action != "up":
|
||||
raise RigError("--conditions applies to up only; the run remembers it")
|
||||
options["conditions"] = True
|
||||
if arguments.source_revision is not None:
|
||||
if arguments.action != "up":
|
||||
raise RigError("--source-revision applies to up only; the run remembers it")
|
||||
options["source_revision"] = arguments.source_revision
|
||||
result = action(**options)
|
||||
print(json.dumps({"run_id": result["run_id"], "state": result.get("state"), "manifest": str(rig.path), "healthy": result.get("healthy")}))
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user