use super::{BYPASS_ON, HOST_LANE_FACT, NO_INTERPRETERS_STAGED, SESSION_FORK_FACT, bypass_line};
#[test]
fn bypass_activation_states_the_no_euphemism_line_naming_the_staged_interpreters() {
let line = bypass_line(
&["python3".to_string(), "perl".to_string()],
false,
false,
&[],
);
assert!(
line.contains("bypass on:"),
"the line opens with the mode's own word, no euphemism: {line}"
);
assert!(
line.contains("every tool call runs without asking"),
"the line says what bypass does: {line}"
);
assert!(
line.contains("every structural guard still applies"),
"the line says what bypass does not touch: {line}"
);
assert!(
line.contains("this session may execute python3, perl as an interpreter"),
"the line names the staged interpreters: {line}"
);
assert!(
line.contains(SESSION_FORK_FACT),
"the session fork fact is stated, not the run's conditional: {line}"
);
assert!(
line.contains("What the interpreter computes is not a reviewed, fixed binary"),
"the warning's honest close is carried: {line}"
);
assert!(
!line.contains("where process-fork is granted"),
"the run surface's parenthetical is a run's clause: {line}"
);
for euphemism in ["yolo", "danger mode", "auto", "unrestricted"] {
assert!(
!line.to_ascii_lowercase().contains(euphemism),
"no friendlier word than bypass appears: {line}"
);
}
}
#[test]
fn the_fork_fact_says_only_what_the_running_platform_enforces() {
#[cfg(target_os = "macos")]
{
assert!(
SESSION_FORK_FACT.contains("refused by the sandbox"),
"macOS denies fork by profile omission — the clause states the refusal"
);
assert!(
!SESSION_FORK_FACT.contains("restricts process-fork"),
"macOS's clause is the denial, not an absence-of-restriction claim"
);
}
#[cfg(target_os = "linux")]
{
assert!(
SESSION_FORK_FACT.contains("restricts process-fork"),
"Linux's confinement restricts no fork — the clause must say so"
);
assert!(
SESSION_FORK_FACT.contains("children an interpreter spawns run"),
"Linux children run; the clause states it"
);
assert!(
!SESSION_FORK_FACT.contains("refused"),
"Linux's clause must not claim the macOS denial — that is the \
overstatement this fix exists to remove"
);
}
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
{
assert!(
SESSION_FORK_FACT.contains("no sandbox on this platform is proven"),
"a platform without a proven sandbox path claims no fork fact"
);
}
}
#[test]
fn the_none_staged_variant_names_the_refusal_instead() {
let line = bypass_line(&[], false, false, &[]);
assert!(
line.contains("bypass on:") && line.contains(NO_INTERPRETERS_STAGED),
"the none-staged line names the door that stays shut: {line}"
);
assert!(
line.contains("[jobs.interpreter] allow"),
"the line names where to stage interpreters: {line}"
);
assert!(
!line.contains("interpreter approval"),
"the staged-interpreter warning must not appear when none are staged: {line}"
);
assert!(
!line.contains(HOST_LANE_FACT),
"the uncomposed line states no lane fact: {line}"
);
}
#[test]
fn the_none_staged_sentence_starts_after_the_sentence_break() {
let line = bypass_line(&[], false, false, &[]);
let (mode_fact, rest) = line
.split_once('\n')
.expect("the none-staged sentence begins on its own line after the mode fact");
assert_eq!(
mode_fact, BYPASS_ON,
"the mode fact is the first line, whole: {line}"
);
assert!(
rest.starts_with(NO_INTERPRETERS_STAGED),
"the design's sentence follows verbatim: {rest}"
);
}
#[test]
fn the_activation_line_references_the_probe_refusal() {
let line = bypass_line(&["python3".to_string()], true, false, &[]);
assert!(
line.contains("run_program is unavailable: the sandbox probe did not prove this host"),
"the probe-refused fact is carried on the activation line: {line}"
);
let proven = bypass_line(&["python3".to_string()], false, false, &[]);
assert!(
!proven.contains("run_program is unavailable"),
"a proven host says nothing about the probe: {proven}"
);
}
#[test]
fn the_launch_journals_bypass_exactly_when_this_process_consented_to_it() {
use super::bypass_activated_at_launch;
assert!(
bypass_activated_at_launch(true, false, "bypass"),
"a fresh session under bypass is an activation"
);
assert!(
bypass_activated_at_launch(false, true, "bypass"),
"an explicit `--approval-mode bypass` on a resume is a new consent"
);
assert!(
!bypass_activated_at_launch(false, false, "bypass"),
"a carried bypass mode is the record's consent, not this process's"
);
for mode in ["ask", "read-only", "never", ""] {
assert!(
!bypass_activated_at_launch(true, false, mode),
"no line for {mode:?}: only bypass activation is journalled"
);
}
}
#[test]
fn the_command_journals_bypass_only_when_it_newly_activates_the_mode() {
use super::bypass_activated_by_command;
assert!(
bypass_activated_by_command("ask", "bypass"),
"the command that flips the mode is the activation it prints"
);
assert!(
!bypass_activated_by_command("bypass", "bypass"),
"a re-statement over an already-bypass session records no new consent"
);
assert!(
!bypass_activated_by_command("bypass", "ask"),
"a narrowing mode change grants nothing"
);
assert!(
bypass_activated_by_command("read-only", "bypass"),
"the widening is real whatever the mode it came from"
);
}
#[test]
fn bypass_line_keeps_its_bytes_under_grouping() {
let staged = vec!["python3".to_string()];
let first = bypass_line(&staged, false, true, &["curl".to_string()]);
let second = bypass_line(&staged, false, true, &["curl".to_string()]);
assert_eq!(
first, second,
"the same facts render the same line: grouping has no input"
);
assert!(
first.starts_with(BYPASS_ON),
"the mode fact opens the line: {first:?}"
);
assert!(
first.contains(HOST_LANE_FACT),
"the composed lane fact rides along: {first:?}"
);
assert!(
first.contains("denied for this session: curl"),
"the deny-list segment rides along: {first:?}"
);
assert!(
!first.contains('▸') && !first.contains('▾'),
"no group marker may touch the activation line: {first:?}"
);
}