Compare commits
6 Commits
main
...
copilot/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2d012b16b | ||
|
|
bb454af8c2 | ||
|
|
b7f5c7d3fe | ||
|
|
c18c7a3fb4 | ||
|
|
34bdb56644 | ||
|
|
c4903faf85 |
18
.github/workflows/pull_request.yml
vendored
18
.github/workflows/pull_request.yml
vendored
@ -25,12 +25,13 @@ jobs:
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-24.04
|
||||
validate: true
|
||||
name: "Proxy Test"
|
||||
- os: windows-2025
|
||||
validate: false
|
||||
name: "Proxy Test (Windows)"
|
||||
- os: macos-15
|
||||
validate: false
|
||||
name: "Proxy Test (Mac)"
|
||||
runs-on: ${{ matrix.os }}
|
||||
name: ${{ matrix.name }}
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
||||
- name: Install Rust
|
||||
@ -45,11 +46,16 @@ jobs:
|
||||
# If we cache PR branches, we may evict the 'main' cache and end up with no cache hits at all.
|
||||
# Ideally, we would have main be 'high priority' and not be evicted but I don't think thats possible.
|
||||
save-if: ${{ github.ref == 'refs/heads/main' }}
|
||||
- name: Start validation dependencies
|
||||
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
|
||||
run: tools/manage-validation-deps.sh start
|
||||
- name: Test
|
||||
run: make test
|
||||
- name: Validate
|
||||
if: ${{ matrix.validate }}
|
||||
run: make validate
|
||||
env:
|
||||
KEYCLOAK_AVAILABLE: ${{ startsWith(matrix.os, 'ubuntu-') && '1' || '' }}
|
||||
- name: Stop validation dependencies
|
||||
if: ${{ always() && startsWith(matrix.os, 'ubuntu-') }}
|
||||
run: tools/manage-validation-deps.sh stop
|
||||
|
||||
proxy-lint:
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
168
crates/agentgateway/tests/validate_examples.rs
Normal file
168
crates/agentgateway/tests/validate_examples.rs
Normal file
@ -0,0 +1,168 @@
|
||||
/// Integration tests that validate all `examples/*/config.yaml` files using the same
|
||||
/// logic as the `--validate-only` CLI flag, without requiring a full recompile/run cycle.
|
||||
///
|
||||
/// Tests that require an external Keycloak instance are skipped unless the
|
||||
/// `KEYCLOAK_AVAILABLE` environment variable is set to `1` or `true`.
|
||||
/// To run those tests locally, first start the dependencies with
|
||||
/// `tools/manage-validation-deps.sh start` and then:
|
||||
///
|
||||
/// KEYCLOAK_AVAILABLE=1 cargo test --test validate_examples
|
||||
use std::path::Path;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use agentgateway::types::agent::ListenerTarget;
|
||||
use agentgateway::types::local::NormalizedLocalConfig;
|
||||
use agentgateway::{BackendConfig, client};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Test infrastructure
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Deterministic 32-byte (64 hex-char) cookie secret used for configs that enable
|
||||
/// OIDC browser auth, matching the value exported by `validate-configs.sh`.
|
||||
const TEST_OIDC_COOKIE_SECRET: &str =
|
||||
"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
|
||||
|
||||
/// Change the process working directory to the workspace root exactly once.
|
||||
///
|
||||
/// All example configs reference files (JWKS keys, TLS certs, OpenAPI schemas)
|
||||
/// relative to the workspace root, mirroring what the binary does when run from
|
||||
/// that directory.
|
||||
static SETUP: OnceLock<()> = OnceLock::new();
|
||||
|
||||
fn workspace_root() -> &'static Path {
|
||||
static WORKSPACE_ROOT: OnceLock<std::path::PathBuf> = OnceLock::new();
|
||||
WORKSPACE_ROOT.get_or_init(|| {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.join("../..")
|
||||
.canonicalize()
|
||||
.expect("workspace root should be resolvable")
|
||||
})
|
||||
}
|
||||
|
||||
fn setup() {
|
||||
SETUP.get_or_init(|| {
|
||||
std::env::set_current_dir(workspace_root())
|
||||
.expect("should be able to set cwd to workspace root");
|
||||
});
|
||||
}
|
||||
|
||||
fn test_config() -> agentgateway::Config {
|
||||
// Supply a deterministic OIDC cookie secret so configs that enable browser
|
||||
// auth (e.g. oidc/) can be compiled without errors, matching the behaviour of
|
||||
// validate-configs.sh which exports OIDC_COOKIE_SECRET.
|
||||
let mut config =
|
||||
agentgateway::config::parse_config("{}".to_string(), None).expect("parse empty config");
|
||||
config.oidc_cookie_encoder = Some(
|
||||
agentgateway::http::sessionpersistence::Encoder::aes(TEST_OIDC_COOKIE_SECRET)
|
||||
.expect("AES encoder"),
|
||||
);
|
||||
config
|
||||
}
|
||||
|
||||
fn test_client(config: &agentgateway::Config) -> client::Client {
|
||||
client::Client::new(&config.dns, None, BackendConfig::default(), None)
|
||||
}
|
||||
|
||||
async fn validate_example(path: &str) -> Result<(), String> {
|
||||
setup();
|
||||
let yaml = std::fs::read_to_string(path).map_err(|e| format!("failed to read {path}: {e}"))?;
|
||||
let config = test_config();
|
||||
let client = test_client(&config);
|
||||
NormalizedLocalConfig::from(
|
||||
&config,
|
||||
client,
|
||||
ListenerTarget {
|
||||
gateway_name: "default".into(),
|
||||
gateway_namespace: "default".into(),
|
||||
listener_name: None,
|
||||
},
|
||||
&yaml,
|
||||
)
|
||||
.await
|
||||
.map(|_| ())
|
||||
.map_err(|e| format!("validation failed for {path}: {e}"))
|
||||
}
|
||||
|
||||
/// Returns true when the external Keycloak instance (and the companion auth_server.py)
|
||||
/// have been started via `tools/manage-validation-deps.sh start`.
|
||||
fn keycloak_available() -> bool {
|
||||
std::env::var("KEYCLOAK_AVAILABLE")
|
||||
.map(|v| matches!(v.as_str(), "1" | "true"))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
fn example_configs() -> Vec<String> {
|
||||
fn walk(dir: &Path, configs: &mut Vec<std::path::PathBuf>) {
|
||||
let mut entries = std::fs::read_dir(dir)
|
||||
.unwrap_or_else(|e| panic!("failed to read {}: {e}", dir.display()))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap_or_else(|e| panic!("failed to list {}: {e}", dir.display()));
|
||||
entries.sort_by_key(|entry| entry.path());
|
||||
|
||||
for entry in entries {
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
walk(&path, configs);
|
||||
} else if path.file_name().is_some_and(|name| name == "config.yaml") {
|
||||
configs.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut configs = Vec::new();
|
||||
walk(&workspace_root().join("examples"), &mut configs);
|
||||
assert!(
|
||||
!configs.is_empty(),
|
||||
"expected at least one examples/**/config.yaml file"
|
||||
);
|
||||
configs
|
||||
.into_iter()
|
||||
.map(|path| {
|
||||
path
|
||||
.strip_prefix(workspace_root())
|
||||
.unwrap_or_else(|_| panic!("{} should live under the workspace root", path.display()))
|
||||
.to_string_lossy()
|
||||
.replace('\\', "/")
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn example_name(path: &str) -> String {
|
||||
let parent = Path::new(path)
|
||||
.parent()
|
||||
.unwrap_or_else(|| panic!("{path} should have a parent folder"));
|
||||
parent
|
||||
.strip_prefix("examples")
|
||||
.unwrap_or(parent)
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
}
|
||||
|
||||
fn example_requires_keycloak(path: &str) -> bool {
|
||||
let yaml = std::fs::read_to_string(path).unwrap_or_else(|e| panic!("failed to read {path}: {e}"));
|
||||
yaml.contains("http://localhost:7080/realms/") || yaml.contains("http://localhost:9000")
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_validate_examples() {
|
||||
setup();
|
||||
let mut failures = Vec::new();
|
||||
|
||||
for path in dbg!(example_configs()) {
|
||||
let name = example_name(&path);
|
||||
if example_requires_keycloak(&path) && !keycloak_available() {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Err(err) = validate_example(&path).await {
|
||||
failures.push(format!("{name} ({path}): {err}"));
|
||||
}
|
||||
}
|
||||
|
||||
assert!(
|
||||
failures.is_empty(),
|
||||
"example validation failed for:\n{}",
|
||||
failures.join("\n")
|
||||
);
|
||||
}
|
||||
@ -48,11 +48,12 @@ case "${1:-}" in
|
||||
# Realm import may complete after container is up; wait for each imported realm's
|
||||
# JWKS specifically so example validation can rely on discovery-backed providers.
|
||||
for jwks_endpoint in "${KEYCLOAK_REALM_JWKS_ENDPOINTS[@]}"; do
|
||||
if ! wait_for_http_ok "$jwks_endpoint" 240 3; then
|
||||
if ! wait_for_http_ok "$jwks_endpoint" 240 1; then
|
||||
echo "Keycloak realm JWKS endpoint did not become available in time: $jwks_endpoint" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
docker logs keycloak
|
||||
;;
|
||||
stop)
|
||||
pkill -f "examples/mcp-authentication/auth_server.py" 2>/dev/null || true
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user