fix: delegate analyze_scene_source to analyze_scene_source_with_hint

Remove duplicate implementation in analyze_scene_source() and replace
with simple delegation to analyze_scene_source_with_hint(source_dir, None).

This eliminates ~50 lines of duplicated logic that could drift apart
from the main implementation. Updated the test to verify the new
behavior where sources without scene-kind meta tag default to
ReportCollection instead of being rejected.

🤖 Generated with [Qoder][https://qoder.com]
This commit is contained in:
木炎
2026-04-16 23:42:46 +08:00
parent 67fe17302e
commit 87cee36173
2 changed files with 8 additions and 54 deletions

View File

@@ -151,54 +151,7 @@ pub fn analyze_scene_source_with_hint(
///
/// Requires meta tags to be present. For new code, use `analyze_scene_source_with_hint`.
pub fn analyze_scene_source(source_dir: &Path) -> Result<SceneSourceAnalysis, AnalyzeSceneError> {
let index_path = source_dir.join("index.html");
let html = fs::read_to_string(&index_path).map_err(|err| {
AnalyzeSceneError::new(format!(
"failed to read scene source {}: {err}",
index_path.display()
))
})?;
let scene_kind = meta_content(&html, "sgclaw-scene-kind");
let tool_kind = meta_content(&html, "sgclaw-tool-kind");
if scene_kind.as_deref() != Some("report_collection")
|| tool_kind.as_deref() != Some("browser_script")
{
return Err(AnalyzeSceneError::new(
"generated scene v1 supports report/collection browser_script only",
));
}
let target_url = meta_content(&html, "sgclaw-target-url");
let expected_domain = meta_content(&html, "sgclaw-expected-domain");
let entry_script = meta_content(&html, "sgclaw-entry-script");
if target_url.as_deref().unwrap_or_default().trim().is_empty()
|| expected_domain
.as_deref()
.unwrap_or_default()
.trim()
.is_empty()
|| entry_script
.as_deref()
.unwrap_or_default()
.trim()
.is_empty()
{
return Err(AnalyzeSceneError::new(
"generated scene source must declare target url, expected domain, and entry script",
));
}
Ok(SceneSourceAnalysis {
scene_kind: SceneKind::ReportCollection,
tool_kind: ToolKind::BrowserScript,
bootstrap: BootstrapAnalysis {
target_url,
expected_domain,
},
collection_entry_script: entry_script,
source_dir: source_dir.to_path_buf(),
})
analyze_scene_source_with_hint(source_dir, None)
}
fn meta_content(html: &str, name: &str) -> Option<String> {