Files
NODEDC_MISSION_CORE/tests/test_insta360_sdk_source.py
T
DCCONSTRUCTIONS a3c15e11e9 Add packaged Insta360 X4 integration and recover paired Node channels
Discover independent camera instances and prepare their versioned runtime
from Node or remote Core. Add isolated SDK workers, camera controls, raw
dual-fisheye WebRTC preview, and shared action/region loading states.

Recover existing Node bindings over known Tailscale addresses after a Core
LAN address change. Preserve identities and trust, pin both peers, migrate
endpoints with revision checks, and require real heartbeats for online status.
Fix the Python client certificate profile for Go X509 verification.

Pin Design Guideline 8c53f73 and retain installer/build/acceptance history.
Node 0.8.19 is installed; X4 0.1.3-3 is bundled but hardware activation is pending.

Validation: qualified DG/Node builds and Go race tests; 31 fleet tests;
Python-to-Go certificate interoperability and live tailnet recovery with five
fresh heartbeats; prior 38 X4 tests and bounded remote WebRTC acceptance.
Clean-OS, replug/power autonomy, local X4 video and long-run stability remain open.
2026-09-10 09:21:24 +03:00

92 lines
3.2 KiB
Python

"""The build must fail before using corrupt, wrong-platform or partial SDK bytes."""
import hashlib
import importlib.util
import json
import struct
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[1]
SPEC = importlib.util.spec_from_file_location(
"x4_sdk_source", ROOT / "plugins/insta360-x4/packaging/fetch_sdk.py"
)
sdk = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(sdk)
def elf(machine=62):
strings = b"\0libc.so.6\0"
table_end = 64 + 3 * 64
data = bytearray(table_end)
data[:7] = b"\x7fELF\x02\x01\x01"
struct.pack_into("<H", data, 18, machine)
struct.pack_into("<Q", data, 40, 64)
struct.pack_into("<HH", data, 58, 64, 3)
struct.pack_into("<IIQQQQIIQQ", data, 128, 0, 3, 0, 0, table_end, len(strings), 0, 0, 1, 0)
struct.pack_into(
"<IIQQQQIIQQ", data, 192, 0, 6, 0, 0, table_end + len(strings), 32, 1, 0, 8, 16
)
return bytes(data) + strings + struct.pack("<qQqQ", 1, 1, 0, 0)
@pytest.fixture
def locked_source(tmp_path, monkeypatch):
source = tmp_path / "source"
(source / "lib").mkdir(parents=True)
data = elf()
(source / "lib/libCameraSDK.so").write_bytes(data)
lock = {
"schema": "missioncore.insta360.sdk-source/v1",
"commit": "a" * 40,
"files": [
{
"path": "lib/libCameraSDK.so",
"bytes": len(data),
"sha256": hashlib.sha256(data).hexdigest(),
"lfs": False,
}
],
}
path = tmp_path / "sdk-lock.json"
path.write_text(json.dumps(lock))
monkeypatch.setattr(sdk, "LOCK", path)
return source, tmp_path / "build/sdk", lock
def test_import_repeat_and_static_dependency_inspection(locked_source):
source, destination, lock = locked_source
assert sdk.fetch(destination, source)["needed"] == ["libc.so.6"]
# A completed build no longer depends on the acquisition folder or network.
assert sdk.fetch(destination, Path("/nonexistent"))["architecture"] == "linux-x86_64"
assert sdk.verify(destination, lock)["needed"] == ["libc.so.6"]
def test_corrupt_source_never_becomes_active_and_stage_is_removed(locked_source):
source, destination, _ = locked_source
(source / "lib/libCameraSDK.so").write_bytes(b"corrupt")
with pytest.raises(ValueError, match="checksum"):
sdk.fetch(destination, source)
assert not destination.exists()
assert not list(destination.parent.glob(".sdk-*"))
def test_existing_corrupt_cache_is_not_silently_reused(locked_source):
source, destination, _ = locked_source
sdk.fetch(destination, source)
(destination / "lib/libCameraSDK.so").write_bytes(b"version https://git-lfs.github.com/spec/v1")
with pytest.raises(ValueError, match="checksum"):
sdk.fetch(destination, source)
def test_wrong_architecture_and_payload_path_are_rejected(tmp_path, locked_source):
path = tmp_path / "aarch64.so"
path.write_bytes(elf(183))
with pytest.raises(ValueError, match="x86_64"):
sdk.inspect_elf(path)
_, _, lock = locked_source
lock["files"][0]["path"] = "../outside"
with pytest.raises(ValueError, match="payload"):
list(sdk.entries(lock))