Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
67 lines
2.2 KiB
Go
67 lines
2.2 KiB
Go
package core
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateCommandOutputFillsDeclaredTableColumns(t *testing.T) {
|
|
output, err := ValidateCommandOutput(CapabilityOutput{
|
|
DefaultMode: OutputModeTable,
|
|
JSON: true,
|
|
Table: &TableOutput{Columns: []TableColumn{{Key: "id", Label: "ID"}}},
|
|
}, CommandOutput{
|
|
Kind: OutputModeTable,
|
|
Rows: []map[string]any{{"id": "job-1"}},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("ValidateCommandOutput() error = %v", err)
|
|
}
|
|
if len(output.Columns) != 1 || output.Columns[0].Key != "id" {
|
|
t.Fatalf("output = %#v", output)
|
|
}
|
|
}
|
|
|
|
func TestValidateCommandOutputRejectsUndeclaredJSON(t *testing.T) {
|
|
_, err := ValidateCommandOutput(CapabilityOutput{
|
|
DefaultMode: OutputModeTable,
|
|
Table: &TableOutput{Columns: []TableColumn{{Key: "id", Label: "ID"}}},
|
|
}, CommandOutput{Kind: OutputModeJSON, Value: map[string]any{"ok": true}})
|
|
if !errors.Is(err, ErrHandlerBadResponse) {
|
|
t.Fatalf("ValidateCommandOutput() error = %v, want ErrHandlerBadResponse", err)
|
|
}
|
|
}
|
|
|
|
func TestDecodeAndValidateWaitContinuation(t *testing.T) {
|
|
output, err := DecodeCommandOutput([]byte(`{
|
|
"kind":"json",
|
|
"value":{"status":"running"},
|
|
"continuation":{"state":"pending","retryAfterMs":500}
|
|
}`))
|
|
if err != nil {
|
|
t.Fatalf("DecodeCommandOutput() error = %v", err)
|
|
}
|
|
if err := ValidateCommandContinuation(&CommandExecution{Mode: CommandExecutionModeWait}, output); err != nil {
|
|
t.Fatalf("ValidateCommandContinuation() error = %v", err)
|
|
}
|
|
if output.Continuation == nil || output.Continuation.RetryAfterMs != 500 {
|
|
t.Fatalf("output = %#v", output)
|
|
}
|
|
}
|
|
|
|
func TestValidateCommandContinuationRejectsHotLoopAndNonWaitCommands(t *testing.T) {
|
|
output := CommandOutput{
|
|
Kind: OutputModeJSON,
|
|
Continuation: &CommandContinuation{
|
|
State: CommandContinuationStatePending, RetryAfterMs: MinContinuationRetryAfterMs - 1,
|
|
},
|
|
}
|
|
if err := ValidateCommandContinuation(&CommandExecution{Mode: CommandExecutionModeWait}, output); !errors.Is(err, ErrHandlerBadResponse) {
|
|
t.Fatalf("hot-loop error = %v", err)
|
|
}
|
|
output.Continuation.RetryAfterMs = MinContinuationRetryAfterMs
|
|
if err := ValidateCommandContinuation(nil, output); !errors.Is(err, ErrHandlerBadResponse) {
|
|
t.Fatalf("non-wait error = %v", err)
|
|
}
|
|
}
|