feat(commands): improve discovery and normalize parameters

This commit is contained in:
tiennm99 committed 2026-07-21 11:45:20 +07:00
1 parent 3316eec74c
commit f5ba9d4032
31 files changed
+479 -56

No files matched your search

+30 -1
View File
@@ -51,7 +51,8 @@ func TestRenderHelp_GroupsByModuleAndSkipsNonPublic(t *testing.T) {
for _, want := range []string{
"<b>alpha</b>",
"<b>beta</b>",
"/a_pub — alpha public",
"/a_pub. alpha public.",
"<pre>/a_pub</pre>",
// HTML in user descriptions must be escaped.
"beta &lt;i&gt;desc&lt;/i&gt;",
// Locks html.EscapeString contract: & → &amp;, " → &#34;.
@@ -71,6 +72,34 @@ func TestRenderHelp_GroupsByModuleAndSkipsNonPublic(t *testing.T) {
}
}
func TestRenderHelp_ShowsParametersAndCopyableExample(t *testing.T) {
command := modules.Command{
Name: "buy",
Visibility: modules.VisibilityPublic,
Description: "Buy & hold",
Parameters: "<quantity> <ticker>",
Example: "/buy 100 TCB",
Handler: helpTestNoop,
}
reg, err := modules.Build(
[]string{"stock"},
map[string]modules.Factory{"stock": fakeFactory("stock", []modules.Command{command})},
storage.NewMemoryProvider(),
modules.BuildOptions{},
)
if err != nil {
t.Fatalf("Build: %v", err)
}
out := util.RenderHelp(reg)
if !strings.Contains(out, "/buy &lt;quantity&gt; &lt;ticker&gt;. Buy &amp; hold.") {
t.Fatalf("help missing formatted invocation and summary:\n%s", out)
}
if !strings.Contains(out, "<pre>/buy 100 TCB</pre>") {
t.Fatalf("help missing copyable example:\n%s", out)
}
}
func TestRenderHelp_ModuleOrderMatchesEnvOrder(t *testing.T) {
cmd := func(name string) modules.Command {
return modules.Command{Name: name, Visibility: modules.VisibilityPublic, Description: name, Handler: helpTestNoop}