#![allow(clippy::expect_used)]
use std::path::PathBuf;
const ALLOWED_POLICY_HOMES: &[&str] = &[
"rig-core/src/providers/internal/adapter.rs",
"rig-core/src/providers/internal/wire.rs",
];
fn is_policy_home(path: &std::path::Path) -> bool {
let unix_path = path.to_string_lossy().replace('\\', "/");
ALLOWED_POLICY_HOMES
.iter()
.any(|suffix| unix_path.ends_with(suffix))
}
const SKIPPED_DIRS: &[&str] = &["tests", "test_utils", "fixtures", "target"];
fn mask_literals_and_comments(source: &str) -> String {
enum State {
Code,
LineComment,
BlockComment(usize),
Str,
RawStr(usize),
Char,
}
let mut masked = String::with_capacity(source.len());
let mut state = State::Code;
let mut chars = source.chars().peekable();
let mut escaped = false;
let emit = |masked: &mut String, ch: char, keep: bool| {
if ch == '\n' || keep {
masked.push(ch);
} else {
masked.push(' ');
}
};
while let Some(ch) = chars.next() {
match state {
State::Code => match ch {
'/' if chars.peek() == Some(&'/') => {
state = State::LineComment;
emit(&mut masked, ch, false);
}
'/' if chars.peek() == Some(&'*') => {
state = State::BlockComment(1);
emit(&mut masked, ch, false);
}
'"' => {
state = State::Str;
emit(&mut masked, ch, false);
}
'r' if matches!(chars.peek(), Some('"') | Some('#')) => {
let mut hashes = 0usize;
let mut lookahead = chars.clone();
while lookahead.peek() == Some(&'#') {
let _ = lookahead.next();
hashes += 1;
}
if lookahead.peek() == Some(&'"') {
for _ in 0..=hashes {
if let Some(consumed) = chars.next() {
emit(&mut masked, consumed, false);
}
}
state = State::RawStr(hashes);
emit(&mut masked, ch, false);
} else {
emit(&mut masked, ch, true);
}
}
'\'' => {
let mut lookahead = chars.clone();
let first = lookahead.next();
let second = lookahead.next();
let is_char_literal = first == Some('\\')
|| (first.is_some() && second == Some('\''))
|| first == Some('\'');
if is_char_literal {
state = State::Char;
emit(&mut masked, ch, false);
} else {
emit(&mut masked, ch, true);
}
}
_ => emit(&mut masked, ch, true),
},
State::LineComment => {
if ch == '\n' {
state = State::Code;
}
emit(&mut masked, ch, false);
}
State::BlockComment(depth) => {
if ch == '/' && chars.peek() == Some(&'*') {
state = State::BlockComment(depth.saturating_add(1));
} else if ch == '*' && chars.peek() == Some(&'/') {
if depth <= 1 {
if let Some(slash) = chars.next() {
emit(&mut masked, ch, false);
emit(&mut masked, slash, false);
state = State::Code;
continue;
}
}
state = State::BlockComment(depth.saturating_sub(1));
}
emit(&mut masked, ch, false);
}
State::Str | State::Char => {
let closing = if matches!(state, State::Str) {
'"'
} else {
'\''
};
if escaped {
escaped = false;
} else if ch == '\\' {
escaped = true;
} else if ch == closing {
state = State::Code;
}
emit(&mut masked, ch, false);
}
State::RawStr(hashes) => {
if ch == '"' {
let mut lookahead = chars.clone();
let mut seen = 0usize;
while seen < hashes && lookahead.peek() == Some(&'#') {
let _ = lookahead.next();
seen += 1;
}
if seen == hashes {
for _ in 0..hashes {
if let Some(consumed) = chars.next() {
emit(&mut masked, consumed, false);
}
}
state = State::Code;
}
}
emit(&mut masked, ch, false);
}
}
}
masked
}
fn end_of_gated_item(masked_lines: &[&str], start: usize) -> usize {
let mut depth: isize = 0;
let mut seen_brace = false;
let mut index = start;
while let Some(line) = masked_lines.get(index) {
for ch in line.chars() {
match ch {
'{' => {
depth += 1;
seen_brace = true;
}
'}' => depth -= 1,
';' if !seen_brace && depth == 0 => return index + 1,
_ => {}
}
}
index += 1;
if seen_brace && depth <= 0 {
return index;
}
}
masked_lines.len()
}
fn shipped_portion(source: &str) -> String {
let masked = mask_literals_and_comments(source);
let lines: Vec<&str> = source.split_inclusive('\n').collect();
let masked_lines: Vec<&str> = masked.split_inclusive('\n').collect();
debug_assert_eq!(lines.len(), masked_lines.len());
let mut shipped = String::with_capacity(source.len());
let mut index = 0usize;
while let Some(line) = lines.get(index) {
let is_gate = masked_lines
.get(index)
.is_some_and(|masked| masked.trim_start().starts_with("#[cfg(test)]"));
if is_gate {
let end = end_of_gated_item(&masked_lines, index);
for blanked in index..end {
if lines.get(blanked).is_some_and(|l| l.ends_with('\n')) {
shipped.push('\n');
}
}
index = end;
continue;
}
shipped.push_str(line);
index += 1;
}
shipped
}
fn for_each_shipped_source(mut visit: impl FnMut(&std::path::Path, &str)) {
let crates_dir: PathBuf = [env!("CARGO_MANIFEST_DIR"), ".."].iter().collect();
let mut pending = vec![crates_dir];
while let Some(dir) = pending.pop() {
let entries = std::fs::read_dir(&dir).expect("workspace directory should be readable");
for entry in entries {
let entry = entry.expect("directory entry should be readable");
let path = entry.path();
let name = entry.file_name();
let name = name.to_string_lossy().into_owned();
if path.is_dir() {
if !SKIPPED_DIRS.contains(&name.as_str()) {
pending.push(path);
}
continue;
}
if path.extension().is_none_or(|ext| ext != "rs") {
continue;
}
let source = std::fs::read_to_string(&path).expect("source file should be readable");
visit(&path, &shipped_portion(&source));
}
}
}
const WALK_FLOOR_FILES: &[&str] = &[
"rig-core/src/providers/internal/adapter.rs",
"rig-core/src/providers/internal/wire.rs",
"rig-core/src/providers/anthropic/streaming.rs",
"rig-core/src/providers/openai/responses_api/streaming.rs",
"rig-bedrock/src/streaming.rs",
"rig-gemini-grpc/src/streaming.rs",
];
fn assert_walk_floor(walked: &[String]) {
let missing: Vec<&&str> = WALK_FLOOR_FILES
.iter()
.filter(|suffix| !walked.iter().any(|path| path.ends_with(*suffix)))
.collect();
assert!(
missing.is_empty(),
"the source walk found nothing at {missing:?} — a collapsed walk \
(moved crate, renamed directory) must fail loudly rather than let \
every scan pass vacuously; walked {} files",
walked.len()
);
}
#[test]
fn every_triage_site_runs_on_the_single_policy_driver() {
let mut violations = Vec::new();
let mut walked = Vec::new();
let mut policy_home_mentions = 0usize;
for_each_shipped_source(|path, shipped| {
walked.push(path.to_string_lossy().replace('\\', "/"));
if is_policy_home(path) {
policy_home_mentions += shipped.matches("WireEvent::").count();
return;
}
for (index, line) in shipped.lines().enumerate() {
if line.contains("WireEvent::Unknown") || line.contains("WireEvent::Corrupt") {
violations.push(format!("{}:{}: {}", path.display(), index + 1, line.trim()));
}
}
});
assert_walk_floor(&walked);
assert!(
policy_home_mentions > 0,
"the policy homes no longer mention `WireEvent::` — the marker this \
scan greps for cannot occur, so the scan is vacuous"
);
assert!(
violations.is_empty(),
"Unknown/Corrupt triage restated outside the driver (adapter.rs) and \
classify layer (wire.rs) — route it through run_wire_stream / \
run_wire_buffered / triage_frame instead:\n{}",
violations.join("\n")
);
}
const RAW_SERDE_MARKERS: &[&str] = &[
"serde_json::from_str",
"serde_json::from_slice",
"serde_json::from_value",
"#[serde(other)]",
"#[serde(untagged)]",
];
const SINGLE_FILE_STREAMING_MODULES: &[&str] = &[
"providers/ollama.rs",
"providers/copilot/mod.rs",
"providers/chatgpt/mod.rs",
];
const WIRE_MACHINERY_MARKERS: &[&str] = &[
"WireEvent",
"WireAdapter",
"WireFrame",
"run_wire_stream",
"run_wire_buffered",
"triage_frame",
];
fn is_serde_wall_target(path: &std::path::Path, shipped: &str) -> bool {
let unix_path = path.to_string_lossy().replace('\\', "/");
if unix_path.contains("/rig-agent/") || unix_path.contains("/test_utils/") {
return false;
}
if is_policy_home(path) {
return false;
}
if SINGLE_FILE_STREAMING_MODULES
.iter()
.any(|suffix| unix_path.ends_with(suffix))
{
return true;
}
if path
.file_name()
.map(|name| name.to_string_lossy().into_owned())
.is_some_and(|name| name.contains("streaming") || name.contains("websocket"))
{
return true;
}
WIRE_MACHINERY_MARKERS
.iter()
.any(|marker| shipped.contains(marker))
}
struct AllowlistEntry {
path_suffix: String,
snippet: String,
used: bool,
}
fn parse_allowlist(raw: &str) -> Vec<AllowlistEntry> {
raw.lines()
.map(str::trim)
.filter(|line| !line.is_empty() && !line.starts_with('#'))
.map(|line| {
let mut fields = line.splitn(3, '|').map(str::trim);
let path_suffix = fields.next().unwrap_or_default().to_string();
let snippet = fields.next().unwrap_or_default().to_string();
let justification = fields.next().unwrap_or_default();
assert!(
!path_suffix.is_empty() && !snippet.is_empty() && !justification.is_empty(),
"malformed serde_policy_allowlist.txt entry (need `path | snippet | justification`): {line}"
);
AllowlistEntry {
path_suffix,
snippet,
used: false,
}
})
.collect()
}
fn scan_streaming_source(
path_label: &str,
shipped: &str,
allowlist: &mut [AllowlistEntry],
) -> Vec<String> {
let mut violations = Vec::new();
for (index, line) in shipped.lines().enumerate() {
if line.trim_start().starts_with("//") {
continue;
}
if !RAW_SERDE_MARKERS.iter().any(|marker| line.contains(marker)) {
continue;
}
let mut covered = false;
for entry in allowlist.iter_mut() {
if path_label.ends_with(entry.path_suffix.as_str()) && line.contains(&entry.snippet) {
entry.used = true;
covered = true;
}
}
if !covered {
violations.push(format!("{}:{}: {}", path_label, index + 1, line.trim()));
}
}
violations
}
fn macro_body(source: &str, start: usize) -> String {
let Some(open) = source[start..].find('(') else {
return source[start..].to_owned();
};
let body = &source[start + open..];
let bytes = body.as_bytes();
let mut comments: Vec<(usize, usize)> = Vec::new();
let assemble = |end: usize, comments: &[(usize, usize)]| {
let mut kept = source[start..start + open].to_owned();
let mut cursor = 0usize;
for &(from, to) in comments {
kept.push_str(&body[cursor..from.min(end)]);
cursor = to.min(end);
}
kept.push_str(&body[cursor..end]);
kept
};
let mut depth = 0usize;
let mut index = 0usize;
while let Some(&byte) = bytes.get(index) {
match byte {
b'"' => {
index += 1;
while let Some(&inner) = bytes.get(index) {
match inner {
b'\\' => index += 1,
b'"' => break,
_ => {}
}
index += 1;
}
}
b'r' if matches!(bytes.get(index + 1), Some(b'"' | b'#')) => {
let mut hashes = 0usize;
let mut probe = index + 1;
while bytes.get(probe) == Some(&b'#') {
hashes += 1;
probe += 1;
}
if bytes.get(probe) == Some(&b'"') {
index = probe + 1;
while let Some(&inner) = bytes.get(index) {
if inner == b'"'
&& bytes
.get(index + 1..index + 1 + hashes)
.is_some_and(|tail| tail.iter().all(|b| *b == b'#'))
{
index += hashes;
break;
}
index += 1;
}
}
}
b'\'' => {
if bytes.get(index + 1) == Some(&b'\\') && bytes.get(index + 3) == Some(&b'\'') {
index += 3;
} else if bytes.get(index + 2) == Some(&b'\'') {
index += 2;
}
}
b'/' if bytes.get(index + 1) == Some(&b'/') => {
let from = index;
while let Some(&inner) = bytes.get(index) {
if inner == b'\n' {
break;
}
index += 1;
}
comments.push((from, index));
continue;
}
b'/' if bytes.get(index + 1) == Some(&b'*') => {
let from = index;
let mut comment_depth = 1usize;
index += 2;
while let Some(&inner) = bytes.get(index) {
if inner == b'/' && bytes.get(index + 1) == Some(&b'*') {
comment_depth += 1;
index += 1;
} else if inner == b'*' && bytes.get(index + 1) == Some(&b'/') {
comment_depth -= 1;
index += 1;
if comment_depth == 0 {
index += 1;
break;
}
}
index += 1;
}
comments.push((from, index));
continue;
}
b'(' => depth += 1,
b')' => {
depth -= 1;
if depth == 0 {
return assemble(index + 1, &comments);
}
}
_ => {}
}
index += 1;
}
assemble(body.len(), &comments)
}
fn body_debug_captures(body: &str) -> bool {
if body.contains("?}") {
return true;
}
let bytes = body.as_bytes();
for (index, _) in body.match_indices('?') {
if !bytes
.get(index + 1)
.is_some_and(|next| next.is_ascii_alphabetic() || *next == b'_')
{
continue;
}
let preceding = body[..index].chars().rev().find(|ch| !ch.is_whitespace());
if !matches!(preceding, Some('(' | ',' | '=')) {
continue;
}
let mut depth = 0usize;
let mut end = body.len();
for (offset, ch) in body[index..].char_indices() {
match ch {
'(' => depth += 1,
')' if depth == 0 => {
end = index + offset;
break;
}
')' => depth -= 1,
',' if depth == 0 => {
end = index + offset;
break;
}
_ => {}
}
}
if body[index..end].contains("std::mem::discriminant") {
continue;
}
return true;
}
false
}
#[test]
fn streaming_modules_never_debug_print_wire_payloads_in_warn_logs() {
let mut violations = Vec::new();
let mut walked = Vec::new();
let mut scanned_targets = 0usize;
for_each_shipped_source(|path, shipped| {
walked.push(path.to_string_lossy().replace('\\', "/"));
if !is_serde_wall_target(path, shipped) {
return;
}
scanned_targets += 1;
for aliased in ["warn as", "event as"] {
for (at, _) in shipped.match_indices(aliased) {
let statement_start = shipped[..at].rfind(';').map_or(0, |semi| semi + 1);
let statement = &shipped[statement_start..at];
if statement.contains("use") && statement.contains("tracing") {
let line_number = shipped[..at].matches('\n').count() + 1;
violations.push(format!(
"{}:{}: a `use … {aliased} …` alias hides WARN call sites from this scan",
path.display(),
line_number,
));
}
}
}
let warn_sites = shipped
.match_indices("warn!")
.map(|(start, _)| (start, false));
let event_sites = shipped
.match_indices("event!")
.map(|(start, _)| (start, true));
for (start, is_event) in warn_sites.chain(event_sites) {
if shipped[..start]
.chars()
.next_back()
.is_some_and(|ch| ch.is_ascii_alphanumeric() || ch == '_')
{
continue;
}
let line_number = shipped[..start].matches('\n').count() + 1;
let line = shipped[..start]
.rfind('\n')
.map_or(&shipped[..start], |at| &shipped[at + 1..start]);
if line.trim_start().starts_with("//") {
continue;
}
let body = macro_body(shipped, start);
if is_event && !body.contains("Level::WARN") {
continue;
}
if body_debug_captures(&body) {
violations.push(format!(
"{}:{}: {}",
path.display(),
line_number,
body.lines().next().unwrap_or(&body).trim()
));
}
}
});
assert_walk_floor(&walked);
assert!(
scanned_targets > 5,
"the payload-warn scan scoped almost nothing ({scanned_targets} files) — vacuous"
);
assert!(
violations.is_empty(),
"a WARN log Debug-captures a wire payload — route it through \
`adapter::warn_unmodeled` (kind + byte size only):\n{}",
violations.join("\n")
);
}
#[test]
fn the_warn_scan_catches_every_capture_spelling() {
for leaking in [
"tracing::warn!(?frame, \"skipping\");",
"tracing::warn!(payload = ?frame, \"skipping\");",
"tracing::warn!(\"bad frame: {:?}\", frame);",
"tracing::warn!(\n ?frame,\n \"skipping\"\n);",
"tracing::warn!(\n payload =\n ?frame,\n \"skipping\"\n);",
"tracing::warn!(\"bad frame: {frame:?}\");",
"tracing::warn!(\"bad frame: {frame:#?}\");",
"tracing::warn!(\"bad frame: {frame:x?}\");",
"tracing::warn!(\"bad frame: {frame:X?}\");",
"tracing::warn!(\"bad frame: {frame:>10?}\");",
"tracing::warn!(\"bad frame: {frame:.3?}\");",
"tracing::warn!(\n // see step 3)\n ?frame,\n \"skipping\"\n);",
"tracing::warn!(\n /* note (a) */\n ?frame,\n \"skipping\"\n);",
"tracing::event!(tracing::Level::WARN, ?frame, \"skipping\");",
] {
let start = leaking
.find("warn!")
.or_else(|| leaking.find("event!"))
.expect("fixture contains a warn-level macro");
assert!(
body_debug_captures(¯o_body(leaking, start)),
"must flag: {leaking}"
);
}
for clean in [
"tracing::warn!(kind, payload_bytes = size, \"skipping unmodeled wire payload\");",
"tracing::warn!(step_index, \"arguments_delta for an unopened step?\");",
"tracing::warn!(\n kind,\n payload_bytes = bytes,\n \"skipping\"\n);",
"tracing::warn!(\n delta = ?std::mem::discriminant(&unknown),\n \"skipping\"\n);",
"tracing::warn!(\"dropped {count} frames\");",
"tracing::warn!(r#\"marker \"quoted\" text\"#, count);",
] {
assert!(
!body_debug_captures(¯o_body(
clean,
clean.find("warn!").expect("fixture contains warn!")
)),
"must not flag: {clean}"
);
}
}
#[test]
fn provider_streaming_modules_never_raw_parse_the_wire() {
let allowlist_path: PathBuf = [
env!("CARGO_MANIFEST_DIR"),
"tests",
"serde_policy_allowlist.txt",
]
.iter()
.collect();
let raw = std::fs::read_to_string(&allowlist_path).expect("allowlist file should be readable");
let mut allowlist = parse_allowlist(&raw);
let mut violations = Vec::new();
let mut walked = Vec::new();
let mut scanned_targets = Vec::new();
for_each_shipped_source(|path, shipped| {
walked.push(path.to_string_lossy().replace('\\', "/"));
if !is_serde_wall_target(path, shipped) {
return;
}
let label = path.to_string_lossy().replace('\\', "/");
scanned_targets.push(label.clone());
violations.extend(scan_streaming_source(&label, shipped, &mut allowlist));
});
assert_walk_floor(&walked);
for suffix in [
"rig-core/src/providers/anthropic/streaming.rs",
"rig-core/src/providers/ollama.rs",
"rig-core/src/providers/openai/responses_api/streaming.rs",
"rig-bedrock/src/streaming.rs",
] {
assert!(
scanned_targets.iter().any(|label| label.ends_with(suffix)),
"the serde wall no longer scans {suffix} — its scoping collapsed; \
scanned {} targets",
scanned_targets.len()
);
}
assert!(
violations.is_empty(),
"raw serde parsing in a provider streaming module — route wire decoding \
through the `wire.rs` classify layer, or (for a genuine non-triage use) \
add a `path | snippet | justification` entry to \
crates/rig-core/tests/serde_policy_allowlist.txt:\n{}",
violations.join("\n")
);
let stale: Vec<&str> = allowlist
.iter()
.filter(|entry| !entry.used)
.map(|entry| entry.snippet.as_str())
.collect();
assert!(
stale.is_empty(),
"stale serde_policy_allowlist.txt entries (the code they covered is gone \
— delete them): {stale:?}"
);
}
#[test]
fn serde_policy_scanner_catches_raw_parses() {
let bad_source = r#"
fn sneak_a_policy_site(data: &str) {
let value = serde_json::from_str::<serde_json::Value>(data);
}
#[serde(other)]
struct Marker;
"#;
let violations = scan_streaming_source(
"crates/rig-core/src/providers/fake/streaming.rs",
bad_source,
&mut [],
);
assert_eq!(
violations.len(),
2,
"the scanner must flag both the raw parse and the serde(other) fallback: {violations:?}"
);
let mut allowlist = parse_allowlist(
"providers/fake/streaming.rs | serde_json::from_str::<serde_json::Value>(data) | synthetic",
);
let violations = scan_streaming_source(
"crates/rig-core/src/providers/fake/streaming.rs",
bad_source,
&mut allowlist,
);
assert_eq!(
violations.len(),
1,
"only the serde(other) line stays flagged"
);
assert!(allowlist.iter().all(|entry| entry.used));
assert!(!is_serde_wall_target(
std::path::Path::new("crates/rig-core/src/providers/internal/wire.rs"),
"fn classify(frame: WireFrame) -> WireEvent { todo!() }",
));
assert!(is_serde_wall_target(
std::path::Path::new("crates/rig-core/src/providers/openai/responses_api/websocket.rs"),
"",
));
}
#[test]
fn serde_wall_scopes_by_machinery_content() {
let compat = std::path::Path::new(
"crates/rig-core/src/providers/internal/openai_chat_completions_compatible.rs",
);
assert!(
is_serde_wall_target(compat, "use super::adapter::run_wire_stream;"),
"a compat helper referencing the machinery must be scanned"
);
let future_helper = std::path::Path::new("crates/rig-core/src/providers/somegateway/sse.rs");
assert!(
is_serde_wall_target(
future_helper,
"let out = run_wire_buffered(adapter, frames);"
),
"any future compat/sse helper opts in the moment it names the machinery"
);
assert!(
!is_serde_wall_target(future_helper, "fn plain_request_builder() {}"),
"machinery-free helpers stay out of scope"
);
}
#[test]
fn foreign_adapter_files_are_not_exempt() {
let foreign = std::path::Path::new("crates/rig-bedrock/src/streaming/adapter.rs");
assert!(
!is_policy_home(foreign),
"guard 1 must scan a foreign adapter.rs for restated policy tables"
);
assert!(
is_serde_wall_target(foreign, "match event { WireEvent::Unknown(_) => {} }"),
"guard 2 must scan a foreign adapter.rs that touches the machinery"
);
assert!(is_policy_home(std::path::Path::new(
"crates/rig-core/src/providers/internal/adapter.rs"
)));
assert!(is_policy_home(std::path::Path::new(
"crates/rig-core/src/providers/internal/wire.rs"
)));
}
#[test]
fn shipped_portion_ignores_cfg_test_mentions_in_comments() {
let source = "\
/// This helper is exercised under #[cfg(test)] elsewhere.
fn shipped_code() { let _ = WireEvent::Unknown; }
#[cfg(test)]
mod tests {
fn test_only() { let _ = WireEvent::Corrupt; }
}
";
let shipped = shipped_portion(source);
assert!(
shipped.contains("WireEvent::Unknown"),
"code after a doc-comment mention still ships"
);
assert!(
!shipped.contains("WireEvent::Corrupt"),
"the real attribute-position marker still removes its item"
);
let indented = "fn a() {}\n #[cfg(test)]\n fn b() {}\n";
assert_eq!(shipped_portion(indented), "fn a() {}\n\n\n");
let plain = "fn a() {}\n";
assert_eq!(shipped_portion(plain), plain);
let block_commented = "\
/*
#[cfg(test)]
*/
fn shipped_code() { let _ = WireEvent::Unknown; }
";
assert!(
shipped_portion(block_commented).contains("WireEvent::Unknown"),
"an attribute inside a block comment must not gate the code below it"
);
}
#[test]
fn shipped_portion_is_item_scoped() {
let source = "\
fn before() { let _ = WireEvent::Unknown; }
#[cfg(test)]
pub(super) fn gated_helper() -> u8 {
let braces_in_a_string = \"unbalanced { brace\";
let raw = r#\"also unbalanced } here\"#;
let _ = (braces_in_a_string, raw);
7
}
fn after() { let _ = run_wire_stream(); }
#[cfg(test)]
mod tests {
fn test_only() { let _ = WireEvent::Corrupt; }
}
fn last() { let _ = triage_frame(); }
";
let shipped = shipped_portion(source);
assert!(shipped.contains("WireEvent::Unknown"), "{shipped}");
assert!(
shipped.contains("run_wire_stream"),
"shipped code AFTER a gated helper must stay visible: {shipped}"
);
assert!(
shipped.contains("triage_frame"),
"shipped code after a gated `mod tests` must stay visible too: {shipped}"
);
assert!(
!shipped.contains("gated_helper") && !shipped.contains("WireEvent::Corrupt"),
"gated items themselves must be blanked: {shipped}"
);
assert_eq!(
shipped.lines().count(),
source.lines().count(),
"blanking must preserve line numbering so violations cite real lines"
);
assert!(
is_serde_wall_target(
std::path::Path::new("crates/rig-core/src/providers/somegateway/compat.rs"),
&shipped,
),
"a file whose only machinery reference sits after a gated helper must still be scanned"
);
let brace_less = "#[cfg(test)]\nuse std::fmt;\nfn after() { let _ = WireEvent::Unknown; }\n";
assert!(shipped_portion(brace_less).contains("WireEvent::Unknown"));
}