| 1 | package capdiag |
| 2 | |
| 3 | import ( |
| 4 | "errors" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/internal/hook" |
| 8 | ) |
| 9 | |
| 10 | func TestHookRuntimeIssueIsActionableAndScoped(t *testing.T) { |
| 11 | entry := hook.Entry{ |
| 12 | Event: hook.SessionStart, |
| 13 | Scope: hook.ScopePlugin, |
| 14 | Source: `C:\Users\Test\AppData\Roaming\reasonix\plugins\superpowers\.codex-plugin\plugin.json`, |
| 15 | } |
| 16 | issue, ok := hookRuntimeIssue(entry, errors.New("hook requires a POSIX shell on Windows, but no usable Git Bash was found"), func(string) string { |
| 17 | return "<reasonix-home>/plugins/superpowers/.codex-plugin/plugin.json" |
| 18 | }) |
| 19 | if !ok { |
| 20 | t.Fatal("missing runtime dependency should produce a diagnostic issue") |
| 21 | } |
| 22 | if issue.Code != "hook.shell_unavailable" || issue.Severity != "error" || issue.Subsystem != "hooks" { |
| 23 | t.Fatalf("issue identity = %+v", issue) |
| 24 | } |
| 25 | if issue.Name != string(hook.SessionStart) || issue.SettingsTab != "hooks" { |
| 26 | t.Fatalf("issue scope = %+v", issue) |
| 27 | } |
| 28 | if issue.Source != "<reasonix-home>/plugins/superpowers/.codex-plugin/plugin.json" { |
| 29 | t.Fatalf("issue source = %q", issue.Source) |
| 30 | } |
| 31 | if issue.Remediation == "" { |
| 32 | t.Fatal("runtime dependency issue must include remediation") |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestHookRuntimeIssueIgnoresAvailableRuntime(t *testing.T) { |
| 37 | if _, ok := hookRuntimeIssue(hook.Entry{}, nil, func(path string) string { return path }); ok { |
| 38 | t.Fatal("available runtime must not produce an issue") |
| 39 | } |
| 40 | } |
| 41 |