fix: dogfood auto_pr_test + status_logic_test — eliminate os + encoding/json
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
76b167a874
commit
12588e8b4e
2 changed files with 16 additions and 39 deletions
|
|
@ -3,8 +3,6 @@
|
|||
package agentic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
"time"
|
||||
|
|
@ -30,39 +28,27 @@ func TestAutoPR_AutoCreatePR_Bad(t *testing.T) {
|
|||
|
||||
// No status file → early return (no panic)
|
||||
wsNoStatus := core.JoinPath(root, "ws-no-status")
|
||||
require.NoError(t, os.MkdirAll(wsNoStatus, 0o755))
|
||||
fs.EnsureDir(wsNoStatus)
|
||||
assert.NotPanics(t, func() {
|
||||
s.autoCreatePR(wsNoStatus)
|
||||
})
|
||||
|
||||
// Empty branch → early return
|
||||
wsNoBranch := core.JoinPath(root, "ws-no-branch")
|
||||
require.NoError(t, os.MkdirAll(wsNoBranch, 0o755))
|
||||
st := &WorkspaceStatus{
|
||||
Status: "completed",
|
||||
Agent: "codex",
|
||||
Repo: "go-io",
|
||||
Branch: "",
|
||||
}
|
||||
data, err := json.MarshalIndent(st, "", " ")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(core.JoinPath(wsNoBranch, "status.json"), data, 0o644))
|
||||
fs.EnsureDir(wsNoBranch)
|
||||
fs.Write(core.JoinPath(wsNoBranch, "status.json"), core.JSONMarshalString(&WorkspaceStatus{
|
||||
Status: "completed", Agent: "codex", Repo: "go-io", Branch: "",
|
||||
}))
|
||||
assert.NotPanics(t, func() {
|
||||
s.autoCreatePR(wsNoBranch)
|
||||
})
|
||||
|
||||
// Empty repo → early return
|
||||
wsNoRepo := core.JoinPath(root, "ws-no-repo")
|
||||
require.NoError(t, os.MkdirAll(wsNoRepo, 0o755))
|
||||
st2 := &WorkspaceStatus{
|
||||
Status: "completed",
|
||||
Agent: "codex",
|
||||
Repo: "",
|
||||
Branch: "agent/fix-tests",
|
||||
}
|
||||
data2, err := json.MarshalIndent(st2, "", " ")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(core.JoinPath(wsNoRepo, "status.json"), data2, 0o644))
|
||||
fs.EnsureDir(wsNoRepo)
|
||||
fs.Write(core.JoinPath(wsNoRepo, "status.json"), core.JSONMarshalString(&WorkspaceStatus{
|
||||
Status: "completed", Agent: "codex", Repo: "", Branch: "agent/fix-tests",
|
||||
}))
|
||||
assert.NotPanics(t, func() {
|
||||
s.autoCreatePR(wsNoRepo)
|
||||
})
|
||||
|
|
@ -75,7 +61,7 @@ func TestAutoPR_AutoCreatePR_Ugly(t *testing.T) {
|
|||
// Set up a real git repo with no commits ahead of origin/dev
|
||||
wsDir := core.JoinPath(root, "ws-no-ahead")
|
||||
repoDir := core.JoinPath(wsDir, "repo")
|
||||
require.NoError(t, os.MkdirAll(repoDir, 0o755))
|
||||
fs.EnsureDir(repoDir)
|
||||
|
||||
// Init the repo
|
||||
cmd := exec.Command("git", "init", "-b", "dev", repoDir)
|
||||
|
|
@ -85,7 +71,7 @@ func TestAutoPR_AutoCreatePR_Ugly(t *testing.T) {
|
|||
cmd = exec.Command("git", "-C", repoDir, "config", "user.email", "test@test.com")
|
||||
require.NoError(t, cmd.Run())
|
||||
|
||||
require.NoError(t, os.WriteFile(core.JoinPath(repoDir, "README.md"), []byte("# test"), 0o644))
|
||||
fs.Write(core.JoinPath(repoDir, "README.md"), "# test")
|
||||
cmd = exec.Command("git", "-C", repoDir, "add", ".")
|
||||
require.NoError(t, cmd.Run())
|
||||
cmd = exec.Command("git", "-C", repoDir, "commit", "-m", "init")
|
||||
|
|
@ -99,9 +85,7 @@ func TestAutoPR_AutoCreatePR_Ugly(t *testing.T) {
|
|||
Branch: "agent/fix-tests",
|
||||
StartedAt: time.Now(),
|
||||
}
|
||||
data, err := json.MarshalIndent(st, "", " ")
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.WriteFile(core.JoinPath(wsDir, "status.json"), data, 0o644))
|
||||
fs.Write(core.JoinPath(wsDir, "status.json"), core.JSONMarshalString(st))
|
||||
|
||||
s := &PrepSubsystem{
|
||||
ServiceRuntime: core.NewServiceRuntime(testCore, AgentOptions{}),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
package agentic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
|
@ -33,9 +32,7 @@ func TestStatus_ReadStatus_Good_AllFields(t *testing.T) {
|
|||
Runs: 2,
|
||||
PRURL: "",
|
||||
}
|
||||
data, err := json.MarshalIndent(original, "", " ")
|
||||
require.NoError(t, err)
|
||||
require.True(t, fs.Write(core.JoinPath(dir, "status.json"), string(data)).OK)
|
||||
require.True(t, fs.Write(core.JoinPath(dir, "status.json"), core.JSONMarshalString(original)).OK)
|
||||
|
||||
st, err := ReadStatus(dir)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -140,11 +137,10 @@ func TestWorkspaceStatus_Good_JSONRoundTrip(t *testing.T) {
|
|||
PRURL: "https://forge.lthn.ai/core/agent/pulls/10",
|
||||
}
|
||||
|
||||
data, err := json.Marshal(original)
|
||||
require.NoError(t, err)
|
||||
jsonStr := core.JSONMarshalString(original)
|
||||
|
||||
var decoded WorkspaceStatus
|
||||
require.NoError(t, json.Unmarshal(data, &decoded))
|
||||
require.True(t, core.JSONUnmarshalString(jsonStr, &decoded).OK)
|
||||
|
||||
assert.Equal(t, original.Status, decoded.Status)
|
||||
assert.Equal(t, original.Agent, decoded.Agent)
|
||||
|
|
@ -162,11 +158,8 @@ func TestWorkspaceStatus_Good_JSONRoundTrip(t *testing.T) {
|
|||
func TestWorkspaceStatus_Good_OmitemptyFields(t *testing.T) {
|
||||
st := WorkspaceStatus{Status: "queued", Agent: "claude"}
|
||||
|
||||
data, err := json.Marshal(st)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Optional fields with omitempty must be absent when zero
|
||||
jsonStr := string(data)
|
||||
jsonStr := core.JSONMarshalString(st)
|
||||
assert.NotContains(t, jsonStr, `"org"`)
|
||||
assert.NotContains(t, jsonStr, `"branch"`)
|
||||
assert.NotContains(t, jsonStr, `"question"`)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue