Detect Go entrypoints under cmd directories#330
Conversation
🧪 Testing GuideWhat this PR addressesGo projects that use the common Steps to reproduce the original issue
What to verify (expected behavior)
Note Posted by PR Testing Guide · Tag @mendral-app with feedback. |
|
✅ Linked to Linear issue ENG-2846 — status: In Progress
Note Posted by Linear Issue Enforcer · Tag @mendral-app with feedback. |
🔍 Interaction FlowHere's how the new sequenceDiagram
participant User as User / CLI
participant Cmd as findGoRootCmdAsString<br/>(commands_go.go)
participant Core as FindGoEntryFile<br/>(core/utils.go)
participant FS as Filesystem
participant Helper as goRunTargetFromEntryFile<br/>(commands_go.go)
User->>Cmd: bl serve / bl deploy
Cmd->>Cmd: Check explicit entrypoint config
alt Explicit config exists
Cmd-->>User: Return configured command
else No explicit config
Cmd->>Core: FindGoEntryFile(folder)
Core->>FS: Check main.go, src/main.go, cmd/main.go
alt Conventional file found
FS-->>Core: Found (e.g. main.go)
Core-->>Cmd: Return path
else No conventional file
Core->>FS: Glob cmd/*/main.go
alt Single match
FS-->>Core: e.g. cmd/api/main.go
Core-->>Cmd: Return path
else Multiple matches
FS-->>Core: cmd/a/main.go, cmd/b/main.go
Core-->>Cmd: Error (ambiguous)
Cmd-->>User: Error: configure [entrypoint] prod
else No matches
Core-->>Cmd: "" (empty)
Cmd-->>User: Error: entrypoint not found
end
end
Cmd->>Helper: goRunTargetFromEntryFile(path)
Helper-->>Cmd: "./cmd/api"
Cmd-->>User: ["go", "run", "./cmd/api"]
end
SummaryThe PR adds a fallback discovery step for Go entrypoints:
The Note Posted by PR Sequence Diagram · Tag @mendral-app with feedback. |
There was a problem hiding this comment.
LGTM
The new commit adds proper input validation via a restrictive regex (^cmd/[A-Za-z0-9_.-]+/main\.go$) before constructing the go run target, closing a potential command injection vector. Tests cover the injection scenario directly. No issues.
Tag @mendral-app with feedback or questions. View session


Detects Go entrypoints under
cmd/*/main.goso existing Go projects can run without adding a manual prod entrypoint.cmd/*/main.gofallback discovery for Go serve/deploy flows.Refs ENG-2846.
Note
Adds a security guard (
safeGoCmdEntrypointPatternregex) to the Go cmd entrypoint autodetection, rejecting directory names with shell-unsafe characters and providing actionable error messages pointing users to explicit config.Written by Mendral for commit ec4875a.