Some checks failed
CI/CD / detect-changes (pull_request) Successful in 23s
CI/CD / test-frontend (pull_request) Has been skipped
CI/CD / test-runners (pull_request) Has been skipped
CI/CD / e2e-smoke (pull_request) Has been skipped
CI/CD / test-go-pg (pull_request) Failing after 2m59s
CI/CD / test-sqlite (pull_request) Failing after 3m22s
CI/CD / build-and-deploy (pull_request) Has been skipped
Extensions declare environment requirements via capabilities.required and capabilities.optional in their manifest. The kernel validates at install time — required capabilities reject with HTTP 422 and rollback, optional capabilities log a warning. Runtime query via settings.has_capability(). Admin endpoint GET /api/v1/admin/capabilities re-probes live. Detected capabilities: postgres, pgvector, object_storage, s3, workspace. 18 new tests, all passing with -race. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
76 lines
1.8 KiB
Go
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)
|
|
}
|
|
}
|