checkpoint: pre-audit baseline state
This commit is contained in:
@@ -342,32 +342,44 @@ class WP_Agentic_Writer_Local_Backend_Provider implements WP_Agentic_Writer_AI_P
|
||||
);
|
||||
}
|
||||
|
||||
// Test /ping endpoint
|
||||
$ping_response = wp_remote_get(
|
||||
$this->base_url . '/ping',
|
||||
array(
|
||||
'timeout' => 5,
|
||||
'sslverify' => false,
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $ping_response ) ) {
|
||||
return new WP_Error(
|
||||
'ping_failed',
|
||||
sprintf(
|
||||
/* translators: %s: error message */
|
||||
__( 'Cannot reach proxy: %s. Is it running?', 'wp-agentic-writer' ),
|
||||
$ping_response->get_error_message()
|
||||
// Best-effort reachability checks. Do not hard-fail here; inference test below is authoritative.
|
||||
$reachable = false;
|
||||
$health_endpoints = array( '/ping', '/health', '/' );
|
||||
foreach ( $health_endpoints as $endpoint ) {
|
||||
$health_response = wp_remote_get(
|
||||
$this->base_url . $endpoint,
|
||||
array(
|
||||
'timeout' => 5,
|
||||
'sslverify' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$ping_body = wp_remote_retrieve_body( $ping_response );
|
||||
if ( 'pong' !== $ping_body ) {
|
||||
return new WP_Error(
|
||||
'invalid_ping',
|
||||
__( 'Proxy responded but with unexpected format', 'wp-agentic-writer' )
|
||||
);
|
||||
if ( is_wp_error( $health_response ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$health_body = trim( (string) wp_remote_retrieve_body( $health_response ) );
|
||||
$health_code = (int) wp_remote_retrieve_response_code( $health_response );
|
||||
$health_json = json_decode( $health_body, true );
|
||||
|
||||
// Any 2xx indicates proxy process is reachable.
|
||||
if ( $health_code >= 200 && $health_code < 300 ) {
|
||||
$reachable = true;
|
||||
}
|
||||
|
||||
// Stronger signal for known proxy responses.
|
||||
if ( strcasecmp( $health_body, 'pong' ) === 0 ) {
|
||||
$reachable = true;
|
||||
break;
|
||||
}
|
||||
if ( is_array( $health_json ) ) {
|
||||
$ok_flag = $health_json['ok'] ?? $health_json['success'] ?? null;
|
||||
$status = strtolower( (string) ( $health_json['status'] ?? '' ) );
|
||||
if ( true === $ok_flag || in_array( $status, array( 'ok', 'healthy', 'pong' ), true ) ) {
|
||||
$reachable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test actual inference with simple prompt
|
||||
@@ -393,6 +405,17 @@ class WP_Agentic_Writer_Local_Backend_Provider implements WP_Agentic_Writer_AI_P
|
||||
);
|
||||
|
||||
if ( is_wp_error( $test_response ) ) {
|
||||
// If both health and inference are unreachable, report connection issue.
|
||||
if ( ! $reachable ) {
|
||||
return new WP_Error(
|
||||
'ping_failed',
|
||||
sprintf(
|
||||
/* translators: %s: error message */
|
||||
__( 'Cannot reach proxy: %s. Is it running and reachable from this server?', 'wp-agentic-writer' ),
|
||||
$test_response->get_error_message()
|
||||
)
|
||||
);
|
||||
}
|
||||
return new WP_Error(
|
||||
'inference_failed',
|
||||
sprintf(
|
||||
|
||||
Reference in New Issue
Block a user