mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-09 03:51:42 +00:00
83 lines
3.5 KiB
Rust
83 lines
3.5 KiB
Rust
//! `doc.list` tells the user's own scripts where the open files are, but AI agents and plugins
|
|
//! get their names only (#1117).
|
|
|
|
use serde_json::json;
|
|
|
|
use crate::Session;
|
|
use crate::components::tests::ex;
|
|
use crate::plugins_tests::{OnRefusal, install, manifest, script};
|
|
|
|
const SECRET: &str = "/home/someone/private/clients/acme.figcraft";
|
|
|
|
fn two_files() -> Session {
|
|
let mut s = Session::new();
|
|
s.docs[0].path = Some(SECRET.into());
|
|
ex(&mut s, "file.new", json!({"name": "Front"}));
|
|
s
|
|
}
|
|
|
|
#[test]
|
|
fn the_users_own_calls_get_the_paths() {
|
|
let mut s = two_files();
|
|
let list = ex(&mut s, "doc.list", json!({}));
|
|
assert_eq!(list[0]["path"], json!(SECRET));
|
|
assert_eq!(list[1]["path"], json!(null), "a new file has none yet");
|
|
}
|
|
|
|
#[test]
|
|
fn an_agent_gets_names_and_ids_but_no_paths() {
|
|
let mut s = two_files();
|
|
let list = s.execute_as(Some("Claude"), "doc.list", &json!({})).unwrap();
|
|
assert_eq!(list.as_array().unwrap().len(), 2);
|
|
assert!(list[0]["id"].is_u64() && list[0]["name"].is_string());
|
|
assert!(list.as_array().unwrap().iter().all(|e| e.get("path").is_none()), "{list}");
|
|
// An agent with no name of its own is an agent too.
|
|
let list = s.execute_as(Some(""), "doc.list", &json!({})).unwrap();
|
|
assert!(!list.to_string().contains(SECRET));
|
|
}
|
|
|
|
#[test]
|
|
fn a_plugin_gets_names_but_no_paths() {
|
|
let mut s = two_files();
|
|
// The reply to its last call becomes its output.
|
|
let tail = "(call $set_output (i32.const 40000) (call $reply_read (i32.const 40000) (i32.const 20000))) (return (i32.const 0))";
|
|
install(&mut s, manifest("org.test.list", "read", &[]), &script(&[("doc.list", json!({}))], OnRefusal::Fail, tail));
|
|
let out = ex(&mut s, "plugin.run", json!({"id": "org.test.list"}))["output"].to_string();
|
|
assert!(out.contains("Front"), "{out}");
|
|
assert!(!out.contains(SECRET) && !out.contains("path"), "{out}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_plugin_gets_library_names_but_not_their_links() {
|
|
const LINK: &str = "ws://tracker.example:9/?file=f&token=per-file-secret";
|
|
let mut s = Session::new();
|
|
s.doc_mut().unwrap().libraries_mut().enabled.push(figcraft_doc::LibraryLink {
|
|
id: "lib".into(),
|
|
name: "Kit".into(),
|
|
path: LINK.into(),
|
|
version: 3,
|
|
});
|
|
let tail = "(call $set_output (i32.const 40000) (call $reply_read (i32.const 40000) (i32.const 20000))) (return (i32.const 0))";
|
|
install(&mut s, manifest("org.test.libs", "read", &[]), &script(&[("library.list", json!({}))], OnRefusal::Fail, tail));
|
|
let out = ex(&mut s, "plugin.run", json!({"id": "org.test.libs"}))["output"].to_string();
|
|
assert!(out.contains("Kit"), "{out}");
|
|
assert!(!out.contains("per-file-secret") && !out.contains("\\\"path\\\""), "{out}");
|
|
}
|
|
|
|
#[test]
|
|
fn a_plugin_gets_a_fixed_message_for_library_update_failures() {
|
|
const LINK: &str = "/home/someone/private/kits/kit.figcraft";
|
|
let mut s = Session::new();
|
|
s.doc_mut().unwrap().libraries_mut().enabled.push(figcraft_doc::LibraryLink {
|
|
id: "lib".into(),
|
|
name: "Kit".into(),
|
|
path: LINK.into(),
|
|
version: 3,
|
|
});
|
|
let tail = "(call $set_output (i32.const 40000) (call $reply_read (i32.const 40000) (i32.const 20000))) (return (i32.const 0))";
|
|
install(&mut s, manifest("org.test.upd", "read", &[]), &script(&[("library.updates", json!({}))], OnRefusal::Fail, tail));
|
|
let out = ex(&mut s, "plugin.run", json!({"id": "org.test.upd"}))["output"].to_string();
|
|
assert!(out.contains("could not be read"), "{out}");
|
|
assert!(!out.contains("someone") && !out.contains("private"), "{out}");
|
|
}
|