Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,25 @@ jobs:
( cd kernels-data/bindings/python && cargo clippy -- -D warnings )
- name: Clippy (kernel-builder)
run: ( cd kernel-builder && cargo clippy -- -D warnings )

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: dtolnay/rust-toolchain@e081816240890017053eacbb1bdf337761dc5582 # 1.95.0
- name: Test (kernel-abi-check)
run: cargo test -p kernel-abi-check
- name: Test (kernels-data)
run: cargo test -p kernels-data
- name: Test (kernel-builder)
run: cargo test -p hf-kernel-builder
18 changes: 9 additions & 9 deletions kernel-builder/src/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,8 @@ mod tests {
assert!(delete_paths.contains("build/torch-cuda/inherited.py"));
}

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

#[test]
fn test_detect_branch_from_metadata() {
Expand All @@ -614,15 +612,15 @@ mod tests {
}

#[test]
fn test_detect_branch_from_metadata_no_version() {
fn test_detect_branch_from_metadata_v0() {
let temp_dir = tempfile::tempdir().unwrap();
let variant = temp_dir.path().join("variant");
fs::create_dir_all(&variant).unwrap();
fs::write(variant.join("metadata.json"), METADATA_NO_VERSION).unwrap();
fs::write(variant.join("metadata.json"), METADATA_V0).unwrap();

let variants = vec![variant];
let branch = detect_branch_from_metadata(&variants).unwrap();
assert_eq!(branch, None);
assert_eq!(branch, Some("v0".to_owned()));
}

#[test]
Expand All @@ -634,12 +632,12 @@ mod tests {
fs::create_dir_all(&v2).unwrap();
fs::write(
v1.join("metadata.json"),
r#"{"version": 1, "python-depends": [], "backend": {"type": "cuda"}}"#,
r#"{"name": "test-kernel", "version": 1, "id": "k1", "license": "Apache-2.0", "python-depends": [], "backend": {"type": "cuda"}}"#,
)
.unwrap();
fs::write(
v2.join("metadata.json"),
r#"{"version": 2, "python-depends": [], "backend": {"type": "cuda"}}"#,
r#"{"name": "test-kernel", "version": 2, "id": "k2", "license": "Apache-2.0", "python-depends": [], "backend": {"type": "cuda"}}"#,
)
.unwrap();

Expand Down Expand Up @@ -711,6 +709,7 @@ mod tests {
kernel_dir.join("build.toml"),
r#"[general]
name = "test-kernel"
license = "Apache-2.0"
backends = ["cuda"]

[general.hub]
Expand Down Expand Up @@ -747,6 +746,7 @@ branch = "custom-branch"
kernel_dir.join("build.toml"),
r#"[general]
name = "test-kernel"
license = "Apache-2.0"
backends = ["cuda"]

[general.hub]
Expand Down
6 changes: 3 additions & 3 deletions kernel-builder/tests/init_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::process::Command;

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

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

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

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

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

let out = Command::new(&bin)
.args([
Expand Down
Loading