@@ -349,6 +349,7 @@ func TestManifestNotFoundError(t *testing.T) {
349349 suggestion := err .Suggestion ()
350350 expectedParts := []string {
351351 "Extension manifest not found" ,
352+ "schema_version:" ,
352353 "name:" ,
353354 "version:" ,
354355 "description:" ,
@@ -426,6 +427,131 @@ func TestManifestValidationError(t *testing.T) {
426427 }
427428}
428429
430+ // TestSchemaVersionError tests the SchemaVersionError type
431+ func TestSchemaVersionError (t * testing.T ) {
432+ err := & SchemaVersionError {
433+ Path : "/path/to/extension.yaml" ,
434+ Found : 99 ,
435+ MaxSupported : 1 ,
436+ }
437+
438+ // Test Error() method
439+ errMsg := err .Error ()
440+ if ! strings .Contains (errMsg , "schema version 99" ) {
441+ t .Errorf ("Error() should contain found version, got: %s" , errMsg )
442+ }
443+ if ! strings .Contains (errMsg , "up to version 1" ) {
444+ t .Errorf ("Error() should contain max supported version, got: %s" , errMsg )
445+ }
446+ if ! strings .Contains (errMsg , "/path/to/extension.yaml" ) {
447+ t .Errorf ("Error() should contain path, got: %s" , errMsg )
448+ }
449+
450+ // Test Suggestion() method
451+ suggestion := err .Suggestion ()
452+ expectedParts := []string {
453+ "not supported" ,
454+ "upgrade sley" ,
455+ "go install" ,
456+ "Documentation:" ,
457+ }
458+ for _ , part := range expectedParts {
459+ if ! strings .Contains (suggestion , part ) {
460+ t .Errorf ("Suggestion() should contain %q, got: %s" , part , suggestion )
461+ }
462+ }
463+ }
464+
465+ // TestSchemaVersion_Validation tests schema_version field behavior
466+ func TestSchemaVersion_Validation (t * testing.T ) {
467+ base := ExtensionManifest {
468+ Name : "test-ext" ,
469+ Version : "1.0.0" ,
470+ Description : "Test extension" ,
471+ Author : "Author" ,
472+ Repository : "https://github.com/test/repo" ,
473+ Entry : "hook.sh" ,
474+ }
475+
476+ tests := []struct {
477+ name string
478+ schemaVersion int
479+ wantErr bool
480+ wantErrType string // "version" or "validation"
481+ wantDefault int // expected SchemaVersion after validation
482+ }{
483+ {
484+ name : "omitted defaults to 1" ,
485+ schemaVersion : 0 ,
486+ wantErr : false ,
487+ wantDefault : DefaultSchemaVersion ,
488+ },
489+ {
490+ name : "explicit version 1 accepted" ,
491+ schemaVersion : 1 ,
492+ wantErr : false ,
493+ wantDefault : 1 ,
494+ },
495+ {
496+ name : "future version 99 rejected" ,
497+ schemaVersion : 99 ,
498+ wantErr : true ,
499+ wantErrType : "version" ,
500+ },
501+ {
502+ name : "negative version rejected" ,
503+ schemaVersion : - 1 ,
504+ wantErr : true ,
505+ wantErrType : "validation" ,
506+ },
507+ }
508+
509+ for _ , tt := range tests {
510+ t .Run (tt .name , func (t * testing.T ) {
511+ m := base
512+ m .SchemaVersion = tt .schemaVersion
513+
514+ err := m .ValidateManifest ()
515+
516+ if (err != nil ) != tt .wantErr {
517+ t .Errorf ("ValidateManifest() error = %v, wantErr %v" , err , tt .wantErr )
518+ return
519+ }
520+
521+ if tt .wantErr {
522+ switch tt .wantErrType {
523+ case "version" :
524+ var vErr * SchemaVersionError
525+ if ! errors .As (err , & vErr ) {
526+ t .Errorf ("expected SchemaVersionError, got %T: %v" , err , err )
527+ }
528+ case "validation" :
529+ var valErr * ManifestValidationError
530+ if ! errors .As (err , & valErr ) {
531+ t .Errorf ("expected ManifestValidationError, got %T: %v" , err , err )
532+ }
533+ }
534+ } else if m .SchemaVersion != tt .wantDefault {
535+ t .Errorf ("expected SchemaVersion %d, got %d" , tt .wantDefault , m .SchemaVersion )
536+ }
537+ })
538+ }
539+ }
540+
541+ // TestSchemaVersionConstants tests that constants are consistent
542+ func TestSchemaVersionConstants (t * testing.T ) {
543+ if CurrentSchemaVersion < 1 {
544+ t .Errorf ("CurrentSchemaVersion should be >= 1, got %d" , CurrentSchemaVersion )
545+ }
546+ if DefaultSchemaVersion < 1 {
547+ t .Errorf ("DefaultSchemaVersion should be >= 1, got %d" , DefaultSchemaVersion )
548+ }
549+ if DefaultSchemaVersion > CurrentSchemaVersion {
550+ t .Errorf ("DefaultSchemaVersion (%d) should not exceed CurrentSchemaVersion (%d)" ,
551+ DefaultSchemaVersion , CurrentSchemaVersion )
552+ }
553+ }
554+
429555// TestManifestValidation_MultipleErrors tests that all missing fields are reported
430556func TestManifestValidation_MultipleErrors (t * testing.T ) {
431557 manifest := ExtensionManifest {
0 commit comments