From 9aad7f36934a0973db810bcd884cb7192de700a5 Mon Sep 17 00:00:00 2001 From: Nick Hale <4175918+njhale@users.noreply.github.com> Date: Mon, 1 Jul 2024 16:28:41 -0400 Subject: [PATCH 1/2] fix: use array and new pluralized name for credential overrides Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com> --- opts.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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"` } From e1ccf96ae553d3540596779061f6097b83be5793 Mon Sep 17 00:00:00 2001 From: Nick Hale <4175918+njhale@users.noreply.github.com> Date: Mon, 1 Jul 2024 18:12:53 -0400 Subject: [PATCH 2/2] test: add credential override test Signed-off-by: Nick Hale <4175918+njhale@users.noreply.github.com> --- gptscript_test.go | 30 ++++++++++++++++++++++++++++++ test/credential-override.gpt | 5 +++++ 2 files changed, 35 insertions(+) create mode 100644 test/credential-override.gpt 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/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}"