G: G4 Drift guard and docs commit the spec and fail tests on drift
This commit is contained in:
1 parent
869b6818e9
commit
34a1e1644c
5 files changed
+1986
No files matched your search
@@ -202,6 +202,72 @@ fn mcp_tool_count_follows_the_peers_flag() {
|
||||
assert!(on.iter().any(|name| name == "get_peer"));
|
||||
}
|
||||
|
||||
/// The committed document is the one the code generates. Regenerate it (and
|
||||
/// commit the result) whenever a route, a tool, a DTO or the crate version
|
||||
/// changes.
|
||||
#[test]
|
||||
fn committed_spec_matches_the_code() {
|
||||
let path = Path::new(MANIFEST).join("docs/openapi.json");
|
||||
let committed = fs::read_to_string(&path).unwrap_or_default();
|
||||
let generated = skyg_linux_tracker::cli::render(true).unwrap();
|
||||
assert_eq!(
|
||||
committed, generated,
|
||||
"docs/openapi.json is stale; regenerate it with\n \
|
||||
cargo run -- openapi --peers > docs/openapi.json"
|
||||
);
|
||||
}
|
||||
|
||||
/// Read-only by construction: every operation is a GET, except the MCP
|
||||
/// endpoint, which is POST by protocol.
|
||||
#[test]
|
||||
fn every_operation_is_read_only() {
|
||||
let doc = document(true);
|
||||
for (path, item) in &doc.paths.paths {
|
||||
for (method, present) in [
|
||||
("post", item.post.is_some()),
|
||||
("put", item.put.is_some()),
|
||||
("delete", item.delete.is_some()),
|
||||
("patch", item.patch.is_some()),
|
||||
] {
|
||||
if present {
|
||||
assert_eq!(
|
||||
(method, path.as_str()),
|
||||
("post", "/mcp"),
|
||||
"{method} {path} is a write path"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Operation ids are unique and every tag is declared, so client generators
|
||||
/// and UI tools do not have to guess.
|
||||
#[test]
|
||||
fn operation_ids_and_tags_are_declared() {
|
||||
let doc = document(true);
|
||||
let declared: Vec<String> = doc
|
||||
.tags
|
||||
.clone()
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|tag| tag.name)
|
||||
.collect();
|
||||
let mut ids = Vec::new();
|
||||
for (path, item) in &doc.paths.paths {
|
||||
for operation in [&item.get, &item.post].into_iter().flatten() {
|
||||
let id = operation.operation_id.clone().expect("operationId");
|
||||
assert!(!ids.contains(&id), "duplicate operationId {id} ({path})");
|
||||
ids.push(id);
|
||||
for tag in operation.tags.iter().flatten() {
|
||||
assert!(
|
||||
declared.iter().any(|declared| declared == tag),
|
||||
"tag {tag} of {path} is not declared"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_spec_is_valid_json_with_the_expected_shape() {
|
||||
let doc = document(true);
|
||||
|
||||
Reference in new issue
Block a user