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
69 changes: 68 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,80 @@ jobs:
exit 1
fi

# The ten live tests of workshop-server, which a normal test run skips:
# they run Workshop's server, the Workshop program, and its window against
# a real Gateway. tools/live-tests.mjs gives each group of tests the
# Gateway state it needs, and names what it runs. The chat model is
# CheapSeek, a test server that speaks the OpenAI chat API and computes
# each reply from fixed rules, so the job runs without a model file or a
# provider's key. The Gateway is the release gateway-pin/pin.json names,
# which `cargo workshop` places beside the Workshop program it builds.
live:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Install cargo-nextest
uses: taiki-e/install-action@4dc1969decfa71b34f25aa7f3dd4656654d9ad1e # nextest

- name: Cache cargo
uses: Swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2

# The window tests drive Workshop through tauri-driver and WebKit's
# own driver, on a display that xvfb-run makes and a message bus that
# dbus-run-session makes.
- name: Install Tauri and window-test packages
timeout-minutes: 20
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libwebkit2gtk-4.1-dev libssl-dev librsvg2-dev \
webkit2gtk-driver xvfb xauth dbus lsof

- uses: actions/setup-node@v4
with:
node-version: 22
cache: npm
cache-dependency-path: crates/workshop/package-lock.json

- name: Install UI dependencies
run: npm ci --prefix crates/workshop

- name: Stage the pinned Gateway
run: node tools/fetch-gateway-sidecar.mjs --target x86_64-unknown-linux-gnu

- name: Build Workshop beside the Gateway
run: cargo workshop

- name: Install tauri-driver
run: cargo install tauri-driver --locked --version 2.1.0

# The action sets CHEAPSEEK_BASE_URL for the step after it.
- name: Start CheapSeek
uses: cppalliance/cheapseek@54d18ebefc024fb2bfe86a3556792303829bcd56 # v1.1.0

- name: Live tests
run: node tools/live-tests.mjs

- name: Remove Gateway sidecar
if: always()
run: node tools/stage-gateway-sidecar.mjs remove --target x86_64-unknown-linux-gnu

- name: Clean tree
shell: bash
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "the build dirtied the repository:"
git status --porcelain
exit 1
fi

# Single required status check for branch protection: it fails when any
# job fails or is cancelled, so a cancelled job cannot read as green.
# needs: is a static list, so every newly added job must be added to it
# or that job bypasses this gate.
ci-green:
runs-on: ubuntu-latest
needs: [fmt, clippy, test, docs, check-workshop, check-workshop-linux, ui, supply-chain, dylint]
needs: [fmt, clippy, test, docs, check-workshop, check-workshop-linux, ui, supply-chain, dylint, live]
if: always()
steps:
- name: Verify every job succeeded
Expand Down
83 changes: 74 additions & 9 deletions crates/workshop/server/src/agents/tests-gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
//! `reachable_gateway` reads the endpoint and the key of the gateway the
//! registry holds now, so a replaced gateway is the one read next, and it
//! reads none when no gateway is registered, when the heartbeat reports
//! the gateway down, and when the gateway's key cannot build.
//! the gateway down, and when the gateway's key cannot build. A prompt's
//! web search, through the web library Plugin, is lent the gateway that is
//! registered when the search starts: a Host built under one gateway
//! searches the gateway that replaced it.

use axum::Router;
use axum::http::{HeaderMap, StatusCode, header};
use axum::response::IntoResponse;
use axum::routing::get;
use axum::routing::{get, post};
use harness_gateway_client::{GatewayBroker, GatewayEndpoint, SecretString};
use runvil::harness::InferenceBroker;
use serde_json::json;
use serde_json::{Value, json};
use workshop_gateway::{GatewayBinding, GatewayHandles, GatewayHealth};
use workshop_registry::{Registration, Registry};

use crate::agents::reachable_gateway;
use super::{WEB_LIBRARY, assert_no_failures, plugin_dir_of, run_prompt, serving};
use crate::agents::{reachable_gateway, server_host};
use crate::app::test_helpers::spawn_gateway;

/// The base URL of a gateway that a test registers and never calls.
Expand All @@ -37,17 +41,21 @@ fn registry_with_gateway(
(registry, binding, health, guard)
}

/// Whether a request with `headers` carries `key` as its bearer.
fn carries(headers: &HeaderMap, key: &str) -> bool {
headers
.get(header::AUTHORIZATION)
.and_then(|value| value.to_str().ok())
.is_some_and(|bearer| bearer == format!("Bearer {key}"))
}

/// A mock Gateway keyed with `key` that lists one model named `model`; a
/// request under another key is refused.
fn keyed_gateway(model: &'static str, key: &'static str) -> Router {
Router::new().route(
"/v1/models",
get(move |headers: HeaderMap| async move {
let keyed = headers
.get(header::AUTHORIZATION)
.and_then(|value| value.to_str().ok())
.is_some_and(|bearer| bearer == format!("Bearer {key}"));
if !keyed {
if !carries(&headers, key) {
return StatusCode::UNAUTHORIZED.into_response();
}
axum::Json(json!({ "data": [{
Expand Down Expand Up @@ -133,3 +141,60 @@ fn a_gateway_whose_key_cannot_build_is_not_read() {
"an empty key builds no bearer"
);
}

/// A mock Gateway keyed with `key` whose web search answers the query it
/// is asked with one result titled `title`; a search under another key
/// is refused.
fn searching_gateway(key: &'static str, title: &'static str) -> Router {
Router::new().route(
"/v1/tools/web_search",
post(
move |headers: HeaderMap, axum::Json(asked): axum::Json<Value>| async move {
if !carries(&headers, key) {
return StatusCode::UNAUTHORIZED.into_response();
}
axum::Json(json!({ "query": asked["query"], "results": [{
"title": title, "url": "https://example.com/docs", "description": "The manual.",
}] }))
.into_response()
},
),
)
}

/// A prompt that declares `web` and returns what `web/search` answers
/// for the query `docs`.
const SEARCHES: &str = "---\nname: searches\ndescription: searches the web\nrunvil: 0\n\
uses:\n - web\n---\n\n## Only\n\n```lua\n\
return tools.call('web/search', { query = 'docs' })\n```\n";

#[tokio::test]
async fn a_prompts_web_search_asks_the_gateway_registered_when_the_search_starts() {
let first = spawn_gateway(searching_gateway("first-key", "First")).await;
let second = spawn_gateway(searching_gateway("second-key", "Second")).await;
let (registry, binding, _health, _guard) = registry_with_gateway(&first, "first-key");
let (dir, _library) = plugin_dir_of("searches-the-web", WEB_LIBRARY);
let host = server_host(serving(SEARCHES), &registry, None, Some(dir.path()));
assert_no_failures(&host);
// The Host is built under the first gateway, and the second replaces
// it before any search starts.
binding
.replace(&second, "second-key")
.expect("the replacement publishes");

let result = run_prompt(host).await;
let Ok(Ok(answer)) = result else {
panic!("the run ends with the search's answer: {result:?}");
};
// The web Pack hands the gateway's results on as compact JSON.
let results = r#"{"query":"docs","results":[{"title":"Second","url":"https://example.com/docs","description":"The manual."}]}"#;
assert!(
answer.contains(results),
"the search asks the gateway that replaced the first, under its key, \
and its results reach the script: {answer}"
);
assert!(
answer.contains("<untrusted_input_"),
"search results reach the script marked as untrusted: {answer}"
);
}
28 changes: 28 additions & 0 deletions crates/workshop/server/src/agents/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,34 @@ async fn an_agent_executes_an_agent_of_the_folder_that_its_prompts_list_names()
);
}

#[tokio::test]
async fn the_servers_of_the_configured_mcp_file_reach_the_mcp_pack() {
// Nothing listens on port 1, so neither server ever becomes ready.
// The Pack's listing still names each server it was handed, and the
// names are all this test reads.
let (_dir, path) = mcp_file(
r#"{ "mcpServers": {
"docs": { "url": "http://127.0.0.1:1/mcp" },
"search": { "url": "http://127.0.0.1:1/mcp" }
} }"#,
);
let lists = "---\nname: lists\ndescription: lists its MCP servers\nrunvil: 0\n\
uses:\n - mcp\n---\n\n\
## Only\n\n```lua\n\
local listing = json.decode(tools.call('mcp/get_dynamic_tools', {}))\n\
local names = {}\n\
for _, server in ipairs(listing.namespaces) do\n\
names[#names + 1] = server.namespace\n\
end\n\
return table.concat(names, ',')\n```\n";
let host = server_host(serving(lists), &Registry::new(), Some(&path), None);
assert_eq!(
run_prompt(host).await,
Ok(Ok("docs,search".to_owned())),
"the mcp Pack lists the two servers the file names, in name order"
);
}

#[tokio::test]
async fn a_prompt_declaring_mcp_prepares_on_a_host_built_on_a_runtime() {
// The Host is built on this test's runtime, as the server builds its
Expand Down
Loading
Loading