From 0c4749b2274f7242503514970e0afbd3d8dc52be Mon Sep 17 00:00:00 2001 From: Integralist Date: Fri, 1 Mar 2024 12:06:11 +0000 Subject: [PATCH 1/2] fix(compute/build): avoid persisting old metadata --- pkg/commands/compute/language_toolchain.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/commands/compute/language_toolchain.go b/pkg/commands/compute/language_toolchain.go index 998b1a3e6..a83652e37 100644 --- a/pkg/commands/compute/language_toolchain.go +++ b/pkg/commands/compute/language_toolchain.go @@ -86,6 +86,12 @@ type BuildToolchain struct { // Build compiles the user's source code into a Wasm binary. func (bt BuildToolchain) Build() error { + // Make sure to delete any pre-existing binary otherwise prior metadata will + // continue to be persisted. + if _, err := os.Stat(binWasmPath); err == nil { + os.Remove(binWasmPath) + } + cmd, args := bt.buildFn(bt.buildScript) if bt.verbose { From b3132e8bd7078e241c98aff2c19570480368b354 Mon Sep 17 00:00:00 2001 From: Integralist Date: Fri, 1 Mar 2024 12:53:18 +0000 Subject: [PATCH 2/2] fix(compute/build): language_other tests --- pkg/commands/compute/build_test.go | 32 +++++++----------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/pkg/commands/compute/build_test.go b/pkg/commands/compute/build_test.go index 72e2621be..84adbc0cf 100644 --- a/pkg/commands/compute/build_test.go +++ b/pkg/commands/compute/build_test.go @@ -860,7 +860,7 @@ func TestBuildOther(t *testing.T) { manifest_version = 2 name = "test" [scripts] - build = "ls ./bin" + build = "cp ./bin/test.main.wasm ./bin/main.wasm" post_build = "echo doing a post build"`, stdin: "N", wantOutput: []string{ @@ -877,7 +877,7 @@ func TestBuildOther(t *testing.T) { manifest_version = 2 name = "test" [scripts] - build = "ls ./bin" + build = "cp ./bin/test.main.wasm ./bin/main.wasm" post_build = "echo doing a post build"`, stdin: "Y", wantOutput: []string{ @@ -894,7 +894,7 @@ func TestBuildOther(t *testing.T) { name = "test" language = "other" [scripts] - build = "ls ./bin" + build = "cp ./bin/test.main.wasm ./bin/main.wasm" post_build = "echo doing a post build"`, stdin: "Y", wantOutput: []string{ @@ -910,7 +910,7 @@ func TestBuildOther(t *testing.T) { manifest_version = 2 name = "test" [scripts] - build = "ls ./bin" + build = "cp ./bin/test.main.wasm ./bin/main.wasm" post_build = "echo doing a post build with no confirmation prompt && exit 1"`, // force an error so post_build is displayed to validate it was run. wantOutput: []string{ "doing a post build with no confirmation prompt", @@ -953,7 +953,8 @@ func TestBuildOther(t *testing.T) { // // NOTE: Our only requirement is that there be a bin directory. The custom // build script we're using in the test is not going to use any files in the - // directory (the script will just `echo` a message). + // directory (the script will just copy a test binary into the expected + // location of the final main.wasm binary). // // NOTE: We create a "valid" main.wasm file with a quick shell script. // @@ -967,7 +968,7 @@ func TestBuildOther(t *testing.T) { rootdir := testutil.NewEnv(testutil.EnvOpts{ T: t, Copy: []testutil.FileIO{ - {Src: "./testdata/main.wasm", Dst: "bin/main.wasm"}, + {Src: "./testdata/main.wasm", Dst: "bin/test.main.wasm"}, }, Write: []testutil.FileIO{ {Src: `#!/usr/bin/env bash @@ -979,7 +980,6 @@ func TestBuildOther(t *testing.T) { }) defer os.RemoveAll(rootdir) wasmtoolsBinPath := filepath.Join(rootdir, wasmtoolsBinName) - mainwasmBinPath := filepath.Join(rootdir, "bin", "main.wasm") // Before running the test, chdir into the build environment. // When we're done, chdir back to our original location. @@ -991,24 +991,6 @@ func TestBuildOther(t *testing.T) { _ = os.Chdir(pwd) }() - // Make a backup of the bin/main.wasm as it will get modified by the - // post_build script and that will cause it to fail validation. - // - // TODO: Check if this backup is still needed? - // We had this back when the test environment was setup once. - // But we've moved to having the test environment created for each test case. - // So we might not need to restore mainwasmBinPath as it's created afresh. - mainWasmBackup, err := os.ReadFile(mainwasmBinPath) - if err != nil { - t.Fatal(err) - } - defer func() { - err := os.WriteFile(mainwasmBinPath, mainWasmBackup, 0o600) - if err != nil { - t.Fatal(err) - } - }() - if testcase.fastlyManifest != "" { if err := os.WriteFile(filepath.Join(rootdir, manifest.Filename), []byte(testcase.fastlyManifest), 0o600); err != nil { t.Fatal(err)