diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000000..c6082ac256 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,31 @@ +name: Automated Tests + +on: + push: + branches: + - master + - next/* + pull_request: + branches: + - master + - next/* + +env: + NODEJS_VERSION: "18.15.0" + ENVIRONMENT: dev-unstable + +jobs: + test: + name: Run Automated Tests + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODEJS_VERSION }} + + - name: Build And Run Tests + run: make test diff --git a/Makefile b/Makefile index 625a4cec28..b7f0f4bd74 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ EMBASSY_SRC := backend/startd.service $(BUILD_SRC) COMPAT_SRC := $(shell git ls-files system-images/compat/) UTILS_SRC := $(shell git ls-files system-images/utils/) BINFMT_SRC := $(shell git ls-files system-images/binfmt/) -BACKEND_SRC := $(shell git ls-files backend) $(shell git ls-files --recurse-submodules patch-db) $(shell git ls-files libs) frontend/dist/static +BACKEND_SRC := $(shell git ls-files backend) $(shell git ls-files --recurse-submodules patch-db) $(shell git ls-files libs) frontend/dist/static frontend/patchdb-ui-seed.json $(GIT_HASH_FILE) FRONTEND_SHARED_SRC := $(shell git ls-files frontend/projects/shared) $(shell ls -p frontend/ | grep -v / | sed 's/^/frontend\//g') frontend/node_modules frontend/config.json patch-db/client/dist frontend/patchdb-ui-seed.json FRONTEND_UI_SRC := $(shell git ls-files frontend/projects/ui) FRONTEND_SETUP_WIZARD_SRC := $(shell git ls-files frontend/projects/setup-wizard) @@ -48,7 +48,7 @@ endif .DELETE_ON_ERROR: -.PHONY: all metadata install clean format sdk snapshots frontends ui backend reflash deb $(IMAGE_TYPE) squashfs sudo wormhole docker-buildx +.PHONY: all metadata install clean format sdk snapshots frontends ui backend reflash deb $(IMAGE_TYPE) squashfs sudo wormhole test all: $(ALL_TARGETS) @@ -82,6 +82,10 @@ format: cd backend && cargo +nightly fmt cd libs && cargo +nightly fmt +test: $(BACKEND_SRC) $(ENVIRONMENT_FILE) + cd backend && cargo build && cargo test + cd libs && cargo test + sdk: cd backend/ && ./install-sdk.sh @@ -164,20 +168,20 @@ upload-ota: results/$(BASENAME).squashfs build/lib/depends build/lib/conflicts: build/dpkg-deps/* build/dpkg-deps/generate.sh -system-images/compat/docker-images/$(ARCH).tar: $(COMPAT_SRC) backend/Cargo.lock | docker-buildx +system-images/compat/docker-images/$(ARCH).tar: $(COMPAT_SRC) backend/Cargo.lock cd system-images/compat && make docker-images/$(ARCH).tar && touch docker-images/$(ARCH).tar -system-images/utils/docker-images/$(ARCH).tar: $(UTILS_SRC) | docker-buildx +system-images/utils/docker-images/$(ARCH).tar: $(UTILS_SRC) cd system-images/utils && make docker-images/$(ARCH).tar && touch docker-images/$(ARCH).tar -system-images/binfmt/docker-images/$(ARCH).tar: $(BINFMT_SRC) | docker-buildx +system-images/binfmt/docker-images/$(ARCH).tar: $(BINFMT_SRC) cd system-images/binfmt && make docker-images/$(ARCH).tar && touch docker-images/$(ARCH).tar snapshots: libs/snapshot_creator/Cargo.toml cd libs/ && ./build-v8-snapshot.sh cd libs/ && ./build-arm-v8-snapshot.sh -$(EMBASSY_BINS): $(BACKEND_SRC) $(ENVIRONMENT_FILE) $(GIT_HASH_FILE) frontend/patchdb-ui-seed.json +$(EMBASSY_BINS): $(BACKEND_SRC) $(ENVIRONMENT_FILE) cd backend && ARCH=$(ARCH) ./build-prod.sh touch $(EMBASSY_BINS) diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 444ad3cf30..d355d5d260 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -169,6 +169,9 @@ zeroize = "1.6.0" [profile.test] opt-level = 3 +[profile.dev] +opt-level = 3 + [profile.dev.package.backtrace] opt-level = 3 diff --git a/backend/src/bins/start_deno.rs b/backend/src/bins/start_deno.rs index 0be507082e..8f5a1451a0 100644 --- a/backend/src/bins/start_deno.rs +++ b/backend/src/bins/start_deno.rs @@ -4,7 +4,7 @@ use serde_json::Value; use crate::procedure::js_scripts::ExecuteArgs; use crate::s9pk::manifest::PackageId; -use crate::util::serde::{display_serializable, parse_stdin_deserializable}; +use crate::util::serde::{display_serializable, parse_stdin_deserializable, IoFormat}; use crate::version::{Current, VersionT}; use crate::Error; @@ -23,6 +23,9 @@ fn deno_api() -> Result<(), Error> { #[command(cli_only, display(display_serializable))] async fn execute( #[arg(stdin, parse(parse_stdin_deserializable))] arg: ExecuteArgs, + #[allow(unused_variables)] + #[arg(long = "format")] + format: Option, ) -> Result, Error> { let ExecuteArgs { procedure, @@ -41,6 +44,9 @@ async fn execute( #[command(cli_only, display(display_serializable))] async fn sandbox( #[arg(stdin, parse(parse_stdin_deserializable))] arg: ExecuteArgs, + #[allow(unused_variables)] + #[arg(long = "format")] + format: Option, ) -> Result, Error> { let ExecuteArgs { procedure, diff --git a/backend/src/bins/start_init.rs b/backend/src/bins/start_init.rs index 0440e0ad69..f189c37238 100644 --- a/backend/src/bins/start_init.rs +++ b/backend/src/bins/start_init.rs @@ -32,19 +32,19 @@ async fn setup_or_init(cfg_path: Option) -> Result, Er .arg("-sf") .arg("/usr/lib/startos/scripts/fake-apt") .arg("/usr/local/bin/apt") - .invoke(crate::ErrorKind::OpenSsh) + .invoke(crate::ErrorKind::Filesystem) .await?; Command::new("ln") .arg("-sf") .arg("/usr/lib/startos/scripts/fake-apt") .arg("/usr/local/bin/apt-get") - .invoke(crate::ErrorKind::OpenSsh) + .invoke(crate::ErrorKind::Filesystem) .await?; Command::new("ln") .arg("-sf") .arg("/usr/lib/startos/scripts/fake-apt") .arg("/usr/local/bin/aptitude") - .invoke(crate::ErrorKind::OpenSsh) + .invoke(crate::ErrorKind::Filesystem) .await?; Command::new("make-ssl-cert") diff --git a/backend/src/net/tor.rs b/backend/src/net/tor.rs index 9926d3c6ce..a00ab9c543 100644 --- a/backend/src/net/tor.rs +++ b/backend/src/net/tor.rs @@ -684,6 +684,7 @@ impl TorControl { } #[tokio::test] +#[ignore] async fn test() { let mut conn = torut::control::UnauthenticatedConn::new( TcpStream::connect(SocketAddr::from(([127, 0, 0, 1], 9051))) diff --git a/backend/src/procedure/js_scripts.rs b/backend/src/procedure/js_scripts.rs index 27756b4a3f..8ad900651a 100644 --- a/backend/src/procedure/js_scripts.rs +++ b/backend/src/procedure/js_scripts.rs @@ -81,8 +81,12 @@ impl JsProcedure { _gid: ProcessGroupId, _rpc_client: Option>, ) -> Result, Error> { - Command::new("start-deno") - .arg("execute") + #[cfg(not(test))] + let mut cmd = Command::new("start-deno"); + #[cfg(test)] + let mut cmd = test_start_deno_command().await?; + + cmd.arg("execute") .input(Some(&mut std::io::Cursor::new(IoFormat::Json.to_vec( &ExecuteArgs { procedure: self.clone(), @@ -111,8 +115,12 @@ impl JsProcedure { timeout: Option, name: ProcedureName, ) -> Result, Error> { - Command::new("start-deno") - .arg("sandbox") + #[cfg(not(test))] + let mut cmd = Command::new("start-deno"); + #[cfg(test)] + let mut cmd = test_start_deno_command().await?; + + cmd.arg("sandbox") .input(Some(&mut std::io::Cursor::new(IoFormat::Json.to_vec( &ExecuteArgs { procedure: self.clone(), @@ -212,6 +220,26 @@ fn unwrap_known_error( } } +#[cfg(test)] +async fn test_start_deno_command() -> Result { + Command::new("cargo") + .arg("build") + .invoke(ErrorKind::Unknown) + .await?; + if tokio::fs::metadata("target/debug/start-deno") + .await + .is_err() + { + Command::new("ln") + .arg("-rsf") + .arg("target/debug/startbox") + .arg("target/debug/start-deno") + .invoke(crate::ErrorKind::Filesystem) + .await?; + } + Ok(Command::new("target/debug/start-deno")) +} + #[tokio::test] async fn js_action_execute() { let js_action = JsProcedure { args: vec![] }; diff --git a/backend/src/procedure/mod.rs b/backend/src/procedure/mod.rs index 62f4de9cf7..3df9b7636a 100644 --- a/backend/src/procedure/mod.rs +++ b/backend/src/procedure/mod.rs @@ -179,5 +179,7 @@ impl<'de> Deserialize<'de> for NoOutput { #[test] fn test_deser_no_output() { serde_json::from_str::("").unwrap(); - serde_json::from_str::>("{\"Ok\": null}").unwrap(); + serde_json::from_str::>("{\"Ok\": null}") + .unwrap() + .unwrap(); } diff --git a/backend/src/system.rs b/backend/src/system.rs index 989cdc4aa8..53216f796f 100644 --- a/backend/src/system.rs +++ b/backend/src/system.rs @@ -841,6 +841,7 @@ async fn get_disk_info() -> Result { } #[tokio::test] +#[ignore] pub async fn test_get_temp() { println!("{}", get_temp().await.unwrap()) } @@ -856,6 +857,7 @@ pub async fn test_get_mem_info() { } #[tokio::test] +#[ignore] pub async fn test_get_disk_usage() { println!("{:?}", get_disk_info().await.unwrap()) } diff --git a/libs/js_engine/src/lib.rs b/libs/js_engine/src/lib.rs index b09e1fbb05..04082e6ca8 100644 --- a/libs/js_engine/src/lib.rs +++ b/libs/js_engine/src/lib.rs @@ -1201,11 +1201,11 @@ mod fns { #[tokio::test] async fn test_is_subset() { - assert!( - !is_subset("/home/drbonez", "/home/drbonez/code/fakedir/../../..") - .await - .unwrap() - ) + let home = std::env::var("HOME").unwrap(); + let home = Path::new(&home); + assert!(!is_subset(home, &home.join("code/fakedir/../../..")) + .await + .unwrap()) } }