This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new c4015041c fix(rmqctl): preserve mutation summary number precision 
(#6319)
c4015041c is described below

commit c4015041c0efffbadf6b327ff7eeddc4d6dbd38e
Author: pilichoumao <[email protected]>
AuthorDate: Fri Nov 27 12:02:24 2026 +0800

    fix(rmqctl): preserve mutation summary number precision (#6319)
---
 docs/ai-agent-architecture.md                    |  3 ++
 rmqctl/cmd/mutation_precision_test.go            | 67 +++++++++++++++++++++++
 rmqctl/internal/types/mutation_precision_test.go | 69 ++++++++++++++++++++++++
 rmqctl/internal/types/types.go                   |  6 ++-
 4 files changed, 144 insertions(+), 1 deletion(-)

diff --git a/docs/ai-agent-architecture.md b/docs/ai-agent-architecture.md
index fb64c8897..40e9d8322 100644
--- a/docs/ai-agent-architecture.md
+++ b/docs/ai-agent-architecture.md
@@ -39,6 +39,9 @@ Studio 自己不再实现工具调用循环,也不把工具直接塞进 JVM 
 所以准确的描述是:`rmqctl` 是一个**带签名、绑定实例、带风险闸门的 MCP 传输壳**,Studio 托管的
 Agent 只是它的第一个客户。环路里最后一跳又回到了 Studio 自己。
 
+独立 CLI 的默认变更摘要保留 `plan` / `result` 中的 JSON 数字,
+例如 offset 重置预览中超过 `2^53` 的队列位置,避免检查变更状态时的再次解码造成舍入。
+
 ### 这个形状真实买到了什么
 
 1. **工具路径唯一。** 同一套能力面、身份模型、风险闸门与审计链路,同时服务于:Studio 托管的
diff --git a/rmqctl/cmd/mutation_precision_test.go 
b/rmqctl/cmd/mutation_precision_test.go
new file mode 100644
index 000000000..42d28f0e4
--- /dev/null
+++ b/rmqctl/cmd/mutation_precision_test.go
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package cmd
+
+import (
+       "bytes"
+       "encoding/json"
+       "fmt"
+       "net/http"
+       "net/http/httptest"
+       "strings"
+       "testing"
+)
+
+func TestMutationPreviewPreservesIntegerPrecision(t *testing.T) {
+       const number = "9007199254740993"
+       server := httptest.NewServer(http.HandlerFunc(func(w 
http.ResponseWriter, r *http.Request) {
+               var request struct {
+                       Name      string                     `json:"name"`
+                       Arguments map[string]json.RawMessage `json:"arguments"`
+               }
+               if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
+                       t.Error(err)
+                       return
+               }
+               if request.Name != "rmq.group.reset_offset" || 
string(request.Arguments["dry_run"]) != "true" {
+                       t.Errorf("expected reset-offset dry-run, got %#v", 
request)
+               }
+               w.Header().Set("Content-Type", "application/json")
+               fmt.Fprint(w, 
`{"code":200,"message":"OK","data":{"status":"PLANNED","instanceId":"test-instance","confirm_token":"synthetic-token","plan":{"before":{"queues":[{"offset":9007199254740993,"lag":0}]},"after":{"queues":[{"offset":42,"lag":0}]}}}}`)
+       }))
+       defer server.Close()
+       for _, format := range []string{"table", "json", "yaml"} {
+               t.Run(format, func(t *testing.T) {
+                       out, errOut := &bytes.Buffer{}, &bytes.Buffer{}
+                       app := NewApp(out, errOut)
+                       app.Store.Getenv = testEnv
+                       app.HTTP = server.Client()
+                       path := newTestConfigPath(t)
+                       if err := app.Store.Save(path, 
newTestConfig(server.URL)); err != nil {
+                               t.Fatal(err)
+                       }
+                       code := app.Execute([]string{"--config", path, 
"--instance-id", "test-instance", "--output", format, "group", "reset-offset", 
"--group-name", "orders", "--topic-name", "orders", "--timestamp", 
"1700000000000", "--dry-run"})
+                       t.Logf("format=%s exit=%d output=%s stderr=%s", format, 
code, out.String(), errOut.String())
+                       if code != 0 {
+                               t.Fatalf("unexpected command failure")
+                       }
+                       if !strings.Contains(out.String(), number) {
+                               t.Errorf("original queue offset %s is absent 
from %s output", number, format)
+                       }
+               })
+       }
+}
diff --git a/rmqctl/internal/types/mutation_precision_test.go 
b/rmqctl/internal/types/mutation_precision_test.go
new file mode 100644
index 000000000..5b0879f86
--- /dev/null
+++ b/rmqctl/internal/types/mutation_precision_test.go
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package types
+
+import (
+       "bytes"
+       "encoding/json"
+       "reflect"
+       "testing"
+)
+
+func TestDecodeMutationOutputPreservesNestedNumbers(t *testing.T) {
+       const nested = 
`{"queues":[{"offset":9007199254740993,"lag":9223372036854775807}],"values":[-9223372036854775808,1.25,1e+20,true,null,"9007199254740993"]}`
+       for _, status := range []MutationStatus{MutationPlanned, 
MutationExecuted} {
+               t.Run(string(status), func(t *testing.T) {
+                       input := MutationOutput{Status: status, InstanceID: 
"test-instance", Plan: json.RawMessage(nested), Result: 
json.RawMessage(nested), ConfirmToken: "synthetic-token"}
+                       decoded, err := DecodeMutationOutput(input)
+                       if err != nil {
+                               t.Fatal(err)
+                       }
+                       if decoded.Status != status || decoded.InstanceID != 
input.InstanceID || decoded.ConfirmToken != input.ConfirmToken {
+                               t.Fatalf("metadata changed: %#v", decoded)
+                       }
+                       for name, value := range map[string]any{"plan": 
decoded.Plan, "result": decoded.Result} {
+                               payload, err := json.Marshal(value)
+                               if err != nil {
+                                       t.Fatal(err)
+                               }
+
+                               var got, want any
+                               gotDecoder := 
json.NewDecoder(bytes.NewReader(payload))
+                               gotDecoder.UseNumber()
+                               if err := gotDecoder.Decode(&got); err != nil {
+                                       t.Fatal(err)
+                               }
+                               wantDecoder := 
json.NewDecoder(bytes.NewBufferString(nested))
+                               wantDecoder.UseNumber()
+                               if err := wantDecoder.Decode(&want); err != nil 
{
+                                       t.Fatal(err)
+                               }
+                               if !reflect.DeepEqual(got, want) {
+                                       t.Errorf("%s = %s, want %s", name, 
payload, nested)
+                               }
+                       }
+               })
+       }
+}
+
+func TestDecodeMutationOutputRejectsInvalidValues(t *testing.T) {
+       for _, value := range []any{make(chan int), map[string]any{"status": 
true}, map[string]any{"status": "UNKNOWN"}} {
+               if _, err := DecodeMutationOutput(value); err == nil {
+                       t.Fatalf("accepted invalid value %#v", value)
+               }
+       }
+}
diff --git a/rmqctl/internal/types/types.go b/rmqctl/internal/types/types.go
index 3ce36e7df..ddcda52a0 100644
--- a/rmqctl/internal/types/types.go
+++ b/rmqctl/internal/types/types.go
@@ -17,6 +17,7 @@
 package types
 
 import (
+       "bytes"
        "encoding/json"
        "fmt"
 )
@@ -49,7 +50,10 @@ func DecodeMutationOutput(value any) (MutationOutput, error) 
{
                return MutationOutput{}, fmt.Errorf("encode mutation output: 
%w", err)
        }
        var mutation MutationOutput
-       if err := json.Unmarshal(payload, &mutation); err != nil {
+       // Plan and Result contain arbitrary JSON; preserve long offsets when 
inspecting them.
+       decoder := json.NewDecoder(bytes.NewReader(payload))
+       decoder.UseNumber()
+       if err := decoder.Decode(&mutation); err != nil {
                return MutationOutput{}, fmt.Errorf("decode mutation output: 
%w", err)
        }
        if mutation.Status != MutationPlanned && mutation.Status != 
MutationExecuted {

Reply via email to