fix(pidfile): replace path.Dir with filepath.Dir for cross-platform compat

- pidfile.go: use filepath.Dir instead of POSIX-only path.Dir (line 55)
- pidfile.go: simplify redundant bytes/string conversions to strings.TrimSpace (lines 44, 105)
- docs/RFC.md: add language identifiers to four untyped fenced code blocks (MD040)
- specs/api/RFC.md: update NewProvider signature to 3-arg form matching implementation

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-04-07 08:59:29 +01:00
parent e41799b320
commit e9b85ae817
3 changed files with 10 additions and 10 deletions

View file

@ -14,7 +14,7 @@
go-process provides the implementation behind `c.Process()`. Core defines the primitive (Section 17). go-process registers the Action handlers that make it work.
```
```text
core/go defines: c.Process().Run(ctx, "git", "log")
→ calls c.Action("process.run").Run(ctx, opts)
@ -37,7 +37,7 @@ The codebase now matches the v0.8.0 target. The bullets below are the historical
### File Layout
```
```text
service.go — main service (factory, lifecycle, process execution)
registry.go — daemon registry (PID files, health, restart)
daemon.go — DaemonEntry, managed daemon lifecycle
@ -233,7 +233,7 @@ func (p *ManagedProcess) Info() ProcessInfo {
Higher-level abstraction over `process.start`:
```
```text
process.start → low level: start a command, get a handle
daemon.Start → high level: PID file, health endpoint, restart policy, signals
```
@ -256,7 +256,7 @@ return core.Result{Value: core.E("process.run", core.Concat("command failed: ",
AX-7: `TestFile_Function_{Good,Bad,Ugly}`
```
```text
TestService_Register_Good — factory returns Result
TestService_OnStartup_Good — registers 5 Actions
TestService_HandleRun_Good — runs command, returns output

View file

@ -1,9 +1,9 @@
package process
import (
"bytes"
"path"
"path/filepath"
"strconv"
"strings"
"sync"
"syscall"
@ -41,7 +41,7 @@ func (p *PIDFile) Acquire() error {
defer p.mu.Unlock()
if data, err := coreio.Local.Read(p.path); err == nil {
pid, err := strconv.Atoi(string(bytes.TrimSpace([]byte(data))))
pid, err := strconv.Atoi(strings.TrimSpace(data))
if err == nil && pid > 0 {
if proc, err := processHandle(pid); err == nil {
if err := proc.Signal(syscall.Signal(0)); err == nil {
@ -52,7 +52,7 @@ func (p *PIDFile) Acquire() error {
_ = coreio.Local.Delete(p.path)
}
if dir := path.Dir(p.path); dir != "." {
if dir := filepath.Dir(p.path); dir != "." {
if err := coreio.Local.EnsureDir(dir); err != nil {
return core.E("pidfile.acquire", "failed to create PID directory", err)
}
@ -102,7 +102,7 @@ func ReadPID(path string) (int, bool) {
return 0, false
}
pid, err := strconv.Atoi(string(bytes.TrimSpace([]byte(data))))
pid, err := strconv.Atoi(strings.TrimSpace(data))
if err != nil || pid <= 0 {
return 0, false
}

View file

@ -16,7 +16,7 @@ Exported fields:
### Package Functions
- `func NewProvider(registry *process.Registry, hub *ws.Hub) *ProcessProvider`: Returns a `ProcessProvider` for the supplied registry and WebSocket hub. When `registry` is `nil`, it uses `process.DefaultRegistry()`.
- `func NewProvider(registry *process.Registry, service *process.Service, hub *ws.Hub) *ProcessProvider`: Returns a `ProcessProvider` for the supplied registry, optional process service, and WebSocket hub. When `registry` is `nil`, it uses `process.DefaultRegistry()`. When `service` is non-`nil`, provider-runner features are enabled.
- `func PIDAlive(pid int) bool`: Returns `false` for non-positive PIDs and otherwise reports whether `os.FindProcess(pid)` followed by signal `0` succeeds.
### `ProcessProvider` Methods