Wave 6: Integration tests, golden tests, index invariant tests, diff command (bd-rex, bd-2gp, bd-1ck)

This commit is contained in:
teernisse
2026-02-12 14:58:25 -05:00
parent 346fef9135
commit 398311ca4c
27 changed files with 2122 additions and 172 deletions

View File

@@ -7,9 +7,10 @@ use clap::Args as ClapArgs;
use serde::Serialize;
use crate::core::cache::{CacheManager, CacheMetadata, compute_hash, validate_alias};
use crate::core::config::{AuthType, Config, CredentialSource, config_path};
use crate::core::config::{AuthType, Config, config_path, resolve_credential};
use crate::core::http::{AsyncHttpClient, ConditionalFetchResult};
use crate::core::indexer::{Format, build_index, detect_format, normalize_to_json};
use crate::core::network::{NetworkPolicy, resolve_policy};
use crate::core::spec::SpecIndex;
use crate::errors::SwaggerCliError;
use crate::output::robot;
@@ -203,24 +204,6 @@ fn compute_diff(old: &SpecIndex, new: &SpecIndex) -> (ChangeSummary, ChangeDetai
(summary, details)
}
// ---------------------------------------------------------------------------
// Auth credential resolution
// ---------------------------------------------------------------------------
fn resolve_credential(source: &CredentialSource) -> Result<String, SwaggerCliError> {
match source {
CredentialSource::Literal { value } => Ok(value.clone()),
CredentialSource::EnvVar { name } => std::env::var(name).map_err(|_| {
SwaggerCliError::Auth(format!(
"environment variable '{name}' not set (required by auth profile)"
))
}),
CredentialSource::Keyring { service, account } => Err(SwaggerCliError::Auth(format!(
"keyring credential lookup not yet implemented (service={service}, account={account})"
))),
}
}
// ---------------------------------------------------------------------------
// Core sync logic (testable with explicit cache path)
// ---------------------------------------------------------------------------
@@ -229,6 +212,8 @@ async fn sync_inner(
args: &Args,
cache_path: PathBuf,
robot_mode: bool,
network_policy: NetworkPolicy,
config_override: Option<&std::path::Path>,
) -> Result<(), SwaggerCliError> {
let start = Instant::now();
@@ -246,8 +231,10 @@ async fn sync_inner(
})?;
// 2. Build HTTP client
let cfg = Config::load(&config_path(None))?;
let mut builder = AsyncHttpClient::builder().allow_insecure_http(url.starts_with("http://"));
let cfg = Config::load(&config_path(config_override))?;
let mut builder = AsyncHttpClient::builder()
.allow_insecure_http(url.starts_with("http://"))
.network_policy(network_policy);
if let Some(profile_name) = &args.auth {
let profile = cfg.auth_profiles.get(profile_name).ok_or_else(|| {
@@ -434,7 +421,12 @@ fn output_changes(
// Public entry point
// ---------------------------------------------------------------------------
pub async fn execute(args: &Args, robot: bool) -> Result<(), SwaggerCliError> {
pub async fn execute(
args: &Args,
robot: bool,
network_flag: &str,
config_override: Option<&std::path::Path>,
) -> Result<(), SwaggerCliError> {
if args.all {
return Err(SwaggerCliError::Usage(
"sync --all is not yet implemented".into(),
@@ -442,7 +434,8 @@ pub async fn execute(args: &Args, robot: bool) -> Result<(), SwaggerCliError> {
}
let cache = crate::core::config::cache_dir();
sync_inner(args, cache, robot).await
let policy = resolve_policy(network_flag)?;
sync_inner(args, cache, robot, policy, config_override).await
}
// ---------------------------------------------------------------------------