This CLI tool allows testing of Moosync WASM extensions by:
- Loading and initializing extensions
- Sending commands to extensions
- Handling UI requests from extensions
cargo install --git https://github.com/Moosync/moodriver
Usage: moodriver [OPTIONS] <WASM>
Arguments:
<WASM> Path to the wasm directory
Options:
-t, --trace <TRACE> Path to the trace file
-d, --dir <DIR> Path to the trace directory
-v, --verbose...
-h, --help Print help
-V, --version Print version
moodriver -t ./traces/sample_trace.json ./ext.wasm
moodriver -v -t ./traces/sample_trace.json ./ext.wasm
moodriver -vv -t ./traces/sample_trace.js ./ext.wasm
There are 2 components to a trace file:
- Commands
- Requests
Commands are used to simulate user actions as they would happen in Moosync.
For example, you can send a command "seeked" to the extension to simulate an action of seeking a song. The below example of a command means that the song was seeked to position 0. The expected property defines what is an appropriate response that should be received by the extension. In this case, the extension should respond with a null since "seeked" events expects no return value.
{
"type": "seeked",
"data": [0],
"expected": null
}
Lets consider another example of the command "getProviderScopes". We want our extension to respond with the scopes "scrobbles" and "accounts". Some commands like this require passing a package name to the command. The below trace expects the extension to respond with the scopes "scrobbles" and "accounts" for the command.
{
"type": "getProviderScopes",
"data": {
"packageName": "moosync.lastfm"
},
"expected": ["scrobbles", "accounts"]
}
More commands can be be found at moosync_edk::ExtensionExtraEvent and moosync_edk::ExtensionCommand
The requests property can be used to simulate responses to requests sent by the extension. For eg, if the extension makes a call to "getSecure", we can reply back with a mock response. The below trace replies back to a getSecure request with a key of "session"
{
"type": "getSecure",
"data": {
"key": "session",
"value": "test"
}
}
More requests can be found at moosync_edk::MainCommandResponse
{
"$schema": "https://raw.githubusercontent.com/Moosync/moodriver/refs/heads/main/schema.json",
"commands": [
{
"type": "seeked",
"data": [0],
"expected": null
},
{
"type": "getProviderScopes",
"data": {
"packageName": "moosync.lastfm"
},
"expected": ["scrobbles", "accounts"]
}
],
"requests": [
{
"type": "getSecure",
"data": {
"key": "not_session",
"value": "not_test"
}
},
{
"type": "getSecure",
"data": {
"key": "session",
"value": "test"
}
}
]
}