diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 68cdc354..2474c7a2 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -898,11 +898,11 @@ func TestTestResolveMetadataInJsonStrWithPackage(t *testing.T) { assert.Equal(t, err, nil) assert.Equal(t, res, string(expectedDepStr)) - + defer func() { err = os.RemoveAll(vendorDir) assert.Equal(t, err, nil) - } () + }() } func TestPkgWithInVendorMode(t *testing.T) { @@ -1212,7 +1212,7 @@ func TestRunWithGitPackage(t *testing.T) { assert.Equal(t, err, nil) expectedCompileResult := `{"apiVersion": "v1", "kind": "Pod", "metadata": {"name": "web-app"}, "spec": {"containers": [{"image": "nginx", "name": "main-container", "ports": [{"containerPort": 80}]}]}}` assert.Equal(t, expectedCompileResult, compileResult.GetRawJsonResult()) - + assert.Equal(t, utils.DirExists(filepath.Join(pkgPath, "kcl.mod.lock")), true) defer func() { @@ -2130,6 +2130,10 @@ func TestRunLocalWithArgs(t *testing.T) { }, []string{ filepath.Join(pkgPath, "with_args", "run_11", "sub", "kcl.yaml"), }, "", false, "", "The_sub_kcl_program: Hello Sub World!"}, + {[]string{ + filepath.Join(pkgPath, "with_args", "run_12", "sub1", "main.k"), + filepath.Join(pkgPath, "with_args", "run_12", "sub2", "main.k"), + }, []string{}, "", false, "", "sub1: 1\nsub2: 2"}, } for _, test := range tests { diff --git a/pkg/client/run.go b/pkg/client/run.go index dd480b7f..b7765331 100644 --- a/pkg/client/run.go +++ b/pkg/client/run.go @@ -507,7 +507,8 @@ func (o *RunOptions) getPkgSource() (*downloader.Source, error) { ) } - if !pkgSource.IsPackaged() && !source.IsPackaged() { + if !pkgSource.IsPackaged() && !source.IsPackaged() && + pkgSource.IsLocalPkg() && source.IsLocalPkg() { tmpRootPath, err := source.FindRootPath() if err != nil { return nil, err diff --git a/pkg/client/test_data/test_run_options/with_args/run_12/sub1/main.k b/pkg/client/test_data/test_run_options/with_args/run_12/sub1/main.k new file mode 100644 index 00000000..03b1da2b --- /dev/null +++ b/pkg/client/test_data/test_run_options/with_args/run_12/sub1/main.k @@ -0,0 +1 @@ +sub1 = 1 \ No newline at end of file diff --git a/pkg/client/test_data/test_run_options/with_args/run_12/sub2/main.k b/pkg/client/test_data/test_run_options/with_args/run_12/sub2/main.k new file mode 100644 index 00000000..2ec11cbe --- /dev/null +++ b/pkg/client/test_data/test_run_options/with_args/run_12/sub2/main.k @@ -0,0 +1 @@ +sub2 = 2 \ No newline at end of file diff --git a/pkg/downloader/source.go b/pkg/downloader/source.go index e9274340..7c173a74 100644 --- a/pkg/downloader/source.go +++ b/pkg/downloader/source.go @@ -77,6 +77,14 @@ func (source *Source) IsPackaged() bool { return source.IsLocalTarPath() || source.Git != nil || source.Oci != nil || source.Registry != nil } +// If the source is a local path, check if it is a real local package(a directory with kcl.mod file). +func (source *Source) IsLocalPkg() bool { + if source.IsLocalPath() { + return utils.DirExists(filepath.Join(source.Local.Path, constants.KCL_MOD)) + } + return false +} + func (source *Source) FindRootPath() (string, error) { if source == nil { return "", fmt.Errorf("source is nil")