Skip to content

Commit e2c28d3

Browse files
committed
Refactor InverseRules to use a slice instead of a string; update related context creation and tests for consistency
1 parent fce67b8 commit e2c28d3

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

cmd/generate/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (h *generateCommandHandler) CreateContextFromPrompt(promptFile string) (*Pr
3232
// Infered intent of the prompt
3333
Intent: "",
3434
Rules: []string{},
35-
InverseRules: "",
35+
InverseRules: []string{},
3636
InputSpec: "",
3737
Tests: "",
3838
TestData: "",

cmd/generate/context_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ messages:
3737
expectedFields: map[string]interface{}{
3838
"intent": "",
3939
"rules": []string{},
40-
"inverseRules": "",
40+
"inverseRules": []string{},
4141
},
4242
},
4343
{
@@ -156,7 +156,7 @@ messages:
156156
t.Errorf("Expected %s to be %q, got %q", field, expectedValue, context.Rules)
157157
}
158158
case "inverseRules":
159-
if context.InverseRules != expectedValue.(string) {
159+
if !reflect.DeepEqual(context.InverseRules, expectedValue.([]string)) {
160160
t.Errorf("Expected %s to be %q, got %q", field, expectedValue, context.InverseRules)
161161
}
162162
}

cmd/generate/pipeline.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ Inverse Rules:`, context.Rules)
212212
if err != nil {
213213
return err
214214
}
215-
context.InverseRules = inverseRules
215+
216+
parsed := ParseRules(inverseRules)
217+
if parsed == nil {
218+
return fmt.Errorf("failed to parse inverse output rules: %s", inverseRules)
219+
}
220+
context.InverseRules = parsed
216221

217222
return nil
218223
}

cmd/generate/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type PromptPexContext struct {
8383
PromptHash string `json:"promptHash" yaml:"promptHash"`
8484
Intent string `json:"intent" yaml:"intent"`
8585
Rules []string `json:"rules" yaml:"rules"`
86-
InverseRules string `json:"inverseRules" yaml:"inverseRules"`
86+
InverseRules []string `json:"inverseRules" yaml:"inverseRules"`
8787
InputSpec string `json:"inputSpec" yaml:"inputSpec"`
8888
Tests string `json:"tests" yaml:"tests"`
8989
PromptPexTests []PromptPexTest `json:"promptPexTests" yaml:"promptPexTests"`

0 commit comments

Comments
 (0)