From f490afdd4b20e6eafc6f9efb2f83b115bfc8446b Mon Sep 17 00:00:00 2001 From: Ashish Vaghela Date: Wed, 2 Dec 2026 13:30:46 +0530 Subject: [PATCH 1/4] test(output): cover integer formatting in YAML output Signed-off-by: Ashish Vaghela --- pkg/output/output_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/output/output_test.go b/pkg/output/output_test.go index 31e048db..801f01c9 100644 --- a/pkg/output/output_test.go +++ b/pkg/output/output_test.go @@ -105,6 +105,21 @@ func TestYAMLFormatter(t *testing.T) { } } +func TestYAMLFormatterKeepsLargeIntegersPlain(t *testing.T) { + r := sampleResult() + r.TestDate = 1795635868754 + out, err := (&YAMLFormatter{}).Format(r) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(out, "testDate: 1795635868754\n") { + t.Errorf("expected plain integer testDate, got:\n%s", out) + } + if !strings.Contains(out, "elapsedTime: 1500\n") { + t.Errorf("expected plain integer elapsedTime, got:\n%s", out) + } +} + func TestGitHubActionsFormatter(t *testing.T) { out, err := (&GitHubActionsFormatter{}).Format(sampleResult()) if err != nil { From b6342ef62b174adcf9b110d8ccbeb2c72f2f16f5 Mon Sep 17 00:00:00 2001 From: Ashish Vaghela Date: Wed, 2 Dec 2026 13:31:21 +0530 Subject: [PATCH 2/4] fix(output): print integers as plain numbers in YAML output Signed-off-by: Ashish Vaghela --- pkg/output/yaml_formatter.go | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/pkg/output/yaml_formatter.go b/pkg/output/yaml_formatter.go index faf101d4..ccd1f484 100644 --- a/pkg/output/yaml_formatter.go +++ b/pkg/output/yaml_formatter.go @@ -16,6 +16,7 @@ package output import ( + "bytes" "encoding/json" "github.com/microcks/microcks-cli/pkg/connectors" @@ -32,12 +33,42 @@ func (f *YAMLFormatter) Format(r *connectors.TestResult) (string, error) { return "", err } var generic interface{} - if err := json.Unmarshal(j, &generic); err != nil { + dec := json.NewDecoder(bytes.NewReader(j)) + dec.UseNumber() + if err := dec.Decode(&generic); err != nil { return "", err } - b, err := yaml.Marshal(generic) + b, err := yaml.Marshal(normalizeNumbers(generic)) if err != nil { return "", err } return string(b), nil } + +// normalizeNumbers converts json.Number values to int64 when possible so that +// large integers such as millisecond timestamps are not rendered in scientific +// notation, falling back to float64 for decimal values. +func normalizeNumbers(v interface{}) interface{} { + switch t := v.(type) { + case map[string]interface{}: + for k, val := range t { + t[k] = normalizeNumbers(val) + } + return t + case []interface{}: + for i, val := range t { + t[i] = normalizeNumbers(val) + } + return t + case json.Number: + if i, err := t.Int64(); err == nil { + return i + } + if f, err := t.Float64(); err == nil { + return f + } + return t.String() + default: + return v + } +} From 22c9f56eff947f703c1d6f4beace0218518cc6ab Mon Sep 17 00:00:00 2001 From: Ashish Vaghela Date: Wed, 2 Dec 2026 13:31:48 +0530 Subject: [PATCH 3/4] test(output): check nested numbers stay unquoted in YAML output Signed-off-by: Ashish Vaghela --- pkg/output/output_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/output/output_test.go b/pkg/output/output_test.go index 801f01c9..36255250 100644 --- a/pkg/output/output_test.go +++ b/pkg/output/output_test.go @@ -118,6 +118,9 @@ func TestYAMLFormatterKeepsLargeIntegersPlain(t *testing.T) { if !strings.Contains(out, "elapsedTime: 1500\n") { t.Errorf("expected plain integer elapsedTime, got:\n%s", out) } + if strings.Contains(out, `: "0"`) { + t.Errorf("expected nested numbers to stay unquoted, got:\n%s", out) + } } func TestGitHubActionsFormatter(t *testing.T) { From c50c99b6955534560504ab44b869899284844eda Mon Sep 17 00:00:00 2001 From: Ashish Vaghela Date: Wed, 2 Dec 2026 13:31:48 +0530 Subject: [PATCH 4/4] refactor(output): simplify decimal fallback in YAML number handling Signed-off-by: Ashish Vaghela --- pkg/output/yaml_formatter.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/output/yaml_formatter.go b/pkg/output/yaml_formatter.go index ccd1f484..3396e430 100644 --- a/pkg/output/yaml_formatter.go +++ b/pkg/output/yaml_formatter.go @@ -64,10 +64,8 @@ func normalizeNumbers(v interface{}) interface{} { if i, err := t.Int64(); err == nil { return i } - if f, err := t.Float64(); err == nil { - return f - } - return t.String() + f, _ := t.Float64() + return f default: return v }