#[cfg(windows)]
#[allow(dead_code)]
const SYS_CURL: &str = "C:\\Windows\\System32\\curl.exe";
#[cfg(not(windows))]
#[allow(dead_code)]
const SYS_CURL: &str = "curl";
#[allow(dead_code)]
fn _helix_allowed(var: &str, what: &str) -> bool {
let ok = std::env::var(var).map(|v| v == "1").unwrap_or(false);
if !ok {
eprintln!("helix: BLOCKED {} -- permission denied (set {}=1 to allow; `hxc run` allows by default, a `hxc build`/`export-rust` binary does not)", what, var);
}
ok
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_exec(mut c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
std::process::exit(13);
}
use std::os::windows::process::CommandExt;
c.creation_flags(0x08000000);
c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_exec(c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
std::process::exit(13);
}
c
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_net(mut c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
std::process::exit(13);
}
use std::os::windows::process::CommandExt;
c.creation_flags(0x08000000);
c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_net(c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
std::process::exit(13);
}
c
}
#[cfg(windows)]
#[test]
fn unsupported_checked_hit_refuses_before_creating_bank() {
use std::{fs, process::Command};
let root = std::env::temp_dir().join(format!("instinct-platform-{}", std::process::id()));
fs::create_dir_all(&root).unwrap();
let bank = root.join("absent.hxdb");
let output = Command::new(env!("CARGO_BIN_EXE_instinct"))
.args([
"hit",
"in-absent",
"--check",
"--trusted-staging",
"--outcome-id",
"one",
"--root",
])
.arg(&root)
.arg("--store")
.arg(&bank)
.output()
.unwrap();
assert!(!output.status.success());
assert!(String::from_utf8_lossy(&output.stderr)
.contains("check-verified hits are not supported on this platform; nothing recorded"));
assert!(
!String::from_utf8_lossy(&output.stderr).contains("instinct check attach"),
"unsupported Windows hits must refuse before POSIX reattach guidance"
);
assert!(!String::from_utf8_lossy(&output.stderr).contains("bank binding"));
assert!(!bank.exists());
assert!(!root.join("absent.hxdb.lock").exists());
fs::remove_dir(&root).unwrap();
}
#[cfg(windows)]
#[test]
fn unsupported_observation_abstains_without_inventory() {
use std::{
io::Write,
process::{Command, Stdio},
};
let mut child = Command::new(env!("CARGO_BIN_EXE_instinct"))
.args([
"check",
"observe",
"--root",
"C:\\not-observed",
"--input",
"-",
])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.unwrap();
child.stdin.take().unwrap().write_all(br#"{"schema":"instinct.artifact-policy/v1","assumptions":{"trusted_quiescent_staging":true},"allowed":[]}"#).unwrap();
let output = child.wait_with_output().unwrap();
let text = String::from_utf8(output.stdout).unwrap();
assert!(output.status.success());
assert!(
text.contains("unsupported_platform")
&& text.contains("\"inventory\":[]")
&& text.contains("\"checks\":[]"),
"{text}"
);
}