use std::collections::{HashMap, HashSet};
use crate::e2e::codegen::c::assertions::{EffectiveConfigSource, FieldConfigSources};
use crate::e2e::field_access::FieldResolver;
use crate::e2e::fixture::Fixture;
fn permissive_resolver() -> FieldResolver {
FieldResolver::new(
&HashMap::new(),
&HashSet::new(),
&HashSet::new(),
&HashSet::new(),
&HashSet::new(),
)
}
fn global_sources() -> FieldConfigSources {
FieldConfigSources {
result_fields: EffectiveConfigSource::Global,
fields: EffectiveConfigSource::Global,
}
}
fn batch_fixture() -> Fixture {
Fixture {
id: "batch_crawl_basic".into(),
description: "Crawl a batch of seed URLs".into(),
input: serde_json::json!({"batch_urls": ["/seed1", "/seed2"]}),
preserve_input_urls: true,
..Fixture::default()
}
}
#[test]
fn batch_url_list_fixture_does_not_fall_back_to_raw_mock_scaffolding() {
let fixture = batch_fixture();
let mut out = String::new();
super::render_engine_factory_test_function(
&mut out,
&fixture,
"sample",
"batch_scrape",
"result",
&permissive_resolver(),
&HashMap::new(),
&HashSet::new(),
"BatchCrawlResults",
"CrawlConfig",
false,
Some("char*"),
&[],
&global_sources(),
)
.expect("engine-factory batch fixture renders");
assert!(
!out.contains("getenv(\"MOCK_SERVER_URL\")"),
"batch fixture must not fall back to raw mock-harness scaffolding \
(this is exactly what `reject_mock_harness_scaffolding` rejects in a doc snippet):\n{out}"
);
assert!(
out.contains("snprintf(url, sizeof(url), \"%s\", \"/seed1\");"),
"expected the first batch_urls entry to become the preserved literal url:\n{out}"
);
}
#[test]
fn batch_url_list_fixture_without_preserve_flag_still_uses_mock_server() {
let mut fixture = batch_fixture();
fixture.preserve_input_urls = false;
let mut out = String::new();
super::render_engine_factory_test_function(
&mut out,
&fixture,
"sample",
"batch_scrape",
"result",
&permissive_resolver(),
&HashMap::new(),
&HashSet::new(),
"BatchCrawlResults",
"CrawlConfig",
false,
Some("char*"),
&[],
&global_sources(),
)
.expect("engine-factory batch fixture renders");
assert!(
out.contains("getenv(\"MOCK_SERVER_URL\")"),
"without preserve_input_urls the mock-server scaffolding must still be emitted:\n{out}"
);
assert!(
!out.contains("/seed1"),
"the batch literal must not leak when preservation is off:\n{out}"
);
}
#[test]
fn empty_batch_url_list_fixture_does_not_fall_back_to_raw_mock_scaffolding() {
let fixture = Fixture {
id: "batch_scrape_empty_urls_error".into(),
description: "Batch scrape rejects an empty URL list".into(),
input: serde_json::json!({"batch_urls": []}),
preserve_input_urls: true,
assertions: vec![crate::e2e::fixture::Assertion {
assertion_type: "error".into(),
field: None,
value: Some(serde_json::Value::String("empty urls".into())),
values: None,
..crate::e2e::fixture::Assertion::default()
}],
..Fixture::default()
};
let mut out = String::new();
super::render_engine_factory_test_function(
&mut out,
&fixture,
"sample",
"batch_scrape",
"result",
&permissive_resolver(),
&HashMap::new(),
&HashSet::new(),
"BatchCrawlResults",
"CrawlConfig",
true,
Some("char*"),
&[],
&global_sources(),
)
.expect("engine-factory empty-batch fixture renders");
assert!(
!out.contains("MOCK_SERVER_URL"),
"an empty, deliberately-declared batch_urls list has nothing to leak and must not \
fall back to mock-harness scaffolding:\n{out}"
);
assert!(
!out.contains("getenv"),
"no mock-harness getenv scaffolding of any kind belongs in this render:\n{out}"
);
assert!(
out.contains("snprintf(url, sizeof(url), \"%s\", \"\");"),
"the deliberately empty list must render as a literal empty url, not be dropped:\n{out}"
);
assert_eq!(
crate::e2e::codegen::declared_error_value(&fixture),
Some("empty urls"),
"the fixture's own error assertion must still be intact after rendering"
);
}