Skip to content

Commit

Permalink
fix: fix 'edge already exists' when kpm run
Browse files Browse the repository at this point in the history
Signed-off-by: zongz <[email protected]>
  • Loading branch information
zong-zhe committed Nov 20, 2024
1 parent f007a54 commit 80505ad
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
42 changes: 42 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
68 changes: 68 additions & 0 deletions pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/README.md
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod
Original file line number Diff line number Diff line change
@@ -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"
29 changes: 29 additions & 0 deletions pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/a/kcl.mod.lock
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'
7 changes: 7 additions & 0 deletions pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "b"
edition = "v0.10.0"
version = "0.0.1"

[dependencies]
fluxcd-source-controller = "v1.3.2"
15 changes: 15 additions & 0 deletions pkg/client/test_data/issues/kcl-lang/kcl/issue/1760/b/kcl.mod.lock
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The_first_kcl_program = 'Hello World!'

0 comments on commit 80505ad

Please sign in to comment.