Skip to content

Commit 3a4850f

Browse files
fix: state with overrides (#33)
* feat: improve output * feat: agent to agent execution * feat: docs updated * fix: rename file * feat: improved logging * feat: override models * feat: update docs * feat: update docs * feat: added more tests * feat: vocieflow to vocieflow agent testing * fix: API key * feat: update code * fix: lint issue * fix: state with overrides * chore(deps): bump anchore/sbom-action from 0.20.1 to 0.20.2 (#31) Bumps [anchore/sbom-action](https://github.com/anchore/sbom-action) from 0.20.1 to 0.20.2. - [Release notes](https://github.com/anchore/sbom-action/releases) - [Changelog](https://github.com/anchore/sbom-action/blob/main/RELEASE.md) - [Commits](anchore/sbom-action@v0.20.1...v0.20.2) --- updated-dependencies: - dependency-name: anchore/sbom-action dependency-version: 0.20.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump sigstore/cosign-installer from 3.9.0 to 3.9.1 (#29) Bumps [sigstore/cosign-installer](https://github.com/sigstore/cosign-installer) from 3.9.0 to 3.9.1. - [Release notes](https://github.com/sigstore/cosign-installer/releases) - [Commits](sigstore/cosign-installer@v3.9.0...v3.9.1) --- updated-dependencies: - dependency-name: sigstore/cosign-installer dependency-version: 3.9.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xavier Portilla Edo <xavi_tb@hotmail.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent e7c2957 commit 3a4850f

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

.github/workflows/release_build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
id: go
3030
- uses: docker/setup-qemu-action@v3
3131
- uses: docker/setup-buildx-action@v3
32-
- uses: sigstore/cosign-installer@v3.9.0
33-
- uses: anchore/sbom-action/download-syft@v0.20.1
32+
- uses: sigstore/cosign-installer@v3.9.1
33+
- uses: anchore/sbom-action/download-syft@v0.20.2
3434
- uses: crazy-max/ghaction-upx@v3
3535
with:
3636
install-only: true

pkg/test/runner.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func runTest(environmentName, userID string, test tests.Test, apiKeyOverride, su
4141
for _, interactionResponse := range interactionResponses {
4242
logCollector.AddLog("\tInteraction Response Type: " + interactionResponse.Type)
4343

44-
validations, err = validateResponse(interactionResponse, validations, environmentName, userID, logCollector)
44+
validations, err = validateResponse(interactionResponse, validations, environmentName, userID, apiKeyOverride, subdomainOverride, logCollector)
4545
if err != nil {
4646
return err
4747
}
@@ -102,7 +102,7 @@ func autoGenerateValidationsIDs(validations []tests.Validation) []tests.Validati
102102

103103
}
104104

105-
func validateResponse(interactionResponse interact.InteractionResponse, validations []tests.Validation, environmentName, userID string, logCollector *LogCollector) ([]tests.Validation, error) {
105+
func validateResponse(interactionResponse interact.InteractionResponse, validations []tests.Validation, environmentName, userID, apiKeyOverride, subdomainOverride string, logCollector *LogCollector) ([]tests.Validation, error) {
106106
messageResponse, ok := getNestedValue(interactionResponse.Payload, "message")
107107
// Ensure payload is of type Speak before accessing its fields
108108
// Create a slice to store validations that should be kept
@@ -153,7 +153,7 @@ func validateResponse(interactionResponse interact.InteractionResponse, validati
153153
}
154154

155155
if validation.Type == "variable" {
156-
if checkVariableValue(validation, environmentName, userID, logCollector) {
156+
if checkVariableValue(validation, environmentName, userID, apiKeyOverride, subdomainOverride, logCollector) {
157157
logCollector.AddLog("\tValidation type: " + validation.Type + " PASSED with values: " + validation.Value + " and config " + fmt.Sprintf("%v", *validation.VariableConfig))
158158
passed = true
159159
}
@@ -167,9 +167,9 @@ func validateResponse(interactionResponse interact.InteractionResponse, validati
167167
return remainingValidations, nil
168168
}
169169

170-
func checkVariableValue(validation tests.Validation, environmentName, userID string, logCollector *LogCollector) bool {
170+
func checkVariableValue(validation tests.Validation, environmentName, userID, apiKeyOverride, subdomainOverride string, logCollector *LogCollector) bool {
171171

172-
state, err := voiceflow.FetchState(environmentName, userID)
172+
state, err := voiceflow.FetchStateWithOverrides(environmentName, userID, apiKeyOverride, subdomainOverride)
173173
if err != nil {
174174
errorMsg := "Error fetching variable state: " + err.Error()
175175
logCollector.AddLog(errorMsg)

pkg/voiceflow/state.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@ import (
1212
)
1313

1414
func FetchState(EnvironmentName, userID string) (state.State, error) {
15-
if global.VoiceflowSubdomain != "" {
16-
global.VoiceflowSubdomain = "." + global.VoiceflowSubdomain
15+
return FetchStateWithOverrides(EnvironmentName, userID, "", "")
16+
}
17+
18+
func FetchStateWithOverrides(EnvironmentName, userID, apiKeyOverride, subdomainOverride string) (state.State, error) {
19+
// Use the provided subdomain override, or fall back to global if not provided
20+
subdomain := global.VoiceflowSubdomain
21+
if subdomainOverride != "" {
22+
subdomain = subdomainOverride
23+
}
24+
25+
// Add the dot prefix if subdomain is not empty
26+
if subdomain != "" {
27+
subdomain = "." + subdomain
1728
}
18-
url := fmt.Sprintf("https://general-runtime%s.voiceflow.com/state/user/%s", global.VoiceflowSubdomain, userID)
29+
30+
url := fmt.Sprintf("https://general-runtime%s.voiceflow.com/state/user/%s", subdomain, userID)
1931

2032
req, err := http.NewRequest("GET", url, nil)
2133

@@ -25,7 +37,13 @@ func FetchState(EnvironmentName, userID string) (state.State, error) {
2537

2638
req.Header.Add("accept", "application/json")
2739
req.Header.Add("content-type", "application/json")
28-
req.Header.Add("Authorization", global.VoiceflowAPIKey)
40+
41+
// Use the provided API key override, or fall back to global if not provided
42+
apiKey := global.VoiceflowAPIKey
43+
if apiKeyOverride != "" {
44+
apiKey = apiKeyOverride
45+
}
46+
req.Header.Add("Authorization", apiKey)
2947
req.Header.Add("versionID", EnvironmentName)
3048

3149
res, err := http.DefaultClient.Do(req)

0 commit comments

Comments
 (0)