feat(diagnostics): preserve Registry and resource fault context for PLN-0176 step 28
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
use serde_json::{Value, json};
|
||||
|
||||
fn schema() -> jsonschema::Validator {
|
||||
let full: Value = serde_json::from_str(include_str!(
|
||||
"../../../../devtools/headless-protocol/response.schema.json"
|
||||
))
|
||||
.unwrap();
|
||||
jsonschema::validator_for(&json!({"$defs":full["$defs"],"$ref":"#/$defs/fault"})).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn published_schema_accepts_structured_resource_fields_and_rejects_unknown_or_negative_values() {
|
||||
let schema = schema();
|
||||
let valid = json!({"kind":"vm_trap","pc":18,"summary":"human wording","trap":{
|
||||
"code":16,"opcode":144,"pc":18,"message":"unrelated localized text","span":{"file_id":7,"start":4,"end":9},
|
||||
"resource":{"resource":"HandleSlots","reason":"Limit","requested":3,"limit":2}}});
|
||||
schema.validate(&valid).unwrap();
|
||||
for (field, value) in [
|
||||
("resource", json!("Bogus")),
|
||||
("requested", json!(-1)),
|
||||
("reason", json!("arbitrary text")),
|
||||
] {
|
||||
let mut invalid = valid.clone();
|
||||
invalid["trap"]["resource"][field] = value;
|
||||
assert!(schema.validate(&invalid).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn published_load_schema_requires_tag_context_and_the_matching_init_payload() {
|
||||
let schema = schema();
|
||||
let valid = json!({"kind":"vm_init","pc":null,"summary":"human wording","initError":{
|
||||
"code":"registry_load_failed","message":"unrelated human text","load":{
|
||||
"code":"LOAD_INVALID_REFERENCE","reason":"TypeId","section":6,"offset":159,"record":4,"member":2,
|
||||
"id_domain":"Type","referenced_id":77,"function":3,"pc":18,"resource":null,"requested":null,"limit":null}}});
|
||||
schema.validate(&valid).unwrap();
|
||||
let mut invalid = valid.clone();
|
||||
invalid["initError"]["load"]["referenced_id"] = json!(4294967296u64);
|
||||
assert!(schema.validate(&invalid).is_err());
|
||||
let mut invalid = valid.clone();
|
||||
invalid["initError"]["load"]["code"] = json!("InvalidReference");
|
||||
assert!(schema.validate(&invalid).is_err());
|
||||
let mut invalid = valid.clone();
|
||||
invalid["initError"]["code"] = json!("invalid_format");
|
||||
assert!(schema.validate(&invalid).is_err());
|
||||
}
|
||||
Reference in New Issue
Block a user