Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c8f44fb
refactor context and events tests with shared helpers
mgomes Feb 21, 2026
eb3a550
refactor db capability tests with shared helpers
mgomes Feb 21, 2026
2e7f79c
refactor job queue capability tests with helpers
mgomes Feb 21, 2026
c88475b
refactor capability foundations tests with helpers
mgomes Feb 21, 2026
284c3bf
refactor recursion tests to shared compile and call helpers
mgomes Feb 21, 2026
7f84939
reduce capability contract test compile boilerplate
mgomes Feb 21, 2026
ada1e2c
deduplicate module fixture engine setup in modules tests
mgomes Feb 21, 2026
a0f263b
refactor module tests to shared compile helper
mgomes Feb 21, 2026
c3b98d1
refactor interpreter tests to shared compile helper
mgomes Feb 21, 2026
2ef772a
deduplicate strict-effects test compile and call setup
mgomes Feb 21, 2026
e8177f8
deduplicate default compile setup in concurrency tests
mgomes Feb 21, 2026
a5059db
use shared compile helper in integration env tests
mgomes Feb 21, 2026
937d900
deduplicate memory quota test compile setup
mgomes Feb 21, 2026
4c6a559
use shared compile helper in runtime fuzz setup
mgomes Feb 21, 2026
52a0c45
deduplicate benchmark compile setup
mgomes Feb 21, 2026
e5ae69c
use compile helper for foreign-function env test
mgomes Feb 21, 2026
8aa4189
share compile-error assertion helpers across tests
mgomes Feb 21, 2026
04e5e71
use shared config compile helper in runtime tests
mgomes Feb 21, 2026
1b6c700
share file-backed compile helpers across tests
mgomes Feb 21, 2026
d415184
route runtime compile helper through shared default helper
mgomes Feb 21, 2026
d4496a2
deduplicate integration call-error assertions
mgomes Feb 21, 2026
2b93bb6
reuse shared call-error helper in class and block tests
mgomes Feb 21, 2026
237f819
centralize engine-backed file compile in integration tests
mgomes Feb 21, 2026
0886c71
reuse compile helper in syntax freeze test cases
mgomes Feb 21, 2026
7c9200c
use shared call helper in class integration success path
mgomes Feb 21, 2026
6bdcd87
use shared call helper for integration run checks
mgomes Feb 21, 2026
fe32c5c
deduplicate memory-quota error assertions in core tests
mgomes Feb 21, 2026
fbc4945
normalize memory-quota error contains assertions
mgomes Feb 21, 2026
f7d3500
reuse call-error helper in random identifier runtime tests
mgomes Feb 21, 2026
f5f2a6e
reuse call-error helper in JSON and regex runtime tests
mgomes Feb 21, 2026
5582f2d
reuse shared error assertion helper in capability constructor tests
mgomes Feb 21, 2026
1def059
use shared error assertion for module policy pattern validation
mgomes Feb 21, 2026
3d83c25
normalize runtime chunk and typed-block error assertions
mgomes Feb 21, 2026
1c50a93
reuse helpers for runtime step-quota error checks
mgomes Feb 21, 2026
b408e65
standardize runtime loop-control error assertions
mgomes Feb 21, 2026
bf4524f
normalize runtime error assertions for conversions and parsing
mgomes Feb 21, 2026
d736570
normalize typed-semantics runtime error assertions
mgomes Feb 21, 2026
668f0e7
standardize remaining runtime error checks to shared helpers
mgomes Feb 21, 2026
cdb37a6
standardize capability contract error assertions
mgomes Feb 21, 2026
ddccf2b
normalize recursion test error assertions
mgomes Feb 21, 2026
1d439f4
normalize module require error-path assertions
mgomes Feb 21, 2026
7b61c85
expand shared error helper usage in module tests
mgomes Feb 21, 2026
4b5caaf
normalize module policy deny assertion helper usage
mgomes Feb 21, 2026
ab4c02a
reuse shared error helper in interpreter and type-check tests
mgomes Feb 21, 2026
90257fb
reuse shared error helper in remaining runtime contains checks
mgomes Feb 21, 2026
c9d5f4c
route table-driven error checks through shared helper
mgomes Feb 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 9 additions & 43 deletions vibes/call_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,14 @@ type callResult struct {
}

func TestScriptCallOverlappingCallsKeepFunctionEnvIsolated(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`def helper
script := compileScriptDefault(t, `def helper
tenant
end

def run
sync.wait()
helper
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

barrier := &blockingSync{
entered: make(chan struct{}, 1),
Expand Down Expand Up @@ -108,8 +104,7 @@ end`)
}

func TestScriptCallOverlappingCallsKeepClassVarsIsolated(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`class Counter
script := compileScriptDefault(t, `class Counter
@@count = 0

def self.bump
Expand All @@ -126,9 +121,6 @@ def run
Counter.bump
Counter.count
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

barrier := &blockingSync{
entered: make(chan struct{}, 1),
Expand Down Expand Up @@ -181,8 +173,7 @@ end`)
}

func TestScriptCallRebindsEscapedFunctionsToCurrentCallEnv(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`def format_tenant(value)
script := compileScriptDefault(t, `def format_tenant(value)
tenant + "-" + value
end

Expand All @@ -193,9 +184,6 @@ end
def run_with(fn, value)
fn(value)
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

exported, err := script.Call(context.Background(), "export_fn", nil, CallOptions{
Globals: map[string]Value{
Expand Down Expand Up @@ -223,8 +211,7 @@ end`)
}

func TestScriptCallRebindingDoesNotMutateSharedArgMaps(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`def format_tenant(value)
script := compileScriptDefault(t, `def format_tenant(value)
tenant + "-" + value
end

Expand All @@ -236,9 +223,6 @@ def run(ctx)
sync.wait()
ctx.fn("value")
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

exported, err := script.Call(context.Background(), "export_fn", nil, CallOptions{
Globals: map[string]Value{
Expand Down Expand Up @@ -311,7 +295,7 @@ end`)
func TestScriptCallPreservesForeignFunctionEnv(t *testing.T) {
engine := MustNewEngine(Config{})

producer, err := engine.Compile(`def helper(value)
producer := compileScriptWithEngine(t, engine, `def helper(value)
"foreign-" + value
end

Expand All @@ -322,16 +306,10 @@ end
def export_fn
wrapper
end`)
if err != nil {
t.Fatalf("compile producer failed: %v", err)
}

consumer, err := engine.Compile(`def run_with(fn, value)
consumer := compileScriptWithEngine(t, engine, `def run_with(fn, value)
fn(value)
end`)
if err != nil {
t.Fatalf("compile consumer failed: %v", err)
}

foreignFn, err := producer.Call(context.Background(), "export_fn", nil, CallOptions{})
if err != nil {
Expand All @@ -351,8 +329,7 @@ end`)
}

func TestScriptCallRebindsEscapedClassValuesToCurrentCall(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`class Bucket
script := compileScriptDefault(t, `class Bucket
@@count = 0

def self.bump
Expand All @@ -373,9 +350,6 @@ def run_with(klass)
klass.bump
klass.snapshot
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

exportedClass, err := script.Call(context.Background(), "export_class", nil, CallOptions{
Globals: map[string]Value{
Expand Down Expand Up @@ -410,8 +384,7 @@ end`)
}

func TestScriptCallRebindsEscapedInstancesToCurrentCallState(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`class Bucket
script := compileScriptDefault(t, `class Bucket
@@count = 0

def initialize(name)
Expand All @@ -431,9 +404,6 @@ end
def run_with(bucket)
bucket.report
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

exportedInstance, err := script.Call(context.Background(), "export_instance", []Value{NewString("seed")}, CallOptions{
Globals: map[string]Value{
Expand Down Expand Up @@ -471,13 +441,9 @@ end`)
}

func TestScriptCallRebindingPreservesHashAndObjectKindsForAliasedMaps(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`def run(a, b)
script := compileScriptDefault(t, `def run(a, b)
[a, b]
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

shared := map[string]Value{"x": NewInt(1)}
hashVal := NewHash(shared)
Expand Down
9 changes: 2 additions & 7 deletions vibes/capability_common_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package vibes

import (
"strings"
"testing"
)

Expand All @@ -26,9 +25,7 @@ func TestValidateCapabilityTypedValueUsesCompositeTypeChecks(t *testing.T) {
if err == nil {
t.Fatalf("expected composite type mismatch")
}
if !strings.Contains(err.Error(), "payload expected array<int | string>, got array<bool | int>") {
t.Fatalf("unexpected composite type mismatch: %v", err)
}
requireErrorContains(t, err, "payload expected array<int | string>, got array<bool | int>")
}

func TestValidateCapabilityTypedValueUsesShapeTypeChecks(t *testing.T) {
Expand All @@ -50,7 +47,5 @@ func TestValidateCapabilityTypedValueUsesShapeTypeChecks(t *testing.T) {
if err == nil {
t.Fatalf("expected shape type mismatch")
}
if !strings.Contains(err.Error(), "payload expected { id: string }, got { extra: int, id: string }") {
t.Fatalf("unexpected shape type mismatch: %v", err)
}
requireErrorContains(t, err, "payload expected { id: string }, got { extra: int, id: string }")
}
84 changes: 24 additions & 60 deletions vibes/capability_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ package vibes

import (
"context"
"strings"
"testing"
)

func TestContextCapabilityResolver(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`def run()
script := compileScriptDefault(t, `def run()
ctx.user.id
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

type ctxKey string
resolver := func(ctx context.Context) (Value, error) {
Expand All @@ -30,25 +25,18 @@ end`)
ctx := context.WithValue(context.Background(), ctxKey("user_id"), "player-1")
ctx = context.WithValue(ctx, ctxKey("role"), "coach")

result, err := script.Call(ctx, "run", nil, CallOptions{
Capabilities: []CapabilityAdapter{MustNewContextCapability("ctx", resolver)},
})
if err != nil {
t.Fatalf("call failed: %v", err)
}
result := callScript(t, ctx, script, "run", nil, callOptionsWithCapabilities(
MustNewContextCapability("ctx", resolver),
))
if result.Kind() != KindString || result.String() != "player-1" {
t.Fatalf("unexpected result: %#v", result)
}
}

func TestContextCapabilityRejectsCallableValue(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`def run()
script := compileScriptDefault(t, `def run()
ctx.user.id
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

resolver := func(ctx context.Context) (Value, error) {
return NewObject(map[string]Value{
Expand All @@ -61,74 +49,50 @@ end`)
}), nil
}

_, err = script.Call(context.Background(), "run", nil, CallOptions{
Capabilities: []CapabilityAdapter{MustNewContextCapability("ctx", resolver)},
})
if err == nil {
t.Fatalf("expected callable context data error")
}
if got := err.Error(); !strings.Contains(got, "ctx capability value must be data-only") {
t.Fatalf("unexpected error: %s", got)
}
err := callScriptErr(t, context.Background(), script, "run", nil, callOptionsWithCapabilities(
MustNewContextCapability("ctx", resolver),
))
requireErrorContains(t, err, "ctx capability value must be data-only")
}

func TestContextCapabilityRejectsNonObjectValue(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`def run()
script := compileScriptDefault(t, `def run()
1
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

resolver := func(ctx context.Context) (Value, error) {
return NewString("invalid"), nil
}

_, err = script.Call(context.Background(), "run", nil, CallOptions{
Capabilities: []CapabilityAdapter{MustNewContextCapability("ctx", resolver)},
})
if err == nil {
t.Fatalf("expected resolver shape error")
}
if got := err.Error(); !strings.Contains(got, "ctx capability resolver must return hash/object") {
t.Fatalf("unexpected error: %s", got)
}
err := callScriptErr(t, context.Background(), script, "run", nil, callOptionsWithCapabilities(
MustNewContextCapability("ctx", resolver),
))
requireErrorContains(t, err, "ctx capability resolver must return hash/object")
}

func TestContextCapabilityRejectsCyclicValue(t *testing.T) {
engine := MustNewEngine(Config{})
script, err := engine.Compile(`def run()
script := compileScriptDefault(t, `def run()
ctx
end`)
if err != nil {
t.Fatalf("compile failed: %v", err)
}

resolver := func(context.Context) (Value, error) {
cyclic := map[string]Value{}
cyclic["self"] = NewHash(cyclic)
return NewHash(cyclic), nil
}

_, err = script.Call(context.Background(), "run", nil, CallOptions{
Capabilities: []CapabilityAdapter{MustNewContextCapability("ctx", resolver)},
})
if err == nil {
t.Fatalf("expected cyclic value error")
}
if got := err.Error(); !strings.Contains(got, "ctx capability value must not contain cyclic references") {
t.Fatalf("unexpected error: %s", got)
}
err := callScriptErr(t, context.Background(), script, "run", nil, callOptionsWithCapabilities(
MustNewContextCapability("ctx", resolver),
))
requireErrorContains(t, err, "ctx capability value must not contain cyclic references")
}

func TestNewContextCapabilityRejectsInvalidArguments(t *testing.T) {
resolver := func(context.Context) (Value, error) { return NewObject(map[string]Value{}), nil }

if _, err := NewContextCapability("", resolver); err == nil || !strings.Contains(err.Error(), "name must be non-empty") {
t.Fatalf("expected empty name error, got %v", err)
}
if _, err := NewContextCapability("ctx", nil); err == nil || !strings.Contains(err.Error(), "requires a resolver") {
t.Fatalf("expected nil resolver error, got %v", err)
}
_, err := NewContextCapability("", resolver)
requireErrorContains(t, err, "name must be non-empty")

_, err = NewContextCapability("ctx", nil)
requireErrorContains(t, err, "requires a resolver")
}
Loading