Skip to content

Commit a3474f4

Browse files
authored
Merge pull request #43 from njhale/chore/update-cred-overrides
fix: use array and new pluralized name for credential overrides
2 parents 869ee34 + e1ccf96 commit a3474f4

File tree

3 files changed

+45
-10
lines changed

3 files changed

+45
-10
lines changed

gptscript_test.go

+30
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,36 @@ func TestStreamRun(t *testing.T) {
345345
}
346346
}
347347

348+
func TestCredentialOverride(t *testing.T) {
349+
wd, err := os.Getwd()
350+
if err != nil {
351+
t.Fatalf("Error getting working directory: %v", err)
352+
}
353+
354+
run, err := g.Run(context.Background(), wd+"/test/credential-override.gpt", Options{
355+
DisableCache: true,
356+
CredentialOverrides: []string{
357+
"test.ts.credential_override:TEST_CRED=foo",
358+
},
359+
})
360+
if err != nil {
361+
t.Fatalf("Error executing file: %v", err)
362+
}
363+
364+
out, err := run.Text()
365+
if err != nil {
366+
t.Errorf("Error reading output: %v", err)
367+
}
368+
369+
if !strings.Contains(out, "foo") {
370+
t.Errorf("Unexpected output: %s", out)
371+
}
372+
373+
if len(run.ErrorOutput()) != 0 {
374+
t.Error("Should have no stderr output")
375+
}
376+
}
377+
348378
func TestParseSimpleFile(t *testing.T) {
349379
wd, err := os.Getwd()
350380
if err != nil {

opts.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ func (g GlobalOptions) toEnv() []string {
2828
type Options struct {
2929
GlobalOptions `json:",inline"`
3030

31-
Confirm bool `json:"confirm"`
32-
Input string `json:"input"`
33-
DisableCache bool `json:"disableCache"`
34-
CacheDir string `json:"cacheDir"`
35-
SubTool string `json:"subTool"`
36-
Workspace string `json:"workspace"`
37-
ChatState string `json:"chatState"`
38-
IncludeEvents bool `json:"includeEvents"`
39-
Prompt bool `json:"prompt"`
40-
CredentialOverride string `json:"credentialOverride"`
31+
Confirm bool `json:"confirm"`
32+
Input string `json:"input"`
33+
DisableCache bool `json:"disableCache"`
34+
CacheDir string `json:"cacheDir"`
35+
SubTool string `json:"subTool"`
36+
Workspace string `json:"workspace"`
37+
ChatState string `json:"chatState"`
38+
IncludeEvents bool `json:"includeEvents"`
39+
Prompt bool `json:"prompt"`
40+
CredentialOverrides []string `json:"credentialOverrides"`
4141
}

test/credential-override.gpt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
credentials: github.com/gptscript-ai/credential as test.ts.credential_override with TEST_CRED as env
2+
3+
#!/usr/bin/env bash
4+
5+
echo "${TEST_CRED}"

0 commit comments

Comments
 (0)