fix: dogfood handlers_test + commands_workspace_test

os.MkdirAll→fs.EnsureDir, os.WriteFile→fs.Write,
json.Marshal→core.JSONMarshalString, os.Stat→fs.Exists/fs.IsDir.
Both files now free of os + encoding/json.

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Snider 2026-03-26 01:55:57 +00:00
parent 56981772c7
commit 7be229d40d
2 changed files with 17 additions and 26 deletions

View file

@ -3,8 +3,6 @@
package agentic
import (
"encoding/json"
"os"
"testing"
"time"
@ -89,21 +87,20 @@ func TestCommandsWorkspace_CmdWorkspaceList_Ugly_NonDirAndCorruptStatus(t *testi
root := t.TempDir()
t.Setenv("CORE_WORKSPACE", root)
wsRoot := core.JoinPath(root, "workspace")
os.MkdirAll(wsRoot, 0o755)
fs.EnsureDir(wsRoot)
// Non-directory entry in workspace root
os.WriteFile(core.JoinPath(wsRoot, "stray-file.txt"), []byte("not a workspace"), 0o644)
fs.Write(core.JoinPath(wsRoot, "stray-file.txt"), "not a workspace")
// Workspace with corrupt status.json
wsCorrupt := core.JoinPath(wsRoot, "ws-corrupt")
os.MkdirAll(wsCorrupt, 0o755)
os.WriteFile(core.JoinPath(wsCorrupt, "status.json"), []byte("{broken json!!!"), 0o644)
fs.EnsureDir(wsCorrupt)
fs.Write(core.JoinPath(wsCorrupt, "status.json"), "{broken json!!!")
// Valid workspace
wsGood := core.JoinPath(wsRoot, "ws-good")
os.MkdirAll(wsGood, 0o755)
data, _ := json.Marshal(WorkspaceStatus{Status: "running", Repo: "go-io", Agent: "codex"})
os.WriteFile(core.JoinPath(wsGood, "status.json"), data, 0o644)
fs.EnsureDir(wsGood)
fs.Write(core.JoinPath(wsGood, "status.json"), core.JSONMarshalString(WorkspaceStatus{Status: "running", Repo: "go-io", Agent: "codex"}))
c := core.New()
s := &PrepSubsystem{
@ -130,9 +127,8 @@ func TestCommandsWorkspace_CmdWorkspaceClean_Bad_UnknownFilterLeavesEverything(t
{"ws-run", "running"},
} {
d := core.JoinPath(wsRoot, ws.name)
os.MkdirAll(d, 0o755)
data, _ := json.Marshal(WorkspaceStatus{Status: ws.status, Repo: "test", Agent: "codex"})
os.WriteFile(core.JoinPath(d, "status.json"), data, 0o644)
fs.EnsureDir(d)
fs.Write(core.JoinPath(d, "status.json"), core.JSONMarshalString(WorkspaceStatus{Status: ws.status, Repo: "test", Agent: "codex"}))
}
c := core.New()
@ -148,8 +144,7 @@ func TestCommandsWorkspace_CmdWorkspaceClean_Bad_UnknownFilterLeavesEverything(t
// All workspaces should still exist
for _, name := range []string{"ws-done", "ws-fail", "ws-run"} {
_, err := os.Stat(core.JoinPath(wsRoot, name))
assert.NoError(t, err, "workspace %s should still exist", name)
assert.True(t, fs.IsDir(core.JoinPath(wsRoot, name)), "workspace %s should still exist", name)
}
}
@ -167,9 +162,8 @@ func TestCommandsWorkspace_CmdWorkspaceClean_Ugly_MixedStatuses(t *testing.T) {
{"ws-blocked", "blocked"},
} {
d := core.JoinPath(wsRoot, ws.name)
os.MkdirAll(d, 0o755)
data, _ := json.Marshal(WorkspaceStatus{Status: ws.status, Repo: "test", Agent: "codex"})
os.WriteFile(core.JoinPath(d, "status.json"), data, 0o644)
fs.EnsureDir(d)
fs.Write(core.JoinPath(d, "status.json"), core.JSONMarshalString(WorkspaceStatus{Status: ws.status, Repo: "test", Agent: "codex"}))
}
c := core.New()
@ -185,13 +179,11 @@ func TestCommandsWorkspace_CmdWorkspaceClean_Ugly_MixedStatuses(t *testing.T) {
// merged, ready-for-review, blocked should be removed
for _, name := range []string{"ws-merged", "ws-review", "ws-blocked"} {
_, err := os.Stat(core.JoinPath(wsRoot, name))
assert.True(t, os.IsNotExist(err), "workspace %s should be removed", name)
assert.False(t, fs.Exists(core.JoinPath(wsRoot, name)), "workspace %s should be removed", name)
}
// running and queued should remain
for _, name := range []string{"ws-running", "ws-queued"} {
_, err := os.Stat(core.JoinPath(wsRoot, name))
assert.NoError(t, err, "workspace %s should still exist", name)
assert.True(t, fs.IsDir(core.JoinPath(wsRoot, name)), "workspace %s should still exist", name)
}
}

View file

@ -4,7 +4,6 @@ package agentic
import (
"context"
"os"
"testing"
"time"
@ -73,11 +72,11 @@ func TestHandlers_RegisterHandlers_Good_QAFailsUpdatesStatus(t *testing.T) {
wsName := "core/test/task-1"
wsDir := core.JoinPath(root, wsName)
repoDir := core.JoinPath(wsDir, "repo")
os.MkdirAll(repoDir, 0o755)
fs.EnsureDir(repoDir)
// Create a Go project that will fail vet/build
os.WriteFile(core.JoinPath(repoDir, "go.mod"), []byte("module test\n\ngo 1.22\n"), 0o644)
os.WriteFile(core.JoinPath(repoDir, "main.go"), []byte("package main\nimport \"fmt\"\n"), 0o644)
fs.Write(core.JoinPath(repoDir, "go.mod"), "module test\n\ngo 1.22\n")
fs.Write(core.JoinPath(repoDir, "main.go"), "package main\nimport \"fmt\"\n")
st := &WorkspaceStatus{
Status: "completed",
@ -109,7 +108,7 @@ func TestHandlers_RegisterHandlers_Good_IngestOnCompletion(t *testing.T) {
wsName := "core/test/task-2"
wsDir := core.JoinPath(root, wsName)
repoDir := core.JoinPath(wsDir, "repo")
os.MkdirAll(repoDir, 0o755)
fs.EnsureDir(repoDir)
st := &WorkspaceStatus{
Status: "completed",