Every agent RTK has no hook for got dsh's tooltip on the RTK tab: "{agent}'s
hooks can only allow or deny a command, not change it" with
rtk-ai/rtk#3847 ("FR: Support DSH"). For Grok Build that is wrong twice:
the issue is dsh's, and Grok's PreToolUse hooks can rewrite a command
(updatedInput, shown on rtk-ai/rtk#1890). What holds is that rtk init has
no Grok agent (src/hooks/init in rtk v1.0.1 has none), and
rtk-ai/rtk#2136 is the open request for Grok Build (#4513 was closed as
its duplicate). Each link was checked with gh issue view; the others in
rtk.go (#3847, #3934, #4311, #3898, #4187, #3404) are right.
rtkNoHookWhy in plugins/library/client.js gives each agent its own reason:
dsh keeps its text and #3847, Grok Build and Grok App cite #2136 (Grok App
runs Grok Build), and an agent with no entry gets a reason with no link.
New strings in zh, zh-TW, ja and de. rtk.go's grok and grok-app reasons,
which the CLI shows, cite #2136 too.
TestRTKNoHookIssuesAreEachAgents fails when an rtkNoHook agent has no page
reason (or the reverse), when the page and rtk.go cite different issues,
when two agents cite the same issues without a reason in sharedRTKIssues,
or when the fallback carries a link. library-rtk-nohook.test.cjs checks
Grok Build's tag says #2136 and never #3847, DeepSeek or "hook".
Run in a worktree rebased on origin/main 16327872c, sandbox HOME, caches
pinned:
- Broken by hand: with the old client.js the new test fails "client.js has
no rtkNoHookWhy: the no-hook tag isn't per agent"; with Grok's page link
set to #3847 it fails "dsh and grok both cite [rtk-ai/rtk#3847]: one's
reason was copied onto the other". Restored, it passes.
- gofmt -l on the changed Go files: empty. go vet ./..., GOOS=linux go vet
-tags nogui ./..., GOOS=windows go vet ./...: ok. go build, GOOS=linux
go build -tags nogui, GOOS=windows go build: ok (before the rebase).
- GUI: i18n-keys plus all 39 library-*.test.cjs, Chromium 351/351 and
WebKit 351/351.
- set -o pipefail; go test -timeout 45m ./... at load ~500-650: 60
packages ok; 4 red, none in the code changed here, each already filed:
internal/agent timed out at 45m (#2544), internal/gateway timed out at
45m (#2870), internal/gui TestSetAnswersWhileDevinAndProvidersHang
10.4s set under load (#1375), internal/library
TestCheckStdio/timeout_ends_the_tree (#2765). go test ./internal/library
-run 'RTK|TestCheckStdio' then passed (136.9s).
- Not tried: the real app with a real Grok Build install; the change is
tooltip text and links only.
112 lines
3.5 KiB
Go
112 lines
3.5 KiB
Go
package library
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"slices"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// sharedRTKIssues are the agents that cite the same rtk-ai/rtk issues on
|
|
// purpose, each with why. Any other two agents citing the same list is a
|
|
// reason copied from one agent onto another.
|
|
var sharedRTKIssues = map[[2]string]string{
|
|
// Grok App runs Grok Build, and rtk-ai/rtk#2136 asks for Grok Build.
|
|
{"grok", "grok-app"}: "Grok App runs Grok Build",
|
|
}
|
|
|
|
var rtkIssueRe = regexp.MustCompile(`github\.com/([\w.-]+/[\w.-]+)/issues/(\d+)`)
|
|
|
|
func rtkIssues(s string) []string {
|
|
var out []string
|
|
for _, m := range rtkIssueRe.FindAllStringSubmatch(s, -1) {
|
|
out = append(out, m[1]+"#"+m[2])
|
|
}
|
|
sort.Strings(out)
|
|
return slices.Compact(out)
|
|
}
|
|
|
|
// The RTK tab's no-hook tag says each agent's own reason and cites its
|
|
// own issues (新v学员 on Discord: Grok Build's tag said DeepSeek Harness's
|
|
// hooks can't rewrite a command and linked dsh's rtk-ai/rtk#3847, since
|
|
// every agent got dsh's text). The page's reasons (rtkNoHookWhy in
|
|
// plugins/library/client.js) cover every agent in rtkNoHook and cite the
|
|
// same issues as rtk.go's, two agents share an issue list only when
|
|
// sharedRTKIssues says why, and the fallback for an agent with no entry
|
|
// cites nothing.
|
|
func TestRTKNoHookIssuesAreEachAgents(t *testing.T) {
|
|
src, err := os.ReadFile(filepath.Join("..", "gui", "assets", "plugins", "library", "client.js"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := string(src)
|
|
start := strings.Index(s, "function rtkNoHookWhy(")
|
|
if start < 0 {
|
|
t.Fatal("client.js has no rtkNoHookWhy: the no-hook tag isn't per agent")
|
|
}
|
|
end := strings.Index(s[start:], "\n }\n")
|
|
if end < 0 {
|
|
t.Fatal("rtkNoHookWhy has no end")
|
|
}
|
|
body := s[start : start+end]
|
|
page := map[string]string{}
|
|
fallback, hasFallback := "", false
|
|
for _, line := range strings.Split(body, "\n") {
|
|
if m := regexp.MustCompile(`^\s*case "([\w-]+)": return (.*)$`).FindStringSubmatch(line); m != nil {
|
|
page[m[1]] = m[2]
|
|
} else if m := regexp.MustCompile(`^\s*default: return (.*)$`).FindStringSubmatch(line); m != nil {
|
|
fallback, hasFallback = m[1], true
|
|
}
|
|
}
|
|
if !hasFallback {
|
|
t.Error("rtkNoHookWhy has no default reason")
|
|
}
|
|
if got := rtkIssues(fallback); len(got) > 0 {
|
|
t.Errorf("the reason for an agent with no entry cites %v", got)
|
|
}
|
|
|
|
ids := make([]string, 0, len(rtkNoHook))
|
|
for id := range rtkNoHook {
|
|
ids = append(ids, id)
|
|
}
|
|
sort.Strings(ids)
|
|
for _, id := range ids {
|
|
why, ok := page[id]
|
|
if !ok {
|
|
t.Errorf("%s is in rtkNoHook but the page has no reason for it", id)
|
|
continue
|
|
}
|
|
if g, p := rtkIssues(rtkNoHook[id]), rtkIssues(why); !slices.Equal(g, p) {
|
|
t.Errorf("%s cites %v in rtk.go and %v on the page", id, g, p)
|
|
}
|
|
}
|
|
for id := range page {
|
|
if _, ok := rtkNoHook[id]; !ok {
|
|
t.Errorf("the page has a reason for %s, which rtkNoHook doesn't list", id)
|
|
}
|
|
}
|
|
|
|
for _, src := range []map[string]string{rtkNoHook, page} {
|
|
for i, a := range ids {
|
|
for _, b := range ids[i+1:] {
|
|
ia, ib := rtkIssues(src[a]), rtkIssues(src[b])
|
|
if len(ia) == 0 || !slices.Equal(ia, ib) {
|
|
continue
|
|
}
|
|
if _, ok := sharedRTKIssues[[2]string{a, b}]; !ok {
|
|
t.Errorf("%s and %s both cite %v: one's reason was copied onto the other", a, b, ia)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// a deliberate share that no longer holds is dropped from the list
|
|
for pair := range sharedRTKIssues {
|
|
if ia := rtkIssues(rtkNoHook[pair[0]]); len(ia) == 0 || !slices.Equal(ia, rtkIssues(rtkNoHook[pair[1]])) {
|
|
t.Errorf("sharedRTKIssues lists %v, which don't share an issue list", pair)
|
|
}
|
|
}
|
|
}
|