From 1410998161c80ff8e726e2675a11f045b3412383 Mon Sep 17 00:00:00 2001 From: ffalcinelli Date: Tue, 14 Jul 2026 14:00:40 +0200 Subject: [PATCH 1/2] feat: handle unreachable server gracefully with configurable timeout --- .jules/testing.md | 2 +- AGENTS.md | 2 +- GEMINI.md | 2 +- README.md | 5 +++++ docs/index.html | 2 +- src/args.rs | 7 +++++++ src/client.rs | 15 ++++++++++++++- src/lib.rs | 20 +++++++++++++++++++- tests/args_debug_test.rs | 1 + tests/client_error_test.rs | 32 ++++++++++++++++++++++++++++++++ tests/lib_test.rs | 2 ++ tests/profile_test.rs | 7 +++++++ tests/run_app_test.rs | 10 ++++++++++ 13 files changed, 101 insertions(+), 6 deletions(-) diff --git a/.jules/testing.md b/.jules/testing.md index 3e13e5d..bc99a08 100644 --- a/.jules/testing.md +++ b/.jules/testing.md @@ -19,7 +19,7 @@ This document provides context and guidelines for Google Jules when writing, ref 2. **Tokio for Async Tests**: * Use `#[tokio::test]` for asynchronous test cases. 3. **Mockito**: - * Optionally used in older tests to mock external HTTP responses (though Axum is preferred for Keycloak API mocking). + * Optionally used in older tests to mock external HTTP responses (though Axum is preferred for Keycloak API mocking). Can also be used to test request timeout scenarios by using `with_chunked_body` to introduce simulated response delays. 4. **Tempfile**: * Use `tempfile::tempdir()` to create temporary workspaces for reading/writing configuration files during tests to avoid polluting the host system. 5. **Cargo Tarpaulin**: diff --git a/AGENTS.md b/AGENTS.md index b3332b6..e4cbefa 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -66,7 +66,7 @@ Multi-environment configurations are managed using the `--profile` (`-p`) flag: ## ⚙️ Project Configuration File (`kaji.toml` / `.kaji.toml`) -Project connection defaults and workspace parameters can be declared inside `kaji.toml` or `.kaji.toml` files in the current working directory. The configuration file is parsed at startup and merged with command-line inputs. +Project connection defaults, request timeouts, and workspace parameters can be declared inside `kaji.toml` or `.kaji.toml` files in the current working directory. The configuration file is parsed at startup and merged with command-line inputs. Settings are resolved in the following precedence order: 1. **CLI Flags** (highest) diff --git a/GEMINI.md b/GEMINI.md index eb1cf06..ae7ec36 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -67,7 +67,7 @@ For any resource `resource.yaml`, `kaji` looks for `resource.{profile}.yaml` and `kaji` supports project-level settings to override defaults and connection variables persistently. ### Architecture & Pipeline -1. **Schema Definition**: The `Config` struct is defined in [src/args.rs](src/args.rs). It represents optional fields for Keycloak connection credentials, vault parameters, and the workspace folder. +1. **Schema Definition**: The `Config` struct is defined in [src/args.rs](src/args.rs). It represents optional fields for Keycloak connection credentials, vault parameters, the workspace folder, and request timeouts. 2. **File Lookup**: In [src/lib.rs](src/lib.rs), `load_config_file` checks for: * A custom config path specified via `--config` CLI flag or `KAJI_CONFIG` env var. * `kaji.toml` in the current working directory. diff --git a/README.md b/README.md index 3ad96b2..8241762 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ server_url: "https://keycloak.prod.example.com" client_id: "kaji-cli" client_secret: "${PROD_KAJI_SECRET}" secrets_file: ".secrets.prod" # Load environment secrets from this file +timeout: 30 # Keycloak request timeout in seconds (optional) ``` ### 2. Use Overlays @@ -159,6 +160,7 @@ When running with `--profile prod`, `kaji` deep-merges the overlay onto the base | `KEYCLOAK_CLIENT_SECRET` | Client Secret (if using client credentials) | | | `VAULT_ADDR` | HashiCorp Vault URL | | | `VAULT_TOKEN` | HashiCorp Vault Token | | +| `KEYCLOAK_TIMEOUT` | Keycloak request timeout in seconds | `10` | ### Configuration File (`kaji.toml` / `.kaji.toml`) @@ -187,6 +189,9 @@ workspace = "kaji-workspace" # HashiCorp Vault Settings vault_addr = "http://vault:8200" vault_token = "my-vault-token" + +# Keycloak request timeout in seconds (optional) +timeout = 10 ``` #### Precedence / Priority Rules diff --git a/docs/index.html b/docs/index.html index 8318c06..08ac3cd 100644 --- a/docs/index.html +++ b/docs/index.html @@ -156,7 +156,7 @@

Dependency-Aware Reconciliation

Profiles & TOML Config

-

Persist connection credentials, workspace paths, and target environments cleanly. Support for profiles, overlays, and project-wide configuration files.

+

Persist connection credentials, request timeouts, workspace paths, and target environments cleanly. Support for profiles, overlays, and project-wide configuration files.