fix(cli): build from module root ("go build .") instead of "./cmd/molecule"

Go 1.25 resolves "./cmd/molecule" relative to cmd.Dir as an absolute path
under the CWD, producing the doubled "cmd/molecule/cmd/molecule" error.
Building the whole module from the root and relying on the binary name
from -o is the idiomatic Go approach and avoids path arithmetic entirely.

Also tightened error message to match the new command.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Molecule AI · sdk-dev 2026-04-22 19:12:49 +00:00
parent 7b254c926c
commit 1ebe5fa999

View File

@ -203,11 +203,14 @@ func repoRoot() string {
func mol(t *testing.T) string {
root := repoRoot()
exe := filepath.Join(t.TempDir(), "molecule")
cmd := exec.Command("go", "build", "-o", exe, "./cmd/molecule")
// Build from the module root (where go.mod lives).
// "go build ." packages the whole module; ./cmd/molecule is unnecessary
// and Go 1.25 may resolve it differently.
cmd := exec.Command("go", "build", "-o", exe, ".")
cmd.Dir = root
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("go build ./cmd/molecule: %v\n%s", err, out)
t.Fatalf("go build: %v\n%s", err, out)
}
return exe
}