Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions engines/lemonade/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use anyhow::{Context, Result, anyhow, bail};
use clap::{Parser, Subcommand};
use rocm_core::{AppPaths, DEFAULT_LOCAL_PORT, normalize_runtime_path_for_host, runtime_is_linux};
use rocm_engine_protocol::{
DetectRequest, DetectResponse, DevicePolicy, EndpointRequest, EndpointResponse,
EngineCapabilities, EngineMethod, EngineRequestEnvelope, EngineResponseEnvelope,
HealthcheckRequest, HealthcheckResponse, InstallRequest, InstallResponse, LaunchRequest,
LaunchResponse, LogsRequest, LogsResponse, ResolveModelRequest, ResolveModelResponse,
StopRequest, StopResponse,
DEFAULT_LOG_TAIL_LINES, DetectRequest, DetectResponse, DevicePolicy, EndpointRequest,
EndpointResponse, EngineCapabilities, EngineMethod, EngineRequestEnvelope,
EngineResponseEnvelope, HealthcheckRequest, HealthcheckResponse, InstallRequest,
InstallResponse, LaunchRequest, LaunchResponse, LogsRequest, LogsResponse, ResolveModelRequest,
ResolveModelResponse, StopRequest, StopResponse,
};
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
Expand Down Expand Up @@ -42,7 +42,7 @@ pub(crate) const LLAMACPP_RECIPE: &str = "llamacpp";
pub(crate) const ROCM_BACKEND_NAME: &str = "rocm";
#[cfg(feature = "e2e-test-hooks")]
const BACKEND_INSTALL_FAILURE_TEST_ENV: &str = "ROCM_E2E_LEMONADE_BACKEND_INSTALL_FAILURE";
const DEFAULT_LOG_TAIL_LINES: usize = 200;

/// How long a stop waits for the server to actually exit after each signal
/// before reporting a timeout (or, under `force`, escalating to `SIGKILL`).
const STOP_GRACE: Duration = Duration::from_secs(10);
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e-cucumber/features/logs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ Feature: Log inspection
Given recorded command logs containing several lines about a topic
When the user asks for one service's logs and a search term together
Then the CLI refuses and explains only one may be used

# Engine plugins answer a `logs` request over the engine-plugin protocol. An
# omitted `tail_lines` must yield the protocol default from every engine; the
# Lemonade engine used to shadow it with its own value (#17). Driven through
# the hidden `__engine-stdio` entry point of the built-in engines, so this
# exercises the same handler an external caller would, with planted logs only.
@id:logs-engine-omitted-tail-uses-protocol-default
Scenario: logs-04 - Every engine returns the same number of log lines when no limit is given
Given a service log longer than the default tail for each built-in engine
When each engine is asked for that service's logs without a line limit
Then every engine returns exactly the protocol default number of lines
72 changes: 72 additions & 0 deletions tests/e2e-cucumber/tests/e2e/logs_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ use crate::E2eWorld;
const TOPIC: &str = "E2ENEEDLE";
/// Number of matching lines planted — asserted exactly in the search result.
const MATCH_COUNT: usize = 9;
/// Built-in engines that answer the engine-plugin `logs` method.
const ENGINES: [&str; 2] = ["lemonade", "vllm"];
/// Service whose log is planted for every engine.
const SERVICE_ID: &str = "e2e-tail-probe";
/// Lines planted per service log; more than the default tail so the limit bites.
const PLANTED_LINES: usize = 200;
/// `rocm_engine_protocol::DEFAULT_LOG_TAIL_LINES`, pinned here as the black-box
/// contract value every engine must honour when `tail_lines` is omitted (#17).
const PROTOCOL_DEFAULT_TAIL: usize = 80;

#[given("recorded command logs containing several lines about a topic")]
async fn plant_command_logs(world: &mut E2eWorld) {
Expand All @@ -41,6 +50,26 @@ async fn plant_command_logs(world: &mut E2eWorld) {
std::fs::write(cli_logs.join("e2e-probe.log"), body).expect("failed to write log file");
}

#[given("a service log longer than the default tail for each built-in engine")]
async fn plant_engine_service_logs(world: &mut E2eWorld) {
let root = world.isolated_root.as_ref().expect("no isolated root");
let body: String = (1..=PLANTED_LINES).fold(String::new(), |mut acc, i| {
let _ = writeln!(acc, "line {i}");
acc
});
for engine in ENGINES {
let logs = root
.path()
.join("data")
.join("engines")
.join(engine)
.join("logs");
std::fs::create_dir_all(&logs).expect("failed to create engine logs dir");
std::fs::write(logs.join(format!("{SERVICE_ID}.log")), &body)
.expect("failed to write engine service log");
}
}

// ── When ───────────────────────────────────────────────────────────

#[when("the user searches the logs for that topic")]
Expand All @@ -64,6 +93,35 @@ async fn service_and_search(world: &mut E2eWorld) {
record(world, stdout, stderr, rc);
}

#[when("each engine is asked for that service's logs without a line limit")]
async fn ask_each_engine_for_logs(world: &mut E2eWorld) {
let envelope = serde_json::json!({
"method": "logs",
"payload": { "service_id": SERVICE_ID },
})
.to_string();
// Record one "<engine> <count> <last line>" row per engine in the shared
// output slot so the Then step can compare engines against each other.
let mut rows = String::new();
for engine in ENGINES {
let (stdout, stderr, rc) =
crate::run_rocm_with_stdin(world, &["__engine-stdio", engine], &envelope, &[]);
assert_eq!(rc, 0, "{engine} logs request failed:\n{stdout}\n{stderr}");
let response: serde_json::Value =
serde_json::from_str(&stdout).expect("engine response is not JSON");
assert_eq!(
response["ok"], true,
"{engine} logs request was rejected:\n{stdout}"
);
let lines = response["data"]["recent_lines"]
.as_array()
.expect("recent_lines missing");
let last = lines.last().and_then(|v| v.as_str()).unwrap_or("");
let _ = writeln!(rows, "{engine} {} {last}", lines.len());
}
record(world, rows, String::new(), 0);
}

// ── Then ───────────────────────────────────────────────────────────

#[then("the CLI reports the matching recent lines")]
Expand Down Expand Up @@ -102,6 +160,20 @@ async fn refuses_conflict(world: &mut E2eWorld) {
);
}

#[then("every engine returns exactly the protocol default number of lines")]
async fn every_engine_returns_default_tail(world: &mut E2eWorld) {
let out = ok_output(world);
let expected_last = format!("line {PLANTED_LINES}");
for engine in ENGINES {
assert!(
out.contains(&format!(
"{engine} {PROTOCOL_DEFAULT_TAIL} {expected_last}\n"
)),
"expected {engine} to return the newest {PROTOCOL_DEFAULT_TAIL} lines, got:\n{out}"
);
}
}

// ── Helpers ────────────────────────────────────────────────────────

fn record(world: &mut E2eWorld, stdout: String, stderr: String, rc: i32) {
Expand Down
Loading