From 7816a1343950b3876e95333538984ca4bf3dc9c8 Mon Sep 17 00:00:00 2001 From: zongz Date: Fri, 15 Nov 2024 16:27:44 +0800 Subject: [PATCH] fix: fill the missing checksum in kcl.mod.lock in api Update Signed-off-by: zongz --- pkg/client/client_test.go | 9 ++++----- .../test_data/test_data_add_deps/kcl.mod.lock | 20 +++++++++---------- .../test_update/test_update_kcl_mod/expected | 1 + .../test_update_kcl_mod/kcl.mod.lock | 9 +++++++++ .../test_update_kcl_mod_lock/kcl.mod.lock | 8 -------- .../update_0/dep_0/kcl.mod.lock | 3 +++ .../update_0/dep_1/kcl.mod.lock | 3 +++ .../update_0/dep_2/kcl.mod.lock | 4 ++++ .../update_0/pkg/kcl.mod.lock | 1 + .../update_1/dep_0/kcl.mod.lock | 3 +++ .../update_1/dep_1/kcl.mod.lock | 3 +++ .../update_1/dep_2/kcl.mod.lock | 3 +++ .../update_1/pkg/kcl.mod.lock | 1 + pkg/client/update.go | 11 ++++++++++ 14 files changed, 55 insertions(+), 24 deletions(-) diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 0dab4754..7ed75871 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -1185,6 +1185,9 @@ func testAddWithNoSumCheck(t *testing.T) { func testUpdateWithNoSumCheck(t *testing.T, kpmcli *KpmClient) { pkgPath := getTestDir("test_update_no_sum_check") + defer func() { + _ = os.Remove(filepath.Join(pkgPath, "kcl.mod.lock")) + }() var buf bytes.Buffer kpmcli.SetLogWriter(&buf) @@ -1198,18 +1201,14 @@ func testUpdateWithNoSumCheck(t *testing.T, kpmcli *KpmClient) { assert.Equal(t, utils.DirExists(filepath.Join(pkgPath, "kcl.mod.lock")), false) buf.Reset() - kpmcli.SetNoSumCheck(false) kclPkg, err = kpmcli.LoadPkgFromPath(pkgPath) assert.Equal(t, err, nil) + kclPkg.NoSumCheck = false err = kpmcli.UpdateDeps(kclPkg) assert.Equal(t, err, nil) assert.Equal(t, utils.DirExists(filepath.Join(pkgPath, "kcl.mod.lock")), true) assert.Equal(t, buf.String(), "") - - defer func() { - _ = os.Remove(filepath.Join(pkgPath, "kcl.mod.lock")) - }() } func testAddWithDiffVersionNoSumCheck(t *testing.T) { diff --git a/pkg/client/test_data/test_data_add_deps/kcl.mod.lock b/pkg/client/test_data/test_data_add_deps/kcl.mod.lock index 05d1a2ce..9942ca8c 100644 --- a/pkg/client/test_data/test_data_add_deps/kcl.mod.lock +++ b/pkg/client/test_data/test_data_add_deps/kcl.mod.lock @@ -1,16 +1,14 @@ [dependencies] - [dependencies.oci_test] + [dependencies.name] + name = "name" + full_name = "test_url_test_tag" + version = "test_tag" + url = "test_url" + git_tag = "test_tag" + [dependencies.oci_name] name = "oci_name" - full_name = "test_version" - version = "test_version" - sum = "test_sum" + full_name = "oci_name_test_tag" + version = "test_tag" reg = "test_reg" repo = "test_repo" oci_tag = "test_tag" - [dependencies.test] - name = "name" - full_name = "test_version" - version = "test_version" - sum = "test_sum" - url = "test_url" - git_tag = "test_tag" diff --git a/pkg/client/test_data/test_update/test_update_kcl_mod/expected b/pkg/client/test_data/test_update/test_update_kcl_mod/expected index c1bebf8c..7eaf9cba 100644 --- a/pkg/client/test_data/test_update/test_update_kcl_mod/expected +++ b/pkg/client/test_data/test_update/test_update_kcl_mod/expected @@ -3,6 +3,7 @@ name = "helloworld" full_name = "helloworld_0.1.2" version = "0.1.2" + sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=" reg = "ghcr.io" repo = "kcl-lang/helloworld" oci_tag = "0.1.2" diff --git a/pkg/client/test_data/test_update/test_update_kcl_mod/kcl.mod.lock b/pkg/client/test_data/test_update/test_update_kcl_mod/kcl.mod.lock index e69de29b..7eaf9cba 100644 --- a/pkg/client/test_data/test_update/test_update_kcl_mod/kcl.mod.lock +++ b/pkg/client/test_data/test_update/test_update_kcl_mod/kcl.mod.lock @@ -0,0 +1,9 @@ +[dependencies] + [dependencies.helloworld] + name = "helloworld" + full_name = "helloworld_0.1.2" + version = "0.1.2" + sum = "PN0OMEV9M8VGFn1CtA/T3bcgZmMJmOo+RkBrLKIWYeQ=" + reg = "ghcr.io" + repo = "kcl-lang/helloworld" + oci_tag = "0.1.2" diff --git a/pkg/client/test_data/test_update/test_update_kcl_mod_lock/kcl.mod.lock b/pkg/client/test_data/test_update/test_update_kcl_mod_lock/kcl.mod.lock index c1bebf8c..e69de29b 100644 --- a/pkg/client/test_data/test_update/test_update_kcl_mod_lock/kcl.mod.lock +++ b/pkg/client/test_data/test_update/test_update_kcl_mod_lock/kcl.mod.lock @@ -1,8 +0,0 @@ -[dependencies] - [dependencies.helloworld] - name = "helloworld" - full_name = "helloworld_0.1.2" - version = "0.1.2" - reg = "ghcr.io" - repo = "kcl-lang/helloworld" - oci_tag = "0.1.2" diff --git a/pkg/client/test_data/test_update_with_mvs/update_0/dep_0/kcl.mod.lock b/pkg/client/test_data/test_update_with_mvs/update_0/dep_0/kcl.mod.lock index 1bc5d15c..d6bb0fa5 100644 --- a/pkg/client/test_data/test_update_with_mvs/update_0/dep_0/kcl.mod.lock +++ b/pkg/client/test_data/test_update_with_mvs/update_0/dep_0/kcl.mod.lock @@ -4,3 +4,6 @@ full_name = "helloworld_0.1.0" version = "0.1.0" sum = "aqrvSsd8zGHzRERbOzxYxARmK6QjvpQMYC1OqemdZvc=" + reg = "ghcr.io" + repo = "kcl-lang/helloworld" + oci_tag = "0.1.0" diff --git a/pkg/client/test_data/test_update_with_mvs/update_0/dep_1/kcl.mod.lock b/pkg/client/test_data/test_update_with_mvs/update_0/dep_1/kcl.mod.lock index 667cdff0..6270d4f4 100644 --- a/pkg/client/test_data/test_update_with_mvs/update_0/dep_1/kcl.mod.lock +++ b/pkg/client/test_data/test_update_with_mvs/update_0/dep_1/kcl.mod.lock @@ -4,3 +4,6 @@ full_name = "helloworld_0.1.1" version = "0.1.1" sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" + reg = "ghcr.io" + repo = "kcl-lang/helloworld" + oci_tag = "0.1.1" diff --git a/pkg/client/test_data/test_update_with_mvs/update_0/dep_2/kcl.mod.lock b/pkg/client/test_data/test_update_with_mvs/update_0/dep_2/kcl.mod.lock index 7b80eba3..d6bb0fa5 100644 --- a/pkg/client/test_data/test_update_with_mvs/update_0/dep_2/kcl.mod.lock +++ b/pkg/client/test_data/test_update_with_mvs/update_0/dep_2/kcl.mod.lock @@ -3,3 +3,7 @@ name = "helloworld" full_name = "helloworld_0.1.0" version = "0.1.0" + sum = "aqrvSsd8zGHzRERbOzxYxARmK6QjvpQMYC1OqemdZvc=" + reg = "ghcr.io" + repo = "kcl-lang/helloworld" + oci_tag = "0.1.0" diff --git a/pkg/client/test_data/test_update_with_mvs/update_0/pkg/kcl.mod.lock b/pkg/client/test_data/test_update_with_mvs/update_0/pkg/kcl.mod.lock index f3d86095..87cb130e 100644 --- a/pkg/client/test_data/test_update_with_mvs/update_0/pkg/kcl.mod.lock +++ b/pkg/client/test_data/test_update_with_mvs/update_0/pkg/kcl.mod.lock @@ -15,6 +15,7 @@ name = "helloworld" full_name = "helloworld_0.1.1" version = "0.1.1" + sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" reg = "ghcr.io" repo = "kcl-lang/helloworld" oci_tag = "0.1.1" diff --git a/pkg/client/test_data/test_update_with_mvs/update_1/dep_0/kcl.mod.lock b/pkg/client/test_data/test_update_with_mvs/update_1/dep_0/kcl.mod.lock index 1bc5d15c..d6bb0fa5 100644 --- a/pkg/client/test_data/test_update_with_mvs/update_1/dep_0/kcl.mod.lock +++ b/pkg/client/test_data/test_update_with_mvs/update_1/dep_0/kcl.mod.lock @@ -4,3 +4,6 @@ full_name = "helloworld_0.1.0" version = "0.1.0" sum = "aqrvSsd8zGHzRERbOzxYxARmK6QjvpQMYC1OqemdZvc=" + reg = "ghcr.io" + repo = "kcl-lang/helloworld" + oci_tag = "0.1.0" diff --git a/pkg/client/test_data/test_update_with_mvs/update_1/dep_1/kcl.mod.lock b/pkg/client/test_data/test_update_with_mvs/update_1/dep_1/kcl.mod.lock index 667cdff0..6270d4f4 100644 --- a/pkg/client/test_data/test_update_with_mvs/update_1/dep_1/kcl.mod.lock +++ b/pkg/client/test_data/test_update_with_mvs/update_1/dep_1/kcl.mod.lock @@ -4,3 +4,6 @@ full_name = "helloworld_0.1.1" version = "0.1.1" sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" + reg = "ghcr.io" + repo = "kcl-lang/helloworld" + oci_tag = "0.1.1" diff --git a/pkg/client/test_data/test_update_with_mvs/update_1/dep_2/kcl.mod.lock b/pkg/client/test_data/test_update_with_mvs/update_1/dep_2/kcl.mod.lock index 7b80eba3..b8d1f053 100644 --- a/pkg/client/test_data/test_update_with_mvs/update_1/dep_2/kcl.mod.lock +++ b/pkg/client/test_data/test_update_with_mvs/update_1/dep_2/kcl.mod.lock @@ -3,3 +3,6 @@ name = "helloworld" full_name = "helloworld_0.1.0" version = "0.1.0" + reg = "ghcr.io" + repo = "kcl-lang/helloworld" + oci_tag = "0.1.0" diff --git a/pkg/client/test_data/test_update_with_mvs/update_1/pkg/kcl.mod.lock b/pkg/client/test_data/test_update_with_mvs/update_1/pkg/kcl.mod.lock index f3d86095..87cb130e 100644 --- a/pkg/client/test_data/test_update_with_mvs/update_1/pkg/kcl.mod.lock +++ b/pkg/client/test_data/test_update_with_mvs/update_1/pkg/kcl.mod.lock @@ -15,6 +15,7 @@ name = "helloworld" full_name = "helloworld_0.1.1" version = "0.1.1" + sum = "7OO4YK2QuRWPq9C7KTzcWcti5yUnueCjptT3OXiPVeQ=" reg = "ghcr.io" repo = "kcl-lang/helloworld" oci_tag = "0.1.1" diff --git a/pkg/client/update.go b/pkg/client/update.go index 2a7d88e9..dd1f3bc5 100644 --- a/pkg/client/update.go +++ b/pkg/client/update.go @@ -37,6 +37,8 @@ func (c *KpmClient) Update(options ...UpdateOption) (*pkg.KclPkg, error) { return nil, fmt.Errorf("kcl package is nil") } + kMod.NoSumCheck = c.noSumCheck + modDeps := kMod.ModFile.Dependencies.Deps if modDeps == nil { return nil, fmt.Errorf("kcl.mod dependencies is nil") @@ -80,6 +82,15 @@ func (c *KpmClient) Update(options ...UpdateOption) (*pkg.KclPkg, error) { } } selectedDep.LocalFullPath = dep.LocalFullPath + if selectedDep.Sum == "" { + sum, err := c.AcquireDepSum(*selectedDep) + if err != nil { + return err + } + if sum != "" { + selectedDep.Sum = sum + } + } kMod.Dependencies.Deps.Set(dep.Name, *selectedDep) return nil