feat(host): expose memcard controls and qualify process persistence
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
Intrepid/Prometeu/Runtime/pipeline/head This commit looks good
This commit is contained in:
+95
@@ -0,0 +1,95 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
root = Path.cwd()
|
||||
scratch = Path(tempfile.mkdtemp(prefix="runtime-memcard-review-"))
|
||||
source = scratch / "image_access.rs"
|
||||
source.write_text(r'''
|
||||
use prometeu_drivers::memcard::FileMemcard;
|
||||
use prometeu_hal::memcard::MemcardIoError;
|
||||
use prometeu_system::memcard::{image::IMAGE_BYTES, transaction::Card};
|
||||
|
||||
fn main() {
|
||||
let args: Vec<_> = std::env::args().collect();
|
||||
let path = std::path::Path::new(&args[1]);
|
||||
if args.get(2).is_some() {
|
||||
let second = FileMemcard::open(path, false)
|
||||
.map_err(|e| format!("{e:?}"))
|
||||
.and_then(|io| Card::mount(Box::new(io)).map_err(|e| format!("{e:?}")));
|
||||
match second {
|
||||
Ok(card) => {
|
||||
println!("second_process_rw_mount_accepted");
|
||||
drop(card);
|
||||
}
|
||||
Err(error) => println!("second_process_rw_mount_rejected:{error}"),
|
||||
}
|
||||
return;
|
||||
}
|
||||
let io = FileMemcard::create(path, IMAGE_BYTES, |io, id| {
|
||||
Card::format(io, id).map_err(|_| MemcardIoError::IoError)
|
||||
}).expect("create private probe image");
|
||||
let first_card = Card::mount(Box::new(io)).expect("first mount");
|
||||
let output = std::process::Command::new(std::env::current_exe().unwrap())
|
||||
.arg(path).arg("child").output().expect("child process");
|
||||
assert!(output.status.success());
|
||||
print!("{}", String::from_utf8(output.stdout).unwrap());
|
||||
drop(first_card);
|
||||
}
|
||||
''')
|
||||
binary = scratch / "image-access"
|
||||
command = ["rustc", "--edition=2024", str(source), "-o", str(binary),
|
||||
"-L", "dependency=" + str(root / "target/debug/deps")]
|
||||
for crate in ("prometeu_drivers", "prometeu_hal", "prometeu_system"):
|
||||
rlib = max((root / "target/debug/deps").glob("lib" + crate + "-*.rlib"),
|
||||
key=lambda p: p.stat().st_mtime_ns)
|
||||
command += ["--extern", crate + "=" + str(rlib)]
|
||||
subprocess.run(command, check=True, capture_output=True, text=True)
|
||||
access = subprocess.run([str(binary), str(scratch / "probe.pmc")],
|
||||
check=True, capture_output=True, text=True)
|
||||
|
||||
process = subprocess.Popen([str(root / "target/debug/prometeu"), "headless", "--stdio"],
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, text=True)
|
||||
hello = json.loads(process.stdout.readline())
|
||||
def request(identity, command, params):
|
||||
process.stdin.write(json.dumps({"requestId": identity, "command": command, "params": params}) + "\n")
|
||||
process.stdin.flush()
|
||||
return json.loads(process.stdout.readline())
|
||||
required = request("probe-capability", "initialize", {
|
||||
"protocolVersion": {"major": 1, "minor": 0}, "requiredCapabilities": ["memcard"]})
|
||||
initialized = request("init", "initialize", {
|
||||
"protocolVersion": {"major": 1, "minor": 0}, "requiredCapabilities": []})
|
||||
invalid = request("probe-field", "boot", {"path": str(scratch), "memcard": {}})
|
||||
state = request("state", "get_state", {})
|
||||
shutdown = request("stop", "shutdown", {})
|
||||
process.stdin.close()
|
||||
process.wait(timeout=10)
|
||||
assert process.returncode == 0
|
||||
assert required["error"]["code"] == "unsupported_capability"
|
||||
assert invalid["error"]["code"] == "invalid_params"
|
||||
assert shutdown["result"] == {"closed": True}
|
||||
report = {
|
||||
"runtime_revision": subprocess.check_output(["git", "rev-parse", "HEAD"], text=True).strip(),
|
||||
"scope": "read-only diagnosis using checkout debug binaries and isolated disposable image; no installed-process persistence qualification",
|
||||
"scratch_directory": str(scratch),
|
||||
"file_access_probe": {
|
||||
"backend": "FileMemcard + Card::mount on a valid freshly created image",
|
||||
"first_process_holds_rw_card": True,
|
||||
"second_process_result": access.stdout.strip(),
|
||||
"payload_writes": False,
|
||||
},
|
||||
"wire_probe": {
|
||||
"capabilities": hello["capabilities"],
|
||||
"required_capability_memcard": required["error"],
|
||||
"unknown_boot_field_memcard": invalid["error"],
|
||||
"get_state_fields": sorted(state["result"]),
|
||||
"shutdown": shutdown["result"],
|
||||
"note": "The memcard capability/field names are intentionally unsupported test input, not a proposed public contract.",
|
||||
},
|
||||
}
|
||||
report_path = scratch / "summary.json"
|
||||
report_path.write_text(json.dumps(report, indent=2) + "\n")
|
||||
print(json.dumps(report, indent=2))
|
||||
print("report_path=" + str(report_path))
|
||||
Reference in New Issue
Block a user