This repository has been archived on 2026-04-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
core/server/sandbox/settings_module_test.go
Jeffrey Smith 00ef970163
All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-frontend (push) Has been skipped
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-go-pg (push) Successful in 2m47s
CI/CD / test-sqlite (push) Successful in 2m52s
CI/CD / build-and-deploy (push) Successful in 30s
Feat v0.8.2 capability negotiation (#69)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com>
Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
2026-04-03 09:14:00 +00:00

76 lines
1.8 KiB
Go

package sandbox
import (
"context"
"testing"
"go.starlark.net/starlark"
"armature/store"
)
func execWithSettings(t *testing.T, caps map[string]bool, script string) (*Result, error) {
t.Helper()
ctx := context.Background()
mod := BuildSettingsModule(ctx, store.Stores{}, "", "", "", caps)
sb := New(DefaultConfig())
return sb.Exec(ctx, "test.star", script, map[string]starlark.Value{
"settings": mod,
})
}
func TestHasCapability_True(t *testing.T) {
caps := map[string]bool{"postgres": true, "pgvector": true}
result, err := execWithSettings(t, caps, `
result = settings.has_capability("pgvector")
`)
if err != nil {
t.Fatalf("exec error: %v", err)
}
v := result.Globals["result"]
if v != starlark.True {
t.Errorf("has_capability('pgvector') = %v, want True", v)
}
}
func TestHasCapability_False(t *testing.T) {
caps := map[string]bool{"postgres": true, "pgvector": false}
result, err := execWithSettings(t, caps, `
result = settings.has_capability("pgvector")
`)
if err != nil {
t.Fatalf("exec error: %v", err)
}
v := result.Globals["result"]
if v != starlark.False {
t.Errorf("has_capability('pgvector') = %v, want False", v)
}
}
func TestHasCapability_UnknownCap(t *testing.T) {
caps := map[string]bool{"postgres": true}
result, err := execWithSettings(t, caps, `
result = settings.has_capability("gpu")
`)
if err != nil {
t.Fatalf("exec error: %v", err)
}
v := result.Globals["result"]
if v != starlark.False {
t.Errorf("has_capability('gpu') = %v, want False", v)
}
}
func TestHasCapability_NilCaps(t *testing.T) {
result, err := execWithSettings(t, nil, `
result = settings.has_capability("postgres")
`)
if err != nil {
t.Fatalf("exec error: %v", err)
}
v := result.Globals["result"]
if v != starlark.False {
t.Errorf("has_capability with nil caps = %v, want False", v)
}
}