From e855088f280c599aedb6aebb7c0e90d09968c450 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Thu, 17 Apr 2025 12:23:39 +0000 Subject: [PATCH 01/11] Add coverage badge, ignore certain files from coverage, and add coverage config file. --- .codecov.yaml | 36 ++++++++++++++++++++++++++++++++++++ .github/workflows/tests.yaml | 7 ++++++- README.md | 9 +++++---- 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 .codecov.yaml diff --git a/.codecov.yaml b/.codecov.yaml new file mode 100644 index 00000000..41069dcb --- /dev/null +++ b/.codecov.yaml @@ -0,0 +1,36 @@ +# https://docs.codecov.com/docs/codecovyml-reference +# curl -X POST --data-binary @.codecov.yaml https://codecov.io/validate +coverage: + status: + patch: true + # project: + # default: + # target: 85.28% + # threshold: 0% + # project: + # default: # default is the status check's name, not default settings + # target: auto + # threshold: 5 + # base: auto + # # flags: + # # - unit + # paths: + # - "src" + # # advanced settings + # branches: + # - dev + # - main + # - uniffi-client + # - guzman-raphael:uniffi-client + # - guzman-raphael/orcapod:uniffi-client + # if_ci_failed: error #success, failure, error, ignore + # informational: false + # only_pulls: false +comment: false +# comment: #this is a top-level key +# layout: " diff, flags, files" +# behavior: default +# require_changes: false # if true: only post the comment if coverage changes +# require_base: false # [true :: must have a base report to post] +# require_head: true # [true :: must have a head report to post] +# hide_project_coverage: false # [true :: only show coverage on the git diff aka patch coverage]] diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index cc76c211..f7b79365 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -24,7 +24,12 @@ jobs: RUST_BACKTRACE: full run: | mkdir -p tests/.tmp - cargo llvm-cov --codecov --output-path target/llvm-cov-target/codecov.json -- --nocapture + cargo llvm-cov \ + --ignore-filename-regex "bin/.*|lib\.rs" \ + --codecov \ + --output-path target/llvm-cov-target/codecov.json \ + -- \ + --nocapture - name: Upload to codecov.io uses: codecov/codecov-action@v5 with: diff --git a/README.md b/README.md index dbfb983d..9a670f0b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![orcapod API docs](https://img.shields.io/website?url=https://walkerlab.github.io/orcapod/&label=docs) ](https://walkerlab.github.io/orcapod/) +[![codecov](https://codecov.io/github/walkerlab/orcapod/graph/badge.svg)](https://codecov.io/github/walkerlab/orcapod) # orcapod @@ -9,12 +10,12 @@ ```bash #!/bin/bash -set -e # stop early on non-zero exit +set -e # fail early on non-zero exit cargo clippy --all-targets -- -D warnings # syntax and style tests cargo fmt --check # formatting test -cargo llvm-cov -- --nocapture # integration tests w/ stdout coverage summary -cargo llvm-cov --html -- --nocapture # integration tests w/ HTML coverage report (target/llvm-cov/html/index.html) -cargo llvm-cov --codecov --output-path target/llvm-cov-target/codecov.json -- --nocapture # integration tests w/ coverage report prepared for codecov +cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" -- --nocapture # integration tests w/ stdout coverage summary +cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" --html -- --nocapture # integration tests w/ HTML coverage report (target/llvm-cov/html/index.html) +cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" --codecov --output-path target/llvm-cov-target/codecov.json -- --nocapture # integration tests w/ coverage report prepared for codecov ``` ## Docs From 09deecf114f0b34e0d0cb883cd277e48e37a6a8f Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Thu, 17 Apr 2025 12:33:35 +0000 Subject: [PATCH 02/11] Re-enable coverage PR comment. --- .codecov.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.codecov.yaml b/.codecov.yaml index 41069dcb..51d77639 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -26,7 +26,7 @@ coverage: # if_ci_failed: error #success, failure, error, ignore # informational: false # only_pulls: false -comment: false +# comment: false # comment: #this is a top-level key # layout: " diff, flags, files" # behavior: default From 5ff52e8dffdbf963b7b1e6c0661d8337b184f1dd Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Thu, 17 Apr 2025 12:44:18 +0000 Subject: [PATCH 03/11] Try using a cobertura coverage report. --- .codecov.yaml | 4 ++++ .github/workflows/tests.yaml | 6 +++--- README.md | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.codecov.yaml b/.codecov.yaml index 51d77639..b3382b1d 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -34,3 +34,7 @@ coverage: # require_base: false # [true :: must have a base report to post] # require_head: true # [true :: must have a head report to post] # hide_project_coverage: false # [true :: only show coverage on the git diff aka patch coverage]] +parsers: + cobertura: + partials_as_hits: false + handle_missing_conditions: false diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f7b79365..ea3650ed 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -26,13 +26,13 @@ jobs: mkdir -p tests/.tmp cargo llvm-cov \ --ignore-filename-regex "bin/.*|lib\.rs" \ - --codecov \ - --output-path target/llvm-cov-target/codecov.json \ + --cobertura \ + --output-path target/llvm-cov-target/cobertura.xml \ -- \ --nocapture - name: Upload to codecov.io uses: codecov/codecov-action@v5 with: fail_ci_if_error: true - files: target/llvm-cov-target/codecov.json + files: target/llvm-cov-target/cobertura.xml verbose: true diff --git a/README.md b/README.md index 9a670f0b..ec7cc17c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ cargo clippy --all-targets -- -D warnings # syntax and style tests cargo fmt --check # formatting test cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" -- --nocapture # integration tests w/ stdout coverage summary cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" --html -- --nocapture # integration tests w/ HTML coverage report (target/llvm-cov/html/index.html) -cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" --codecov --output-path target/llvm-cov-target/codecov.json -- --nocapture # integration tests w/ coverage report prepared for codecov +cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" --codecov --output-path target/llvm-cov-target/codecov.json -- --nocapture # integration tests w/ codecov coverage report +cargo llvm-cov --ignore-filename-regex "bin/.*|lib\.rs" --cobertura --output-path target/llvm-cov-target/cobertura.xml -- --nocapture # integration tests w/ cobertura coverage report ``` ## Docs From f4a0ed98cb0ea4254822a642869805e3386c1afd Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Thu, 17 Apr 2025 12:49:57 +0000 Subject: [PATCH 04/11] Toggle the partial hit config in cobertura reports. --- .codecov.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.codecov.yaml b/.codecov.yaml index b3382b1d..2b93ef52 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -36,5 +36,5 @@ coverage: # hide_project_coverage: false # [true :: only show coverage on the git diff aka patch coverage]] parsers: cobertura: - partials_as_hits: false - handle_missing_conditions: false + partials_as_hits: true + handle_missing_conditions: true From 26050bbafe0f4e2ce50af19af3392486194d21f1 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Thu, 17 Apr 2025 13:01:35 +0000 Subject: [PATCH 05/11] Modify the coverage config to test bot. --- .codecov.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.codecov.yaml b/.codecov.yaml index 2b93ef52..740282f4 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -37,4 +37,4 @@ coverage: parsers: cobertura: partials_as_hits: true - handle_missing_conditions: true + # handle_missing_conditions: true From 9f294b43ef9d728385391feec80d699055ed93b9 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Thu, 17 Apr 2025 13:07:33 +0000 Subject: [PATCH 06/11] Modify the coverage config to test bot 2. --- .codecov.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.codecov.yaml b/.codecov.yaml index 740282f4..b75021ed 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -36,5 +36,5 @@ coverage: # hide_project_coverage: false # [true :: only show coverage on the git diff aka patch coverage]] parsers: cobertura: - partials_as_hits: true + partials_as_hits: false # handle_missing_conditions: true From b3b1462a0cb20b3e5983a0454ccd6cf9800cbac5 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Thu, 17 Apr 2025 13:17:49 +0000 Subject: [PATCH 07/11] Update patch settings for coverage reports. --- .codecov.yaml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.codecov.yaml b/.codecov.yaml index b75021ed..3749d77a 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -2,7 +2,10 @@ # curl -X POST --data-binary @.codecov.yaml https://codecov.io/validate coverage: status: - patch: true + patch: + default: + target: 100% + threshold: 0% # project: # default: # target: 85.28% @@ -34,7 +37,7 @@ coverage: # require_base: false # [true :: must have a base report to post] # require_head: true # [true :: must have a head report to post] # hide_project_coverage: false # [true :: only show coverage on the git diff aka patch coverage]] -parsers: - cobertura: - partials_as_hits: false +# parsers: +# cobertura: +# partials_as_hits: false # handle_missing_conditions: true From f7223847805be8a29a576b14f32532979aecb392 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Thu, 17 Apr 2025 13:21:37 +0000 Subject: [PATCH 08/11] Clean up. --- .codecov.yaml | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/.codecov.yaml b/.codecov.yaml index 3749d77a..2e9b94a4 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -6,38 +6,3 @@ coverage: default: target: 100% threshold: 0% - # project: - # default: - # target: 85.28% - # threshold: 0% - # project: - # default: # default is the status check's name, not default settings - # target: auto - # threshold: 5 - # base: auto - # # flags: - # # - unit - # paths: - # - "src" - # # advanced settings - # branches: - # - dev - # - main - # - uniffi-client - # - guzman-raphael:uniffi-client - # - guzman-raphael/orcapod:uniffi-client - # if_ci_failed: error #success, failure, error, ignore - # informational: false - # only_pulls: false -# comment: false -# comment: #this is a top-level key -# layout: " diff, flags, files" -# behavior: default -# require_changes: false # if true: only post the comment if coverage changes -# require_base: false # [true :: must have a base report to post] -# require_head: true # [true :: must have a head report to post] -# hide_project_coverage: false # [true :: only show coverage on the git diff aka patch coverage]] -# parsers: -# cobertura: -# partials_as_hits: false - # handle_missing_conditions: true From 045e8e285296a99e8257f95fcb9cfca7345e669e Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Fri, 18 Apr 2025 20:17:06 +0000 Subject: [PATCH 09/11] Add coverage for a couple OrcaErrors and simplify. --- tests/error.rs | 42 +++++++++++++++++++++++++++++++----------- tests/orchestrator.rs | 12 +++--------- tests/store.rs | 5 ++--- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/tests/error.rs b/tests/error.rs index 835a16b1..fcc2e4e7 100644 --- a/tests/error.rs +++ b/tests/error.rs @@ -1,4 +1,4 @@ -#![expect(missing_docs, clippy::expect_used, reason = "OK in tests.")] +#![expect(missing_docs, clippy::panic_in_result_fn, reason = "OK in tests.")] pub mod fixture; use fixture::{NAMESPACE_LOOKUP_READ_ONLY, pod_job_style}; @@ -9,11 +9,10 @@ use orcapod::uniffi::{ }; use serde_json; use serde_yaml; -use std::{collections::HashMap, fmt, fs, path::PathBuf, result}; +use std::{collections::HashMap, fs, path::PathBuf}; -fn check>(value: result::Result) -> String { - let error: OrcaError = value.expect_err("Did not return an expected error.").into(); - format!("{error:?}") +fn contains_debug(error: impl Into) -> bool { + !format!("{:?}", error.into()).is_empty() } #[test] @@ -21,31 +20,52 @@ fn external_bollard() -> Result<()> { let orch = LocalDockerOrchestrator::new()?; let mut pod_job = pod_job_style(&NAMESPACE_LOOKUP_READ_ONLY)?; pod_job.pod.image = "nonexistent_image".to_owned(); - check(orch.start_blocking(&NAMESPACE_LOOKUP_READ_ONLY, &pod_job)); + assert!( + orch.start_blocking(&NAMESPACE_LOOKUP_READ_ONLY, &pod_job) + .is_err_and(contains_debug), + "Did not raise a bollard error." + ); Ok(()) } #[test] fn external_glob() { - check(glob("a**/b")); + assert!( + glob("a**/b").is_err_and(contains_debug), + "Did not raise a glob error." + ); } #[test] fn external_io() { - check(fs::read_to_string("nonexistent_file.txt")); + assert!( + fs::read_to_string("nonexistent_file.txt").is_err_and(contains_debug), + "Did not raise an I/O error." + ); } #[test] fn external_path_prefix() { - check(PathBuf::from("/fake/path").strip_prefix("/missing/path")); + assert!( + PathBuf::from("/fake/path") + .strip_prefix("/missing/path") + .is_err_and(contains_debug), + "Did not raise a path prefix error." + ); } #[test] fn external_json() { - check(serde_json::from_str::>("{")); + assert!( + serde_json::from_str::>("{").is_err_and(contains_debug), + "Did not raise a serde json error." + ); } #[test] fn external_yaml() { - check(serde_yaml::from_str::>(":")); + assert!( + serde_yaml::from_str::>(":").is_err_and(contains_debug), + "Did not raise a serde yaml error." + ); } diff --git a/tests/orchestrator.rs b/tests/orchestrator.rs index ad455f46..fa4c9620 100644 --- a/tests/orchestrator.rs +++ b/tests/orchestrator.rs @@ -1,9 +1,4 @@ -#![expect( - clippy::expect_used, - missing_docs, - clippy::panic_in_result_fn, - reason = "OK in tests." -)] +#![expect(missing_docs, clippy::panic_in_result_fn, reason = "OK in tests.")] pub mod fixture; use fixture::{TestContainerImage, TestDirs, container_image_style, pod_job_style}; @@ -75,9 +70,8 @@ where assert!( orchestrator .get_info_blocking(&pod_run) - .expect_err("Unexpectedly succeeded.") - .is_purged_pod_run(), - "Returned a different OrcaError than one expected when getting info of a purged pod run." + .is_err_and(|error| error.is_purged_pod_run() && !format!("{error:?}").is_empty()), + "Did not raise a purged pod run error." ); Ok(()) } diff --git a/tests/store.rs b/tests/store.rs index 3b52d989..782140c0 100644 --- a/tests/store.rs +++ b/tests/store.rs @@ -223,9 +223,8 @@ fn pod_annotation_delete() -> Result<()> { assert!( store .delete_annotation::("style-transfer", "9.9.9") - .expect_err("Unexpectedly succeeded.") - .is_invalid_annotation(), - "Returned a different OrcaError than one expected when deleting an invalid annotation." + .is_err_and(|error| error.is_invalid_annotation() && !format!("{error:?}").is_empty()), + "Did not raise an invalid annotation error." ); Ok(()) } From 0ab92099b78994372b2549cde100fe48639b5a48 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Fri, 18 Apr 2025 20:58:58 +0000 Subject: [PATCH 10/11] Add coverage for some internal errors. --- tests/error.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/error.rs b/tests/error.rs index fcc2e4e7..537ee374 100644 --- a/tests/error.rs +++ b/tests/error.rs @@ -3,9 +3,12 @@ pub mod fixture; use fixture::{NAMESPACE_LOOKUP_READ_ONLY, pod_job_style}; use glob::glob; -use orcapod::uniffi::{ - error::{OrcaError, Result}, - orchestrator::{Orchestrator as _, docker::LocalDockerOrchestrator}, +use orcapod::{ + core::crypto::hash_file, + uniffi::{ + error::{OrcaError, Result}, + orchestrator::{Orchestrator as _, docker::LocalDockerOrchestrator}, + }, }; use serde_json; use serde_yaml; @@ -69,3 +72,19 @@ fn external_yaml() { "Did not raise a serde yaml error." ); } + +#[test] +fn internal_invalid_filepath() { + assert!( + hash_file("nonexistent_file.txt").is_err_and(contains_debug), + "Did not raise an invalid filepath error." + ); +} + +#[test] +fn internal_key_missing() { + assert!( + pod_job_style(&HashMap::new()).is_err_and(contains_debug), + "Did not raise a key missing error." + ); +} From 7b1108e61e0b08ab0287f9062ec08497b4d0cf43 Mon Sep 17 00:00:00 2001 From: guzman-raphael Date: Sat, 19 Apr 2025 03:19:44 +0000 Subject: [PATCH 11/11] Set coverage reports as only informational. --- .codecov.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.codecov.yaml b/.codecov.yaml index 2e9b94a4..db335665 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -6,3 +6,4 @@ coverage: default: target: 100% threshold: 0% + informational: true