Files
skillshare/internal/server/handler_hooks_contract_test.go
Willie 0dc2018747 feat(hooks): browse, edit and remove unmanaged hooks in the import dialog (#920)
* feat(hooks): browse, edit and remove unmanaged hooks in the import dialog

The import dialog listed every target's hooks in one long scroll of
full commands, so it was hard to read and hard to tell which target a
row belonged to. It also offered no way to change a hook without first
handing it to skillshare.

The dialog now shows one target at a time from a rail, with two-line
rows that open to the full commands. A hook that lives as an event in a
target's settings file can be edited or removed in place: the change
stays pending, a review step shows the file diff, and only then is the
file written, with a backup that restores it. The hook stays unmanaged.

The write is a new operation in internal/hooks (PreviewNativeEdits and
ApplyNativeEdits) that addresses elements by content, refuses anything
a ledger record holds, and reuses the existing backup and journal path.
Whole-file hooks, Copilot files and Antigravity blocks still have to be
imported first.

* fix(hooks): keep repeated restores and retries from writing a hook twice

Two ways an unmanaged hook could end up in a target file twice:

Restoring the backup of a removal a second time appended the hook
again. An unmanaged hook has no ledger record, so nothing marked the
backup as restored. PreviewRestore now reports a conflict when the
removed hook is already in the file.

When the dialog's native write succeeded and a later import failed, the
retry compared each pending change with the row it was made in. An edit
that moves or adds a command under another event comes back as other
rows, so the change stayed pending and was written again, and the new
row was picked for import. The dialog now drops every change once the
write went through (or reports files it already applied), and keeps
only the rows picked before as imports for the targets it wrote.

* chore: release as 0.30.9

Keep the next release on the patch version the maintainer asked for,
instead of the 0.31.0 that Release Please derives from the feat commit.

Release-As: 0.30.9

* fix(hooks): tell a restored hook from a surviving twin, keep unwritten edits

The check that refuses a second restore of a removed unmanaged hook
looked for any unmanaged hook with the same content. When one of two
identical hooks was removed, the survivor made the first restore look
done. A removal that shifts later hooks is stored as an update plus a
removal, which the check did not cover, and a restored hook that was
imported afterwards no longer counted, so those backups could still
restore twice. Every change to an unmanaged hook now records how many
identical hooks the write left, and a restore is refused only when the
file holds more than that.

When a native write failed after its first file, the dialog dropped
every pending change, including those of files the write never reached.
The failure response now lists the applied files in error_params, and
the dialog drops only the changes of those files. Pasted candidates are
no longer unpicked by a write to the target they were pasted for.

* fix(ui): show a hook row's edit and remove actions once

An open row in the import dialog showed the pencil and trash icons next
to the labelled Edit and Remove buttons below, which do the same thing.
The icons now hide while the row is open; their space is kept so the
chevron stays where it was clicked.

* chore: release as 0.30.9

Keep the next release on the patch version the maintainer asked for,
instead of the 0.31.0 that Release Please derives from the feat commit.

Release-As: 0.30.9

* fix(hooks): count surviving twins for every backup, not only native edits

Only the native edit preview recorded how many identical hooks a write
left, so the backup a restore writes had no count. Undoing a restore
through Backups was then refused whenever a hook with the same content
was still in the file. The count now happens where every backup is
written.

* fix(ui): keep the row icons as the only edit and remove actions

The labelled Edit and Remove buttons under an open row repeated the
icons and stood out too much, so they are gone and the icons stay
visible on open rows again. Each icon now has a tooltip that says what
it does.

* chore: release as 0.30.9

Keep the next release on the patch version the maintainer asked for,
instead of the 0.31.0 that Release Please derives from the feat commit.

Release-As: 0.30.9

* fix(ui): put the import dialog's hooks on one card, with fewer lines and fills

The dialog mixed a grey rail, a grey footer, grey expanded rows and a
divider around every region, and the editor stacked its own Cancel and
Done above the dialog's. It read as cluttered, and a long JSON line
pushed the editor's controls out of the dialog.

The dialog now sits on the page background with the hook list, or the
editor, as one card. Rows are separated only by the list separator, the
row icons are neutral until hovered, and code is the only sunken fill.
One row is open at a time, and a single command no longer repeats its
event as a heading.

While a hook is edited, the dialog's footer holds the editor's actions,
so there is one row of buttons and Cancel returns to the list instead
of closing the dialog with the draft. Commands are sections of the card
and wrap instead of scrolling sideways. The dialog is larger.

The hint is one line, the edit note moved to the footer, and the name
field is labelled by where the name is used.

* chore: release as 0.30.9

Keep the next release on the patch version the maintainer asked for,
instead of the 0.31.0 that Release Please derives from the feat commit.

Release-As: 0.30.9

* fix(ui): give the import review step the same card-on-ground look

The review step still had the white body, the grey footer and the
bordered summary box, so it looked like a different dialog from the
list it follows. It now sits on the page background with the summary
as one card, and the removal tile is neutral with only its icon in the
danger colour.

* chore: release as 0.30.9

Keep the next release on the patch version the maintainer asked for,
instead of the 0.31.0 that Release Please derives from the feat commit.

Release-As: 0.30.9
2026-11-16 22:55:13 +08:00

436 lines
18 KiB
Go

package server
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"skillshare/internal/config"
"skillshare/internal/hooks"
"strings"
"testing"
)
// These tests replay the requests the dashboard sends (ui/src/api/hooks.ts and its callers)
// against the real handlers: the same endpoints, the same mutation JSON, and the revision
// taken from the preview the dialog used. UI tests mock one fixed revision, so a mismatch
// between what the dashboard previews and what it saves only shows up here.
type hooksUIView struct {
Source struct {
Entries map[string]json.RawMessage `json:"entries"`
Projects map[string]struct {
Entries map[string]json.RawMessage `json:"entries"`
} `json:"projects"`
} `json:"source"`
Plan *struct {
Blocked bool `json:"blocked"`
Changes []struct {
Name string `json:"name"`
Root string `json:"root"`
Action string `json:"action"`
} `json:"changes"`
} `json:"plan"`
Backups []struct {
ID string `json:"id"`
Path string `json:"path"`
} `json:"backups"`
Unmanaged []struct {
Path string `json:"path"`
Names []string `json:"names"`
} `json:"unmanaged"`
}
func hooksUIList(t *testing.T, s *Server) hooksUIView {
t.Helper()
w := httptest.NewRecorder()
s.handleHooksList(w, httptest.NewRequest(http.MethodGet, "/api/hooks", nil))
var view hooksUIView
if w.Code != http.StatusOK || json.Unmarshal(w.Body.Bytes(), &view) != nil {
t.Fatalf("list: %d %s", w.Code, w.Body)
}
return view
}
// hooksUIConfigure is hooksApi.configure.
func hooksUIConfigure(s *Server, mutation, revision string, sync bool) *httptest.ResponseRecorder {
body, _ := json.Marshal(map[string]any{"mutation": json.RawMessage(mutation), "revision": revision, "sync": sync})
return hooksPost(s, s.handleHooksConfigure, "/api/hooks", string(body))
}
// hooksUISync is HooksSyncDialog without a project, and the Sync page: preview nothing, apply that plan.
func hooksUISync(t *testing.T, s *Server) {
t.Helper()
if w := hooksUIConfigure(s, `{}`, hooksPreviewRevision(t, s, `{}`), true); w.Code != http.StatusOK {
t.Fatalf("sync: %d %s", w.Code, w.Body)
}
}
func hooksEntryJSON(command string) string {
return `{"bindings":{"claude":{"events":{"PreToolUse":[{"matcher":"Bash","hooks":[{"type":"command","command":"` + command + `"}]}]}}}}`
}
// hooksUIScope is one place the dashboard manages hooks from: the global page, a
// hooks.projects root's tab, or a server started in project mode.
type hooksUIScope struct {
name string
s *Server
project string // mutation.project, empty outside a hooks.projects root
settings string
}
var hooksUIScopes = []func(t *testing.T) hooksUIScope{
func(t *testing.T) hooksUIScope {
s, _ := newTestServerWithExtras(t, nil, "")
home := hooksTestHome(t)
return hooksUIScope{"global", s, "", filepath.Join(home, ".claude", "settings.json")}
},
func(t *testing.T) hooksUIScope {
s, _ := newTestServerWithExtras(t, nil, "")
hooksTestHome(t)
root := t.TempDir()
return hooksUIScope{"hooks.projects root", s, root, filepath.Join(root, ".claude", "settings.json")}
},
func(t *testing.T) hooksUIScope {
s, root := newTestProjectServerWithExtras(t, nil)
hooksTestHome(t)
return hooksUIScope{"project mode", s, "", filepath.Join(root, ".claude", "settings.json")}
},
}
var hooksUIScopeNames = []string{"global", "hooks.projects root", "project mode"}
// mutation adds the scope's project field the way the dialogs spread `...(project && { project })`.
func (sc hooksUIScope) mutation(fields string) string {
if sc.project == "" {
return `{` + fields + `}`
}
return `{"project":"` + sc.project + `",` + fields + `}`
}
// addAndSync is HookDialog with "Save and sync": preview the mutation, configure with that revision.
func (sc hooksUIScope) addAndSync(t *testing.T, name, command string) {
t.Helper()
mutation := sc.mutation(`"name":"` + name + `","entry":` + hooksEntryJSON(command))
if w := hooksUIConfigure(sc.s, mutation, hooksPreviewRevision(t, sc.s, mutation), true); w.Code != http.StatusOK {
t.Fatalf("%s: add and sync: %d %s", sc.name, w.Code, w.Body)
}
if !strings.Contains(readOrEmpty(sc.settings), command) {
t.Fatalf("%s: not written:\n%s", sc.name, readOrEmpty(sc.settings))
}
}
func (sc hooksUIScope) entries(t *testing.T) map[string]json.RawMessage {
view := hooksUIList(t, sc.s)
if sc.project != "" {
return view.Source.Projects[sc.project].Entries
}
return view.Source.Entries
}
// HooksRemoveDialog: all three choices, in every scope.
func TestHooksUIContract_RemoveDialog(t *testing.T) {
for i, newScope := range hooksUIScopes {
for _, choice := range []string{"sync", "source only", "stop managing"} {
t.Run(hooksUIScopeNames[i]+"/"+choice, func(t *testing.T) {
sc := newScope(t)
sc.addAndSync(t, "guard", "echo contract-guard")
removal := sc.mutation(`"name":"guard","remove":true`)
planRevision := hooksPreviewRevision(t, sc.s, removal)
var w *httptest.ResponseRecorder
switch choice {
case "sync":
w = hooksUIConfigure(sc.s, removal, planRevision, true)
case "source only":
w = hooksUIConfigure(sc.s, removal, planRevision, false)
case "stop managing":
unmanage := sc.mutation(`"name":"guard","remove":true,"unmanage":true`)
w = hooksUIConfigure(sc.s, unmanage, hooksPreviewRevision(t, sc.s, unmanage), false)
}
if w.Code != http.StatusOK {
t.Fatalf("%d %s", w.Code, w.Body)
}
if _, ok := sc.entries(t)["guard"]; ok {
t.Fatal("still in the source")
}
written := strings.Contains(readOrEmpty(sc.settings), "echo contract-guard")
view := hooksUIList(t, sc.s)
pending := view.Plan != nil && len(view.Plan.Changes) > 0
switch choice {
case "sync":
if written || pending {
t.Fatalf("written=%v pending=%v", written, pending)
}
case "source only":
if !written || !pending || view.Plan.Changes[0].Action != "remove" {
t.Fatalf("written=%v plan=%+v", written, view.Plan)
}
case "stop managing":
if !written || pending || len(view.Unmanaged) != 1 || view.Unmanaged[0].Path != sc.settings {
t.Fatalf("written=%v plan=%+v unmanaged=%+v", written, view.Plan, view.Unmanaged)
}
}
})
}
}
}
// Stop managing plans no file change, so its revision differs from the removal preview's.
// A dashboard that reuses the removal preview's revision is refused as stale (fixed in the UI
// by previewing the unmanage mutation itself); this pins the server side of that contract.
func TestHooksUIContract_StopManagingRejectsTheRemovalPreviewRevision(t *testing.T) {
sc := hooksUIScopes[0](t)
sc.addAndSync(t, "guard", "echo contract-guard")
removalRevision := hooksPreviewRevision(t, sc.s, `{"name":"guard","remove":true}`)
w := hooksUIConfigure(sc.s, `{"name":"guard","remove":true,"unmanage":true}`, removalRevision, false)
if w.Code != http.StatusConflict || !strings.Contains(w.Body.String(), "changed since preview") {
t.Fatalf("%d %s", w.Code, w.Body)
}
if _, ok := sc.entries(t)["guard"]; !ok {
t.Fatal("a refused save changed the source")
}
}
// HookDialog edit: same name, new entry, no replace flag; then save-only edits and HooksScope's
// enable switch, which saves the entry with enabled:false.
func TestHooksUIContract_EditAndToggle(t *testing.T) {
for i, newScope := range hooksUIScopes {
t.Run(hooksUIScopeNames[i], func(t *testing.T) {
sc := newScope(t)
sc.addAndSync(t, "guard", "echo contract-v1")
sc.addAndSync(t, "guard", "echo contract-v2")
if got := readOrEmpty(sc.settings); strings.Contains(got, "contract-v1") {
t.Fatalf("edit kept the old command:\n%s", got)
}
hooksSave(t, sc.s, sc.mutation(`"name":"guard","entry":`+strings.Replace(hooksEntryJSON("echo contract-v2"), `{"bindings"`, `{"enabled":false,"bindings"`, 1)))
hooksUISync(t, sc.s)
if strings.Contains(readOrEmpty(sc.settings), "contract-v2") {
t.Fatal("a disabled hook stayed in the target file")
}
hooksSave(t, sc.s, sc.mutation(`"name":"guard","entry":`+hooksEntryJSON("echo contract-v2")))
hooksUISync(t, sc.s)
if !strings.Contains(readOrEmpty(sc.settings), "contract-v2") {
t.Fatal("enabling did not write the hook back")
}
})
}
}
// HooksSyncDialog with a takeover (and HookDialog with its takeover box): the source entry
// with replace:true, previewed and applied with sync, overwrites an outside edit.
func TestHooksUIContract_TakeOverOutsideEdit(t *testing.T) {
for i, newScope := range hooksUIScopes {
t.Run(hooksUIScopeNames[i], func(t *testing.T) {
sc := newScope(t)
sc.addAndSync(t, "guard", "echo contract-guard")
edited := strings.Replace(readOrEmpty(sc.settings), "echo contract-guard", "echo edited-outside", 1)
if err := os.WriteFile(sc.settings, []byte(edited), 0644); err != nil {
t.Fatal(err)
}
if view := hooksUIList(t, sc.s); view.Plan == nil || !view.Plan.Blocked {
t.Fatalf("outside edit is not a conflict: %+v", view.Plan)
}
takeover := sc.mutation(`"name":"guard","entry":` + string(sc.entries(t)["guard"]) + `,"replace":true`)
if w := hooksUIConfigure(sc.s, takeover, hooksPreviewRevision(t, sc.s, takeover), true); w.Code != http.StatusOK {
t.Fatalf("takeover: %d %s", w.Code, w.Body)
}
if got := readOrEmpty(sc.settings); strings.Contains(got, "edited-outside") || !strings.Contains(got, "contract-guard") {
t.Fatalf("takeover did not restore the source hook:\n%s", got)
}
if view := hooksUIList(t, sc.s); view.Plan == nil || view.Plan.Blocked {
t.Fatalf("still blocked after takeover: %+v", view.Plan)
}
})
}
}
// HooksImportDialog in a hooks.projects root: import with root, save with adopt, then the
// project's sync adopts the registration in place.
func TestHooksUIContract_ProjectImportAdopt(t *testing.T) {
s, _ := newTestServerWithExtras(t, nil, "")
hooksTestHome(t)
root := t.TempDir()
hooksSave(t, s, `{"project":"`+root+`"}`) // AddProjectDialog
settings := filepath.Join(root, ".claude", "settings.json")
if err := os.MkdirAll(filepath.Dir(settings), 0755); err != nil {
t.Fatal(err)
}
native := `{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"echo project-native"}]}]}}`
if err := os.WriteFile(settings, []byte(native), 0644); err != nil {
t.Fatal(err)
}
w := hooksPost(s, s.handleHooksImport, "/api/hooks/import", `{"from":"claude","root":"`+root+`"}`)
var imported struct {
Candidates []struct {
Name string `json:"name"`
Entry json.RawMessage `json:"entry"`
} `json:"candidates"`
}
if w.Code != http.StatusOK || json.Unmarshal(w.Body.Bytes(), &imported) != nil || len(imported.Candidates) != 1 {
t.Fatalf("import: %d %s", w.Code, w.Body)
}
hooksSave(t, s, `{"project":"`+root+`","name":"stop","entry":`+string(imported.Candidates[0].Entry)+`,"adopt":true}`)
if w := hooksPost(s, s.handleHooksConfigure, "/api/hooks", `{"mutation":{},"revision":"`+hooksPreviewRevision(t, s, `{}`)+`","sync":true,"root":"`+root+`"}`); w.Code != http.StatusOK {
t.Fatalf("project sync: %d %s", w.Code, w.Body)
}
view := hooksUIList(t, s)
if len(view.Unmanaged) != 0 || view.Plan == nil || view.Plan.Blocked || view.Plan.Changes[0].Action != "unchanged" {
t.Fatalf("adopted hook is not managed: unmanaged=%+v plan=%+v", view.Unmanaged, view.Plan)
}
if readOrEmpty(settings) != native {
t.Fatalf("adopting rewrote the file:\n%s", readOrEmpty(settings))
}
hooksSave(t, s, `{"project":"`+root+`","remove":true}`) // ProjectDetailPage removing the project
if _, ok := hooksUIList(t, s).Source.Projects[root]; ok {
t.Fatal("project still configured")
}
}
// The global sync writes the whole plan, hooks.projects roots included.
func TestHooksUIContract_GlobalSyncWritesEveryScope(t *testing.T) {
s, _ := newTestServerWithExtras(t, nil, "")
home := hooksTestHome(t)
root := t.TempDir()
hooksSave(t, s, hooksTestMutation)
hooksSave(t, s, hooksProjectEntry(root, "a", "echo hook-a"))
hooksUISync(t, s)
if !strings.Contains(readOrEmpty(filepath.Join(home, ".claude", "settings.json")), "skillshare-hooks-test") || !strings.Contains(readOrEmpty(filepath.Join(root, ".claude", "settings.json")), "echo hook-a") {
t.Fatal("global sync skipped a scope")
}
}
// HooksRestoreDialog: preview the backup, restore with that revision. A shared settings file
// gets back only what that write changed; the rest of the file stays.
func TestHooksUIContract_RestoreBackup(t *testing.T) {
sc := hooksUIScopes[0](t)
if err := os.MkdirAll(filepath.Dir(sc.settings), 0755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(sc.settings, []byte(`{"model":"opus"}`), 0644); err != nil {
t.Fatal(err)
}
sc.addAndSync(t, "guard", "echo contract-guard")
backups := hooksUIList(t, sc.s).Backups
if len(backups) != 1 {
t.Fatalf("backups: %+v", backups)
}
preview := hooksPost(sc.s, sc.s.handleHooksRestore, "/api/hooks/restore", `{"backupId":"`+backups[0].ID+`","preview":true}`)
var p struct {
Revision string `json:"revision"`
}
if preview.Code != http.StatusOK || json.Unmarshal(preview.Body.Bytes(), &p) != nil || p.Revision == "" {
t.Fatalf("restore preview: %d %s", preview.Code, preview.Body)
}
if w := hooksPost(sc.s, sc.s.handleHooksRestore, "/api/hooks/restore", `{"backupId":"`+backups[0].ID+`","revision":"`+p.Revision+`"}`); w.Code != http.StatusOK {
t.Fatalf("restore: %d %s", w.Code, w.Body)
}
if got := readOrEmpty(sc.settings); strings.Contains(got, "contract-guard") || !strings.Contains(got, `"model":"opus"`) {
t.Fatalf("restored file:\n%s", got)
}
}
// HookDialog with its takeover box ticked but saved without sync: replace is not kept in the
// source, so the conflict stays for the next takeover preview to resolve.
func TestHooksUIContract_TakeOverSaveOnlyKeepsTheConflict(t *testing.T) {
sc := hooksUIScopes[0](t)
sc.addAndSync(t, "guard", "echo contract-guard")
edited := strings.Replace(readOrEmpty(sc.settings), "echo contract-guard", "echo edited-outside", 1)
if err := os.WriteFile(sc.settings, []byte(edited), 0644); err != nil {
t.Fatal(err)
}
hooksSave(t, sc.s, `{"name":"guard","entry":`+hooksEntryJSON("echo contract-v2")+`,"replace":true}`)
if view := hooksUIList(t, sc.s); view.Plan == nil || !view.Plan.Blocked {
t.Fatalf("save-only takeover resolved the conflict: %+v", view.Plan)
}
if readOrEmpty(sc.settings) != edited {
t.Fatal("save-only takeover wrote the target file")
}
}
func TestHooksUIContract_AccountTargets(t *testing.T) {
s, _ := newTestServer(t)
home := hooksTestHome(t)
dir := filepath.Join(home, ".codex-2")
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatal(err)
}
s.cfg.Targets["codex-2"] = config.TargetConfig{Agent: "codex", ConfigDir: dir}
w := httptest.NewRecorder()
s.handleHooksList(w, httptest.NewRequest(http.MethodGet, "/api/hooks", nil))
var inv hooks.Inventory
if w.Code != http.StatusOK || json.Unmarshal(w.Body.Bytes(), &inv) != nil {
t.Fatalf("%d %s", w.Code, w.Body)
}
found := false
for _, target := range inv.Targets {
if target.Name == "codex-2" && target.Agent == "codex" && target.Kind == "command" {
found = true
}
}
if !found || inv.Paths["codex-2"] != filepath.Join(dir, "hooks.json") {
t.Fatalf("%+v", inv)
}
mutation := `{"name":"k","entry":{"bindings":{"codex-2":{"events":{"Stop":[{"hooks":[{"type":"command","command":"x"}]}]}}}}}`
w = hooksPost(s, s.handleHooksPreview, "/api/hooks/preview", `{"mutation":`+mutation+`}`)
if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), `"target":"codex-2"`) {
t.Fatalf("%d %s", w.Code, w.Body)
}
}
// HooksImportDialog editing a hook that was never imported: preview the edit, apply it
// with that revision. The hook changes in the target's file and stays unmanaged.
func TestHooksUIContract_EditUnmanagedHook(t *testing.T) {
for i, newScope := range hooksUIScopes {
t.Run(hooksUIScopeNames[i], func(t *testing.T) {
sc := newScope(t)
// A managed hook registers the scope and shares the file with the user's own hook.
sc.addAndSync(t, "guard", "echo contract-guard")
mine := `{"hooks":[{"type":"command","command":"echo mine"}]}`
var doc struct {
Hooks map[string]json.RawMessage `json:"hooks"`
}
if err := json.Unmarshal([]byte(readOrEmpty(sc.settings)), &doc); err != nil {
t.Fatal(err)
}
doc.Hooks["SessionEnd"] = json.RawMessage(`[` + mine + `]`)
own, err := json.Marshal(doc)
if err != nil {
t.Fatal(err)
}
if err := os.WriteFile(sc.settings, own, 0644); err != nil {
t.Fatal(err)
}
root := ""
if sc.project != "" {
root = `"root":"` + sc.project + `",`
}
edits := `[{"target":"claude",` + root + `"before":{"SessionEnd":[` + mine + `]},"after":{"SessionEnd":[` + strings.Replace(mine, "echo mine", "echo edited", 1) + `]}}]`
preview := hooksPost(sc.s, sc.s.handleHooksNativePreview, "/api/hooks/native/preview", `{"edits":`+edits+`}`)
var p struct {
Revision string `json:"revision"`
Files []struct {
After string `json:"after"`
} `json:"files"`
}
if preview.Code != http.StatusOK || json.Unmarshal(preview.Body.Bytes(), &p) != nil || len(p.Files) != 1 || !strings.Contains(p.Files[0].After, "echo edited") {
t.Fatalf("native preview: %d %s", preview.Code, preview.Body)
}
if w := hooksPost(sc.s, sc.s.handleHooksNativeApply, "/api/hooks/native", `{"edits":`+edits+`}`); w.Code != http.StatusBadRequest {
t.Fatalf("apply without a preview: %d %s", w.Code, w.Body)
}
if w := hooksPost(sc.s, sc.s.handleHooksNativeApply, "/api/hooks/native", `{"edits":`+edits+`,"revision":"`+p.Revision+`"}`); w.Code != http.StatusOK {
t.Fatalf("native apply: %d %s", w.Code, w.Body)
}
if got := readOrEmpty(sc.settings); !strings.Contains(got, "echo edited") || strings.Contains(got, "echo mine") || !strings.Contains(got, "echo contract-guard") {
t.Fatalf("edited file:\n%s", got)
}
if _, ok := sc.entries(t)["guard"]; !ok || len(sc.entries(t)) != 1 {
t.Fatalf("the edited hook must stay out of the source: %v", sc.entries(t))
}
})
}
}