Experiment formal simulator rust unit preflight 01 - kmosoti/FabricO11y GitHub Wiki
Simulator Rust unit preflight
Prospective; no execution or result. Original registered command omits release profile. Compilation uses the immutable admitted helper-source bundle in fresh launcher-owned scratch, not the changing harness worktree. Native Fedora OpenSSL/compiler observations are recorded at execution; no Debian ABI or package claim.
{
"command": [
"python3",
"-B",
"/run/media/kmosoti/data/FabricO11y/results/candidate-build-fresh-8fb6f413179b-01/run-step-simulator-documentation-01.py",
"simulator-native-rust-unit-01",
"17179869184",
"env",
"PYTHONPATH=tools",
"python3",
"-B",
"/run/media/kmosoti/data/FabricO11y/results/candidate-build-fresh-8fb6f413179b-01/run-simulator-rust-unit-01.py"
],
"runner_sha256": "10b93a1d533e25b8da2b2e5dc1a944c7784076618781edbffd225a2929d23a83",
"driver_sha256": "39333a5c90b16f2f75a69a030c69c9272a62c44fbb6b43fec10d27111cdfcea1",
"harness": "6bd5250a6223fe3663b254c25627ce4ff2b4c9e0",
"scope": "Original registered seven native_witness_ Rust tests, native Fedora host only, no Debian ABI/package/publication certification.",
"source": "Immutable admitted bundle4c2e8be5b1495be3c02ac9ba5dfd3ffb5ca3ca4d1c7487e0b8bdefb3c0c8a3da, commit1a923e70bed65b899382c7aad06590ae11d46855/tree5b49e6b9502c53adddf0d1ec6fef797266d67a30",
"limits": "Serial,16GiB reserve/default16/20GiB memory,noSwap,1500s inner/1800s outer,2cargo jobs,0.5s sampled15GiB owned/1GiB output guard; DATA95e9 census; source/registry/target entirely launcher scratch; sample overshoot not a strict disk peak bound. Exact7 tests must run,0failed/ignored; failureevidence retained."
}
The unchanged source/build admission already exited0 before this plan. Registry pin is47646ea10bb1e5fe179fc11ce36e0fe11acb6f5dacd9aa7d09c0c9a6d18577ce (438223080bytes); both source and copied registry must be ordinary, complete and exact. Canonical helpers/packages remain immutable. Successful outer launcher cleanup removes owned source/registry/target; failed runs retain evidence. No strict transient disk bound is inferred from sampled growth.
"""Run only the seven registered Rust witness tests on the native host."""
import hashlib
import json
import os
from pathlib import Path
import re
import shutil
import stat
import subprocess
import time
from resource_group import require_limits, require_storage
DATA = Path('/run/media/kmosoti/data/FabricO11y')
ROOT = DATA / 'scratch/simulator-exposure-witness'
TOOLCHAIN = DATA / 'toolchain-cache/rustup/toolchains/1.99.0-x86_64-unknown-linux-gnu'
OUT = DATA / 'results/simulator-native-rust-unit-01'
COMMAND = [str(TOOLCHAIN / 'bin/cargo'), 'test', '--offline', '--locked',
'--example', 'spindle_sim', 'native_witness_', '--', '--test-threads=1']
def require(value, reason):
if not value:
raise RuntimeError(reason)
def sha(path):
with path.open('rb') as stream:
return hashlib.file_digest(stream, 'sha256').hexdigest()
group = require_limits()
require(require_storage() == DATA, 'DATA only')
require(sha(TOOLCHAIN / 'bin/rustc') == 'f3834d26669b03f6855fa54bd2381443123e860167bc0c7a8dd137e5cf6e5e4f'
and sha(TOOLCHAIN / 'bin/cargo') == 'e951141cc55a6cd7b9876d187bd30a3720e6086b99413af95e3b8de1cdd72f14', 'pinned compiler')
scratch = Path(os.environ['FABRIC_SCRATCH_ROOT']).resolve(strict=True)
require(scratch.is_relative_to(DATA / 'scratch') and not OUT.exists(), 'fresh owned DATA paths')
OUT.mkdir(mode=0o700)
bundle = DATA / 'results/simulator-native-source-01/provenance/frozen-source.bundle'
require(sha(bundle) == '4c2e8be5b1495be3c02ac9ba5dfd3ffb5ca3ca4d1c7487e0b8bdefb3c0c8a3da', 'admitted frozen bundle')
source = scratch / 'unit-source'
subprocess.run(['git', '-c', 'core.hooksPath=/dev/null', 'clone', '--no-checkout', str(bundle), str(source)], check=True, timeout=60)
subprocess.run(['git', '-C', str(source), '-c', 'core.hooksPath=/dev/null', 'checkout', '--detach', '1a923e70bed65b899382c7aad06590ae11d46855'], check=True, timeout=60)
require(subprocess.check_output(['git', '-C', str(source), 'rev-parse', 'HEAD^{tree}'], text=True).strip()
== '5b49e6b9502c53adddf0d1ec6fef797266d67a30', 'admitted source tree')
require(sha(source / 'examples/spindle_sim.rs') == '1073e32336f04959ac9f78ac9f5ac97d02860c605037c98dcc1f2f8fbce045e4', 'frozen Rust helper source')
cargo_home = scratch / 'unit-cargo'
cargo_home.mkdir(mode=0o700)
registry = DATA / 'toolchain-cache/cargo/registry'
require(not registry.is_symlink() and registry.resolve(strict=True).is_relative_to(DATA), 'DATA registry only')
def registry_error(error):
raise error
entries, copied = [], 0
for directory, dirs, files in os.walk(registry, followlinks=False, onerror=registry_error):
dirs.sort()
require(not any((Path(directory) / name).is_symlink() for name in dirs + files), 'registry symlink refused')
for name in sorted(files):
path = Path(directory) / name
require(stat.S_ISREG(path.stat().st_mode), 'ordinary registry files')
copied += path.stat().st_size
entries.append((path.relative_to(registry).as_posix(), path.stat().st_size, sha(path)))
registry_sha = hashlib.sha256(json.dumps(entries, separators=(',', ':')).encode()).hexdigest()
require(copied == 438223080 and registry_sha == '47646ea10bb1e5fe179fc11ce36e0fe11acb6f5dacd9aa7d09c0c9a6d18577ce', 'registered registry inventory')
shutil.copytree(registry, cargo_home / 'registry', symlinks=True)
copied_paths = set()
for directory, dirs, files in os.walk(cargo_home / 'registry', followlinks=False, onerror=registry_error):
require(not any((Path(directory) / name).is_symlink() for name in dirs + files), 'copied registry symlink refused')
copied_paths.update((Path(directory) / name).relative_to(cargo_home / 'registry').as_posix() for name in files)
require(copied_paths == {relative for relative, _, _ in entries}, 'complete copied registry set')
for relative, size, digest in entries:
path = cargo_home / 'registry' / relative
require(not path.is_symlink() and path.stat().st_size == size and sha(path) == digest, 'copied registry bytes')
environment = {key: value for key, value in os.environ.items()
if not key.startswith(('CARGO_', 'RUST')) and key not in ('LD_PRELOAD', 'LD_AUDIT', 'LD_LIBRARY_PATH')}
environment.update(PATH=str(TOOLCHAIN / 'bin') + ':' + os.environ['PATH'],
CARGO_HOME=str(cargo_home), CARGO_TARGET_DIR=str(scratch / 'unit-target'),
CARGO_BUILD_JOBS='2', CARGO_NET_OFFLINE='true', RUSTUP_HOME=str(DATA / 'toolchain-cache/rustup'))
receipt = dict(classification='finite native-host Rust source tests; no package or publication certification',
command=COMMAND, cgroup=str(group), source_sha256=sha(source / 'examples/spindle_sim.rs'),
source_commit='1a923e70bed65b899382c7aad06590ae11d46855', source_bundle_sha256=sha(bundle),
storage_root=str(DATA), state='running', exit=None,
target=str(scratch / 'unit-target'), scratch_cleanup='owned by outer resource launcher',
owned_growth_samples=[], owned_sampled_limit=15 * 2**30, registry_sha256=registry_sha,
host_openssl=subprocess.check_output(['pkg-config', '--modversion', 'openssl'], text=True, timeout=10).strip(),
host_openssl_link=subprocess.check_output(['pkg-config', '--libs', '--cflags', 'openssl'], text=True, timeout=10).strip(),
rustc_version=subprocess.check_output([str(TOOLCHAIN / 'bin/rustc'), '-vV'], env=environment, text=True, timeout=10).strip())
def sample():
total = 0
def walk_error(error):
if not isinstance(error, FileNotFoundError):
raise error
for directory, _, files in os.walk(scratch, followlinks=False, onerror=walk_error):
for name in files:
try: value = (Path(directory) / name).lstat()
except FileNotFoundError: continue # Concurrent compiler rename/unlink; census is sampled.
if stat.S_ISREG(value.st_mode):
total += value.st_size
receipt['owned_growth_samples'].append(dict(monotonic_ns=time.monotonic_ns(), bytes=total))
require(total < 15 * 2**30 and (OUT / 'cargo.log').stat().st_size < 2**30, 'sampled owned/output growth guard')
try:
with (OUT / 'cargo.log').open('xb') as stream:
process = subprocess.Popen(COMMAND, cwd=source, env=environment, stdout=stream, stderr=subprocess.STDOUT)
end = time.monotonic() + 1500
try:
while process.poll() is None:
require(time.monotonic() < end, '1500-second inner deadline')
sample()
time.sleep(.5)
finally:
if process.poll() is None:
process.terminate()
try: process.wait(timeout=5)
except subprocess.TimeoutExpired: process.kill(); process.wait(timeout=5)
sample()
receipt.update(state='completed', exit=process.returncode, log_sha256=sha(OUT / 'cargo.log'))
require((OUT / 'cargo.log').stat().st_size <= 2**20, 'bounded unit log')
log = (OUT / 'cargo.log').read_text()
summaries = re.findall(r'test result: ok\. (\d+) passed; (\d+) failed; (\d+) ignored;', log)
names = re.findall(r'^test tests::(native_witness_[a-z_]+) \.\.\. ok$', log, re.M)
require(process.returncode == 0 and summaries == [('7', '0', '0')] and len(names) == len(set(names)) == 7,
'exact seven registered tests must execute without ignored or failed tests')
receipt['executed_tests'] = names
except BaseException as error:
receipt.update(state='failed', exit=2, error=type(error).__name__ + ': ' + str(error))
finally:
(OUT / 'receipt.json').write_text(json.dumps(receipt, indent=2) + '\n')
raise SystemExit(receipt['exit'])