Read-only enforcement applies to stages with shell but no edit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-03 12:55:10 +00:00
parent 87016ef5dc
commit 57ea922c59
7 changed files with 22 additions and 17 deletions
+1 -1
View File
@@ -126,7 +126,7 @@ func TestChatTurnDiffMarksBoundedPatchesTruncated(t *testing.T) {
dir := gitRepo(t, map[string]string{"a.txt": "x\n"})
h := turnDiffHub(t, dir)
h.startRoomTurnDiff("ses_1")
writeTurnFile(t, dir, "big.txt", strings.Repeat("line\n", 6000))
writeTurnFile(t, dir, "big.txt", strings.Repeat("line\n", 21000))
endDiffTurn(h, "ses_1")
turns := recordedTurns(t, h, "ses_1")
if len(turns) != 1 || !turns[0].Truncated || turns[0].Files != 1 || turns[0].Status != "partial" {
+13 -6
View File
@@ -68,20 +68,27 @@ func checkVerdict(output stage.Values) *protocol.StageVerdict {
return &protocol.StageVerdict{Reason: summary, ReasonSource: protocol.VerdictReasonFallback}
}
// readOnlyViolation reports the files a stage without edit left changed in
// the run directory. Paths under the stage's artifacts directory, the run's
// shared public directory and a harness state directory that lives inside the
// workspace (for example CLAUDE_CONFIG_DIR) are the harness's or the run's own
// and are not counted. It returns "" when the stage may change files or none
// changed.
// readOnlyViolation reports the files a stage with shell but without edit
// left changed in the run directory: its shell is for reading, testing and
// committing, not for writing. A stage without shell cannot write at all (a
// change during it is not its own), and a stage with edit may write. Paths
// under the stage's artifacts directory, the run's shared public directory and
// a harness state directory that lives inside the workspace (for example
// CLAUDE_CONFIG_DIR) are the harness's or the run's own and are not counted.
// It returns "" when the stage may change files or none changed.
func readOnlyViolation(def stage.Definition, tools []string, explicitTools bool, changes *protocol.StageFileChanges, workspace string, ignored []string) string {
if stage.EffectiveType(def.Type) != stage.ModelType || !explicitTools || def.Configs["allow_workspace_changes"] == "true" || changes == nil {
return ""
}
shell := false
for _, tool := range tools {
if tool == "edit" {
return ""
}
shell = shell || tool == "shell"
}
if !shell {
return ""
}
var prefixes []string
for _, dir := range ignored {
+2 -1
View File
@@ -195,7 +195,8 @@ func TestReadOnlyViolationIgnoresHarnessAndRunDirectories(t *testing.T) {
t.Fatal(v)
}
for name, ok := range map[string]bool{
"edit tool": readOnlyViolation(def, []string{"edit"}, true, changes, "/w", nil) == "",
"edit tool": readOnlyViolation(def, []string{"edit", "shell"}, true, changes, "/w", nil) == "",
"no shell (cannot write)": readOnlyViolation(def, []string{"read"}, true, changes, "/w", nil) == "",
"no tools block (legacy bundle)": readOnlyViolation(def, nil, false, changes, "/w", nil) == "",
} {
if !ok {
+2 -5
View File
@@ -597,10 +597,7 @@ esac
runStage := func(name, tools string) (status, sessions, diagnostic string) {
t.Helper()
workspace := t.TempDir()
// The fake harness keeps its counters outside the workspace: a read-only
// stage must leave the run directory unchanged.
state := t.TempDir()
script := strings.ReplaceAll(scriptTemplate, "@STATE@", state)
script := strings.ReplaceAll(scriptTemplate, "@STATE@", workspace)
if err := os.WriteFile(executable, []byte(script), 0700); err != nil {
t.Fatal(err)
}
@@ -626,7 +623,7 @@ esac
if len(detail.Steps) > 0 {
diagnostic = detail.Steps[0].Diagnostic
}
if data, err := os.ReadFile(filepath.Join(state, "sessions")); err == nil {
if data, err := os.ReadFile(filepath.Join(workspace, "sessions")); err == nil {
sessions = strings.TrimSpace(string(data))
}
return detail.Status, sessions, diagnostic