diff --git a/pkg/client/client.go b/pkg/client/client.go index 1454ec3d..618e5a4c 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -211,7 +211,14 @@ func (c *KpmClient) AcquireDepSum(dep pkg.Dependency) (string, error) { // ResolveDepsIntoMap will calculate the map of kcl package name and local storage path of the external packages. func (c *KpmClient) ResolveDepsIntoMap(kclPkg *pkg.KclPkg) (map[string]string, error) { - err := c.ResolvePkgDepsMetadata(kclPkg, true) + var err error + if kclPkg.IsVendorMode() { + err = c.VendorDeps(kclPkg) + } else { + kclPkg, err = c.Update( + WithUpdatedKclPkg(kclPkg), + ) + } if err != nil { return nil, err } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 3248f9ab..4c947ca0 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -2254,3 +2254,45 @@ func testPushWithInsecureSkipTLSverify(t *testing.T) { assert.Equal(t, buf.String(), "Called Success\n") } + +func TestIssues(t *testing.T) { + // "kcl-lang/kcl/issue/1760" is the repo where the issue was actually raised and the issue id. + // "testIssue1760" is the test case cover the issue. + RunTestWithGlobalLockAndKpmCli(t, "kcl-lang/kcl/issue/1760", testIssue1760) +} + +func testIssue1760(t *testing.T, kpmcli *KpmClient) { + rootPath := getTestDir("issues") + mainKFilePath := filepath.Join(rootPath, "kcl-lang/kcl/issue/1760", "a", "main.k") + var buf bytes.Buffer + kpmcli.SetLogWriter(&buf) + + res, err := kpmcli.Run( + WithRunSource( + &downloader.Source{ + Local: &downloader.Local{ + Path: mainKFilePath, + }, + }, + ), + ) + + if err != nil { + t.Fatal(err) + } + + assert.Contains(t, + utils.RmNewline(buf.String()), + "downloading 'kcl-lang/fluxcd-source-controller:v1.3.2' from 'ghcr.io/kcl-lang/fluxcd-source-controller:v1.3.2'", + ) + assert.Contains(t, + utils.RmNewline(buf.String()), + "downloading 'kcl-lang/k8s:1.31.2' from 'ghcr.io/kcl-lang/k8s:1.31.2'", + ) + + assert.Contains(t, + utils.RmNewline(buf.String()), + "downloading 'kcl-lang/fluxcd-helm-controller:v1.0.3' from 'ghcr.io/kcl-lang/fluxcd-helm-controller:v1.0.3'", + ) + assert.Equal(t, res.GetRawYamlResult(), "The_first_kcl_program: Hello World!") +} diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/README.md b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/README.md new file mode 100644 index 00000000..84229c48 --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/README.md @@ -0,0 +1,68 @@ +## Bug Report + +https://github.com/kcl-lang/kcl/issues/1760 + +### 1. Minimal reproduce step (Required) + +1. Two empty modules within the same directory: + +|- modules +| |- a +| | |- kcl.mod +| | |- main.k +| |- b +| | |- kcl.mod +| | |- main.k + +2. Content `/modules/a/kcl.mod` : + +``` +[package] +name = "a" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +b = { path = "../b" } +fluxcd-source-controller = "v1.3.2" +fluxcd-helm-controller = "v1.0.3" +``` + +3. Content `/modules/b/kcl.mod` : + +``` +[package] +name = "b" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +fluxcd-source-controller = "v1.3.2" +``` + +4. Ensure your `$USER/.kcl/kpm/` directory is empty. + + +### 2. What did you expect to see? (Required) +``` +$ kcl run /modules/a/main.k +downloading 'kcl-lang/fluxcd-helm-controller:v1.0.3' from 'ghcr.io/kcl-lang/fluxcd-helm-controller:v1.0.3' +downloading 'kcl-lang/fluxcd-source-controller:v1.3.2' from 'ghcr.io/kcl-lang/fluxcd-source-controller:v1.3.2' +downloading 'kcl-lang/k8s:1.31.2' from 'ghcr.io/kcl-lang/k8s:1.31.2' +The_first_kcl_program: Hello World! +``` + +### 3. What did you see instead (Required) +``` +$ kcl run /modules/a/main.k +downloading 'kcl-lang/fluxcd-helm-controller:v1.0.3' from 'ghcr.io/kcl-lang/fluxcd-helm-controller:v1.0.3' +downloading 'kcl-lang/fluxcd-source-controller:v1.3.2' from 'ghcr.io/kcl-lang/fluxcd-source-controller:v1.3.2' +downloading 'kcl-lang/k8s:1.31.2' from 'ghcr.io/kcl-lang/k8s:1.31.2' +edge already exists +``` + +--> **kcl exited with error code 1** + +### 4. What is your KCL components version? (Required) + +0.10.8-linux-amd64 diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod new file mode 100644 index 00000000..b2d34c61 --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod @@ -0,0 +1,9 @@ +[package] +name = "a" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +b = { path = "../b", version = "0.0.1" } +fluxcd-helm-controller = "v1.0.3" +fluxcd-source-controller = "v1.3.2" diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod.lock b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod.lock new file mode 100644 index 00000000..6a6d847e --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod.lock @@ -0,0 +1,29 @@ +[dependencies] + [dependencies.b] + name = "b" + full_name = "b_0.0.1" + version = "0.0.1" + [dependencies.fluxcd-helm-controller] + name = "fluxcd-helm-controller" + full_name = "fluxcd-helm-controller_v1.0.3" + version = "v1.0.3" + sum = "IfDYAw0NW8XsbUSygAfqkgrJ8LdI7x4NIq7e9TuTbKY=" + reg = "ghcr.io" + repo = "kcl-lang/fluxcd-helm-controller" + oci_tag = "v1.0.3" + [dependencies.fluxcd-source-controller] + name = "fluxcd-source-controller" + full_name = "fluxcd-source-controller_v1.3.2" + version = "v1.3.2" + sum = "iZlc0kXOSajJNUmzvOlcIZgk60WGJbl4xKy4AVWYfkM=" + reg = "ghcr.io" + repo = "kcl-lang/fluxcd-source-controller" + oci_tag = "v1.3.2" + [dependencies.k8s] + name = "k8s" + full_name = "k8s_1.31.2" + version = "1.31.2" + sum = "xBZgPsnpVVyWBpahuPQHReeRx28eUHGFoaPeqbct+vs=" + reg = "ghcr.io" + repo = "kcl-lang/k8s" + oci_tag = "1.31.2" diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/main.k b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod new file mode 100644 index 00000000..2ecbc73d --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod @@ -0,0 +1,7 @@ +[package] +name = "b" +edition = "v0.10.0" +version = "0.0.1" + +[dependencies] +fluxcd-source-controller = "v1.3.2" diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod.lock b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod.lock new file mode 100644 index 00000000..b67bef5c --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod.lock @@ -0,0 +1,15 @@ +[dependencies] + [dependencies.fluxcd-source-controller] + name = "fluxcd-source-controller" + full_name = "fluxcd-source-controller_v1.3.2" + version = "v1.3.2" + reg = "ghcr.io" + repo = "kcl-lang/fluxcd-source-controller" + oci_tag = "v1.3.2" + [dependencies.k8s] + name = "k8s" + full_name = "k8s_1.31.2" + version = "1.31.2" + reg = "ghcr.io" + repo = "kcl-lang/k8s" + oci_tag = "1.31.2" diff --git a/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/main.k b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/main.k new file mode 100644 index 00000000..fa7048e6 --- /dev/null +++ b/pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/main.k @@ -0,0 +1 @@ +The_first_kcl_program = 'Hello World!' \ No newline at end of file