Skip to content

Commit

Permalink
Test with plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 5, 2023
1 parent a7d3cf4 commit 82b8e01
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .prototools
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[plugins]
moon-test = "source:https://raw.githubusercontent.com/moonrepo/moon/master/proto-plugin.toml"
wasm-test = "source:./plugins/target/wasm32-wasi/debug/proto_wasm_test.wasm"

[tools.wasm-test]
number = 123
string = "foo"
boolean = true
list = ["a", "b", "c"]
map = { "a" = 123 }
11 changes: 6 additions & 5 deletions crates/core/src/proto_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,12 @@ pub struct ProtoConfigFile {

#[derive(Debug)]
pub struct ProtoConfigManager {
// Paths are sorted from smallest to largest components,
// so we need to traverse in reverse order. Furthermore,
// the special config at `~/.proto/.prototools` is mapped
// "/" to give it the lowest precedence. We also don't
// expect users to put configs in the actual root...
// Paths are sorted from current working directory,
// up until the root or user directory, whichever is first.
// The special `~/.proto/.prototools` config is always
// loaded last, and is the last entry in the list.
// For directories without a config, we still insert
// an empty entry. This helps with traversal logic.
pub files: Vec<ProtoConfigFile>,

merged_config: Arc<OnceCell<ProtoConfig>>,
Expand Down
4 changes: 2 additions & 2 deletions crates/warpgate/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ pub enum WarpgateError {

#[diagnostic(code(plugin::call_func::failed))]
#[error("Failed to call plugin function {}: {error}", .func.style(Style::Id))]
PluginCallFailed { func: String, error: extism::Error },
PluginCallFailed { func: String, error: String },

#[diagnostic(code(plugin::failed))]
#[diagnostic(code(plugin::call_func::failed))]
#[error("{error}")]
PluginCallFailedRelease { error: String },

Expand Down
2 changes: 1 addition & 1 deletion crates/warpgate/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'plugin> PluginContainer<'plugin> {
{
WarpgateError::PluginCallFailed {
func: func.to_owned(),
error,
error: error.to_string(),
}
}
// When in release mode, errors don't render properly with the
Expand Down
15 changes: 15 additions & 0 deletions plugins/wasm-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ extern "ExtismHost" {
// fn to_virtual_path(path: &str) -> String;
}

#[derive(Debug, Default, Deserialize)]
#[serde(default, deny_unknown_fields, rename_all = "kebab-case")]
struct WasmTestConfig {
number: usize,
string: String,
boolean: bool,
unknown: Option<usize>,
list: Vec<String>,
map: HashMap<String, usize>,
}

#[plugin_fn]
pub fn register_tool(_: ()) -> FnResult<Json<ToolMetadataOutput>> {
host_log!(stdout, "Registering tool");
Expand All @@ -26,6 +37,10 @@ pub fn register_tool(_: ()) -> FnResult<Json<ToolMetadataOutput>> {
// let real = real_path!(PathBuf::from("/proto"));
// let _virtual = virtual_path!(&real);

let config = get_tool_config::<WasmTestConfig>()?;

host_log!("Config = {:?}", config);

Ok(Json(ToolMetadataOutput {
name: "WASM Test".into(),
type_of: PluginType::CLI,
Expand Down

0 comments on commit 82b8e01

Please sign in to comment.