mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Git 2.54 added named config hooks, but keeping their registrations and helper paths consistent across machines still required manual config edits. Bring them into the same preview, sync, and recovery workflow as Agent hooks. - Global and project scope, with linked worktrees sharing the common dir - Portable helper files, collision detection, and ownership tracking of generated files and include.path entries - Backups and restore preserve unrelated settings and conditional includes - Management never executes hooks; Git below 2.54 is reported as inactive while outputs are still generated - CLI/API inventory, raw YAML editing in the dashboard, localized docs
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package hooks
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestHookSchemaEntryDoesNotAdvertiseUnknownFields(t *testing.T) {
|
|
data, err := os.ReadFile("../../schemas/hooks.schema.json")
|
|
must(t, err)
|
|
var schema struct {
|
|
Defs map[string]json.RawMessage `json:"$defs"`
|
|
}
|
|
must(t, json.Unmarshal(data, &schema))
|
|
var definition struct {
|
|
Properties map[string]json.RawMessage `json:"properties"`
|
|
Additional *bool `json:"additionalProperties"`
|
|
}
|
|
must(t, json.Unmarshal(schema.Defs["entry"], &definition))
|
|
for field := range definition.Properties {
|
|
var value any
|
|
// Give the parser a valid value for known fields. Schema keys must be
|
|
// accepted source fields rather than editor-only phantom properties.
|
|
switch field {
|
|
case "description":
|
|
value = "description"
|
|
case "enabled":
|
|
value = true
|
|
default:
|
|
value = map[string]any{}
|
|
}
|
|
doc, _ := json.Marshal(map[string]any{"bindings": map[string]any{}, field: value})
|
|
if _, err := ParseEntry(doc); err != nil {
|
|
t.Errorf("schema advertises rejected entry field %s: %v", field, err)
|
|
}
|
|
}
|
|
if definition.Additional == nil || *definition.Additional {
|
|
t.Fatal("schema must explicitly reject unknown entry fields with additionalProperties: false")
|
|
}
|
|
}
|
|
|
|
func TestGitSchemaAvailableInBothScopes(t *testing.T) {
|
|
data, err := os.ReadFile("../../schemas/hooks.schema.json")
|
|
must(t, err)
|
|
var schema struct {
|
|
Defs map[string]struct {
|
|
Properties map[string]struct {
|
|
Ref string `json:"$ref"`
|
|
} `json:"properties"`
|
|
} `json:"$defs"`
|
|
}
|
|
must(t, json.Unmarshal(data, &schema))
|
|
for _, scope := range []string{"bindings", "globalBindings"} {
|
|
if ref := schema.Defs[scope].Properties["git"].Ref; ref != "#/$defs/gitBinding" {
|
|
t.Errorf("%s cannot validate Git commands: %q", scope, ref)
|
|
}
|
|
}
|
|
}
|