fix(ai): handle custom LLM models that emit test-case declarations#201
Open
DavidHoenisch wants to merge 1 commit intocweill:developfrom
Open
fix(ai): handle custom LLM models that emit test-case declarations#201DavidHoenisch wants to merge 1 commit intocweill:developfrom
DavidHoenisch wants to merge 1 commit intocweill:developfrom
Conversation
When using a custom Ollama model (e.g. llama3.2:latest) the LLM often
outputs the generated test cases as a Go variable declaration instead
of a bare array literal or a complete test function:
tests := []struct {
name string
args args
want int
}{
{name: "case 1", args: args{...}, want: 42},
}
Two parser bugs caused these responses to be rejected:
1. parseGoTestCases() only recognised bare composite literals or
complete func Test... blocks. The tests := form fell through to
parseTestCaseArray, which wrapped it in another literal producing
invalid Go.
2. ensureTrailingComma() saw the declaration ended with '}' and was
not a func Test, so it appended a comma: "tests := []struct{}{...},"
which is invalid Go syntax.
Both issues caused GenerateTestCases() to return an error. The error
output (which contained the LLM's generated cases) was printed to
stderr/stdout, while the actual test file only received the TODO
fallback comment.
Fix:
- Detect tests := / tests= declarations in parseGoTestCases and wrap
them in a func init() so the existing AST parser can extract cases.
- Teach ensureTrailingComma to skip tests := and var tests declarations.
Verified with llama3.2:latest and qwen2.5-coder:0.5b.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When using an override Ollama model (e.g. llama3.2:latest) the LLM often outputs the generated test cases as a Go variable declaration instead of a bare array literal or a complete test function:
Two parser bugs caused these responses to be rejected:
parseGoTestCases() only recognised bare composite literals or complete func Test... blocks. The tests := form fell through to parseTestCaseArray, which wrapped it in another literal producing invalid Go.
ensureTrailingComma() saw the declaration ended with '}' and was not a func Test, so it appended a comma: "tests := []struct{}{...}," which is invalid Go syntax.
Both issues caused GenerateTestCases() to return an error. The error output (which contained the LLM's generated cases) was printed to stderr/stdout, while the actual test file only received the TODO fallback comment.
Fix:
Verified with llama3.2:latest and qwen2.5-coder:0.5b.