diff --git a/gptscript_test.go b/gptscript_test.go index 9a667da..3c06a81 100644 --- a/gptscript_test.go +++ b/gptscript_test.go @@ -345,6 +345,36 @@ func TestStreamRun(t *testing.T) { } } +func TestCredentialOverride(t *testing.T) { + wd, err := os.Getwd() + if err != nil { + t.Fatalf("Error getting working directory: %v", err) + } + + run, err := g.Run(context.Background(), wd+"/test/credential-override.gpt", Options{ + DisableCache: true, + CredentialOverrides: []string{ + "test.ts.credential_override:TEST_CRED=foo", + }, + }) + if err != nil { + t.Fatalf("Error executing file: %v", err) + } + + out, err := run.Text() + if err != nil { + t.Errorf("Error reading output: %v", err) + } + + if !strings.Contains(out, "foo") { + t.Errorf("Unexpected output: %s", out) + } + + if len(run.ErrorOutput()) != 0 { + t.Error("Should have no stderr output") + } +} + func TestParseSimpleFile(t *testing.T) { wd, err := os.Getwd() if err != nil { diff --git a/opts.go b/opts.go index 0315b2c..1a16085 100644 --- a/opts.go +++ b/opts.go @@ -28,14 +28,14 @@ func (g GlobalOptions) toEnv() []string { type Options struct { GlobalOptions `json:",inline"` - Confirm bool `json:"confirm"` - Input string `json:"input"` - DisableCache bool `json:"disableCache"` - CacheDir string `json:"cacheDir"` - SubTool string `json:"subTool"` - Workspace string `json:"workspace"` - ChatState string `json:"chatState"` - IncludeEvents bool `json:"includeEvents"` - Prompt bool `json:"prompt"` - CredentialOverride string `json:"credentialOverride"` + Confirm bool `json:"confirm"` + Input string `json:"input"` + DisableCache bool `json:"disableCache"` + CacheDir string `json:"cacheDir"` + SubTool string `json:"subTool"` + Workspace string `json:"workspace"` + ChatState string `json:"chatState"` + IncludeEvents bool `json:"includeEvents"` + Prompt bool `json:"prompt"` + CredentialOverrides []string `json:"credentialOverrides"` } diff --git a/test/credential-override.gpt b/test/credential-override.gpt new file mode 100644 index 0000000..6211989 --- /dev/null +++ b/test/credential-override.gpt @@ -0,0 +1,5 @@ +credentials: github.com/gptscript-ai/credential as test.ts.credential_override with TEST_CRED as env + +#!/usr/bin/env bash + +echo "${TEST_CRED}"