From d0da629ececf5c9221c77f0d28c4faaf816e3e4b Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 8 Sep 2023 18:09:11 -0700 Subject: [PATCH 1/5] Update deps. --- Cargo.lock | 26 ++++++++++++++++++++------ Cargo.toml | 6 +++--- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7cfcee..08c9602 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2055,7 +2055,9 @@ dependencies = [ [[package]] name = "proto_core" -version = "0.16.4" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301ba4904d65b120a91e923061b8b7ce74fe693f0775f280edd68717f0668d16" dependencies = [ "cached", "extism", @@ -2083,7 +2085,9 @@ dependencies = [ [[package]] name = "proto_pdk" -version = "0.6.5" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f50967234069bfa3aea1a6017b0b7a0c38fc9ade11588d045ef560d455fd294" dependencies = [ "anyhow", "extism-pdk", @@ -2095,7 +2099,9 @@ dependencies = [ [[package]] name = "proto_pdk_api" -version = "0.6.3" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e458d93c3eadbe10869d644d9461806861f2635f87c3171c347c70b12b5183a6" dependencies = [ "anyhow", "semver", @@ -2107,7 +2113,9 @@ dependencies = [ [[package]] name = "proto_pdk_test_utils" -version = "0.5.9" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "023385b68543e04e2a6e3af1edc281d9a1e42c47b692f0ca0ff75e1492b76dac" dependencies = [ "extism", "proto_core", @@ -2118,7 +2126,9 @@ dependencies = [ [[package]] name = "proto_wasm_plugin" -version = "0.6.3" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11e4a5135da5ab3ca908b247f0cdbe7970c7e2ee4bae01308df2dfba8640854" dependencies = [ "extism", "proto_pdk_api", @@ -3231,7 +3241,9 @@ dependencies = [ [[package]] name = "warpgate" -version = "0.5.3" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e105ab7fd178b2fc6b59439046418278b478e761549658a41eb48c97a9944a" dependencies = [ "extism", "miette", @@ -3253,6 +3265,8 @@ dependencies = [ [[package]] name = "warpgate_api" version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87f4f62fa42fa715ce697387b4c5c66ae0380723b841b1e0ff9fd285c78ab5f" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml index b5e4edc..d56894b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,15 +11,15 @@ crate-type = ['cdylib'] [dependencies] extism-pdk = "0.3.4" once_cell = "1.18.0" -proto_pdk = { version = "0.6.5", path = "../../proto/crates/pdk" } +proto_pdk = { version = "0.7.0" } # , path = "../../proto/crates/pdk" } regex = "1.9.5" serde = "1.0.188" [dev-dependencies] -proto_pdk_test_utils = { version = "0.5.9", path = "../../proto/crates/pdk-test-utils" } +proto_pdk_test_utils = { version = "0.6.1" } # , path = "../../proto/crates/pdk-test-utils" } starbase_sandbox = "0.1.10" tokio = "1.32.0" [profile.release] +codegen-units = 1 lto = true -opt-level = "s" From a8094f04afd952d307bc3c006712ceee5400674f Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 8 Sep 2023 18:23:34 -0700 Subject: [PATCH 2/5] Add tests. --- tests/download_test.rs | 3 ++ tests/globals_test.rs | 5 +++ tests/metadata_test.rs | 17 ++++++++++ tests/shims_test.rs | 4 +++ .../shims_test__creates_global_shims.snap | 13 ++++++++ tests/versions_test.rs | 31 +++++++++++++++++++ 6 files changed, 73 insertions(+) create mode 100644 tests/download_test.rs create mode 100644 tests/globals_test.rs create mode 100644 tests/metadata_test.rs create mode 100644 tests/shims_test.rs create mode 100644 tests/snapshots/shims_test__creates_global_shims.snap create mode 100644 tests/versions_test.rs diff --git a/tests/download_test.rs b/tests/download_test.rs new file mode 100644 index 0000000..cb3fedb --- /dev/null +++ b/tests/download_test.rs @@ -0,0 +1,3 @@ +use proto_pdk_test_utils::*; + +generate_download_install_tests!("python-test", "3.10.0"); diff --git a/tests/globals_test.rs b/tests/globals_test.rs new file mode 100644 index 0000000..e320fca --- /dev/null +++ b/tests/globals_test.rs @@ -0,0 +1,5 @@ +// use proto_pdk_test_utils::*; + +// // Currently times out on Windows! +// #[cfg(not(windows))] +// generate_globals_test!("go-test", "golang.org/x/tools/cmd/stringer@latest", "GOBIN"); diff --git a/tests/metadata_test.rs b/tests/metadata_test.rs new file mode 100644 index 0000000..87ae6c1 --- /dev/null +++ b/tests/metadata_test.rs @@ -0,0 +1,17 @@ +use proto_pdk_test_utils::*; +use starbase_sandbox::create_empty_sandbox; + +#[test] +fn registers_metadata() { + let sandbox = create_empty_sandbox(); + let plugin = create_plugin("python-test", sandbox.path()); + + assert_eq!( + plugin.register_tool(ToolMetadataInput::default()), + ToolMetadataOutput { + name: "Python".into(), + plugin_version: Some(env!("CARGO_PKG_VERSION").into()), + ..ToolMetadataOutput::default() + } + ); +} diff --git a/tests/shims_test.rs b/tests/shims_test.rs new file mode 100644 index 0000000..64b5983 --- /dev/null +++ b/tests/shims_test.rs @@ -0,0 +1,4 @@ +use proto_pdk_test_utils::*; + +#[cfg(not(windows))] +generate_global_shims_test!("python-test"); diff --git a/tests/snapshots/shims_test__creates_global_shims.snap b/tests/snapshots/shims_test__creates_global_shims.snap new file mode 100644 index 0000000..c314d27 --- /dev/null +++ b/tests/snapshots/shims_test__creates_global_shims.snap @@ -0,0 +1,13 @@ +--- +source: tests/shims_test.rs +expression: "std::fs::read_to_string(sandbox.path().join(\".proto/bin\").join(if cfg!(windows)\n {\n format!(\"{}.cmd\", \"python-test\")\n } else { \"python-test\".to_string() })).unwrap()" +--- +#!/usr/bin/env bash +set -e +[ -n "$PROTO_DEBUG" ] && set -x + + + +exec proto run python-test -- "$@" + + diff --git a/tests/versions_test.rs b/tests/versions_test.rs new file mode 100644 index 0000000..a74aeeb --- /dev/null +++ b/tests/versions_test.rs @@ -0,0 +1,31 @@ +use proto_pdk_test_utils::*; +use starbase_sandbox::create_empty_sandbox; + +generate_resolve_versions_tests!("python-test", { + "2.3" => "2.3.7", + "3.10.1" => "3.10.1", + "3.10" => "3.10.13", + "3" => "3.11.5", +}); + +#[test] +fn loads_versions_from_git() { + let sandbox = create_empty_sandbox(); + let plugin = create_plugin("python-test", sandbox.path()); + + let output = plugin.load_versions(LoadVersionsInput::default()); + + assert!(!output.versions.is_empty()); +} + +#[test] +fn sets_latest_alias() { + let sandbox = create_empty_sandbox(); + let plugin = create_plugin("python-test", sandbox.path()); + + let output = plugin.load_versions(LoadVersionsInput::default()); + + assert!(output.latest.is_some()); + assert!(output.aliases.contains_key("latest")); + assert_eq!(output.aliases.get("latest"), output.latest.as_ref()); +} From 2543a179aceab9f41dbd2417b8e02000074e5ff1 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 8 Sep 2023 18:25:19 -0700 Subject: [PATCH 3/5] Test pip. --- tests/globals_test.rs | 5 ----- tests/shims_test.rs | 2 +- .../shims_test__creates_global_shims-2.snap.new | 14 ++++++++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) delete mode 100644 tests/globals_test.rs create mode 100644 tests/snapshots/shims_test__creates_global_shims-2.snap.new diff --git a/tests/globals_test.rs b/tests/globals_test.rs deleted file mode 100644 index e320fca..0000000 --- a/tests/globals_test.rs +++ /dev/null @@ -1,5 +0,0 @@ -// use proto_pdk_test_utils::*; - -// // Currently times out on Windows! -// #[cfg(not(windows))] -// generate_globals_test!("go-test", "golang.org/x/tools/cmd/stringer@latest", "GOBIN"); diff --git a/tests/shims_test.rs b/tests/shims_test.rs index 64b5983..24580ef 100644 --- a/tests/shims_test.rs +++ b/tests/shims_test.rs @@ -1,4 +1,4 @@ use proto_pdk_test_utils::*; #[cfg(not(windows))] -generate_global_shims_test!("python-test"); +generate_global_shims_test!("python-test", ["pip"]); diff --git a/tests/snapshots/shims_test__creates_global_shims-2.snap.new b/tests/snapshots/shims_test__creates_global_shims-2.snap.new new file mode 100644 index 0000000..13a97c2 --- /dev/null +++ b/tests/snapshots/shims_test__creates_global_shims-2.snap.new @@ -0,0 +1,14 @@ +--- +source: tests/shims_test.rs +assertion_line: 4 +expression: "std::fs::read_to_string(sandbox.path().join(\".proto/bin\").join(if cfg!(windows)\n {\n format!(\"{}.cmd\", \"pip\")\n } else { \"pip\".to_string() })).unwrap()" +--- +#!/usr/bin/env bash +set -e +[ -n "$PROTO_DEBUG" ] && set -x + + + +exec proto run python-test -- -m pip "$@" + + From d990a589f7eafbf4c6c792fc20dec4c09b2a7949 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 8 Sep 2023 19:14:00 -0700 Subject: [PATCH 4/5] Bump version. --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08c9602..f2e5f78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2055,9 +2055,9 @@ dependencies = [ [[package]] name = "proto_core" -version = "0.17.1" +version = "0.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301ba4904d65b120a91e923061b8b7ce74fe693f0775f280edd68717f0668d16" +checksum = "7f9d66bf857561212ef611c073ce1f83f09a3bc70ee8b5edbdf1dff433f8e71d" dependencies = [ "cached", "extism", @@ -2085,9 +2085,9 @@ dependencies = [ [[package]] name = "proto_pdk" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f50967234069bfa3aea1a6017b0b7a0c38fc9ade11588d045ef560d455fd294" +checksum = "c2e7ee5ae588b5cda3bcbd90c87f2875292bba9ce846569f4ed427fc520ba96d" dependencies = [ "anyhow", "extism-pdk", @@ -2099,9 +2099,9 @@ dependencies = [ [[package]] name = "proto_pdk_api" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e458d93c3eadbe10869d644d9461806861f2635f87c3171c347c70b12b5183a6" +checksum = "33aee2bcc06bc3f8d0033e2c733e0ddaf8e1fcd141e151064ef7f73867e123cd" dependencies = [ "anyhow", "semver", @@ -2113,9 +2113,9 @@ dependencies = [ [[package]] name = "proto_pdk_test_utils" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "023385b68543e04e2a6e3af1edc281d9a1e42c47b692f0ca0ff75e1492b76dac" +checksum = "9b799a8c37613832e1129d7a52887406a1e2aabf1565484b1925d4ad3d3dac98" dependencies = [ "extism", "proto_core", @@ -2126,9 +2126,9 @@ dependencies = [ [[package]] name = "proto_wasm_plugin" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11e4a5135da5ab3ca908b247f0cdbe7970c7e2ee4bae01308df2dfba8640854" +checksum = "a377902a50bcfd6658744b43c416b18088921d6c52db0de2be0e8f7a76ec4aed" dependencies = [ "extism", "proto_pdk_api", diff --git a/Cargo.toml b/Cargo.toml index d56894b..2801e55 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,12 +11,12 @@ crate-type = ['cdylib'] [dependencies] extism-pdk = "0.3.4" once_cell = "1.18.0" -proto_pdk = { version = "0.7.0" } # , path = "../../proto/crates/pdk" } +proto_pdk = { version = "0.7.1" } # , path = "../../proto/crates/pdk" } regex = "1.9.5" serde = "1.0.188" [dev-dependencies] -proto_pdk_test_utils = { version = "0.6.1" } # , path = "../../proto/crates/pdk-test-utils" } +proto_pdk_test_utils = { version = "0.6.2" } # , path = "../../proto/crates/pdk-test-utils" } starbase_sandbox = "0.1.10" tokio = "1.32.0" From 14d69db56b9f90988fff23d777b47fbcb01a4477 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Fri, 8 Sep 2023 19:40:11 -0700 Subject: [PATCH 5/5] Handle canary. --- src/proto.rs | 12 +++++++----- ...p.new => shims_test__creates_global_shims-2.snap} | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) rename tests/snapshots/{shims_test__creates_global_shims-2.snap.new => shims_test__creates_global_shims-2.snap} (95%) diff --git a/src/proto.rs b/src/proto.rs index 6ab7d38..6acd17c 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -62,16 +62,18 @@ pub fn download_prebuilt( Json(input): Json, ) -> FnResult> { let env = get_proto_environment()?; + let version = input.context.version; + + if version == "canary" { + return err!(PluginError::UnsupportedCanary { tool: NAME.into() }.into()); + } let releases: HashMap> = fetch_url_with_cache( "https://raw.githubusercontent.com/moonrepo/python-plugin/master/releases.json", )?; - let Some(release_triples) = releases.get(&input.context.version) else { - return err!( - "No pre-built available for version {}!", - input.context.version - ); + let Some(release_triples) = releases.get(&version) else { + return err!("No pre-built available for version {}!", version); }; let triple = get_target_triple(&env, NAME)?; diff --git a/tests/snapshots/shims_test__creates_global_shims-2.snap.new b/tests/snapshots/shims_test__creates_global_shims-2.snap similarity index 95% rename from tests/snapshots/shims_test__creates_global_shims-2.snap.new rename to tests/snapshots/shims_test__creates_global_shims-2.snap index 13a97c2..e166aeb 100644 --- a/tests/snapshots/shims_test__creates_global_shims-2.snap.new +++ b/tests/snapshots/shims_test__creates_global_shims-2.snap @@ -1,6 +1,5 @@ --- source: tests/shims_test.rs -assertion_line: 4 expression: "std::fs::read_to_string(sandbox.path().join(\".proto/bin\").join(if cfg!(windows)\n {\n format!(\"{}.cmd\", \"pip\")\n } else { \"pip\".to_string() })).unwrap()" --- #!/usr/bin/env bash