fix: 按契约显示统一创作表头

This commit is contained in:
2026-06-06 23:51:53 +08:00
parent 18908609fc
commit d0be3f36aa
7 changed files with 21 additions and 147 deletions

View File

@@ -99,7 +99,6 @@ pub struct UnifiedCreationFieldResponse {
}
pub const UNIFIED_CREATION_FIELD_KINDS: [&str; 4] = ["text", "select", "image", "audio"];
pub const LEGACY_UNIFIED_CREATION_TITLE: &str = "想做个什么玩法?";
pub fn build_phase1_unified_creation_spec(play_id: &str) -> Option<UnifiedCreationSpecResponse> {
let (workspace_stage, generation_stage, result_stage, fields) = match play_id {
@@ -138,16 +137,7 @@ pub fn build_phase1_unified_creation_spec(play_id: &str) -> Option<UnifiedCreati
"jump-hop-workspace",
"jump-hop-generating",
"jump-hop-result",
vec![
unified_creation_field("workTitle", "text", "作品标题", true),
unified_creation_field("workDescription", "text", "作品简介", true),
unified_creation_field("themeTags", "text", "主题标签", true),
unified_creation_field("difficulty", "select", "难度", true),
unified_creation_field("stylePreset", "select", "风格", true),
unified_creation_field("characterPrompt", "text", "角色提示词", true),
unified_creation_field("tilePrompt", "text", "地块提示词", true),
unified_creation_field("endMoodPrompt", "text", "终点氛围", false),
],
vec![unified_creation_field("themeText", "text", "主题", true)],
),
"wooden-fish" => (
"wooden-fish-workspace",
@@ -236,26 +226,6 @@ pub fn default_unified_creation_title(play_id: &str) -> Option<&'static str> {
}
}
pub fn normalize_unified_creation_spec_title_for_entry(
play_id: &str,
entry_title: &str,
mut spec: UnifiedCreationSpecResponse,
) -> UnifiedCreationSpecResponse {
let entry_title = entry_title.trim();
if entry_title.is_empty() {
return spec;
}
let spec_title = spec.title.trim();
let default_title = default_unified_creation_title(play_id).unwrap_or_default();
if spec_title == LEGACY_UNIFIED_CREATION_TITLE
|| (!default_title.is_empty() && spec_title == default_title)
{
spec.title = entry_title.to_string();
}
spec
}
pub fn validate_unified_creation_spec_response(
spec: &UnifiedCreationSpecResponse,
) -> Result<(), String> {
@@ -339,27 +309,10 @@ pub fn resolve_unified_creation_spec_response(
play_id: &str,
value: Option<&str>,
) -> Option<UnifiedCreationSpecResponse> {
resolve_unified_creation_spec_response_with_entry_title(
play_id,
default_unified_creation_title(play_id).unwrap_or_default(),
value,
)
}
pub fn resolve_unified_creation_spec_response_with_entry_title(
play_id: &str,
entry_title: &str,
value: Option<&str>,
) -> Option<UnifiedCreationSpecResponse> {
let spec = match value {
match value {
Some(raw) => decode_unified_creation_spec_response(raw).ok(),
None => build_phase1_unified_creation_spec(play_id),
}?;
Some(normalize_unified_creation_spec_title_for_entry(
play_id,
entry_title,
spec,
))
}
}
fn unified_creation_field(
@@ -400,18 +353,8 @@ mod tests {
let jump_hop = build_phase1_unified_creation_spec("jump-hop").expect("jump-hop spec");
assert_eq!(jump_hop.title, "跳一跳");
assert!(
jump_hop
.fields
.iter()
.any(|field| field.id == "stylePreset")
);
assert!(
jump_hop
.fields
.iter()
.any(|field| field.id == "endMoodPrompt")
);
assert_eq!(jump_hop.fields.len(), 1);
assert_eq!(jump_hop.fields[0].id, "themeText");
let wooden_fish =
build_phase1_unified_creation_spec("wooden-fish").expect("wooden-fish spec");
@@ -438,7 +381,7 @@ mod tests {
}
#[test]
fn unified_creation_spec_title_can_fallback_to_entry_title() {
fn unified_creation_spec_title_uses_contract_content() {
let raw = r#"{
"playId": "puzzle",
"title": "想做个什么玩法?",
@@ -455,25 +398,10 @@ mod tests {
]
}"#;
let spec = resolve_unified_creation_spec_response_with_entry_title(
"puzzle",
"定制拼图",
Some(raw),
)
.expect("puzzle spec");
let spec =
resolve_unified_creation_spec_response("puzzle", Some(raw)).expect("puzzle spec");
assert_eq!(spec.title, "定制拼图");
}
#[test]
fn unified_creation_spec_title_keeps_admin_custom_copy() {
let mut spec = build_phase1_unified_creation_spec("jump-hop").expect("jump-hop spec");
spec.title = "你的跳一跳是...".to_string();
let normalized =
normalize_unified_creation_spec_title_for_entry("jump-hop", "跳一跳", spec);
assert_eq!(normalized.title, "你的跳一跳是...");
assert_eq!(spec.title, "想做个什么玩法?");
}
#[test]