mirror of
https://github.com/Twigpine/zero.git
synced 2026-11-08 09:49:34 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
772419f8ba | ||
|
|
5476250061 |
No files matched your search
@@ -775,12 +775,20 @@ func (tool writeStdinTool) Run(ctx context.Context, args map[string]any) Result
|
||||
}
|
||||
|
||||
func (tool writeStdinTool) RunWithOptions(ctx context.Context, args map[string]any, _ RunOptions) Result {
|
||||
if value, ok := args["session_id"]; !ok || value == nil {
|
||||
return errorResult("Error: Invalid arguments for write_stdin: session_id is required")
|
||||
}
|
||||
sessionID, err := intArg(args, "session_id", 0, 1, 0)
|
||||
if err != nil {
|
||||
return errorResult("Error: Invalid arguments for write_stdin: " + err.Error())
|
||||
// A missing, non-integer, or < 1 session_id all mean the same thing: the model
|
||||
// has no live session to write to. Route them to the SAME recovery guidance the
|
||||
// no-live-session case uses (UnknownExecSessionError) instead of a terse
|
||||
// "session_id must be at least 1". The terse error gives no way forward and, by
|
||||
// naming the minimum, nudges the model to try 1, 2, 3... — the exact id-probing
|
||||
// #749 works to suppress. The recovery message instead tells it to start a
|
||||
// session or edit files directly, and because that message is id-invariant, the
|
||||
// missing/zero/non-integer entry points and id-probing collapse to ONE
|
||||
// repeated-failure signature, so any mix of them accumulates toward the halt
|
||||
// rather than resetting the streak on each class of mistake.
|
||||
value, present := args["session_id"]
|
||||
sessionID, sessionErr := intArg(args, "session_id", 0, 1, 0)
|
||||
if !present || value == nil || sessionErr != nil {
|
||||
return errorResult(UnknownExecSessionError(sessionID))
|
||||
}
|
||||
chars, err := stringArgWithEmpty(args, "chars", "", false, true)
|
||||
if err != nil {
|
||||
|
||||
@@ -923,19 +923,35 @@ func TestWriteStdinSchemaPinsSessionIDMinimum(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A missing, zero, negative, or non-integer session_id all mean the model has no
|
||||
// live session, so write_stdin returns the SAME recovery guidance the no-live-
|
||||
// session case uses (start a session with exec_command, or edit files directly),
|
||||
// not a terse "session_id must be at least 1" that gives no way forward and names
|
||||
// a minimum that nudges the model to probe ids 1, 2, 3... Sharing one id-invariant
|
||||
// message also keeps a single repeated-failure signature, so any mix of these
|
||||
// mistakes accumulates toward the halt instead of resetting the streak (#749).
|
||||
func TestWriteStdinRequiresPositiveSessionID(t *testing.T) {
|
||||
tool := NewWriteStdinTool(newExecSessionManager())
|
||||
for _, args := range []map[string]any{
|
||||
{},
|
||||
{"session_id": 0},
|
||||
want := UnknownExecSessionError(0)
|
||||
for name, args := range map[string]map[string]any{
|
||||
"missing": {},
|
||||
"nil": {"session_id": nil},
|
||||
"zero": {"session_id": 0},
|
||||
"negative": {"session_id": -3},
|
||||
"non-integer": {"session_id": "abc"},
|
||||
} {
|
||||
result := tool.Run(context.Background(), args)
|
||||
if result.Status != StatusError {
|
||||
t.Fatalf("Run(%#v) status = %s, want error", args, result.Status)
|
||||
}
|
||||
if !strings.Contains(result.Output, "Invalid arguments for write_stdin") {
|
||||
t.Fatalf("Run(%#v) output = %q, want invalid arguments", args, result.Output)
|
||||
}
|
||||
t.Run(name, func(t *testing.T) {
|
||||
result := tool.Run(context.Background(), args)
|
||||
if result.Status != StatusError {
|
||||
t.Fatalf("status = %s, want error", result.Status)
|
||||
}
|
||||
if result.Output != want {
|
||||
t.Fatalf("output = %q,\n want the recovery message %q", result.Output, want)
|
||||
}
|
||||
if strings.Contains(result.Output, "must be at least 1") {
|
||||
t.Fatalf("still returns the terse minimum error: %q", result.Output)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user