Feature: return web-console remarks from the Go MCP host tools
list_hosts and get_host_detail now include the remark an admin set in the web console, and the name/query filters match it like the Win32 server (name: hostname + remark; query: hostname + remark + IP). The text-only host table gains a remark column, and the MCP instructions stop claiming the Go server keeps no remarks. The remark table is injected through a small Note() interface so the mcp package still does not import web. An optional Notes() snapshot capability is borrowed once per call, so a listing neither takes a read lock per device nor mixes labels across a concurrent save. The design docs are updated to match the new fields and table column. Verified: go build ./..., go vet, gofmt and the full go test ./... pass; new tests cover remark projection, both filters and the snapshot path. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
95d2bbc1b6
commit
5f764b2425
8 files changed
+136
-28
No files matched your search
@@ -213,8 +213,22 @@ func TestAppendRowsSanitizesCells(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// fakeRemarks stands in for web.DeviceNotes: the map value is the remark. It
|
||||
// only implements Note, so it exercises the per-device fallback path.
|
||||
type fakeRemarks map[string]string
|
||||
|
||||
func (f fakeRemarks) Note(deviceID string) string { return f[deviceID] }
|
||||
|
||||
// fakeRemarkSnapshot also implements Notes(), the snapshot capability the
|
||||
// shipped web.DeviceNotes provides.
|
||||
type fakeRemarkSnapshot map[string]string
|
||||
|
||||
func (f fakeRemarkSnapshot) Note(deviceID string) string { return f[deviceID] }
|
||||
func (f fakeRemarkSnapshot) Notes() map[string]string { return f }
|
||||
|
||||
func TestListHostsPoolsAndProjection(t *testing.T) {
|
||||
f := newLocalFixture(t)
|
||||
f.srv.cfg.DeviceRemarks = fakeRemarkSnapshot{"1001": "Reception PC"}
|
||||
|
||||
text, sc := mustCallLocal(t, f.srv, "list_hosts", `{}`)
|
||||
hosts := hostList(t, sc)
|
||||
@@ -236,11 +250,11 @@ func TestListHostsPoolsAndProjection(t *testing.T) {
|
||||
}
|
||||
// Text-only MCP clients never see structuredContent, so the table in the
|
||||
// text block must carry the id every follow-up call is addressed by.
|
||||
if !strings.Contains(text, "id\tname\tip\tgroup\tos\tonline\tclientType\tlast_seen") {
|
||||
if !strings.Contains(text, "id\tname\tremark\tip\tgroup\tos\tonline\tclientType\tlast_seen") {
|
||||
t.Fatalf("text = %q, want host table header", text)
|
||||
}
|
||||
if !strings.Contains(text, "1001\tALPHA\t10.0.0.1\tdefault\tWindows 10\ttrue\tEXE\t-") {
|
||||
t.Fatalf("text = %q, want ALPHA row with id first", text)
|
||||
if !strings.Contains(text, "1001\tALPHA\tReception PC\t10.0.0.1\tdefault\tWindows 10\ttrue\tEXE\t-") {
|
||||
t.Fatalf("text = %q, want ALPHA row with id first and remark", text)
|
||||
}
|
||||
|
||||
alpha := hosts[0]
|
||||
@@ -268,7 +282,13 @@ func TestListHostsPoolsAndProjection(t *testing.T) {
|
||||
if _, ok := alpha["last_seen"]; ok {
|
||||
t.Fatal("online host carries last_seen")
|
||||
}
|
||||
for _, absent := range []string{"remark", "authStatus", "tls"} {
|
||||
if got := strField(t, alpha, "remark"); got != "Reception PC" {
|
||||
t.Fatalf("remark = %q, want the web console's label", got)
|
||||
}
|
||||
if _, ok := hosts[1]["remark"]; ok {
|
||||
t.Fatalf("unset remark present on %v", hosts[1]["id"])
|
||||
}
|
||||
for _, absent := range []string{"authStatus", "tls"} {
|
||||
if _, ok := alpha[absent]; ok {
|
||||
t.Fatalf("%s present but the Go server has no such data", absent)
|
||||
}
|
||||
@@ -306,6 +326,7 @@ func TestListHostsPoolsAndProjection(t *testing.T) {
|
||||
|
||||
func TestListHostsFilters(t *testing.T) {
|
||||
f := newLocalFixture(t)
|
||||
f.srv.cfg.DeviceRemarks = fakeRemarks{"1001": "Reception PC"}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
@@ -313,6 +334,7 @@ func TestListHostsFilters(t *testing.T) {
|
||||
want []string
|
||||
}{
|
||||
{"name substring", `{"name":"beta"}`, []string{"1002"}},
|
||||
{"name matches remark", `{"name":"reception"}`, []string{"1001"}},
|
||||
{"group substring", `{"group":"office"}`, []string{"1002", "1003"}},
|
||||
{"os substring case-insensitive", `{"os":"windows"}`, []string{"1001", "1002"}},
|
||||
{"client type", `{"client_type":"lnx"}`, []string{"1003"}},
|
||||
@@ -320,6 +342,7 @@ func TestListHostsFilters(t *testing.T) {
|
||||
{"peer ip fallback", `{"ip":"192.168.1.2"}`, []string{"1002"}},
|
||||
{"query matches name", `{"query":"gamma"}`, []string{"1003"}},
|
||||
{"query matches ip", `{"query":"10.0.0.1"}`, []string{"1001"}},
|
||||
{"query matches remark", `{"query":"reception"}`, []string{"1001"}},
|
||||
{"filters are ANDed", `{"group":"office","os":"ubuntu"}`, []string{"1003"}},
|
||||
{"no match", `{"name":"zzz"}`, nil},
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user