Improve approval and sandbox flows

This commit is contained in:
Codex
2026-05-28 11:17:40 +00:00
parent 44384a90c7
commit 372d5831fa
4 changed files with 496 additions and 47 deletions
+59 -1
View File
@@ -371,6 +371,57 @@ func TestRenderApprovalDetailsAvoidsRawJSONDump(t *testing.T) {
}
}
func TestRenderApprovalDetailsSummarizesPolicyFields(t *testing.T) {
raw := json.RawMessage(`{
"command":"git push gitea master",
"cwd":"/workspace/project",
"reason":"Need to publish changes",
"proposedExecpolicyAmendment":["git","push","gitea","master"],
"availableDecisions":[
{"acceptWithExecpolicyAmendment":{"execpolicy_amendment":["git","push","gitea","master"]}},
"decline"
]
}`)
text := renderApprovalHTML("item/commandExecution/requestApproval", raw, "")
for _, want := range []string{"Proposed command rule", "git push gitea master", "Available decisions", "Approve rule", "Deny"} {
if !strings.Contains(text, want) {
t.Fatalf("approval render missing concise field %q in %q", want, text)
}
}
for _, unwanted := range []string{"execpolicy_amendment", "acceptWithExecpolicyAmendment", "availableDecisions"} {
if strings.Contains(text, unwanted) {
t.Fatalf("approval render still contains verbose field %q in %q", unwanted, text)
}
}
if strings.Count(text, "Need to publish changes") != 1 {
t.Fatalf("reason should only appear once in summary: %q", text)
}
}
func TestCombinedCommandApprovalOmitsDuplicateCommandDetails(t *testing.T) {
toolHTML := renderCodexItemStarted(codexThreadItemView{
Type: "commandExecution",
Command: "go test ./...",
CWD: "/workspace/project",
})
approvalHTML := renderApprovalHTML("item/commandExecution/requestApproval", json.RawMessage(`{
"command":"go test ./...",
"cwd":"/workspace/project",
"reason":"Need to run tests"
}`), "")
text := combineToolApprovalHTML(toolHTML, approvalHTML)
for _, want := range []string{"Tool call: command started", "Codex requests command approval", "Need to run tests"} {
if !strings.Contains(text, want) {
t.Fatalf("combined approval missing %q in %q", want, text)
}
}
for _, duplicate := range []string{"<b>CWD:</b>", "<b>Command:</b>"} {
if got := strings.Count(text, duplicate); got != 1 {
t.Fatalf("%s count = %d, want 1 in %q", duplicate, got, text)
}
}
}
func TestApprovalOnlyToolMessageCanReceiveCompletionDetails(t *testing.T) {
exitCode := 0
duration := int64(1234)
@@ -464,7 +515,7 @@ func TestResumeThreadListText(t *testing.T) {
}
}
func TestModelAndEffortCallbackData(t *testing.T) {
func TestModelEffortAndSandboxCallbackData(t *testing.T) {
modelID := strings.Join([]string{"server", "model", "id"}, "-")
data, ok := ModelCallbackData(modelID)
if !ok {
@@ -479,4 +530,11 @@ func TestModelAndEffortCallbackData(t *testing.T) {
if !ok || effort != effortName {
t.Fatalf("unexpected effort callback parse: effort=%q ok=%v", effort, ok)
}
sandbox, ok := ParseSandboxCallbackData(SandboxCallbackData("workspace-write"))
if !ok || sandbox != "workspace-write" {
t.Fatalf("unexpected sandbox callback parse: sandbox=%q ok=%v", sandbox, ok)
}
if _, ok := ParseSandboxCallbackData(SandboxCallbackData("bad")); ok {
t.Fatal("bad sandbox callback should not parse")
}
}