Skip to content

Commit 7571825

Browse files
committed
Refactor PromptPexTest struct by changing pointer fields to values; update related parsing and test logic for consistency
1 parent 025e32e commit 7571825

5 files changed

Lines changed: 56 additions & 33 deletions

File tree

cmd/generate/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (h *generateCommandHandler) ParseTestsFromLLMResponse(content string) ([]Pr
5555
test := PromptPexTest{}
5656

5757
if scenario, ok := rawTest["scenario"].(string); ok {
58-
test.Scenario = &scenario
58+
test.Scenario = scenario
5959
}
6060

6161
// Handle testinput - can be string or structured object
@@ -83,7 +83,7 @@ func (h *generateCommandHandler) ParseTestsFromLLMResponse(content string) ([]Pr
8383
}
8484

8585
if reasoning, ok := rawTest["reasoning"].(string); ok {
86-
test.Reasoning = &reasoning
86+
test.Reasoning = reasoning
8787
}
8888

8989
tests = append(tests, test)

cmd/generate/parser_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ func TestParseTestsFromLLMResponse_DirectUnmarshal(t *testing.T) {
2525
if result[0].TestInput != "input" {
2626
t.Errorf("ParseTestsFromLLMResponse() TestInput mismatch. Expected: 'input', Got: '%s'", result[0].TestInput)
2727
}
28-
if result[0].Scenario == nil || *result[0].Scenario != "test" {
28+
if result[0].Scenario != "test" {
2929
t.Errorf("ParseTestsFromLLMResponse() Scenario mismatch")
3030
}
31-
if result[0].Reasoning == nil || *result[0].Reasoning != "reason" {
31+
if result[0].Reasoning != "reason" {
3232
t.Errorf("ParseTestsFromLLMResponse() Reasoning mismatch")
3333
}
3434
})
@@ -210,12 +210,12 @@ func TestParseTestsFromLLMResponse_SpecialValues(t *testing.T) {
210210
t.Errorf("ParseTestsFromLLMResponse() expected 1 test, got %d", len(result))
211211
}
212212

213-
// Null values should not set the pointer fields
214-
if result[0].Scenario != nil {
215-
t.Errorf("ParseTestsFromLLMResponse() Scenario should be nil for null value")
213+
// Null values should result in empty strings with non-pointer fields
214+
if result[0].Scenario != "" {
215+
t.Errorf("ParseTestsFromLLMResponse() Scenario should be empty for null value")
216216
}
217-
if result[0].Reasoning != nil {
218-
t.Errorf("ParseTestsFromLLMResponse() Reasoning should be nil for null value")
217+
if result[0].Reasoning != "" {
218+
t.Errorf("ParseTestsFromLLMResponse() Reasoning should be empty for null value")
219219
}
220220
if result[0].TestInput != "test" {
221221
t.Errorf("ParseTestsFromLLMResponse() TestInput mismatch")
@@ -234,13 +234,13 @@ func TestParseTestsFromLLMResponse_SpecialValues(t *testing.T) {
234234
}
235235

236236
// Empty strings should set the fields to empty strings
237-
if result[0].Scenario == nil || *result[0].Scenario != "" {
237+
if result[0].Scenario != "" {
238238
t.Errorf("ParseTestsFromLLMResponse() Scenario should be empty string")
239239
}
240240
if result[0].TestInput != "" {
241241
t.Errorf("ParseTestsFromLLMResponse() TestInput should be empty string")
242242
}
243-
if result[0].Reasoning == nil || *result[0].Reasoning != "" {
243+
if result[0].Reasoning != "" {
244244
t.Errorf("ParseTestsFromLLMResponse() Reasoning should be empty string")
245245
}
246246
})
@@ -256,7 +256,7 @@ func TestParseTestsFromLLMResponse_SpecialValues(t *testing.T) {
256256
t.Errorf("ParseTestsFromLLMResponse() expected 1 test, got %d", len(result))
257257
}
258258

259-
if result[0].Scenario == nil || *result[0].Scenario != "unicode test 🚀" {
259+
if result[0].Scenario != "unicode test 🚀" {
260260
t.Errorf("ParseTestsFromLLMResponse() unicode scenario failed")
261261
}
262262
if result[0].TestInput != "测试输入 with émojis 🎉" {
@@ -301,7 +301,7 @@ func TestParseTestsFromLLMResponse_RealWorldExamples(t *testing.T) {
301301
if test.TestInput == "" {
302302
t.Errorf("ParseTestsFromLLMResponse() test %d has empty TestInput", i)
303303
}
304-
if test.Scenario == nil || *test.Scenario == "" {
304+
if test.Scenario == "" {
305305
t.Errorf("ParseTestsFromLLMResponse() test %d has empty Scenario", i)
306306
}
307307
}
@@ -328,10 +328,10 @@ func TestParseTestsFromLLMResponse_RealWorldExamples(t *testing.T) {
328328
t.Errorf("ParseTestsFromLLMResponse() expected 1 test, got %d", len(result))
329329
}
330330

331-
if result[0].Scenario == nil || *result[0].Scenario != "API request validation" {
331+
if result[0].Scenario != "API request validation" {
332332
t.Errorf("ParseTestsFromLLMResponse() concatenation failed in scenario")
333333
}
334-
if result[0].Reasoning == nil || *result[0].Reasoning != "Tests API endpoint validation" {
334+
if result[0].Reasoning != "Tests API endpoint validation" {
335335
t.Errorf("ParseTestsFromLLMResponse() concatenation failed in reasoning")
336336
}
337337
})

cmd/generate/pipeline.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ Generate exactly %d diverse test cases:`, nTests,
312312
testViews := make([]string, len(context.Tests)*2)
313313
for i, test := range context.Tests {
314314
testViews[i*2] = test.TestInput
315-
testViews[i*2+1] = fmt.Sprintf(" %s%s", BOX_END, *test.Reasoning)
315+
testViews[i*2+1] = fmt.Sprintf(" %s%s", BOX_END, test.Reasoning)
316316
}
317317
h.WriteEndListBox(testViews, PREVIEW_TEST_COUNT)
318318
return nil
@@ -401,19 +401,19 @@ func (h *generateCommandHandler) generateGroundtruth(context *PromptPexContext)
401401
for i := range context.Tests {
402402
test := &context.Tests[i]
403403
h.WriteToLine(test.TestInput)
404-
if test.Groundtruth == nil || *test.Groundtruth == "" {
404+
if test.Groundtruth == "" {
405405
// Generate groundtruth output
406406
output, err := h.runSingleTestWithContext(test.TestInput, groundtruthModel, context)
407407
if err != nil {
408408
h.cfg.WriteToOut(fmt.Sprintf("Failed to generate groundtruth for test %d: %v", i, err))
409409
continue
410410
}
411-
test.Groundtruth = &output
412-
test.GroundtruthModel = &groundtruthModel
411+
test.Groundtruth = output
412+
test.GroundtruthModel = groundtruthModel
413413

414414
h.SaveContext(context) // Save context after generating groundtruth
415415
}
416-
h.WriteToLine(fmt.Sprintf(" %s%s", BOX_END, *test.Groundtruth)) // Write groundtruth output
416+
h.WriteToLine(fmt.Sprintf(" %s%s", BOX_END, test.Groundtruth)) // Write groundtruth output
417417
}
418418

419419
h.WriteEndBox(fmt.Sprintf("%d items", len(context.Tests)))
@@ -427,8 +427,8 @@ func (h *generateCommandHandler) updatePromptFile(context *PromptPexContext) err
427427
for _, test := range context.Tests {
428428
item := prompt.TestDataItem{}
429429
item["input"] = test.TestInput
430-
if test.Groundtruth != nil {
431-
item["expected"] = *test.Groundtruth
430+
if test.Groundtruth != "" {
431+
item["expected"] = test.Groundtruth
432432
}
433433
testData = append(testData, item)
434434
}

cmd/generate/types.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,16 @@ type PromptPexContext struct {
5050

5151
// PromptPexTest represents a single test case
5252
type PromptPexTest struct {
53-
RuleID *int `json:"ruleid,omitempty" yaml:"ruleid,omitempty"`
54-
TestID *int `json:"testid,omitempty" yaml:"testid,omitempty"`
55-
Baseline *bool `json:"baseline,omitempty" yaml:"baseline,omitempty"`
56-
GroundtruthModel *string `json:"groundtruthModel,omitempty" yaml:"groundtruthModel,omitempty"`
57-
Groundtruth *string `json:"groundtruth,omitempty" yaml:"groundtruth,omitempty"`
58-
TestInput string `json:"testinput" yaml:"testinput"`
59-
TestInputOriginal *string `json:"testinputOriginal,omitempty" yaml:"testinputOriginal,omitempty"`
60-
ExpectedOutput *string `json:"expectedoutput,omitempty" yaml:"expectedoutput,omitempty"`
61-
Reasoning *string `json:"reasoning,omitempty" yaml:"reasoning,omitempty"`
62-
Scenario *string `json:"scenario,omitempty" yaml:"scenario,omitempty"`
63-
Generation *int `json:"generation,omitempty" yaml:"generation,omitempty"`
53+
RuleID int `json:"ruleid,omitempty" yaml:"ruleid,omitempty"`
54+
TestID int `json:"testid,omitempty" yaml:"testid,omitempty"`
55+
Baseline bool `json:"baseline,omitempty" yaml:"baseline,omitempty"`
56+
GroundtruthModel string `json:"groundtruthModel,omitempty" yaml:"groundtruthModel,omitempty"`
57+
Groundtruth string `json:"groundtruth,omitempty" yaml:"groundtruth,omitempty"`
58+
TestInput string `json:"testinput" yaml:"testinput"`
59+
TestInputOriginal string `json:"testinputOriginal,omitempty" yaml:"testinputOriginal,omitempty"`
60+
ExpectedOutput string `json:"expectedoutput,omitempty" yaml:"expectedoutput,omitempty"`
61+
Reasoning string `json:"reasoning,omitempty" yaml:"reasoning,omitempty"`
62+
Scenario string `json:"scenario,omitempty" yaml:"scenario,omitempty"`
6463
}
6564

6665
// Effort levels

test_types.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/github/gh-models/cmd/generate"
7+
)
8+
9+
func main() {
10+
test := generate.PromptPexTest{
11+
Scenario: "test scenario",
12+
Reasoning: "test reasoning",
13+
TestInput: "test input",
14+
RuleID: 1,
15+
TestID: 2,
16+
Baseline: true,
17+
}
18+
19+
fmt.Printf("Scenario type: %T, value: %s\n", test.Scenario, test.Scenario)
20+
fmt.Printf("Reasoning type: %T, value: %s\n", test.Reasoning, test.Reasoning)
21+
fmt.Printf("RuleID type: %T, value: %d\n", test.RuleID, test.RuleID)
22+
fmt.Printf("TestID type: %T, value: %d\n", test.TestID, test.TestID)
23+
fmt.Printf("Baseline type: %T, value: %t\n", test.Baseline, test.Baseline)
24+
}

0 commit comments

Comments
 (0)