Reject provider-incompatible ref siblings
This commit is contained in:
parent
31eae440bb
commit
d78c2060ba
2 changed files with 20 additions and 4 deletions
|
|
@ -232,9 +232,6 @@ struct CompiledSeed {
|
|||
world_time: DateTime<Utc>,
|
||||
#[schemars(range(min = 1))]
|
||||
tick_hours: u32,
|
||||
#[schemars(
|
||||
description = "The single human-controlled player boundary. Never repeat this subject in actors or gestalt_members."
|
||||
)]
|
||||
player: CompiledActorState,
|
||||
locations: Vec<CompiledLocation>,
|
||||
#[schemars(
|
||||
|
|
@ -5634,8 +5631,9 @@ mod tests {
|
|||
let serialized = serde_json::to_string(&schema).unwrap();
|
||||
assert!(serialized.contains("\"route_id\""));
|
||||
assert!(serialized.contains("\"subject_id\""));
|
||||
assert!(serialized.contains("single human-controlled player boundary"));
|
||||
assert!(serialized.contains("Autonomous nonplayer actors only"));
|
||||
assert_eq!(schema["properties"]["player"].as_object().unwrap().len(), 1);
|
||||
assert!(schema["properties"]["player"].get("$ref").is_some());
|
||||
|
||||
let mut agency = serde_json::to_value(schema_for!(CompiledAgencySkeleton)).unwrap();
|
||||
crate::model_connector::project_strict_responses_schema(&mut agency).unwrap();
|
||||
|
|
|
|||
|
|
@ -276,6 +276,9 @@ pub(crate) fn project_strict_responses_schema(schema: &mut serde_json::Value) ->
|
|||
fn responses_schema_is_strict(schema: &serde_json::Value) -> bool {
|
||||
match schema {
|
||||
serde_json::Value::Object(map) => {
|
||||
if map.contains_key("$ref") && map.len() != 1 {
|
||||
return false;
|
||||
}
|
||||
if (map.contains_key("const") || map.contains_key("enum")) && !map.contains_key("type")
|
||||
{
|
||||
return false;
|
||||
|
|
@ -309,6 +312,9 @@ fn responses_schema_is_strict(schema: &serde_json::Value) -> bool {
|
|||
fn require_closed_responses_objects(schema: &mut serde_json::Value, path: &str) -> Result<()> {
|
||||
match schema {
|
||||
serde_json::Value::Object(map) => {
|
||||
if map.contains_key("$ref") && map.len() != 1 {
|
||||
bail!("Responses schema {path} places sibling keywords beside $ref")
|
||||
}
|
||||
let describes_object = schema_map_describes_object(map);
|
||||
if describes_object {
|
||||
map.insert("type".to_string(), serde_json::json!("object"));
|
||||
|
|
@ -677,6 +683,18 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strict_schema_projection_rejects_ref_siblings_before_provider_submission() {
|
||||
let mut schema = serde_json::json!({
|
||||
"$ref":"#/$defs/Answer",
|
||||
"description":"provider-incompatible sibling"
|
||||
});
|
||||
let error = project_strict_responses_schema(&mut schema)
|
||||
.unwrap_err()
|
||||
.to_string();
|
||||
assert!(error.contains("sibling keywords beside $ref"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cache_key_tracks_stable_stage_contract_not_dynamic_world_context() -> Result<()> {
|
||||
let request = ModelStageRequest {
|
||||
|
|
|
|||
Loading…
Reference in a new issue