build(packaging): retain qualified payloads through verified owner archives
This commit is contained in:
@@ -13,6 +13,7 @@ NODE = Path(__file__).resolve().parents[1]
|
||||
REPO = NODE.parents[1]
|
||||
sys.path.insert(0, str(REPO / "scripts/packaging"))
|
||||
from build_retention import input_hold, publish_input # noqa: E402
|
||||
from qualified_payloads import QualifiedPayloads # noqa: E402
|
||||
|
||||
DG = REPO.parent / "NODEDC_DESIGN_GUIDELINE"
|
||||
DG_COMMIT = "bbbfa8912f9f51914c6927e13ef32b823c536b9f"
|
||||
@@ -73,7 +74,9 @@ def build(qualified, node_only=False, base=None):
|
||||
package_name = "mission-core-insta360-x4_" + profile["version"] + "_amd64.deb"
|
||||
if qualified.name != package_name:
|
||||
raise ValueError("Unexpected model package name")
|
||||
package = qualified.read_bytes()
|
||||
payloads = QualifiedPayloads(qualified.parent, REPO / 'plugins/insta360-x4/build', REPO)
|
||||
with payloads.locked() as store:
|
||||
package = store.read(qualified.name)
|
||||
if len(package) != profile["bytes"] or hashlib.sha256(package).hexdigest() != profile["sha256"]:
|
||||
raise ValueError("Qualified model package changed")
|
||||
entries = {str(path.relative_to(REPO.parent)): path for path in sorted(set(paths))}
|
||||
@@ -92,7 +95,8 @@ def build(qualified, node_only=False, base=None):
|
||||
native = json.loads((native_root / "packaging/native-runtime.json").read_text())
|
||||
native_path = native_root / "build/native-runtime" / native["file"]
|
||||
native_bytes = native_path.read_bytes()
|
||||
if len(native_bytes) != native["bytes"] or hashlib.sha256(native_bytes).hexdigest() != native["sha256"]:
|
||||
if (len(native_bytes) != native["bytes"]
|
||||
or hashlib.sha256(native_bytes).hexdigest() != native["sha256"]):
|
||||
raise ValueError("Qualified VESC Tool runtime changed")
|
||||
entries[REPO.name + "/plugins/vesc/build/native-runtime/" + native["file"]] = native_path
|
||||
catalog = json.loads((native_root / "packaging/firmware-catalog.json").read_text())
|
||||
@@ -105,7 +109,9 @@ def build(qualified, node_only=False, base=None):
|
||||
package_pin=json.loads((native_root / "packaging/package-catalog.json").read_text())
|
||||
package_path=native_root / "build/package-catalog/vesc_pkg_all.rcc"
|
||||
package_bytes=package_path.read_bytes()
|
||||
if len(package_bytes)!=package_pin["bytes"] or hashlib.sha256(package_bytes).hexdigest()!=package_pin["sha256"]:raise ValueError("Pinned extension catalogue changed")
|
||||
if (len(package_bytes) != package_pin["bytes"]
|
||||
or hashlib.sha256(package_bytes).hexdigest() != package_pin["sha256"]):
|
||||
raise ValueError("Pinned extension catalogue changed")
|
||||
entries[str(package_path.relative_to(REPO.parent))]=package_path
|
||||
usbcan_library = REPO / "plugins/usb-can/build/sdk/libcontrolcanfd.so"
|
||||
if hashlib.sha256(usbcan_library.read_bytes()).hexdigest() != USB_CAN_SDK_SHA256:
|
||||
@@ -113,13 +119,15 @@ def build(qualified, node_only=False, base=None):
|
||||
entries[str(usbcan_library.relative_to(REPO.parent))] = usbcan_library
|
||||
metadata = {}
|
||||
for name, path in entries.items():
|
||||
data = path.read_bytes()
|
||||
data = package if name == virtual else path.read_bytes()
|
||||
if len(data) > 100 * 1024 * 1024:
|
||||
raise ValueError(f"Source file exceeds the artifact bound: {name}")
|
||||
metadata[name] = {
|
||||
"bytes": len(data),
|
||||
"sha256": hashlib.sha256(data).hexdigest(),
|
||||
"mode": 0o755 if path.stat().st_mode & stat.S_IXUSR else 0o644,
|
||||
"mode": 0o644 if name == virtual else (
|
||||
0o755 if path.stat().st_mode & stat.S_IXUSR else 0o644
|
||||
),
|
||||
}
|
||||
entrypoint = (NODE / "packaging/linux_build_entry.py").read_bytes()
|
||||
manifest = {
|
||||
@@ -146,7 +154,9 @@ def build(qualified, node_only=False, base=None):
|
||||
payload_names = {name for name, item in metadata.items()
|
||||
if baseline["files"].get(name) != item}
|
||||
with base.open("rb") as stream:
|
||||
manifest["base"] = {"name": base.name, "sha256": hashlib.file_digest(stream, "sha256").hexdigest()}
|
||||
manifest["base"] = {
|
||||
"name": base.name, "sha256": hashlib.file_digest(stream, "sha256").hexdigest(),
|
||||
}
|
||||
manifest["payload_files"] = sorted(payload_names)
|
||||
raw = json.dumps(manifest, sort_keys=True, indent=2).encode() + b"\n"
|
||||
identifier = hashlib.sha256(raw).hexdigest()[:24]
|
||||
@@ -165,6 +175,13 @@ def build(qualified, node_only=False, base=None):
|
||||
for name, path in entries.items():
|
||||
if name not in payload_names:
|
||||
continue
|
||||
if name == virtual:
|
||||
# The verified package may exist only inside the owner installer.
|
||||
# Stream the captured bytes into the input bundle, without a loose copy.
|
||||
info = zipfile.ZipInfo('source/' + name, date_time=(2026, 9, 8, 0, 0, 0))
|
||||
info.external_attr = 0o644 << 16
|
||||
archive.writestr(info, package)
|
||||
continue
|
||||
archive.write(
|
||||
path,
|
||||
"source/" + name,
|
||||
@@ -187,6 +204,8 @@ if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--model-package", type=Path, required=True)
|
||||
parser.add_argument("--node-only", action="store_true")
|
||||
parser.add_argument("--base", type=Path, help="Complete verified archive already staged in the build root")
|
||||
parser.add_argument(
|
||||
"--base", type=Path, help="Complete verified archive already staged in the build root",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
print(json.dumps(build(args.model_package.resolve(), args.node_only, args.base)))
|
||||
|
||||
@@ -4,17 +4,29 @@ import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import zipfile
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
NODE_DEPENDENCIES = ('timescaledb-2-loader-postgresql-16_2.29.2~ubuntu24.04-1615_amd64.deb', 'timescaledb-2-oss-postgresql-16_2.29.2~ubuntu24.04-1615_amd64.deb')
|
||||
NODE_DEPENDENCIES = (
|
||||
'timescaledb-2-loader-postgresql-16_2.29.2~ubuntu24.04-1615_amd64.deb',
|
||||
'timescaledb-2-oss-postgresql-16_2.29.2~ubuntu24.04-1615_amd64.deb',
|
||||
)
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
REPO = ROOT.parents[1]
|
||||
sys.path.insert(0, str(REPO / 'scripts/packaging'))
|
||||
from qualified_payloads import QualifiedPayloads # noqa: E402
|
||||
|
||||
|
||||
def build(qualified):
|
||||
evidence = json.loads((qualified / "qualification.json").read_text())
|
||||
with QualifiedPayloads(qualified, ROOT / 'build', REPO).locked() as store:
|
||||
return _build(store)
|
||||
|
||||
|
||||
def _build(store):
|
||||
qualified = store.qualified
|
||||
raw_evidence = (qualified / "qualification.json").read_bytes()
|
||||
evidence = json.loads(raw_evidence)
|
||||
if evidence["state"] != "complete":
|
||||
raise ValueError("A completed Ubuntu qualification is required")
|
||||
candidates = [name for name in evidence["artifacts"] if name.startswith("mission-core-node_")]
|
||||
@@ -26,7 +38,7 @@ def build(qualified):
|
||||
)
|
||||
if not match:
|
||||
raise ValueError("Invalid package name")
|
||||
payload = (qualified / package).read_bytes()
|
||||
payload = store.read(package)
|
||||
expected = evidence["artifacts"][package]
|
||||
if (
|
||||
len(payload) != expected["bytes"]
|
||||
@@ -36,12 +48,20 @@ def build(qualified):
|
||||
files = {
|
||||
package: payload,
|
||||
"install": (ROOT / "packaging/install-owner-release").read_bytes(),
|
||||
"install_release.py": (ROOT / "packaging/vesc_hall_recovery.py").read_bytes() + b"\n" + (ROOT / "packaging/can_maintenance.py").read_bytes() + b"\n" + (ROOT / "packaging/install_owner_release.py").read_bytes(),
|
||||
"install_release.py": b"\n".join(
|
||||
(ROOT / "packaging" / name).read_bytes()
|
||||
for name in (
|
||||
"vesc_hall_recovery.py",
|
||||
"can_maintenance.py",
|
||||
"k1_maintenance.py",
|
||||
"install_owner_release.py",
|
||||
)
|
||||
),
|
||||
}
|
||||
# Carry non-Ubuntu dependencies in the actual owner artifact. They were
|
||||
# verified against the signed vendor index by the qualified Linux job.
|
||||
for name in NODE_DEPENDENCIES:
|
||||
data = (qualified / name).read_bytes()
|
||||
data = store.read(name)
|
||||
info = evidence["artifacts"][name]
|
||||
if len(data) != info["bytes"] or hashlib.sha256(data).hexdigest() != info["sha256"]:
|
||||
raise ValueError("Qualified dependency changed")
|
||||
@@ -52,7 +72,7 @@ def build(qualified):
|
||||
"version": match[1],
|
||||
"qualification_profile": "node-package-and-local-ui",
|
||||
"qualification_sha256": hashlib.sha256(
|
||||
(qualified / "qualification.json").read_bytes()
|
||||
raw_evidence
|
||||
).hexdigest(),
|
||||
"clean_image_qualified": False,
|
||||
"dependencies": list(NODE_DEPENDENCIES),
|
||||
@@ -66,15 +86,16 @@ def build(qualified):
|
||||
raw = json.dumps(manifest, indent=2, sort_keys=True).encode() + b"\n"
|
||||
identifier = hashlib.sha256(raw).hexdigest()[:24]
|
||||
output = ROOT / "build" / ("mission-core-node-install-" + identifier + ".pyz")
|
||||
with output.open("xb") as stream, zipfile.ZipFile(stream, "w") as archive:
|
||||
for name, data in {"__main__.py": entry, "release.json": raw, **files}.items():
|
||||
archive.writestr(name, data)
|
||||
output.chmod(0o600)
|
||||
published = store.publish(output, {"__main__.py": entry, "release.json": raw, **files})
|
||||
store.register(published, {name: files[name] for name in [package, *NODE_DEPENDENCIES]},
|
||||
'qualification.json', raw_evidence)
|
||||
cleanup = store.closeout()
|
||||
return {
|
||||
"artifact": str(output),
|
||||
"release_id": identifier,
|
||||
"bytes": output.stat().st_size,
|
||||
"sha256": hashlib.sha256(output.read_bytes()).hexdigest(),
|
||||
"sha256": published['sha256'],
|
||||
"payload_cleanup": cleanup,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
"""Reconstruct a qualified Debian package from an exact retained owner release.
|
||||
|
||||
Transport only: never installs, invokes package scripts or changes system state.
|
||||
Both input package and final complete package are SHA-256 verified.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import sys
|
||||
import tarfile
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def sha(raw):
|
||||
return hashlib.sha256(raw).hexdigest()
|
||||
|
||||
|
||||
def parts(raw):
|
||||
stream, archives = io.BytesIO(raw), {}
|
||||
assert stream.read(8) == b"!<arch>\n"
|
||||
while header := stream.read(60):
|
||||
size = int(header[48:58])
|
||||
archives[header[:16].decode().strip().rstrip("/")] = stream.read(size)
|
||||
if size % 2:
|
||||
stream.read(1)
|
||||
result = {}
|
||||
for name in ("control.tar.gz", "data.tar.gz"):
|
||||
with tarfile.open(fileobj=io.BytesIO(archives[name]), mode="r:gz") as archive:
|
||||
result[name] = [
|
||||
(m.name, archive.extractfile(m).read(), m.mode) for m in archive if m.isfile()
|
||||
]
|
||||
return result
|
||||
|
||||
|
||||
def build(base, target, output):
|
||||
old, new = base.read_bytes(), target.read_bytes()
|
||||
before, after = parts(old), parts(new)
|
||||
manifest = dict(
|
||||
base_sha256=sha(old), target_sha256=sha(new), target_name=target.name, archives={}
|
||||
)
|
||||
repo = Path(__file__).resolve().parents[3]
|
||||
with zipfile.ZipFile(output, "x", compression=zipfile.ZIP_DEFLATED) as archive:
|
||||
archive.writestr("__main__.py", Path(__file__).read_bytes())
|
||||
archive.writestr("debian.py", (repo / "scripts/packaging/debian.py").read_bytes())
|
||||
for category, entries in after.items():
|
||||
originals = {name: (data, mode) for name, data, mode in before[category]}
|
||||
manifest["archives"][category] = []
|
||||
for index, (name, data, mode) in enumerate(entries):
|
||||
changed = originals.get(name) != (data, mode)
|
||||
key = f"{category}/{index}" if changed else ""
|
||||
manifest["archives"][category].append(
|
||||
dict(name=name, mode=mode, key=key, sha256=sha(data))
|
||||
)
|
||||
if changed:
|
||||
archive.writestr(key, data)
|
||||
archive.writestr("delta.json", json.dumps(manifest))
|
||||
print(
|
||||
json.dumps(
|
||||
dict(path=str(output), bytes=output.stat().st_size, sha256=sha(output.read_bytes()))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def apply(owner, output):
|
||||
from debian import package
|
||||
|
||||
with zipfile.ZipFile(sys.argv[0]) as delta:
|
||||
manifest = json.loads(delta.read("delta.json"))
|
||||
if owner.is_dir():
|
||||
release = json.loads((owner / "release.json").read_bytes())
|
||||
candidates = [n for n in release["files"] if n.startswith("mission-core-node_")]
|
||||
assert len(candidates) == 1 and Path(candidates[0]).name == candidates[0]
|
||||
raw = (owner / candidates[0]).read_bytes()
|
||||
else:
|
||||
with zipfile.ZipFile(owner) as archive:
|
||||
release = json.loads(archive.read("release.json"))
|
||||
candidates = [n for n in release["files"] if n.startswith("mission-core-node_")]
|
||||
assert len(candidates) == 1
|
||||
raw = archive.read(candidates[0])
|
||||
assert sha(raw) == manifest["base_sha256"], "Retained base does not match"
|
||||
before = parts(raw)
|
||||
result = {}
|
||||
for category, entries in manifest["archives"].items():
|
||||
originals = {name: data for name, data, _ in before[category]}
|
||||
rows = []
|
||||
for entry in entries:
|
||||
data = delta.read(entry["key"]) if entry["key"] else originals[entry["name"]]
|
||||
assert sha(data) == entry["sha256"]
|
||||
rows.append((entry["name"], data, entry["mode"]))
|
||||
result[category] = rows
|
||||
final = package(result["control.tar.gz"], result["data.tar.gz"])
|
||||
assert sha(final) == manifest["target_sha256"], "Reconstructed package differs"
|
||||
target = output / manifest["target_name"]
|
||||
with target.open("xb") as stream:
|
||||
stream.write(final)
|
||||
print(json.dumps(dict(package=str(target), sha256=sha(final), bytes=len(final))))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("action", choices=("build", "apply"))
|
||||
parser.add_argument("base", type=Path)
|
||||
parser.add_argument("target", type=Path)
|
||||
parser.add_argument("--output", type=Path)
|
||||
args = parser.parse_args()
|
||||
if args.action == "build":
|
||||
build(args.base, args.target, args.output)
|
||||
else:
|
||||
apply(args.base, args.target)
|
||||
@@ -0,0 +1,150 @@
|
||||
"""Versioned runtime/UI update over an exact qualified Node package.
|
||||
|
||||
Preserves every OS integration, dependency and preparation payload from the
|
||||
predecessor. Only the executable, version and provenance can change.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from node_package_delta import parts
|
||||
|
||||
REPO = Path(__file__).resolve().parents[3]
|
||||
sys.path.insert(0, str(REPO / "scripts/packaging"))
|
||||
from debian import package # noqa: E402
|
||||
from qualified_payloads import QualifiedPayloads # noqa: E402
|
||||
|
||||
|
||||
def verify_embedded_ui(executable):
|
||||
built = REPO / "apps/node-agent/ui/dist"
|
||||
embedded = REPO / "apps/node-agent/web/dist"
|
||||
|
||||
def files(root):
|
||||
return {str(p.relative_to(root)): p for p in root.rglob("*") if p.is_file()}
|
||||
expected, actual = files(built), files(embedded)
|
||||
if not expected or expected.keys() != actual.keys():
|
||||
raise ValueError("Built and embedded Node UI inventories differ; sync UI before compiling")
|
||||
for name, source in expected.items():
|
||||
if (hashlib.sha256(source.read_bytes()).digest()
|
||||
!= hashlib.sha256(actual[name].read_bytes()).digest()):
|
||||
raise ValueError("Built and embedded Node UI differ: " + name)
|
||||
# Go embed stores these bytes verbatim. Detect a binary compiled before the
|
||||
# UI was copied, even when both source directories have since been synced.
|
||||
index = expected["index.html"].read_bytes()
|
||||
entries = re.findall(rb'<script[^>]+src="([^"]+\.js)"', index)
|
||||
if not entries or index not in executable:
|
||||
raise ValueError("Executable does not embed the built Node UI index")
|
||||
for entry in entries:
|
||||
path = entry.decode().removeprefix("/").removeprefix("./")
|
||||
if path not in expected or expected[path].read_bytes() not in executable:
|
||||
raise ValueError("Executable does not embed the built Node UI entry")
|
||||
|
||||
|
||||
def build(base, base_sha, binary, version, output, uplink=False, vesc_evidence=False):
|
||||
if output.exists():
|
||||
raise FileExistsError("Published releases are immutable")
|
||||
if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+-[1-9][0-9]*", version):
|
||||
raise ValueError("Invalid version")
|
||||
with QualifiedPayloads(base.parent, REPO / 'apps/node-agent/build', REPO).locked() as store:
|
||||
raw = store.read(base.name)
|
||||
if hashlib.sha256(raw).hexdigest() != base_sha:
|
||||
raise ValueError("Qualified predecessor changed")
|
||||
archives = parts(raw)
|
||||
executable = binary.read_bytes()
|
||||
if executable[:6] != b"\x7fELF\x02\x01" or executable[18:20] != b"\x3e\x00":
|
||||
raise ValueError("Expected Linux amd64 executable")
|
||||
verify_embedded_ui(executable)
|
||||
provenance_path = "usr/share/doc/mission-core-node/provenance.json"
|
||||
previous = dict((n, d) for n, d, _ in archives["data.tar.gz"])
|
||||
sources = {}
|
||||
for folder in (
|
||||
"apps/node-agent/internal", "apps/node-agent/ui/src", "apps/node-agent/web/dist",
|
||||
"packages/router-ui/src", "packages/sensor-ui/src",
|
||||
):
|
||||
for path in sorted((REPO / folder).rglob("*")):
|
||||
if path.is_file():
|
||||
sources[str(path.relative_to(REPO))] = hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
provenance = dict(schema="missioncore.node.runtime-revision/v1", version=version,
|
||||
predecessor_sha256=base_sha,
|
||||
predecessor=json.loads(previous[provenance_path]),
|
||||
binary_sha256=hashlib.sha256(executable).hexdigest(), sources=sources)
|
||||
changes = {"usr/lib/mission-core-node/node-agent": executable,
|
||||
provenance_path: (json.dumps(provenance, indent=2) + "\n").encode()}
|
||||
if vesc_evidence:
|
||||
# A diagnostic-only revision must prove that executable statements outside
|
||||
# this one trace call are identical to the qualified motor controller.
|
||||
import ast
|
||||
|
||||
target = "usr/lib/mission-core-vesc/runtime/remote_control.py"
|
||||
source = REPO / "plugins/vesc/runtime/remote_control.py"
|
||||
desired = source.read_bytes()
|
||||
|
||||
class WithoutLeaseTrace(ast.NodeTransformer):
|
||||
def visit_Expr(self, node):
|
||||
call = node.value
|
||||
if (isinstance(call, ast.Call) and isinstance(call.func, ast.Attribute)
|
||||
and ast.unparse(call.func) == "self.trace.add" and call.args
|
||||
and isinstance(call.args[0], ast.Constant)
|
||||
and call.args[0].value == "lease_expired"):
|
||||
return ast.Pass()
|
||||
return self.generic_visit(node)
|
||||
|
||||
def authority(raw):
|
||||
return ast.dump(WithoutLeaseTrace().visit(ast.parse(raw)), include_attributes=False)
|
||||
|
||||
if authority(previous[target]) != authority(desired):
|
||||
raise ValueError("VESC change exceeds diagnostic trace fields")
|
||||
changes[target] = desired
|
||||
sources[str(source.relative_to(REPO))] = hashlib.sha256(desired).hexdigest()
|
||||
provenance["vesc_evidence_only"] = True
|
||||
changes[provenance_path] = (json.dumps(provenance, indent=2) + "\n").encode()
|
||||
if uplink:
|
||||
packaging = REPO / 'apps/node-agent/packaging'
|
||||
for path in [packaging / 'uplink_helper.py', packaging / 'qualify_uplink_namespace.py',
|
||||
*sorted((packaging / 'uplink').glob('*.py'))]:
|
||||
name = 'usr/lib/mission-core-node/' + str(path.relative_to(packaging))
|
||||
changes[name] = path.read_bytes()
|
||||
sources[str(path.relative_to(REPO))] = hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
provenance['scope'] = ('Runtime and reversible NetBird uplink routing; '
|
||||
'qualified predecessor retained')
|
||||
changes[provenance_path] = (json.dumps(provenance, indent=2) + '\n').encode()
|
||||
controls = []
|
||||
changed_controls = ['control']
|
||||
for name, data, mode in archives["control.tar.gz"]:
|
||||
if name == "control":
|
||||
data, count = re.subn(rb"(?m)^Version: [^\n]+$", b"Version: " + version.encode(), data)
|
||||
assert count == 1
|
||||
if uplink and name == 'prerm':
|
||||
replacement = (REPO / 'apps/node-agent/packaging/prerm').read_bytes()
|
||||
if replacement != data:
|
||||
changed_controls.append(name)
|
||||
data = replacement
|
||||
controls.append((name, data, mode))
|
||||
payload = [(n, changes.get(n, d), m) for n, d, m in archives["data.tar.gz"]]
|
||||
payload += [(n, d, 0o644) for n, d in changes.items() if n not in previous]
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
with output.open("xb") as stream:
|
||||
stream.write(package(controls, payload))
|
||||
report = dict(version=version, base_sha256=base_sha, bytes=output.stat().st_size,
|
||||
sha256=hashlib.sha256(output.read_bytes()).hexdigest(),
|
||||
changed_controls=changed_controls, changed_payloads=list(changes))
|
||||
output.with_suffix(".json").write_text(json.dumps(report, indent=2) + "\n")
|
||||
return report
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--base", type=Path, required=True)
|
||||
parser.add_argument("--base-sha256", required=True)
|
||||
parser.add_argument("--binary", type=Path, required=True)
|
||||
parser.add_argument("--version", required=True)
|
||||
parser.add_argument("--output", type=Path, required=True)
|
||||
parser.add_argument('--uplink', action='store_true')
|
||||
parser.add_argument('--vesc-evidence', action='store_true')
|
||||
args = parser.parse_args()
|
||||
print(json.dumps(build(args.base, args.base_sha256, args.binary, args.version, args.output,
|
||||
uplink=args.uplink, vesc_evidence=args.vesc_evidence)))
|
||||
@@ -0,0 +1,41 @@
|
||||
"""Packaging must reject a stale local UI even after its sources were synced."""
|
||||
import importlib.util
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"repack_runtime", Path(__file__).with_name("repack_runtime.py")
|
||||
)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
class EmbeddedUITest(unittest.TestCase):
|
||||
def test_stale_directory_and_stale_binary_are_rejected(self):
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
old_root = module.REPO
|
||||
module.REPO = Path(folder)
|
||||
try:
|
||||
built = module.REPO / 'apps/node-agent/ui/dist'
|
||||
embedded = module.REPO / 'apps/node-agent/web/dist'
|
||||
for root in [built, embedded]:
|
||||
(root / 'assets').mkdir(parents=True)
|
||||
(root / 'index.html').write_bytes(b'<script src="/assets/app.js"></script>')
|
||||
(root / 'assets/app.js').write_bytes(b'new interface')
|
||||
current = b'ELF prefix' + (built / 'index.html').read_bytes() + b'new interface'
|
||||
module.verify_embedded_ui(current)
|
||||
with self.assertRaisesRegex(ValueError, 'Executable'):
|
||||
module.verify_embedded_ui(b'old executable')
|
||||
(embedded / 'assets/app.js').write_bytes(b'old interface')
|
||||
with self.assertRaisesRegex(ValueError, 'UI differ'):
|
||||
module.verify_embedded_ui(current)
|
||||
(embedded / 'orphan.js').write_bytes(b'orphan')
|
||||
with self.assertRaisesRegex(ValueError, 'inventories differ'):
|
||||
module.verify_embedded_ui(current)
|
||||
finally:
|
||||
module.REPO = old_root
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user