Skip to content

capture probe samples#88

Open
vsilent wants to merge 2 commits intotrydirect:masterfrom
vsilent:feature/pipe-probe-capture
Open

capture probe samples#88
vsilent wants to merge 2 commits intotrydirect:masterfrom
vsilent:feature/pipe-probe-capture

Conversation

@vsilent
Copy link
Copy Markdown
Collaborator

@vsilent vsilent commented Apr 11, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 11, 2026 07:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds optional “sample response” capture to the probe_endpoints command so callers can retrieve example payloads from OpenAPI specs and (heuristically) capture a live REST response body for discovered REST endpoints.

Changes:

  • Added capture_samples flag to ProbeEndpointsCommand (defaults to false).
  • Extended OpenAPI probing to optionally attach sample_response per operation (via new extract_response_example helper).
  • Extended REST heuristic probing to optionally attach a sample_response at the endpoint level and added unit tests covering the new behavior.

Comment on lines +4505 to +4515
/// Extract a sample response from an OpenAPI operation's response schema.
/// Looks for: responses -> 200 -> content -> application/json -> example/schema/examples
fn extract_response_example(spec: &Value, operation: &Value) -> Option<Value> {
let responses = operation.get("responses")?;

// Try 200, 201, then default
let response = responses
.get("200")
.or_else(|| responses.get("201"))
.or_else(|| responses.get("default"))?;

Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract_response_example is compiled unconditionally, but it is only used from extract_openapi_operations, which is behind #[cfg(any(feature = "docker", test))]. In a --no-default-features --features minimal build, this function will be unused and is likely to trigger a dead_code warning (and fail CI when running clippy with -D warnings). Consider gating extract_response_example with the same cfg(any(feature = "docker", test)) (or adding an allow(dead_code) under not(feature="docker")) to keep minimal builds warning-free.

Copilot uses AI. Check for mistakes.
Comment on lines +4831 to +4851
// Capture sample response body for REST endpoints
let mut sample_response = None;
if data.capture_samples && code == "200" {
let body_cmd = format!(
"curl -sf -m {} http://localhost:{}{} 2>/dev/null || true",
data.probe_timeout, port, path
);
if let Ok(Ok((0, body, _))) = tokio::time::timeout(
std::time::Duration::from_secs((data.probe_timeout + 2) as u64),
docker::exec_in_container_with_output(&target_name, &body_cmd),
)
.await
{
let body = body.trim();
if !body.is_empty() {
// Try to parse as JSON; fall back to string
sample_response = Some(
serde_json::from_str::<Value>(body)
.unwrap_or_else(|_| json!(body)),
);
}
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capturing REST sample_response via curl has no response-size limit, so a /api endpoint that returns a large payload (or unexpected binary/HTML) can significantly increase memory usage and the size of the command result returned to the controller. Consider adding a hard cap (e.g., fetch only the first N bytes), and optionally applying the existing redact_message logic before attaching the sample to the result to reduce risk of leaking secrets.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants