ac-algorithm 0.2.0

Algorithm competition domain logic for ac
Documentation
//! Local test runs: one solution executed against one case (or ad-hoc
//! input) through the job manager.

use std::path::PathBuf;
use std::time::{Duration, SystemTime};

use serde::{Deserialize, Serialize};

use ac_services::jobs::JobId;

use crate::ids::{CaseId, SolutionId, TestRunId};
use crate::verdict::LocalVerdict;

/// Lifecycle of a [`TestRun`].
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum TestRunStatus {
    /// Recorded but not yet dispatched to the job manager.
    Pending,
    /// Executing under a [`JobId`].
    Running,
    /// Finished with a [`LocalVerdict`].
    Finished,
    /// The run itself failed (compile error, harness fault, lost job).
    Failed,
    /// Cancelled by the user or the session.
    Cancelled,
}

/// A single local execution of a solution against a case.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct TestRun {
    /// Run identifier.
    pub id: TestRunId,
    /// Solution that was executed.
    pub solution: SolutionId,
    /// Case under test, or `None` for ad-hoc input.
    pub case: Option<CaseId>,
    /// Job that executes the run, once dispatched (C-06).
    pub job: Option<JobId>,
    /// Current lifecycle state.
    pub status: TestRunStatus,
    /// Local verdict once finished. Never an official judge result.
    pub verdict: Option<LocalVerdict>,
    /// Process exit code, when the run produced one.
    pub exit_code: Option<i32>,
    /// Wall-clock duration of the run.
    pub duration: Option<Duration>,
    /// Path to captured stdout/stderr log, when retained.
    pub log_path: Option<PathBuf>,
    /// When execution started.
    pub started_at: Option<SystemTime>,
    /// When execution finished.
    pub finished_at: Option<SystemTime>,
}