mirror of
https://github.com/andrewyng/openworker.git
synced 2026-11-20 20:37:44 +00:00
Allow developers to easily build AI apps without worrying about the harness part. Bundles the Rust agent runtime as a SDK (Rust and TypeScript) for building desktop and web applications. Applications can manage a local harness or connect to an authenticated harness service on k8s with separately scaled workers and sandbox execution. The implementation is primarily contained in harness/, with deployment tooling in deploy/, Markdown guides in docs/harness/guides/, and the static documentation site in docs-site/. It does not replace the existing Python harness or migrate OpenWorker Desktop. Co-authored-by: Devika Verma <devikaverma11@gmail.com>
63 lines
2.7 KiB
Rust
63 lines
2.7 KiB
Rust
use openworker_runtime::{bundle::Bundle, http_mcp, servers};
|
|
use openworker_tools::ToolRegistry;
|
|
use serde_json::json;
|
|
use std::{fs, path::Path};
|
|
fn fixture(root: &Path) {
|
|
fs::create_dir_all(root.join("bundle/coworker")).unwrap();
|
|
fs::write(
|
|
root.join("bundle/coworker/manifest.md"),
|
|
"---\nid: test\nname: Test\n---\nUse selected tools.",
|
|
)
|
|
.unwrap();
|
|
fs::write(
|
|
root.join("bundle/tools.json"),
|
|
json!({"version":3,"tools":["acer.status"]}).to_string(),
|
|
)
|
|
.unwrap();
|
|
}
|
|
#[test]
|
|
fn local_endpoints_are_explicit_not_arbitrary_network_access() {
|
|
for url in ["http://127.0.0.1:1234/mcp", "http://[::1]:1234/mcp"] {
|
|
http_mcp::validate_url(url).unwrap();
|
|
}
|
|
for url in [
|
|
"https://example.com/mcp",
|
|
"http://localhost:123/mcp",
|
|
"http://127.0.0.1:123/mcp?token=secret",
|
|
"http://user:secret@127.0.0.1/mcp",
|
|
"http://127.0.0.1/mcp#x",
|
|
"http://0.0.0.0/mcp",
|
|
"http://127.0.0.1:0/mcp",
|
|
] {
|
|
assert!(http_mcp::validate_url(url).is_err(), "{url}");
|
|
}
|
|
}
|
|
#[test]
|
|
fn app_configuration_resolves_only_selected_names_and_rejects_ambiguity() {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
let root = tmp.path().canonicalize().unwrap();
|
|
fixture(&root);
|
|
let path = root.join("servers.json");
|
|
let good = json!({"version":1,"servers":[{"namespace":"acer","transport":"streamable_http","url":"http://127.0.0.1:9876/mcp"}]});
|
|
fs::write(&path, good.to_string()).unwrap();
|
|
let mut registry = ToolRegistry::default();
|
|
servers::load(&path, &root.join("bundle"), &mut registry).unwrap();
|
|
let b = Bundle::load_with_registry(&root.join("bundle"), ®istry).unwrap();
|
|
assert_eq!(b.tools.bindings["acer__status"].tool, "status");
|
|
assert_eq!(b.tools.servers["acer"].program, "$HTTP");
|
|
assert_eq!(registry.config_sources(), std::slice::from_ref(&path));
|
|
assert!(servers::load(&path, &root.join("bundle"), &mut registry).is_err());
|
|
for bad in [
|
|
json!({"version":1,"servers":[good["servers"][0].clone(),good["servers"][0].clone()]}),
|
|
json!({"version":1,"servers":[{"namespace":"acer","transport":"streamable_http","url":"http://example.com/mcp"}]}),
|
|
json!({"version":1,"servers":[{"namespace":"acer","transport":"streamable_http","url":"http://127.0.0.1/mcp","authorization":"secret"}]}),
|
|
json!({"version":1,"servers":[],"extra":true}),
|
|
] {
|
|
fs::write(&path, bad.to_string()).unwrap();
|
|
assert!(servers::load(&path, &root.join("bundle"), &mut ToolRegistry::default()).is_err());
|
|
}
|
|
let bundled = root.join("bundle/servers.json");
|
|
fs::write(&bundled, good.to_string()).unwrap();
|
|
assert!(servers::load(&bundled, &root.join("bundle"), &mut ToolRegistry::default()).is_err());
|
|
}
|