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}"
);
}