Skip to content

Commit 2cf45e0

Browse files
committed
Add CI example/fuzz gates and fix parser panic
1 parent f0459d0 commit 2cf45e0

5 files changed

Lines changed: 46 additions & 1 deletion

File tree

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,23 @@ jobs:
5656
if: runner.os == 'Windows'
5757
shell: pwsh
5858
run: golangci-lint run --timeout=10m --out-format=colored-line-number
59+
60+
quality-gates:
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Checkout
64+
uses: actions/checkout@v4
65+
66+
- name: Set up Go
67+
uses: actions/setup-go@v5
68+
with:
69+
go-version-file: go.mod
70+
71+
- name: Gate examples coverage
72+
run: go test ./vibes -run 'TestExamples|TestDocsExampleSnippetsCompile'
73+
74+
- name: Gate parser fuzz target
75+
run: go test ./vibes -run '^$' -fuzz=FuzzCompileScriptDoesNotPanic -fuzztime=5s
76+
77+
- name: Gate runtime fuzz target
78+
run: go test ./vibes -run '^$' -fuzz=FuzzRuntimeEdgeCasesDoNotPanic -fuzztime=5s

ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Goal: improve day-to-day developer productivity and interpreter robustness.
341341

342342
- [ ] Tooling commands are documented and stable.
343343
- [ ] Performance regressions are tracked with benchmarks.
344-
- [ ] CI includes example and fuzz coverage gates.
344+
- [x] CI includes example and fuzz coverage gates.
345345

346346
---
347347

vibes/parser.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,9 @@ func (p *parser) parseExpression(precedence int) Expression {
691691
}
692692

693693
left := prefix()
694+
if left == nil {
695+
return nil
696+
}
694697

695698
for p.peekToken.Type != tokenEOF && precedence < p.peekPrecedence() {
696699
infix := p.infixFns[p.peekToken.Type]
@@ -699,6 +702,9 @@ func (p *parser) parseExpression(precedence int) Expression {
699702
}
700703
p.nextToken()
701704
left = infix(left)
705+
if left == nil {
706+
return nil
707+
}
702708
}
703709

704710
return left
@@ -948,6 +954,9 @@ func (p *parser) parseRangeExpression(left Expression) Expression {
948954
}
949955

950956
func (p *parser) parseCallExpression(function Expression) Expression {
957+
if function == nil {
958+
return nil
959+
}
951960
expr := &CallExpr{Callee: function, position: function.Pos()}
952961
args := []Expression{}
953962
kwargs := []KeywordArg{}

vibes/runtime_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ func callFunc(t *testing.T, script *Script, name string, args []Value) Value {
2828
return result
2929
}
3030

31+
func TestCompileMalformedCallTargetDoesNotPanic(t *testing.T) {
32+
engine := MustNewEngine(Config{})
33+
defer func() {
34+
if r := recover(); r != nil {
35+
t.Fatalf("compile panicked: %v", r)
36+
}
37+
}()
38+
39+
_, err := engine.Compile(`be(in (000000000`)
40+
if err == nil {
41+
t.Fatalf("expected compile error for malformed input")
42+
}
43+
}
44+
3145
func TestHashMergeAndKeys(t *testing.T) {
3246
script := compileScript(t, `
3347
def merged()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go test fuzz v1
2+
[]byte("be(in (000000000")

0 commit comments

Comments
 (0)