All checks were successful
CI/CD / detect-changes (push) Successful in 4s
CI/CD / test-runners (push) Has been skipped
CI/CD / e2e-smoke (push) Has been skipped
CI/CD / test-frontend (push) Successful in 5s
CI/CD / test-go-pg (push) Successful in 2m46s
CI/CD / test-sqlite (push) Successful in 2m57s
CI/CD / build-and-deploy (push) Successful in 44s
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
352 lines
8.3 KiB
Go
352 lines
8.3 KiB
Go
package handlers
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateManifest_ValidSurface(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-surface",
|
|
"title": "My Surface",
|
|
"type": "surface",
|
|
}
|
|
info, err := ValidateManifest(m)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if info.ID != "my-surface" {
|
|
t.Errorf("expected id 'my-surface', got %q", info.ID)
|
|
}
|
|
if info.Type != "surface" {
|
|
t.Errorf("expected type 'surface', got %q", info.Type)
|
|
}
|
|
if info.Version != "0.0.0" {
|
|
t.Errorf("expected default version '0.0.0', got %q", info.Version)
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_MissingID(t *testing.T) {
|
|
m := map[string]any{
|
|
"title": "No ID",
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for missing id")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_MissingTitle(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "no-title",
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for missing title")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_InvalidID(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "UPPERCASE-BAD",
|
|
"title": "Bad ID",
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for invalid package id")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_InvalidType(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-pkg",
|
|
"title": "My Package",
|
|
"type": "invalid",
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for invalid type")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_ExtensionNoTools(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-ext",
|
|
"title": "My Extension",
|
|
"type": "extension",
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for extension without tools/pipes/hooks")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_LibraryNoExports(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-lib",
|
|
"title": "My Library",
|
|
"type": "library",
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for library without exports")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_ValidLibrary(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-lib",
|
|
"title": "My Library",
|
|
"type": "library",
|
|
"version": "1.2.0",
|
|
"exports": []any{"module_a", "module_b"},
|
|
}
|
|
info, err := ValidateManifest(m)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if info.Version != "1.2.0" {
|
|
t.Errorf("expected version '1.2.0', got %q", info.Version)
|
|
}
|
|
if !info.HasExports {
|
|
t.Error("expected HasExports to be true")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_NilManifest(t *testing.T) {
|
|
_, err := ValidateManifest(nil)
|
|
if err == nil {
|
|
t.Fatal("expected error for nil manifest")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_SignatureField(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-pkg",
|
|
"title": "Signed Package",
|
|
"type": "surface",
|
|
"signature": "sha256:abc123",
|
|
}
|
|
info, err := ValidateManifest(m)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if info.Signature != "sha256:abc123" {
|
|
t.Errorf("expected signature 'sha256:abc123', got %q", info.Signature)
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_Dependencies(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "consumer",
|
|
"title": "Consumer Package",
|
|
"type": "surface",
|
|
"dependencies": map[string]any{
|
|
"chat-core": ">=1.0.0",
|
|
},
|
|
}
|
|
info, err := ValidateManifest(m)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if len(info.Dependencies) != 1 {
|
|
t.Errorf("expected 1 dependency, got %d", len(info.Dependencies))
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_ValidTestRunner(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "icd-test-runner",
|
|
"title": "ICD Test Runner",
|
|
"type": "test-runner",
|
|
}
|
|
info, err := ValidateManifest(m)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if info.Type != "test-runner" {
|
|
t.Errorf("expected type 'test-runner', got %q", info.Type)
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_TestRunnerWithRequires(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "chat-runner",
|
|
"title": "Chat Runner",
|
|
"type": "test-runner",
|
|
"requires": []any{"chat", "chat-core"},
|
|
}
|
|
info, err := ValidateManifest(m)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if len(info.Requires) != 2 {
|
|
t.Errorf("expected 2 requires, got %d", len(info.Requires))
|
|
}
|
|
if info.Requires[0] != "chat" || info.Requires[1] != "chat-core" {
|
|
t.Errorf("unexpected requires: %v", info.Requires)
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_WorkflowNoDef(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-wf",
|
|
"title": "My Workflow",
|
|
"type": "workflow",
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for workflow without workflow_definition")
|
|
}
|
|
}
|
|
|
|
// ── Surfaces validation ─────────────────────────────────────
|
|
|
|
func TestValidateManifest_ValidSurfaces(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "bug-tracker",
|
|
"title": "Bug Tracker",
|
|
"type": "full",
|
|
"hooks": []any{"surface"},
|
|
"surfaces": []any{
|
|
map[string]any{"path": "/", "title": "Dashboard"},
|
|
map[string]any{"path": "/submit", "access": "public", "title": "Report a Bug"},
|
|
map[string]any{"path": "/:id", "title": "Bug Detail", "nav": false},
|
|
map[string]any{"path": "/admin", "access": "admin", "title": "Settings"},
|
|
},
|
|
}
|
|
info, err := ValidateManifest(m)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if !info.HasSurfaces {
|
|
t.Error("expected HasSurfaces to be true")
|
|
}
|
|
if !info.HasRoute {
|
|
t.Error("expected HasRoute to be true")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_EmptySurfaces(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-pkg",
|
|
"title": "My Package",
|
|
"type": "surface",
|
|
"surfaces": []any{},
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for empty surfaces array")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_SurfaceMissingPath(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-pkg",
|
|
"title": "My Package",
|
|
"type": "surface",
|
|
"surfaces": []any{
|
|
map[string]any{"title": "No Path"},
|
|
},
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for surface without path")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_SurfacePathNoSlash(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-pkg",
|
|
"title": "My Package",
|
|
"type": "surface",
|
|
"surfaces": []any{
|
|
map[string]any{"path": "submit"},
|
|
},
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for path not starting with /")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_SurfaceDuplicatePath(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-pkg",
|
|
"title": "My Package",
|
|
"type": "surface",
|
|
"surfaces": []any{
|
|
map[string]any{"path": "/"},
|
|
map[string]any{"path": "/"},
|
|
},
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for duplicate surface path")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_SurfaceInvalidAccess(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-pkg",
|
|
"title": "My Package",
|
|
"type": "surface",
|
|
"surfaces": []any{
|
|
map[string]any{"path": "/", "access": "superuser"},
|
|
},
|
|
}
|
|
_, err := ValidateManifest(m)
|
|
if err == nil {
|
|
t.Fatal("expected error for invalid access level")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_SurfaceGroupAccess(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "my-pkg",
|
|
"title": "My Package",
|
|
"type": "surface",
|
|
"surfaces": []any{
|
|
map[string]any{"path": "/", "access": "group:engineering"},
|
|
},
|
|
}
|
|
info, err := ValidateManifest(m)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if !info.HasSurfaces {
|
|
t.Error("expected HasSurfaces to be true")
|
|
}
|
|
}
|
|
|
|
func TestValidateManifest_AutoSynthesizeSurfaces(t *testing.T) {
|
|
m := map[string]any{
|
|
"id": "legacy-pkg",
|
|
"title": "Legacy Package",
|
|
"type": "surface",
|
|
"auth": "public",
|
|
"layout": "editor",
|
|
}
|
|
info, err := ValidateManifest(m)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if !info.HasSurfaces {
|
|
t.Error("expected HasSurfaces after auto-synthesis")
|
|
}
|
|
// Verify the synthesized surfaces array was injected into the manifest
|
|
surfaces, ok := m["surfaces"].([]any)
|
|
if !ok || len(surfaces) != 1 {
|
|
t.Fatalf("expected 1 synthesized surface, got %v", m["surfaces"])
|
|
}
|
|
s := surfaces[0].(map[string]any)
|
|
if s["path"] != "/" {
|
|
t.Errorf("expected path '/', got %q", s["path"])
|
|
}
|
|
if s["access"] != "public" {
|
|
t.Errorf("expected access 'public', got %q", s["access"])
|
|
}
|
|
if s["layout"] != "editor" {
|
|
t.Errorf("expected layout 'editor', got %q", s["layout"])
|
|
}
|
|
}
|