-
Notifications
You must be signed in to change notification settings - Fork 8
Add non-ui framework template #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gohlub
wants to merge
13
commits into
master
Choose a base branch
from
feat/app-framework-template
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
34873b8
compiles, tests not working rn
Gohlub e222f28
alphabeticized the 'request_capabilities'
Gohlub eb8bb2b
mimick behavior with regular echo template
Gohlub 50a8f10
removed unecessary comments
Gohlub af25db3
made type conventions better
Gohlub a487bee
streamlined imports (got rid of unused, fixed imports for serde in a …
Gohlub 9017221
Changed names
Gohlub 829d953
Updated template naming convetions
Gohlub bc18f24
Got tests to Work! along with some other small bug fixes
Gohlub 489b772
Format Rust code using rustfmt
github-actions[bot] 321f252
new: tweak hyperapp-echo
nick1udwig 5119355
Merge branch 'develop' into feat/app-framework-template
nick1udwig b58cb5a
Merge pull request #337 from hyperware-ai/hf/hyperapp-echo-edits
Gohlub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| api | ||
| !test/hyperapp-echo-test/api | ||
| *swp | ||
| **/target | ||
| pkg/*.wasm | ||
| pkg/*.zip | ||
| pkg/ui | ||
| crates/ | ||
| caller-utils/ | ||
| **/.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [profile.release] | ||
| lto = true | ||
| opt-level = "s" | ||
| panic = "abort" | ||
|
|
||
| [workspace] | ||
| members = [ | ||
| "hyperapp-echo", | ||
| "test/hyperapp-echo-test/hyperapp-echo-test", | ||
| ] | ||
| resolver = "2" |
31 changes: 31 additions & 0 deletions
31
src/new/templates/rust/no-ui/hyperapp-echo/hyperapp-echo/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| [dependencies] | ||
| process_macros = "0.1" | ||
| serde_json = "1.0" | ||
| wit-bindgen = "0.36.0" | ||
|
|
||
|
|
||
| [dependencies.hyperprocess_macro] | ||
| git = "https://github.com/hyperware-ai/hyperprocess-macro" | ||
| rev = "47400ab" | ||
|
|
||
| [dependencies.hyperware_app_common] | ||
| git = "https://github.com/hyperware-ai/hyperprocess-macro" | ||
| rev = "47400ab" | ||
|
|
||
| [dependencies.serde] | ||
| features = ["derive"] | ||
| version = "1.0" | ||
|
|
||
| [features] | ||
| simulation-mode = [] | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] | ||
|
|
||
| [package] | ||
| edition = "2021" | ||
| name = "hyperapp-echo" | ||
| version = "0.1.0" | ||
|
|
||
| [package.metadata.component] | ||
| package = "hyperware:process" |
53 changes: 53 additions & 0 deletions
53
src/new/templates/rust/no-ui/hyperapp-echo/hyperapp-echo/src/lib.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| use serde::{Serialize, Deserialize}; | ||
| use hyperprocess_macro::hyperprocess; | ||
| use hyperware_process_lib::println; | ||
|
|
||
| #[derive(Default, Debug, Serialize, Deserialize)] | ||
| pub struct HyperappEchoState {} | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug)] | ||
| pub struct Argument { | ||
| header: String, | ||
| body: String, | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug)] | ||
| pub struct ReturnValue { | ||
| response: String, | ||
| } | ||
|
|
||
| #[hyperprocess( | ||
| name = "HyperappEcho", | ||
| ui = None, | ||
| endpoints = vec![ | ||
| Binding::Http { | ||
| path: "/api", | ||
| config: HttpBindingConfig::new(false, false, false, None), | ||
| }, | ||
| Binding::Ws { | ||
| path: "/ws", | ||
| config: WsBindingConfig::new(false, false, false), | ||
| } | ||
| ], | ||
| save_config = SaveOptions::Never, | ||
| wit_world = "hyperapp-echo-template-dot-os-v0" | ||
| )] | ||
|
|
||
| impl HyperappEchoState { | ||
| // Initialize the process, every application needs an init function | ||
| #[init] | ||
| async fn initialize(&mut self) { | ||
| println!("init HyperappEcho"); | ||
| } | ||
|
|
||
| // Endpoint accepting both local, remote Hyperware requests, and HTTP requests | ||
| #[local] | ||
| #[remote] | ||
| #[http] | ||
| async fn echo(&self, arg: Argument) -> ReturnValue { | ||
| println!("header: {:?}, body: {:?}", arg.header, arg.body); | ||
|
|
||
| ReturnValue { response: "Ack".to_string() } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "name": "Hyperapp Echo", | ||
| "description": "Echo process for Hyperapp framework.", | ||
| "image": "", | ||
| "properties": { | ||
| "package_name": "hyperapp-echo", | ||
| "current_version": "0.1.0", | ||
| "publisher": "template.os", | ||
| "mirrors": [], | ||
| "code_hashes": { | ||
| "0.1.0": "" | ||
| }, | ||
| "wit_version": 1, | ||
| "dependencies": [ | ||
| "hyperapp-echo:template.os" | ||
| ] | ||
| }, | ||
| "external_url": "https://hyperware.ai", | ||
| "animation_url": "" | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/new/templates/rust/no-ui/hyperapp-echo/pkg/manifest.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| [ | ||
| { | ||
| "process_name": "hyperapp-echo", | ||
| "process_wasm_path": "/hyperapp-echo.wasm", | ||
| "on_exit": "Restart", | ||
| "request_networking": true, | ||
| "request_capabilities": [ | ||
| "homepage:homepage:sys", | ||
| "http-client:distro:sys", | ||
| "http-server:distro:sys", | ||
| "terminal:terminal:sys", | ||
| "vfs:distro:sys" | ||
| ], | ||
| "grant_capabilities": [ | ||
| "homepage:homepage:sys", | ||
| "http-client:distro:sys", | ||
| "http-server:distro:sys", | ||
| "terminal:terminal:sys", | ||
| "vfs:distro:sys" | ||
| ], | ||
| "public": false | ||
| } | ||
| ] |
10 changes: 10 additions & 0 deletions
10
src/new/templates/rust/no-ui/hyperapp-echo/test/hyperapp-echo-test/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [workspace] | ||
| resolver = "2" | ||
| members = [ | ||
| "hyperapp-echo-test", | ||
| ] | ||
|
|
||
| [profile.release] | ||
| panic = "abort" | ||
| opt-level = "s" | ||
| lto = true |
5 changes: 5 additions & 0 deletions
5
...no-ui/hyperapp-echo/test/hyperapp-echo-test/api/hyperapp-echo-test-template-dot-os-v0.wit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| world hyperapp-echo-test-template-dot-os-v0 { | ||
| import hyperapp-echo; | ||
| import tester; | ||
| include process-v1; | ||
| } |
27 changes: 27 additions & 0 deletions
27
.../templates/rust/no-ui/hyperapp-echo/test/hyperapp-echo-test/hyperapp-echo-test/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [package] | ||
| name = "hyperapp-echo-test" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [dependencies.caller-utils] | ||
| path = "../../../target/caller-utils" | ||
|
|
||
| [dependencies.hyperware_app_common] | ||
| git = "https://github.com/hyperware-ai/hyperprocess-macro" | ||
| rev = "b6ad495" | ||
|
|
||
| [dependencies] | ||
| anyhow = "1.0" | ||
| hyperware_process_lib = { git = "https://github.com/hyperware-ai/process_lib", features = ["logging"], rev = "b7c9d27" } | ||
| process_macros = "0.1.0" | ||
| serde = { version = "1.0", features = ["derive"] } | ||
| serde_json = "1.0" | ||
| wit-bindgen = "0.36.0" | ||
|
|
||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] | ||
|
|
||
| [package.metadata.component] | ||
| package = "hyperware:process" |
88 changes: 88 additions & 0 deletions
88
.../templates/rust/no-ui/hyperapp-echo/test/hyperapp-echo-test/hyperapp-echo-test/src/lib.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| // Import necessary types and functions explicitly from caller_utils | ||
| use caller_utils::{Argument, ReturnValue}; // Import types directly (via path dependency) | ||
| use caller_utils::hyperapp_echo::{echo_local_rpc, echo_remote_rpc}; // Import RPC functions | ||
|
|
||
| // Add this import here, as fail! is expanded in this file | ||
| use crate::hyperware::process::tester::{FailResponse, Response as TesterResponse}; | ||
|
|
||
| mod tester_lib; | ||
|
|
||
| async_test_suite!( | ||
| "hyperapp-echo-test-template-dot-os-v0", | ||
|
|
||
| test_basic_math: async { | ||
| if 2 + 2 != 4 { | ||
| fail!("wrong result"); | ||
| } | ||
| Ok(()) | ||
| }, | ||
|
|
||
| // Test local echo RPC call | ||
| test_echo_local_rpc: async { | ||
| // Define the target process address | ||
| let address: Address = ("hyperapp-echo.os", "hyperapp-echo", "hyperapp-echo", "template.os").into(); | ||
| // Define the argument for the echo function | ||
| let arg = Argument { | ||
| header: "LocalTestHeader".to_string(), | ||
| body: "LocalTestBody".to_string(), | ||
| }; | ||
| // Define the expected return value | ||
| let expected_return = ReturnValue { | ||
| response: "Ack".to_string(), | ||
| }; | ||
|
|
||
| match echo_local_rpc(&address, arg).await { | ||
| Ok(actual_value) => { | ||
| // Compare the 'response' field directly | ||
| if actual_value.response != expected_return.response { | ||
| // fail! macro uses FailResponse/TesterResponse imported above | ||
| fail!(format!( | ||
| "echo_local_rpc unexpected result: expected {:?}, got {:?}", | ||
| expected_return, actual_value // Keep original structs for error message | ||
| )); | ||
| } | ||
| // If the result matches, the test passes for this step | ||
| Ok(()) | ||
| } | ||
| Err(e) => { | ||
| // Use fail! macro if the RPC call itself returned an error | ||
| fail!(format!("echo_local_rpc failed: {:?}", e)); | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| // Test remote echo RPC call | ||
| test_echo_remote_rpc: async { | ||
| // Define the target process address | ||
| let address: Address = ("hyperapp-echo.os", "hyperapp-echo", "hyperapp-echo", "template.os").into(); | ||
| // Define the argument for the echo function | ||
| let arg = Argument { | ||
| header: "RemoteTestHeader".to_string(), | ||
| body: "RemoteTestBody".to_string(), | ||
| }; | ||
| // Define the expected return value | ||
| let expected_return = ReturnValue { | ||
| response: "Ack".to_string(), | ||
| }; | ||
|
|
||
| // Call the remote echo RPC stub | ||
| match echo_remote_rpc(&address, arg).await { | ||
| Ok(actual_value) => { | ||
| // Compare the 'response' field directly | ||
| if actual_value.response != expected_return.response { | ||
| // fail! macro uses FailResponse/TesterResponse imported above | ||
| fail!(format!( | ||
| "echo_remote_rpc unexpected result: expected {:?}, got {:?}", | ||
| expected_return, actual_value // Keep original structs for error message | ||
| )); | ||
| } | ||
| // If the result matches, the test passes for this step | ||
| Ok(()) | ||
| } | ||
| Err(e) => { | ||
| // Use fail! macro if the RPC call itself returned an error | ||
| fail!(format!("echo_remote_rpc failed: {:?}", e)); | ||
| } | ||
| } | ||
| }, | ||
| ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to put serde_json::Value as the type for the body field (to represent a generic JSON object, but I checked the WIT conversion and we don't handle this type of WIT type (I am not entirely sure whether its technically possible, but putting an arbitrary JSON object as an argument does seem useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that definitely won't work. We always serialize to either a bytes string (with
serde_json::to_vec()) or a string (serde_json::to_string()), so those are your two options. When we serialize the whole struct using JSON, we should choose to serializebodyto aStringbecause that will play nicer with JSON than an array of bytes