Wave 5: Schemas command, sync command, network policy, test fixtures (bd-x15, bd-3f4, bd-1cv, bd-lx6)

- Implement schemas command with list/show modes, regex filtering, ref expansion
- Implement sync command with conditional fetch, content hash diffing, dry-run
- Add NetworkPolicy enum (Auto/Offline/OnlineOnly) with env var + CLI flag resolution
- Integrate network policy into AsyncHttpClient and fetch command
- Create test fixtures (petstore.json/yaml, minimal.json) and integration test helpers
- Fix clippy lints: derivable_impls, len_zero, borrow-after-move, deprecated API
- 192 tests passing (179 unit + 13 integration), all quality gates green
This commit is contained in:
teernisse
2026-02-12 14:36:22 -05:00
parent faa6281790
commit 346fef9135
11 changed files with 2051 additions and 31 deletions

106
tests/integration_test.rs Normal file
View File

@@ -0,0 +1,106 @@
mod helpers;
#[test]
fn test_petstore_json_is_valid() {
let path = helpers::fixture_path("petstore.json");
let content = std::fs::read_to_string(&path).unwrap();
let json: serde_json::Value = serde_json::from_str(&content).unwrap();
assert!(json.get("openapi").is_some());
assert!(json.get("paths").is_some());
assert!(json.get("components").is_some());
}
#[test]
fn test_petstore_yaml_is_valid() {
let path = helpers::fixture_path("petstore.yaml");
let content = std::fs::read_to_string(&path).unwrap();
let yaml: serde_json::Value = serde_yaml::from_str(&content).unwrap();
assert!(yaml.get("openapi").is_some());
assert!(yaml.get("paths").is_some());
assert!(yaml.get("components").is_some());
}
#[test]
fn test_minimal_json_is_valid() {
let path = helpers::fixture_path("minimal.json");
let content = std::fs::read_to_string(&path).unwrap();
let json: serde_json::Value = serde_json::from_str(&content).unwrap();
assert_eq!(json["openapi"], "3.0.3");
assert_eq!(json["info"]["title"], "Minimal API");
let paths = json["paths"].as_object().unwrap();
assert_eq!(paths.len(), 2); // /items and /items/{id}
// Count total operations: GET /items, POST /items, GET /items/{id} = 3
let items_ops = json["paths"]["/items"].as_object().unwrap();
let item_by_id_ops = json["paths"]["/items/{id}"].as_object().unwrap();
let op_count = items_ops.len() + item_by_id_ops.len();
// /items has get+post (2), /items/{id} has get+parameters (but parameters isn't an op)
assert!(op_count >= 3);
let schemas = json["components"]["schemas"].as_object().unwrap();
assert_eq!(schemas.len(), 2); // Item and ItemList
}
#[test]
fn test_petstore_yaml_matches_json_structure() {
let json_path = helpers::fixture_path("petstore.json");
let yaml_path = helpers::fixture_path("petstore.yaml");
let json_content = std::fs::read_to_string(&json_path).unwrap();
let yaml_content = std::fs::read_to_string(&yaml_path).unwrap();
let json_val: serde_json::Value = serde_json::from_str(&json_content).unwrap();
let yaml_val: serde_json::Value = serde_yaml::from_str(&yaml_content).unwrap();
// Both should have the same top-level keys
assert_eq!(json_val["openapi"], yaml_val["openapi"]);
assert_eq!(json_val["info"]["title"], yaml_val["info"]["title"]);
assert_eq!(json_val["info"]["version"], yaml_val["info"]["version"]);
// Same number of paths
let json_paths = json_val["paths"].as_object().unwrap();
let yaml_paths = yaml_val["paths"].as_object().unwrap();
assert_eq!(json_paths.len(), yaml_paths.len());
// Same schemas
let json_schemas = json_val["components"]["schemas"].as_object().unwrap();
let yaml_schemas = yaml_val["components"]["schemas"].as_object().unwrap();
assert_eq!(json_schemas.len(), yaml_schemas.len());
}
#[test]
fn test_fetch_and_list_fixture() {
let env = helpers::TestEnv::new();
helpers::fetch_fixture(&env, "petstore.json", "petstore");
let assert = helpers::run_cmd(&env, &["list", "petstore", "--robot"]).success();
let json = helpers::parse_robot_json(&assert.get_output().stdout);
assert_eq!(json["ok"], true);
assert!(!json["data"]["endpoints"].as_array().unwrap().is_empty());
assert!(json["data"]["total"].as_u64().unwrap() > 0);
}
#[test]
fn test_fetch_yaml_fixture() {
let env = helpers::TestEnv::new();
helpers::fetch_fixture(&env, "petstore.yaml", "petstore-yaml");
let assert = helpers::run_cmd(&env, &["list", "petstore-yaml", "--robot"]).success();
let json = helpers::parse_robot_json(&assert.get_output().stdout);
assert_eq!(json["ok"], true);
}
#[test]
fn test_fetch_minimal_fixture() {
let env = helpers::TestEnv::new();
helpers::fetch_fixture(&env, "minimal.json", "minimal");
let assert = helpers::run_cmd(&env, &["list", "minimal", "--robot"]).success();
let json = helpers::parse_robot_json(&assert.get_output().stdout);
assert_eq!(json["ok"], true);
assert_eq!(json["data"]["total"], 3);
}