diff --git a/crates/ghostlight/src/controllers.rs b/crates/ghostlight/src/controllers.rs index 7165200..b6131ee 100644 --- a/crates/ghostlight/src/controllers.rs +++ b/crates/ghostlight/src/controllers.rs @@ -7633,6 +7633,86 @@ mod tests { eprintln!("schema walk: {} tools, worst (optional, bytes) = {worst:?}", tools.len()); } + + /// The prose-only gate refuses every deviation from one user text, no + /// tools, automatic choice, serial calls and no output schema. + #[test] + fn the_prose_shape_gate_refuses_each_deviation() { + let request = persona_request(CommandId::new(), "claude-haiku-5-5", "Speak.".into()).unwrap(); + let valid = PreparedInference::prepare("runtime", 4_102_444_800_000, request).unwrap(); + assert!(prose_request_shape_is_valid(&valid)); + assert!(persona_request_shape_is_valid(&valid)); + let deviations: Vec<(&str, Box)> = vec![ + ( + "a second input item", + Box::new(|r| r.input.push(InputItem::UserText { text: "more".into() })), + ), + ( + "an assistant opening", + Box::new(|r| r.input = vec![InputItem::AssistantText { text: "no".into() }]), + ), + ( + "a tool", + Box::new(|r| { + r.tools.push(ToolDefinition { + name: "t".into(), + description: "d".into(), + parameters_json: "{}".into(), + }) + }), + ), + ("a required tool choice", Box::new(|r| r.tool_choice = ToolChoice::Required)), + ("parallel calls", Box::new(|r| r.parallel_tool_calls = true)), + ( + "an output schema", + Box::new(|r| r.output_schema_json = Some("{}".into())), + ), + ]; + for (name, deviate) in deviations { + let mut prepared = valid.clone(); + deviate(&mut prepared.invocation.request); + assert!(!prose_request_shape_is_valid(&prepared), "{name} passed the gate"); + } + } + + /// The trace file renders what the provider is sent, every input kind + /// included. + #[test] + fn the_trace_renders_every_input_kind_and_the_tools() { + let mut provider = ProviderRequest::new("r", "c", "claude-haiku-5-5", "Be brief.", 100); + provider.input = vec![ + InputItem::UserText { text: "u-text".into() }, + InputItem::AssistantText { text: "a-text".into() }, + InputItem::ToolCall { + call_id: "k".into(), + name: "t-name".into(), + arguments: "{\"a\":1}".into(), + }, + InputItem::ToolResult { call_id: "k".into(), output: "t-out".into() }, + InputItem::ReasoningState { + provider: "p".into(), + model: "m".into(), + state: vec![1], + }, + ]; + provider.tools = vec![ToolDefinition { + name: "t-name".into(), + description: "t-desc".into(), + parameters_json: "{}".into(), + }]; + let prepared = PreparedInference::prepare( + "runtime", + 4_102_444_800_000, + InferenceRequest { purpose: InferencePurpose::Persona, provider }, + ) + .unwrap(); + let rendered = TracingInferencePort::render_request(&prepared); + for needle in [ + "Be brief.", "u-text", "a-text", "t-name", "{\"a\":1}", "t-out", "[reasoning state]", "t-desc", + ] { + assert!(rendered.contains(needle), "the trace lacks {needle}: {rendered}"); + } + } #[test] fn a_planted_twenty_fifth_optional_parameter_fails_the_limit() { let properties = |count: usize| -> String {