#[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
}
use std::{
fs,
io::Write,
process::{Command, Stdio},
sync::atomic::{AtomicUsize, Ordering},
};
static NEXT: AtomicUsize = AtomicUsize::new(0);
struct Fixture(std::path::PathBuf);
impl Fixture {
fn new() -> Self {
let p = std::env::temp_dir().join(format!(
"icontinue-cli-{}-{}",
std::process::id(),
NEXT.fetch_add(1, Ordering::Relaxed)
));
fs::create_dir(&p).unwrap();
Self(fs::canonicalize(p).unwrap())
}
fn call(&self, event: &str) -> std::process::Output {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_instinct"))
.args(["continue-tasks", "--session", "fixture", "--tasks-dir"])
.arg(&self.0)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.unwrap();
cmd.stdin.take().unwrap().write_all(event.as_bytes()).ok();
cmd.wait_with_output().unwrap()
}
}
impl Drop for Fixture {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.0);
}
}
const STOP: &str = r#"{"session_id":"fixture","hook_event_name":"Stop","stop_hook_active":false}"#;
#[test]
fn unfinished_work_continues_and_completion_silences() {
let f = Fixture::new();
let p = f.0.join("1.json");
fs::write(
&p,
r#"{"id":"1","status":"in_progress","subject":"PRIVATE_SUBJECT"}"#,
)
.unwrap();
let before = fs::read(&p).unwrap();
let out = f.call(STOP);
assert!(out.status.success());
let text = String::from_utf8(out.stdout).unwrap();
assert!(text.contains("\"decision\":\"block\"") && text.contains("TaskGet for task 1"));
assert!(!text.contains("PRIVATE_SUBJECT"));
assert_eq!(before, fs::read(&p).unwrap());
fs::write(&p, r#"{"id":"1","status":"completed"}"#).unwrap();
assert!(f.call(STOP).stdout.is_empty());
}
#[test]
fn recursive_and_other_session_events_are_silent() {
let f = Fixture::new();
fs::write(f.0.join("1.json"), r#"{"id":"1","status":"pending"}"#).unwrap();
for input in [
STOP.replace("false", "true"),
STOP.replace("fixture", "another"),
STOP.replace("Stop", "SessionEnd"),
] {
let out = f.call(&input);
assert!(out.status.success() && out.stdout.is_empty());
}
}
#[test]
fn malformed_snapshot_never_invents_actionable_work() {
let f = Fixture::new();
fs::write(f.0.join("1.json"), "invalid").unwrap();
let out = f.call(STOP);
assert!(out.status.success() && out.stdout.is_empty());
assert!(String::from_utf8(out.stderr)
.unwrap()
.contains("no continuation decision"));
}
#[test]
fn real_blocker_and_dependency_allow_stop() {
let f = Fixture::new();
fs::write(f.0.join("1.json"),r#"{"id":"1","status":"pending","metadata":{"continuation_blocked_reason":"Owner approval required"}}"#).unwrap();
fs::write(
f.0.join("2.json"),
r#"{"id":"2","status":"pending","blockedBy":["1"]}"#,
)
.unwrap();
let out = f.call(STOP);
assert!(out.status.success() && out.stdout.is_empty());
}