Skip to content

Commit 9b7c2e6

Browse files
authored
Fix update tests for kernel data lib and path and add ci rust tests (#514)
* fix: update test cases for kernel data library * fix: adjust e2e test path * feat: add cargo tests * fix: re format
1 parent ab23eed commit 9b7c2e6

3 files changed

Lines changed: 34 additions & 12 deletions

File tree

.github/workflows/rust.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,25 @@ jobs:
4949
( cd kernels-data/bindings/python && cargo clippy -- -D warnings )
5050
- name: Clippy (kernel-builder)
5151
run: ( cd kernel-builder && cargo clippy -- -D warnings )
52+
53+
test:
54+
name: Test
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
58+
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
59+
with:
60+
path: |
61+
~/.cargo/bin/
62+
~/.cargo/registry/index/
63+
~/.cargo/registry/cache/
64+
~/.cargo/git/db/
65+
target/
66+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
67+
- uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
68+
- name: Test (kernel-abi-check)
69+
run: cargo test -p kernel-abi-check
70+
- name: Test (kernels-data)
71+
run: cargo test -p kernels-data
72+
- name: Test (kernel-builder)
73+
run: cargo test -p hf-kernel-builder

kernel-builder/src/upload.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -594,10 +594,8 @@ mod tests {
594594
assert!(delete_paths.contains("build/torch-cuda/inherited.py"));
595595
}
596596

597-
const METADATA_V3: &str =
598-
r#"{"id": "kernel_id", "version": 3, "python-depends": [], "backend": {"type": "cuda"}}"#;
599-
const METADATA_NO_VERSION: &str =
600-
r#"{"id": "kernel_id", "python-depends": [], "backend": {"type": "cuda"}}"#;
597+
const METADATA_V3: &str = r#"{"name": "test-kernel", "id": "kernel_id", "version": 3, "license": "Apache-2.0", "python-depends": [], "backend": {"type": "cuda"}}"#;
598+
const METADATA_V0: &str = r#"{"name": "test-kernel", "id": "kernel_id", "version": 0, "license": "Apache-2.0", "python-depends": [], "backend": {"type": "cuda"}}"#;
601599

602600
#[test]
603601
fn test_detect_branch_from_metadata() {
@@ -612,15 +610,15 @@ mod tests {
612610
}
613611

614612
#[test]
615-
fn test_detect_branch_from_metadata_no_version() {
613+
fn test_detect_branch_from_metadata_v0() {
616614
let temp_dir = tempfile::tempdir().unwrap();
617615
let variant = temp_dir.path().join("variant");
618616
fs::create_dir_all(&variant).unwrap();
619-
fs::write(variant.join("metadata.json"), METADATA_NO_VERSION).unwrap();
617+
fs::write(variant.join("metadata.json"), METADATA_V0).unwrap();
620618

621619
let variants = vec![variant];
622620
let branch = detect_branch_from_metadata(&variants).unwrap();
623-
assert_eq!(branch, None);
621+
assert_eq!(branch, Some("v0".to_owned()));
624622
}
625623

626624
#[test]
@@ -632,12 +630,12 @@ mod tests {
632630
fs::create_dir_all(&v2).unwrap();
633631
fs::write(
634632
v1.join("metadata.json"),
635-
r#"{"version": 1, "python-depends": [], "backend": {"type": "cuda"}}"#,
633+
r#"{"name": "test-kernel", "version": 1, "id": "k1", "license": "Apache-2.0", "python-depends": [], "backend": {"type": "cuda"}}"#,
636634
)
637635
.unwrap();
638636
fs::write(
639637
v2.join("metadata.json"),
640-
r#"{"version": 2, "python-depends": [], "backend": {"type": "cuda"}}"#,
638+
r#"{"name": "test-kernel", "version": 2, "id": "k2", "license": "Apache-2.0", "python-depends": [], "backend": {"type": "cuda"}}"#,
641639
)
642640
.unwrap();
643641

@@ -709,6 +707,7 @@ mod tests {
709707
kernel_dir.join("build.toml"),
710708
r#"[general]
711709
name = "test-kernel"
710+
license = "Apache-2.0"
712711
backends = ["cuda"]
713712
714713
[general.hub]
@@ -745,6 +744,7 @@ branch = "custom-branch"
745744
kernel_dir.join("build.toml"),
746745
r#"[general]
747746
name = "test-kernel"
747+
license = "Apache-2.0"
748748
backends = ["cuda"]
749749
750750
[general.hub]

kernel-builder/tests/init_e2e.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::process::Command;
33

44
fn run_init(args: &[&str]) -> (bool, String, tempfile::TempDir) {
55
let temp = tempfile::tempdir().unwrap();
6-
let bin = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("target/debug/kernel-builder");
6+
let bin = std::path::PathBuf::from(env!("CARGO_BIN_EXE_kernel-builder"));
77

88
let output = Command::new(&bin)
99
.args(["init"])
@@ -57,7 +57,7 @@ fn test_init_fails_on_existing_scaffold_file() {
5757
// Pre-create a scaffold file - should cause init to fail
5858
fs::write(dir.join("build.toml"), "existing content").unwrap();
5959

60-
let bin = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("target/debug/kernel-builder");
60+
let bin = std::path::PathBuf::from(env!("CARGO_BIN_EXE_kernel-builder"));
6161

6262
let out = Command::new(&bin)
6363
.args(["init", "--name", "user/exists", "--backends", "cpu"])
@@ -82,7 +82,7 @@ fn test_init_overwrite() {
8282
fs::write(dir.join("build.toml"), "old scaffold").unwrap();
8383
fs::write(dir.join("custom.txt"), "user content").unwrap();
8484

85-
let bin = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("target/debug/kernel-builder");
85+
let bin = std::path::PathBuf::from(env!("CARGO_BIN_EXE_kernel-builder"));
8686

8787
let out = Command::new(&bin)
8888
.args([

0 commit comments

Comments
 (0)