mirror of
https://github.com/openai/codex.git
synced 2026-11-02 19:43:24 +00:00
crate
This commit is contained in:
+10
-43
@@ -1,6 +1,6 @@
|
||||
use clap::Args;
|
||||
use codex_status::CodexStatus;
|
||||
use codex_status::StatusClient;
|
||||
use codex_status::fetch_codex_health;
|
||||
use codex_status::ComponentHealth;
|
||||
use std::io::Write;
|
||||
use std::io::{self};
|
||||
|
||||
@@ -12,80 +12,47 @@ pub struct StatusCommand {
|
||||
}
|
||||
|
||||
pub async fn run_status(cmd: StatusCommand) -> anyhow::Result<()> {
|
||||
let client = StatusClient::new()?;
|
||||
let codex_status = client.fetch_codex_status().await?;
|
||||
let component_health = fetch_codex_health().await?;
|
||||
|
||||
if cmd.json {
|
||||
let json = serde_json::to_string_pretty(&codex_status)?;
|
||||
let json = serde_json::to_string_pretty(&component_health)?;
|
||||
println!("{json}");
|
||||
} else {
|
||||
write_human(&codex_status, &mut io::stdout())?;
|
||||
write_human(component_health, &mut io::stdout())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_human<W: Write>(status: &CodexStatus, writer: &mut W) -> anyhow::Result<()> {
|
||||
writeln!(writer, "Codex status: {}", status.status)?;
|
||||
writeln!(writer, "operational: {}", status.is_operational)?;
|
||||
writeln!(writer, "component_id: {}", status.component_id)?;
|
||||
|
||||
if let Some(affected) = &status.raw_affected {
|
||||
writeln!(writer, "affected status: {}", affected.status)?;
|
||||
} else {
|
||||
writeln!(writer, "affected status: none")?;
|
||||
}
|
||||
|
||||
fn write_human<W: Write>(status: ComponentHealth, writer: &mut W) -> anyhow::Result<()> {
|
||||
writeln!(writer, "Codex status: {status}")?;
|
||||
writeln!(writer, "operational: {}", status.is_operational())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use codex_status::AffectedComponent;
|
||||
use codex_status::ComponentHealth;
|
||||
|
||||
#[test]
|
||||
fn human_output_handles_absent_affected_entry() -> anyhow::Result<()> {
|
||||
let status = CodexStatus {
|
||||
component_id: "cmp-1".to_string(),
|
||||
name: "Codex".to_string(),
|
||||
status: ComponentHealth::Operational,
|
||||
is_operational: true,
|
||||
raw_affected: None,
|
||||
};
|
||||
|
||||
let mut buffer = Vec::new();
|
||||
write_human(&status, &mut buffer)?;
|
||||
write_human(ComponentHealth::Operational, &mut buffer)?;
|
||||
|
||||
let output = String::from_utf8(buffer).expect("utf8");
|
||||
assert!(output.contains("Codex status: operational"));
|
||||
assert!(output.contains("operational: true"));
|
||||
assert!(output.contains("component_id: cmp-1"));
|
||||
assert!(output.contains("affected status: none"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn human_output_shows_affected_status() -> anyhow::Result<()> {
|
||||
let status = CodexStatus {
|
||||
component_id: "cmp-1".to_string(),
|
||||
name: "Codex".to_string(),
|
||||
status: ComponentHealth::DegradedPerformance,
|
||||
is_operational: false,
|
||||
raw_affected: Some(AffectedComponent {
|
||||
component_id: "cmp-1".to_string(),
|
||||
status: ComponentHealth::DegradedPerformance,
|
||||
}),
|
||||
};
|
||||
|
||||
let mut buffer = Vec::new();
|
||||
write_human(&status, &mut buffer)?;
|
||||
write_human(ComponentHealth::DegradedPerformance, &mut buffer)?;
|
||||
|
||||
let output = String::from_utf8(buffer).expect("utf8");
|
||||
assert!(output.contains("Codex status: degraded_performance"));
|
||||
assert!(output.contains("operational: false"));
|
||||
assert!(output.contains("affected status: degraded_performance"));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user