feat: integrate new agentexec pkg (#15609)

- Integrates the `agentexec` pkg into the agent and removes the
legacy system of iterating over the process tree. It adds some linting
rules to hopefully catch future improper uses of `exec.Command` in the package.
This commit is contained in:
Jon Ayers
2024-11-27 20:12:15 +02:00
committed by GitHub
parent 45d9274aca
commit 1f238fed59
22 changed files with 147 additions and 1176 deletions
+36
View File
@@ -487,3 +487,39 @@ func workspaceActivity(m dsl.Matcher) {
!m.File().Name.Matches(`_test\.go$`),
).Report("Updating workspace activity should always be done in the workspacestats package.")
}
// noExecInAgent ensures that packages under agent/ don't use exec.Command or
// exec.CommandContext directly.
//
//nolint:unused,deadcode,varnamelen
func noExecInAgent(m dsl.Matcher) {
m.Import("os/exec")
m.Match(
`exec.Command($*_)`,
`exec.CommandContext($*_)`,
).
Where(
m.File().PkgPath.Matches("/agent/") &&
!m.File().PkgPath.Matches("/agentexec") &&
!m.File().Name.Matches(`_test\.go$`),
).
Report("The agent and its subpackages should not use exec.Command or exec.CommandContext directly. Consider using agentexec.CommandContext instead.")
}
// noPTYInAgent ensures that packages under agent/ don't use pty.Command or
// pty.CommandContext directly.
//
//nolint:unused,deadcode,varnamelen
func noPTYInAgent(m dsl.Matcher) {
m.Import("github.com/coder/coder/v2/pty")
m.Match(
`pty.Command($*_)`,
`pty.CommandContext($*_)`,
).
Where(
m.File().PkgPath.Matches(`/agent/`) &&
!m.File().PkgPath.Matches(`/agentexec`) &&
!m.File().Name.Matches(`_test\.go$`),
).
Report("The agent and its subpackages should not use pty.Command or pty.CommandContext directly. Consider using agentexec.PTYCommandContext instead.")
}