Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ concurrency:
cancel-in-progress: true

env:
COVER_MIN: "90"
COVER_MIN: "95"

jobs:
lint:
Expand Down
6 changes: 6 additions & 0 deletions pkg/pluginsdk/config/config_more_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func TestValidateManifestNilAndEmptySchema(t *testing.T) {
if err := config.ValidateManifestGlobalValue(manifest, "bad", map[string]any{}); err == nil {
t.Fatal("expected invalid schema JSON error")
}
if err := config.ValidateValue(&pluginv1.ConfigSchema{
Key: "bad-schema",
JsonSchema: `{"type":42}`,
}, "plugin global config", "bad-schema", map[string]any{}); err == nil {
t.Fatal("expected schema compile error")
}
if err := config.ValidateManifestUserValue(manifest, "prefs", map[string]any{"x": 1}); err != nil {
t.Fatalf("user value: %v", err)
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/pluginsdk/convert/convert_more_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,34 @@ func TestDecodeCapability_FullMetadataAndErrors(t *testing.T) {
t.Fatal("expected error")
}
})

t.Run("nil metadata value becomes empty struct", func(t *testing.T) {
got, err := convert.DecodeCapability(convert.CapabilityRecord{
Metadata: map[string]any{
"metadata": nil,
},
})
if err != nil {
t.Fatalf("DecodeCapability: %v", err)
}
if got.GetMetadata() == nil || len(got.GetMetadata().GetFields()) != 0 {
t.Fatalf("metadata = %+v, want empty struct", got.GetMetadata())
}
})

t.Run("non map metadata value becomes empty struct", func(t *testing.T) {
got, err := convert.DecodeCapability(convert.CapabilityRecord{
Metadata: map[string]any{
"metadata": []any{"ignored"},
},
})
if err != nil {
t.Fatalf("DecodeCapability: %v", err)
}
if got.GetMetadata() == nil || len(got.GetMetadata().GetFields()) != 0 {
t.Fatalf("metadata = %+v, want empty struct", got.GetMetadata())
}
})
}

func TestCapabilityRecordsFromManifest_ErrorsAndExtras(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/pluginsdk/manifest/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,12 @@ func TestLoadWithChecksumAppliesVersionOverrideBeforeValidation(t *testing.T) {
t.Fatalf("version override: got %q want 9.9.9", m.GetVersion())
}
}

func TestLoadWithChecksumRejectsInvalidManifest(t *testing.T) {
if _, err := LoadWithChecksum([]byte(`not-json`), ""); err == nil {
t.Fatal("expected decode error")
}
if _, err := LoadWithChecksum([]byte(`{"plugin_id":"prairie.invalid"}`), ""); err == nil {
t.Fatal("expected validation error")
}
}
40 changes: 40 additions & 0 deletions pkg/pluginsdk/manifest/watch_sync_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ func TestValidateWatchSyncProviderRejectsMissingDescriptor(t *testing.T) {
}
}

func TestValidateWatchSyncProviderRejectsUnsafeID(t *testing.T) {
manifest := validWatchSyncManifest()
manifest.Capabilities[0].Id = "Not Safe"
if err := publicmanifest.Validate(manifest); err == nil {
t.Fatal("expected unsafe capability id to fail")
}
}

func TestValidateWatchSyncProviderRejectsEmptyAuthMethods(t *testing.T) {
manifest := validWatchSyncManifest()
manifest.Capabilities[0].WatchSyncProvider.AuthMethods = nil
if err := publicmanifest.Validate(manifest); err == nil {
t.Fatal("expected empty auth methods to fail")
}
}

func TestValidateWatchSyncProviderRejectsUnspecifiedAuthMethod(t *testing.T) {
manifest := validWatchSyncManifest()
manifest.Capabilities[0].WatchSyncProvider.AuthMethods = []pluginv1.WatchSyncAuthMethod{
Expand All @@ -56,6 +72,22 @@ func TestValidateWatchSyncProviderRejectsUnspecifiedAuthMethod(t *testing.T) {
}
}

func TestValidateWatchSyncProviderRejectsEmptyOperations(t *testing.T) {
manifest := validWatchSyncManifest()
manifest.Capabilities[0].WatchSyncProvider.ExportWatched = false
if err := publicmanifest.Validate(manifest); err == nil {
t.Fatal("expected no enabled operations to fail")
}
}

func TestValidateWatchSyncProviderRejectsInvalidBatchSize(t *testing.T) {
manifest := validWatchSyncManifest()
manifest.Capabilities[0].WatchSyncProvider.MaxBatchSize = 101
if err := publicmanifest.Validate(manifest); err == nil {
t.Fatal("expected invalid batch size to fail")
}
}

func TestValidateWatchSyncProviderRejectsEmptyMediaTypes(t *testing.T) {
manifest := validWatchSyncManifest()
manifest.Capabilities[0].WatchSyncProvider.SupportedMediaTypes = nil
Expand All @@ -74,6 +106,14 @@ func TestValidateWatchSyncProviderRejectsUnspecifiedMediaType(t *testing.T) {
}
}

func TestValidateWatchSyncProviderRejectsInvalidNamespace(t *testing.T) {
manifest := validWatchSyncManifest()
manifest.Capabilities[0].WatchSyncProvider.ExternalIdNamespaces = []string{"bad namespace"}
if err := publicmanifest.Validate(manifest); err == nil {
t.Fatal("expected invalid external id namespace to fail")
}
}

func TestValidateWatchSyncProviderAllowsUnknownFutureEnums(t *testing.T) {
manifest := validWatchSyncManifest()
manifest.Capabilities[0].WatchSyncProvider.AuthMethods = []pluginv1.WatchSyncAuthMethod{
Expand Down
3 changes: 3 additions & 0 deletions pkg/pluginsdk/runtimehost/coverage_more_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ func TestClientRPCErrorPaths(t *testing.T) {
if _, err := c.CallPluginHTTP(ctx, runtimehost.CallPluginHTTPRequest{InstallationID: 1, Path: "/x"}); err == nil {
t.Fatal("CallPluginHTTP")
}
if _, err := c.MintScopedStream(ctx, runtimehost.ScopedStreamRequest{MediaFileID: 1}); err == nil {
t.Fatal("MintScopedStream")
}
if _, err := c.ResolveCatalogImageURLs(ctx, []string{"a"}, ""); err == nil {
t.Fatal("ResolveCatalogImageURLs")
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-coverage.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Fail if total statement coverage is below COVER_MIN (percent).
set -euo pipefail
COVER_MIN="${COVER_MIN:-70}"
COVER_MIN="${COVER_MIN:-95}"
PROFILE="${1:-coverage.out}"
if [[ ! -f "$PROFILE" ]]; then
echo "coverage profile missing: $PROFILE" >&2
Expand Down