| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/provider" |
| 9 | "reasonix/internal/tool" |
| 10 | ) |
| 11 | |
| 12 | type secretOutputTool struct{} |
| 13 | |
| 14 | func (secretOutputTool) Name() string { return "secret_output" } |
| 15 | func (secretOutputTool) Description() string { return "" } |
| 16 | func (secretOutputTool) Schema() json.RawMessage { return json.RawMessage(`{"type":"object"}`) } |
| 17 | func (secretOutputTool) ReadOnly() bool { return true } |
| 18 | func (secretOutputTool) Execute(context.Context, json.RawMessage) (string, error) { |
| 19 | return "DEEPSEEK_API_KEY=sk-real-secret-value-123456\n", nil |
| 20 | } |
| 21 | |
| 22 | func TestExecuteOnePreservesToolResultBeforeHistory(t *testing.T) { |
| 23 | reg := tool.NewRegistry() |
| 24 | reg.Add(secretOutputTool{}) |
| 25 | a := &Agent{tools: reg, session: NewSession("")} |
| 26 | |
| 27 | outcome := a.executeOne(context.Background(), provider.ToolCall{ID: "call_1", Name: "secret_output", Arguments: `{}`}) |
| 28 | const want = "DEEPSEEK_API_KEY=sk-real-secret-value-123456\n" |
| 29 | if outcome.output != want { |
| 30 | t.Fatalf("tool outcome = %q, want byte-preserving output %q", outcome.output, want) |
| 31 | } |
| 32 | } |
| 33 |