Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: memory_unit json unmarshaling format error (#2051)
Kyle Mendell7b317b9fa59e
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 0b0a71ec5..14caa2f29 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -36,6 +36,11 @@ jobs:timeout: 10gcc: falsecgo_enabled: "1"+ - name: types+ path: types+ timeout: 10+ gcc: false+ cgo_enabled: "1"steps:- name: Checkoutuses: actions/checkout@v6diff --git a/Justfile b/Justfileindex d03266d4e..ac4e7e681 100644--- a/Justfile+++ b/Justfile@@ -853,13 +853,19 @@ _test-backend:_test-cli:cd cli && go test ./... -race -coverprofile=coverage.txt -covermode=atomic -v+# Run shared types Go tests+[group('tests')]+_test-types:+ cd types && go test ./... -race -coverprofile=coverage.txt -covermode=atomic -v+[group('tests')]_test-all:@just _test-e2e@just _test-backend@just _test-cli+ @just _test-types-# Run tests. Valid targets: "e2e", "backend", "cli", "all".+# Run tests. Valid targets: "e2e", "backend", "cli", "types", "all".[group('tests')]test target="all":@just "_test-{{ target }}"diff --git a/cli/internal/integrationtest/command_helpers_test.go b/cli/internal/integrationtest/command_helpers_test.gonew file mode 100644index 000000000..ca7a92719--- /dev/null+++ b/cli/internal/integrationtest/command_helpers_test.go@@ -0,0 +1,72 @@+package integrationtest++import (+ "io"+ "os"+ "path/filepath"+ "runtime"+ "strings"+ "sync"+ "testing"++ clipkg "github.com/getarcaneapp/arcane/cli/pkg"+)++var stdoutCaptureMuInternal sync.Mutex++func writeCLIIntegrationConfigInternal(t *testing.T, serverURL string) string {+ t.Helper()++ tempDir := t.TempDir()+ configPath := filepath.Join(tempDir, "arcanecli.yml")+ configContent := strings.Join([]string{+ "server_url: " + serverURL,+ "api_key: arc_test_key",+ "default_environment: \"0\"",+ "log_level: info",+ "",+ }, "\n")+ if err := os.WriteFile(configPath, []byte(configContent), 0o600); err != nil {+ t.Fatalf("write config: %v", err)+ }++ return configPath+}++func executeCLIIntegrationCommandInternal(t *testing.T, args []string) (string, string, error) {+ t.Helper()++ root := clipkg.RootCommand()+ errOut := &strings.Builder{}+ root.SetErr(errOut)+ root.SetArgs(args)++ stdoutCaptureMuInternal.Lock()+ defer stdoutCaptureMuInternal.Unlock()++ stdout := os.Stdout+ reader, writer, err := os.Pipe()+ if err != nil {+ t.Fatalf("pipe: %v", err)+ }+ os.Stdout = writer+ defer func() {+ _ = writer.Close()+ os.Stdout = stdout+ }()++ runErr := root.Execute()++ _ = writer.Close()+ stdoutBytes, readErr := io.ReadAll(reader)+ if readErr != nil {+ t.Fatalf("read stdout: %v", readErr)+ }++ outBuf := string(stdoutBytes)+ if runtime.GOOS == "windows" {+ outBuf = strings.ReplaceAll(outBuf, "\r\n", "\n")+ }++ return outBuf, errOut.String(), runErr+}diff --git a/cli/internal/integrationtest/json_contract_test.go b/cli/internal/integrationtest/json_contract_test.goindex 08721d50f..1601197e2 100644--- a/cli/internal/integrationtest/json_contract_test.go+++ b/cli/internal/integrationtest/json_contract_test.go@@ -2,16 +2,10 @@ package integrationtestimport ("encoding/json"- "io""net/http""net/http/httptest"- "os"- "path/filepath"- "runtime""strings""testing"-- clipkg "github.com/getarcaneapp/arcane/cli/pkg")func TestContainersListJSONContract(t *testing.T) {@@ -32,46 +26,14 @@ func TestContainersListJSONContract(t *testing.T) {}))defer srv.Close()- tempDir := t.TempDir()- configPath := filepath.Join(tempDir, "arcanecli.yml")- configContent := strings.Join([]string{- "server_url: " + srv.URL,- "api_key: arc_test_key",- "default_environment: \"0\"",- "log_level: info",- "",- }, "\n")- if err := os.WriteFile(configPath, []byte(configContent), 0o600); err != nil {- t.Fatalf("write config: %v", err)- }-- root := clipkg.RootCommand()- errOut := &strings.Builder{}- root.SetErr(errOut)- root.SetArgs([]string{"--config", configPath, "containers", "list", "--json"})-- stdout := os.Stdout- r, w, err := os.Pipe()- if err != nil {- t.Fatalf("pipe: %v", err)- }- os.Stdout = w- defer func() {- _ = w.Close()- os.Stdout = stdout- }()+ configPath := writeCLIIntegrationConfigInternal(t, srv.URL)- if err := root.Execute(); err != nil {- t.Fatalf("execute: %v (%s)", err, errOut.String())- }- _ = w.Close()- stdoutBytes, err := io.ReadAll(r)+ outBuf, errOut, err := executeCLIIntegrationCommandInternal(+ t,+ []string{"--config", configPath, "containers", "list", "--json"},+ )if err != nil {- t.Fatalf("read stdout: %v", err)- }- outBuf := string(stdoutBytes)- if runtime.GOOS == "windows" {- outBuf = strings.ReplaceAll(outBuf, "\r\n", "\n")+ t.Fatalf("execute: %v (%s)", err, errOut)}var got map[string]anydiff --git a/cli/internal/integrationtest/projects_json_compat_test.go b/cli/internal/integrationtest/projects_json_compat_test.gonew file mode 100644index 000000000..0614a8f99--- /dev/null+++ b/cli/internal/integrationtest/projects_json_compat_test.go@@ -0,0 +1,112 @@+package integrationtest++import (+ "encoding/json"+ "net/http"+ "net/http/httptest"+ "strings"+ "testing"+)++func TestProjectsJSONCompatibilityForComposeUnitBytes(t *testing.T) {+ projectResponse := `{+ "success": true,+ "data": {+ "id": "project-1",+ "name": "myproject",+ "path": "/tmp/myproject",+ "status": "running",+ "serviceCount": 1,+ "runningCount": 1,+ "createdAt": "2026-03-13T00:00:00Z",+ "updatedAt": "2026-03-13T00:00:00Z",+ "services": [+ {+ "name": "myapp",+ "image": "nginx:latest",+ "mem_limit": "256m",+ "build": {+ "context": ".",+ "shm_size": "64m"+ },+ "deploy": {+ "resources": {+ "limits": {+ "memory": "512m"+ }+ }+ }+ }+ ],+ "runtimeServices": [+ {+ "name": "myapp",+ "image": "nginx:latest",+ "status": "running",+ "serviceConfig": {+ "name": "myapp",+ "image": "nginx:latest",+ "mem_limit": "256m"+ }+ }+ ]+ }+ }`++ downCalled := false+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ switch {+ case r.Method == http.MethodGet && r.URL.Path == "/api/environments/0/projects/myproject":+ w.Header().Set("Content-Type", "application/json")+ _, _ = w.Write([]byte(projectResponse))+ case r.Method == http.MethodPost && r.URL.Path == "/api/environments/0/projects/project-1/down":+ downCalled = true+ w.Header().Set("Content-Type", "application/json")+ _, _ = w.Write([]byte(`{"success":true,"data":{"message":"stopped"}}`))+ default:+ w.WriteHeader(http.StatusNotFound)+ _, _ = w.Write([]byte(`{"success":false,"error":"not found"}`))+ }+ }))+ defer srv.Close()++ configPath := writeCLIIntegrationConfigInternal(t, srv.URL)++ getStdout, getStderr, err := executeCLIIntegrationCommandInternal(+ t,+ []string{"--config", configPath, "projects", "get", "myproject", "--json"},+ )+ if err != nil {+ t.Fatalf("projects get failed: %v (%s)", err, getStderr)+ }++ var decoded map[string]any+ if err := json.Unmarshal([]byte(strings.TrimSpace(getStdout)), &decoded); err != nil {+ t.Fatalf("projects get produced invalid JSON: %v\noutput=%s", err, getStdout)+ }++ services, ok := decoded["services"].([]any)+ if !ok || len(services) != 1 {+ t.Fatalf("expected one service in JSON output, got %#v", decoded["services"])+ }++ serviceMap, ok := services[0].(map[string]any)+ if !ok {+ t.Fatalf("expected service entry to be a map, got %#v", services[0])+ }++ if got := serviceMap["mem_limit"]; got != "268435456" {+ t.Fatalf("expected mem_limit to round-trip as normalized bytes, got %#v", got)+ }++ _, downStderr, err := executeCLIIntegrationCommandInternal(+ t,+ []string{"--config", configPath, "projects", "down", "myproject"},+ )+ if err != nil {+ t.Fatalf("projects down failed: %v (%s)", err, downStderr)+ }+ if !downCalled {+ t.Fatal("expected projects down to issue a POST after resolving the project")+ }+}diff --git a/types/coverage.txt b/types/coverage.txtnew file mode 100644index 000000000..be3a59498--- /dev/null+++ b/types/coverage.txt@@ -0,0 +1,281 @@+mode: atomic+github.com/getarcaneapp/arcane/types/base/json.go:18.51,19.14 1 0+github.com/getarcaneapp/arcane/types/base/json.go:19.14,21.3 1 0+github.com/getarcaneapp/arcane/types/base/json.go:22.2,22.24 1 0+github.com/getarcaneapp/arcane/types/base/json.go:29.44,30.18 1 0+github.com/getarcaneapp/arcane/types/base/json.go:30.18,33.3 2 0+github.com/getarcaneapp/arcane/types/base/json.go:34.2,34.27 1 0+github.com/getarcaneapp/arcane/types/base/json.go:35.14,36.30 1 0+github.com/getarcaneapp/arcane/types/base/json.go:37.14,38.38 1 0+github.com/getarcaneapp/arcane/types/base/json.go:39.10,40.32 1 0+github.com/getarcaneapp/arcane/types/volume/volume.go:126.41,139.24 2 0+github.com/getarcaneapp/arcane/types/volume/volume.go:139.24,143.3 3 0+github.com/getarcaneapp/arcane/types/volume/volume.go:145.2,145.12 1 0+github.com/getarcaneapp/arcane/types/network/network.go:264.76,275.19 2 0+github.com/getarcaneapp/arcane/types/network/network.go:275.19,277.3 1 0+github.com/getarcaneapp/arcane/types/network/network.go:279.2,279.13 1 0+github.com/getarcaneapp/arcane/types/network/network.go:282.34,283.8 1 0+github.com/getarcaneapp/arcane/types/network/network.go:283.8,285.3 1 0+github.com/getarcaneapp/arcane/types/network/network.go:287.2,287.11 1 0+github.com/getarcaneapp/arcane/types/network/network.go:290.44,296.33 2 0+github.com/getarcaneapp/arcane/types/network/network.go:296.33,297.51 1 0+github.com/getarcaneapp/arcane/types/network/network.go:297.51,299.4 1 0+github.com/getarcaneapp/arcane/types/network/network.go:302.2,302.19 1 0+github.com/getarcaneapp/arcane/types/network/network.go:305.68,309.47 3 0+github.com/getarcaneapp/arcane/types/network/network.go:309.47,312.3 2 0+github.com/getarcaneapp/arcane/types/network/network.go:313.2,313.46 1 0+github.com/getarcaneapp/arcane/types/network/network.go:313.46,316.3 2 0+github.com/getarcaneapp/arcane/types/network/network.go:317.2,317.48 1 0+github.com/getarcaneapp/arcane/types/network/network.go:317.48,320.3 2 0+github.com/getarcaneapp/arcane/types/network/network.go:321.2,321.58 1 0+github.com/getarcaneapp/arcane/types/network/network.go:321.58,324.3 2 0+github.com/getarcaneapp/arcane/types/network/network.go:326.2,326.26 1 0+github.com/getarcaneapp/arcane/types/network/network.go:329.51,331.16 2 0+github.com/getarcaneapp/arcane/types/network/network.go:331.16,333.3 1 0+github.com/getarcaneapp/arcane/types/network/network.go:335.2,335.21 1 0+github.com/getarcaneapp/arcane/types/network/network.go:338.47,340.16 2 0+github.com/getarcaneapp/arcane/types/network/network.go:340.16,342.3 1 0+github.com/getarcaneapp/arcane/types/network/network.go:344.2,344.19 1 0+github.com/getarcaneapp/arcane/types/network/network.go:347.74,348.26 1 0+github.com/getarcaneapp/arcane/types/network/network.go:348.26,350.3 1 0+github.com/getarcaneapp/arcane/types/network/network.go:352.2,353.39 2 0+github.com/getarcaneapp/arcane/types/network/network.go:353.39,354.43 1 0+github.com/getarcaneapp/arcane/types/network/network.go:354.43,356.4 1 0+github.com/getarcaneapp/arcane/types/network/network.go:359.2,359.12 1 0+github.com/getarcaneapp/arcane/types/network/network.go:375.44,390.2 1 0+github.com/getarcaneapp/arcane/types/meta/job_metadata.go:194.55,197.2 2 0+github.com/getarcaneapp/arcane/types/meta/job_metadata.go:199.49,201.2 1 0+github.com/getarcaneapp/arcane/types/meta/job_metadata.go:203.155,218.2 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:364.122,383.45 2 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:383.45,384.50 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:384.50,389.25 3 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:390.26,391.30 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:392.22,393.26 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:394.24,395.28 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:396.21,397.25 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:398.25,399.29 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:400.12,401.29 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:403.4,403.26 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:407.2,407.15 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:410.70,423.22 2 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:423.22,425.36 2 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:425.36,426.28 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:426.28,429.5 2 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:430.4,430.28 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:430.28,433.5 2 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:435.3,435.43 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:435.43,437.4 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:441.2,441.28 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:441.28,442.71 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:442.71,444.4 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:446.2,446.31 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:446.31,447.74 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:447.74,449.4 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:452.2,452.13 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:455.39,456.11 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:457.18,458.26 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:459.14,460.22 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:461.16,462.24 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:463.13,464.21 1 0+github.com/getarcaneapp/arcane/types/vulnerability/vulnerability.go:465.10,466.25 1 0+github.com/getarcaneapp/arcane/types/container/container.go:742.46,744.31 2 0+github.com/getarcaneapp/arcane/types/container/container.go:744.31,746.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:748.2,749.28 2 0+github.com/getarcaneapp/arcane/types/container/container.go:749.28,756.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:758.2,759.29 2 0+github.com/getarcaneapp/arcane/types/container/container.go:759.29,770.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:772.2,773.67 2 0+github.com/getarcaneapp/arcane/types/container/container.go:773.67,774.51 1 0+github.com/getarcaneapp/arcane/types/container/container.go:774.51,776.4 1 0+github.com/getarcaneapp/arcane/types/container/container.go:779.2,797.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:801.55,803.64 2 0+github.com/getarcaneapp/arcane/types/container/container.go:803.64,804.52 1 0+github.com/getarcaneapp/arcane/types/container/container.go:804.52,809.26 3 0+github.com/getarcaneapp/arcane/types/container/container.go:809.26,814.13 2 0+github.com/getarcaneapp/arcane/types/container/container.go:816.4,816.31 1 0+github.com/getarcaneapp/arcane/types/container/container.go:816.31,824.5 2 0+github.com/getarcaneapp/arcane/types/container/container.go:828.2,829.29 2 0+github.com/getarcaneapp/arcane/types/container/container.go:829.29,840.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:842.2,843.67 2 0+github.com/getarcaneapp/arcane/types/container/container.go:843.67,844.51 1 0+github.com/getarcaneapp/arcane/types/container/container.go:844.51,846.4 1 0+github.com/getarcaneapp/arcane/types/container/container.go:849.2,850.25 2 0+github.com/getarcaneapp/arcane/types/container/container.go:850.25,858.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:860.2,863.21 4 0+github.com/getarcaneapp/arcane/types/container/container.go:863.21,872.29 3 0+github.com/getarcaneapp/arcane/types/container/container.go:872.29,874.4 1 0+github.com/getarcaneapp/arcane/types/container/container.go:877.2,880.20 3 0+github.com/getarcaneapp/arcane/types/container/container.go:880.20,888.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:890.2,905.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:908.71,909.14 1 0+github.com/getarcaneapp/arcane/types/container/container.go:909.14,911.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:913.2,914.25 2 0+github.com/getarcaneapp/arcane/types/container/container.go:914.25,916.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:918.2,919.25 2 0+github.com/getarcaneapp/arcane/types/container/container.go:919.25,921.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:923.2,924.27 2 0+github.com/getarcaneapp/arcane/types/container/container.go:924.27,926.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:928.2,929.29 2 0+github.com/getarcaneapp/arcane/types/container/container.go:929.29,931.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:933.2,934.35 2 0+github.com/getarcaneapp/arcane/types/container/container.go:934.35,936.3 1 0+github.com/getarcaneapp/arcane/types/container/container.go:938.2,954.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:48.59,50.58 2 3+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:50.58,52.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:54.2,57.16 3 3+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:57.16,59.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:60.2,62.12 2 3+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:72.52,74.58 2 5+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:74.58,76.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:78.2,81.28 3 5+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:81.28,84.3 2 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:86.2,87.42 2 5+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:87.42,89.17 2 5+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:89.17,91.4 1 1+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:92.3,92.21 1 4+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:92.21,93.12 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:95.3,95.40 1 4+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:97.2,99.12 2 4+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:105.90,107.63 2 8+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:107.63,109.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:111.2,112.61 2 8+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:112.61,114.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:116.2,117.16 2 8+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:117.16,119.3 1 1+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:121.2,122.16 2 7+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:122.16,124.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:126.2,127.66 2 7+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:127.66,129.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:131.2,131.22 1 7+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:136.57,140.2 3 16+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:148.79,149.37 1 32+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:149.37,151.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:153.2,153.41 1 32+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:153.41,154.19 1 4+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:154.19,156.4 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:157.3,157.29 1 4+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:160.2,160.31 1 32+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:160.31,162.3 1 10+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:164.2,164.25 1 22+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:165.22,166.53 1 13+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:167.36,168.52 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:169.19,170.50 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:175.58,176.20 1 9+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:179.2,179.19 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:184.80,186.9 2 13+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:186.9,188.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:190.2,191.32 2 13+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:191.32,193.3 1 32+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:195.2,195.43 1 13+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:195.43,197.26 2 801+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:197.26,198.12 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:201.3,201.22 1 801+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:201.22,203.18 2 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:203.18,205.5 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:206.4,207.10 2 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:207.10,209.5 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:210.4,210.12 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:213.3,214.10 2 801+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:214.10,215.12 1 28+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:218.3,219.14 2 773+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:219.14,220.12 1 749+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:223.3,224.17 2 24+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:224.17,226.4 1 1+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:227.3,227.42 1 23+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:230.2,230.24 1 12+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:235.79,237.9 2 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:237.9,239.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:241.2,242.29 2 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:242.29,244.17 2 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:244.17,246.4 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:247.3,247.33 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:250.2,250.24 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:255.77,256.45 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:256.45,258.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:260.2,261.9 2 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:261.9,263.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:265.2,266.31 2 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:266.31,268.17 2 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:268.17,270.4 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:271.3,271.35 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:274.2,274.24 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:284.54,285.27 1 10+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:286.19,287.43 1 2+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:287.43,289.4 1 2+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:291.3,292.17 2 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:292.17,294.4 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:295.3,295.47 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:295.47,297.4 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:298.3,298.32 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:300.14,302.17 2 8+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:302.17,304.4 1 1+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:305.3,305.21 1 7+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:307.15,308.29 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:308.29,310.4 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:311.3,311.23 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:313.11,314.23 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:315.12,316.23 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:317.13,318.23 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:319.13,320.23 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:321.13,322.16 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:323.12,324.32 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:324.32,326.4 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:327.3,327.23 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:328.13,329.23 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:330.14,331.23 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:332.14,333.23 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:334.14,335.24 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:335.24,337.4 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:338.3,338.23 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:339.10,340.20 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:346.62,348.16 2 801+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:348.16,350.3 1 28+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:352.2,352.15 1 773+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:352.15,354.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:356.2,357.16 2 773+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:357.16,359.3 1 0+github.com/getarcaneapp/arcane/types/project/marshal_utils.go:361.2,361.19 1 773+github.com/getarcaneapp/arcane/types/image/image.go:179.56,182.48 2 0+github.com/getarcaneapp/arcane/types/image/image.go:182.48,184.3 1 0+github.com/getarcaneapp/arcane/types/image/image.go:184.8,186.3 1 0+github.com/getarcaneapp/arcane/types/image/image.go:188.2,192.38 2 0+github.com/getarcaneapp/arcane/types/image/image.go:192.38,193.22 1 0+github.com/getarcaneapp/arcane/types/image/image.go:193.22,195.4 1 0+github.com/getarcaneapp/arcane/types/image/image.go:195.9,195.30 1 0+github.com/getarcaneapp/arcane/types/image/image.go:195.30,197.4 1 0+github.com/getarcaneapp/arcane/types/image/image.go:199.2,199.12 1 0+github.com/getarcaneapp/arcane/types/image/image.go:498.48,499.38 1 0+github.com/getarcaneapp/arcane/types/image/image.go:499.38,501.3 1 0+github.com/getarcaneapp/arcane/types/image/image.go:502.2,502.62 1 0+github.com/getarcaneapp/arcane/types/image/image.go:502.62,504.3 1 0+github.com/getarcaneapp/arcane/types/image/image.go:505.2,505.20 1 0+github.com/getarcaneapp/arcane/types/image/image.go:509.70,510.28 1 0+github.com/getarcaneapp/arcane/types/image/image.go:510.28,512.3 1 0+github.com/getarcaneapp/arcane/types/image/image.go:513.2,513.19 1 0+github.com/getarcaneapp/arcane/types/image/image.go:513.19,515.3 1 0+github.com/getarcaneapp/arcane/types/image/image.go:516.2,516.12 1 0+github.com/getarcaneapp/arcane/types/image/image.go:523.65,525.16 2 2+github.com/getarcaneapp/arcane/types/image/image.go:525.16,527.3 1 1+github.com/getarcaneapp/arcane/types/image/image.go:529.2,536.23 7 1+github.com/getarcaneapp/arcane/types/image/image.go:536.23,537.39 1 0+github.com/getarcaneapp/arcane/types/image/image.go:537.39,539.43 2 0+github.com/getarcaneapp/arcane/types/image/image.go:539.43,541.5 1 0+github.com/getarcaneapp/arcane/types/image/image.go:543.3,543.30 1 0+github.com/getarcaneapp/arcane/types/image/image.go:543.30,545.4 1 0+github.com/getarcaneapp/arcane/types/image/image.go:546.3,546.30 1 0+github.com/getarcaneapp/arcane/types/image/image.go:546.30,548.4 1 0+github.com/getarcaneapp/arcane/types/image/image.go:549.3,549.34 1 0+github.com/getarcaneapp/arcane/types/image/image.go:549.34,551.38 2 0+github.com/getarcaneapp/arcane/types/image/image.go:551.38,553.5 1 0+github.com/getarcaneapp/arcane/types/image/image.go:555.3,556.50 2 0+github.com/getarcaneapp/arcane/types/image/image.go:559.2,563.28 4 1+github.com/getarcaneapp/arcane/types/image/image.go:563.28,565.34 2 0+github.com/getarcaneapp/arcane/types/image/image.go:565.34,567.4 1 0+github.com/getarcaneapp/arcane/types/image/image.go:570.2,571.32 2 1+github.com/getarcaneapp/arcane/types/image/image.go:571.32,573.3 1 1+github.com/getarcaneapp/arcane/types/image/image.go:575.2,575.40 1 1+github.com/getarcaneapp/arcane/types/image/image.go:575.40,577.3 1 0+github.com/getarcaneapp/arcane/types/image/image.go:580.2,582.30 3 1+github.com/getarcaneapp/arcane/types/image/image.go:582.30,584.22 2 1+github.com/getarcaneapp/arcane/types/image/image.go:584.22,586.4 1 1+github.com/getarcaneapp/arcane/types/image/image.go:589.2,589.12 1 1diff --git a/types/go.mod b/types/go.modindex 6161db861..980451a5b 100644--- a/types/go.mod+++ b/types/go.mod@@ -4,6 +4,7 @@ go 1.26.0require (github.com/compose-spec/compose-go/v2 v2.10.1+ github.com/docker/go-units v0.5.0github.com/moby/moby/api v1.54.0github.com/moby/moby/client v0.3.0)@@ -16,7 +17,6 @@ require (github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirectgithub.com/distribution/reference v0.6.0 // indirectgithub.com/docker/go-connections v0.6.0 // indirect- github.com/docker/go-units v0.5.0 // indirectgithub.com/felixge/httpsnoop v1.0.4 // indirectgithub.com/go-logr/logr v1.4.3 // indirectgithub.com/go-logr/stdr v1.2.2 // indirectdiff --git a/types/project/marshal_utils.go b/types/project/marshal_utils.gonew file mode 100644index 000000000..b55f6a7ff--- /dev/null+++ b/types/project/marshal_utils.go@@ -0,0 +1,330 @@+package project++import (+ "bytes"+ "encoding/json"+ "fmt"+ "reflect"+ "strconv"+ "strings"++ composetypes "github.com/compose-spec/compose-go/v2/types"+ "github.com/docker/go-units"+)++// unitBytesType is used to detect compose-go fields that need string-or-number+// normalization before they can be decoded by encoding/json.+var unitBytesType = reflect.TypeOf(composetypes.UnitBytes(0))++// runtimeServiceJSON is an internal decode shape that lets RuntimeService+// handle serviceConfig separately from the rest of the payload.+type runtimeServiceJSON struct {+ runtimeServiceAlias+ ServiceConfig json.RawMessage `json:"serviceConfig,omitempty"`+}++// runtimeServiceAlias prevents recursive calls back into RuntimeService's+// custom UnmarshalJSON implementation.+type runtimeServiceAlias RuntimeService++// detailsJSON is an internal decode shape that lets Details intercept the+// services array while still decoding the rest of the struct normally.+type detailsJSON struct {+ detailsAlias+ Services []json.RawMessage `json:"services,omitempty"`+ RuntimeServices []RuntimeService `json:"runtimeServices,omitempty"`+}++// detailsAlias prevents recursive calls back into Details.UnmarshalJSON.+type detailsAlias Details++// UnmarshalJSON makes RuntimeService tolerant of compose-go UnitBytes fields+// encoded as either JSON strings or JSON numbers inside serviceConfig.+//+// This only affects JSON decoding of RuntimeService values. It does not change+// API response shapes, backend serialization, YAML loading, or any non-JSON+// code paths.+func (r *RuntimeService) UnmarshalJSON(data []byte) error {+ var aux runtimeServiceJSON+ if err := decodeJSONWithNumbersInternal(data, &aux); err != nil {+ return err+ }++ *r = RuntimeService(aux.runtimeServiceAlias)++ serviceConfig, err := unmarshalComposeServiceConfigJSONInternal(aux.ServiceConfig)+ if err != nil {+ return fmt.Errorf("serviceConfig: %w", err)+ }+ r.ServiceConfig = serviceConfig++ return nil+}++// UnmarshalJSON makes Details tolerant of compose-go UnitBytes fields encoded+// as either JSON strings or JSON numbers inside services and runtime service+// configs.+//+// The rest of the Details payload is decoded normally. Only compose service+// payloads are normalized before they are unmarshaled into+// composetypes.ServiceConfig values.+func (d *Details) UnmarshalJSON(data []byte) error {+ var aux detailsJSON+ if err := decodeJSONWithNumbersInternal(data, &aux); err != nil {+ return err+ }++ *d = Details(aux.detailsAlias)+ d.RuntimeServices = aux.RuntimeServices++ if len(aux.Services) == 0 {+ d.Services = nil+ return nil+ }++ services := make([]composetypes.ServiceConfig, 0, len(aux.Services))+ for i, rawService := range aux.Services {+ service, err := unmarshalComposeServiceConfigJSONInternal(rawService)+ if err != nil {+ return fmt.Errorf("services[%d]: %w", i, err)+ }+ if service == nil {+ continue+ }+ services = append(services, *service)+ }+ d.Services = services++ return nil+}++// unmarshalComposeServiceConfigJSON decodes a raw service JSON object into a+// compose-go ServiceConfig after recursively normalizing any UnitBytes-backed+// fields so compose-go can accept string and numeric JSON representations.+func unmarshalComposeServiceConfigJSONInternal(data []byte) (*composetypes.ServiceConfig, error) {+ trimmed := bytes.TrimSpace(data)+ if len(trimmed) == 0 || bytes.Equal(trimmed, []byte("null")) {+ return nil, nil+ }++ var raw any+ if err := decodeJSONWithNumbersInternal(trimmed, &raw); err != nil {+ return nil, err+ }++ normalized, err := normalizeJSONValueForTypeInternal(raw, reflect.TypeOf(composetypes.ServiceConfig{}))+ if err != nil {+ return nil, err+ }++ normalizedBytes, err := json.Marshal(normalized)+ if err != nil {+ return nil, err+ }++ var service composetypes.ServiceConfig+ if err := json.Unmarshal(normalizedBytes, &service); err != nil {+ return nil, err+ }++ return &service, nil+}++// decodeJSONWithNumbers preserves JSON numbers as json.Number so the+// normalizer can distinguish integer-like values from quoted strings.+func decodeJSONWithNumbersInternal(data []byte, dest any) error {+ decoder := json.NewDecoder(bytes.NewReader(data))+ decoder.UseNumber()+ return decoder.Decode(dest)+}++// normalizeJSONValueForType walks decoded JSON using the destination Go type+// as the source of truth.+//+// That keeps the fix generic: any field reachable from ServiceConfig that uses+// composetypes.UnitBytes gets normalized without maintaining a hardcoded field+// name list.+func normalizeJSONValueForTypeInternal(value any, destType reflect.Type) (any, error) {+ if destType == nil || value == nil {+ return value, nil+ }++ for destType.Kind() == reflect.Pointer {+ destType = destType.Elem()+ }++ if destType == unitBytesType {+ return normalizeUnitBytesValueInternal(value)+ }++ switch destType.Kind() {+ case reflect.Struct:+ return normalizeJSONObjectForTypeInternal(value, destType)+ case reflect.Slice, reflect.Array:+ return normalizeJSONArrayForTypeInternal(value, destType)+ case reflect.Map:+ return normalizeJSONMapForTypeInternal(value, destType)+ case reflect.Pointer:+ // Pointer kinds are fully dereferenced above. This branch only exists to+ // keep the reflect.Kind switch exhaustive for linting.+ return value, nil+ case reflect.Invalid, reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16,+ reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16,+ reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64,+ reflect.Complex64, reflect.Complex128, reflect.Chan, reflect.Func, reflect.Interface,+ reflect.String, reflect.UnsafePointer:+ return value, nil+ }++ return value, nil+}++// normalizeJSONObjectForType normalizes a decoded JSON object according to the+// exported JSON fields of the destination struct type.+func normalizeJSONObjectForTypeInternal(value any, destType reflect.Type) (any, error) {+ object, ok := value.(map[string]any)+ if !ok {+ return value, nil+ }++ normalized := make(map[string]any, len(object))+ for key, item := range object {+ normalized[key] = item+ }++ for i := 0; i < destType.NumField(); i++ {+ field := destType.Field(i)+ if field.PkgPath != "" {+ continue+ }++ if field.Anonymous {+ embedded, err := normalizeJSONValueForTypeInternal(normalized, field.Type)+ if err != nil {+ return nil, err+ }+ embeddedMap, ok := embedded.(map[string]any)+ if ok {+ normalized = embeddedMap+ }+ continue+ }++ fieldName, ok := jsonFieldNameInternal(field)+ if !ok {+ continue+ }++ fieldValue, exists := normalized[fieldName]+ if !exists {+ continue+ }++ normalizedValue, err := normalizeJSONValueForTypeInternal(fieldValue, field.Type)+ if err != nil {+ return nil, fmt.Errorf("%s: %w", fieldName, err)+ }+ normalized[fieldName] = normalizedValue+ }++ return normalized, nil+}++// normalizeJSONArrayForType normalizes each decoded array element according to+// the destination element type.+func normalizeJSONArrayForTypeInternal(value any, destType reflect.Type) (any, error) {+ items, ok := value.([]any)+ if !ok {+ return value, nil+ }++ normalized := make([]any, len(items))+ for i, item := range items {+ normalizedItem, err := normalizeJSONValueForTypeInternal(item, destType.Elem())+ if err != nil {+ return nil, fmt.Errorf("[%d]: %w", i, err)+ }+ normalized[i] = normalizedItem+ }++ return normalized, nil+}++// normalizeJSONMapForType normalizes map values for string-keyed JSON objects+// whose destination type is a Go map.+func normalizeJSONMapForTypeInternal(value any, destType reflect.Type) (any, error) {+ if destType.Key().Kind() != reflect.String {+ return value, nil+ }++ items, ok := value.(map[string]any)+ if !ok {+ return value, nil+ }++ normalized := make(map[string]any, len(items))+ for key, item := range items {+ normalizedItem, err := normalizeJSONValueForTypeInternal(item, destType.Elem())+ if err != nil {+ return nil, fmt.Errorf("%s: %w", key, err)+ }+ normalized[key] = normalizedItem+ }++ return normalized, nil+}++// normalizeUnitBytesValue converts supported JSON representations for+// compose-go UnitBytes fields into integer byte counts.+//+// Supported inputs:+// - json numbers+// - quoted byte strings such as "268435456"+// - human-readable Docker memory strings such as "256m" or "1g"+func normalizeUnitBytesValueInternal(value any) (any, error) {+ switch v := value.(type) {+ case json.Number:+ if parsed, err := v.Int64(); err == nil {+ return parsed, nil+ }++ floatValue, err := strconv.ParseFloat(v.String(), 64)+ if err != nil {+ return nil, err+ }+ if floatValue != float64(int64(floatValue)) {+ return nil, fmt.Errorf("invalid UnitBytes value %q", v.String())+ }+ return int64(floatValue), nil++ case string:+ parsed, err := units.RAMInBytes(strings.TrimSpace(v))+ if err != nil {+ return nil, err+ }+ return parsed, nil++ default:+ return nil, fmt.Errorf("unsupported type %T for UnitBytes field", value)+ }+}++// jsonFieldName returns the JSON field name that should be used for a struct+// field during normalization.+func jsonFieldNameInternal(field reflect.StructField) (string, bool) {+ tag := field.Tag.Get("json")+ if tag == "-" {+ return "", false+ }++ if tag == "" {+ return field.Name, true+ }++ name := strings.Split(tag, ",")[0]+ if name == "" {+ return field.Name, true+ }++ return name, true+}diff --git a/types/project/marshal_utils_test.go b/types/project/marshal_utils_test.gonew file mode 100644index 000000000..db120d430--- /dev/null+++ b/types/project/marshal_utils_test.go@@ -0,0 +1,175 @@+package project++import (+ "encoding/json"+ "strings"+ "testing"+)++func TestDetailsUnmarshalJSON_AcceptsUnitBytesMemLimitFormats(t *testing.T) {+ tests := []struct {+ name string+ memLimitRaw string+ expected int64+ }{+ {+ name: "human-readable string",+ memLimitRaw: `"256m"`,+ expected: 268435456,+ },+ {+ name: "quoted byte string",+ memLimitRaw: `"268435456"`,+ expected: 268435456,+ },+ {+ name: "numeric bytes",+ memLimitRaw: `268435456`,+ expected: 268435456,+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ payload := `{+ "id": "project-1",+ "name": "test-project",+ "path": "/tmp/test-project",+ "status": "running",+ "serviceCount": 1,+ "runningCount": 1,+ "createdAt": "2026-03-13T00:00:00Z",+ "updatedAt": "2026-03-13T00:00:00Z",+ "services": [+ {+ "name": "web",+ "image": "nginx:latest",+ "mem_limit": ` + tt.memLimitRaw + `+ }+ ],+ "runtimeServices": [+ {+ "name": "web",+ "image": "nginx:latest",+ "status": "running",+ "serviceConfig": {+ "name": "web",+ "image": "nginx:latest",+ "mem_limit": ` + tt.memLimitRaw + `+ }+ }+ ]+ }`++ var details Details+ if err := json.Unmarshal([]byte(payload), &details); err != nil {+ t.Fatalf("unmarshal details: %v", err)+ }++ if len(details.Services) != 1 {+ t.Fatalf("expected 1 service, got %d", len(details.Services))+ }+ if got := int64(details.Services[0].MemLimit); got != tt.expected {+ t.Fatalf("expected services[0].MemLimit=%d, got %d", tt.expected, got)+ }++ if len(details.RuntimeServices) != 1 {+ t.Fatalf("expected 1 runtime service, got %d", len(details.RuntimeServices))+ }+ if details.RuntimeServices[0].ServiceConfig == nil {+ t.Fatal("expected runtime service config to be decoded")+ }+ if got := int64(details.RuntimeServices[0].ServiceConfig.MemLimit); got != tt.expected {+ t.Fatalf("expected runtimeServices[0].serviceConfig.MemLimit=%d, got %d", tt.expected, got)+ }+ })+ }+}++func TestDetailsUnmarshalJSON_NormalizesNestedUnitBytesFields(t *testing.T) {+ payload := `{+ "id": "project-1",+ "name": "test-project",+ "path": "/tmp/test-project",+ "status": "running",+ "serviceCount": 1,+ "runningCount": 1,+ "createdAt": "2026-03-13T00:00:00Z",+ "updatedAt": "2026-03-13T00:00:00Z",+ "services": [+ {+ "name": "web",+ "image": "nginx:latest",+ "build": {+ "context": ".",+ "shm_size": "64m"+ },+ "deploy": {+ "resources": {+ "limits": {+ "memory": "512m"+ },+ "reservations": {+ "memory": "128m"+ }+ }+ }+ }+ ]+ }`++ var details Details+ if err := json.Unmarshal([]byte(payload), &details); err != nil {+ t.Fatalf("unmarshal details: %v", err)+ }++ if len(details.Services) != 1 {+ t.Fatalf("expected 1 service, got %d", len(details.Services))+ }++ service := details.Services[0]+ if service.Build == nil {+ t.Fatal("expected build config to be decoded")+ }+ if got := int64(service.Build.ShmSize); got != 67108864 {+ t.Fatalf("expected build.shm_size=67108864, got %d", got)+ }++ if service.Deploy == nil || service.Deploy.Resources.Limits == nil || service.Deploy.Resources.Reservations == nil {+ t.Fatal("expected deploy resource limits and reservations to be decoded")+ }+ if got := int64(service.Deploy.Resources.Limits.MemoryBytes); got != 536870912 {+ t.Fatalf("expected deploy.resources.limits.memory=536870912, got %d", got)+ }+ if got := int64(service.Deploy.Resources.Reservations.MemoryBytes); got != 134217728 {+ t.Fatalf("expected deploy.resources.reservations.memory=134217728, got %d", got)+ }+}++func TestDetailsUnmarshalJSON_InvalidUnitBytesValueReturnsError(t *testing.T) {+ payload := `{+ "id": "project-1",+ "name": "test-project",+ "path": "/tmp/test-project",+ "status": "running",+ "serviceCount": 1,+ "runningCount": 1,+ "createdAt": "2026-03-13T00:00:00Z",+ "updatedAt": "2026-03-13T00:00:00Z",+ "services": [+ {+ "name": "web",+ "image": "nginx:latest",+ "mem_limit": "definitely-not-valid"+ }+ ]+ }`++ err := json.Unmarshal([]byte(payload), &Details{})+ if err == nil {+ t.Fatal("expected invalid mem_limit to fail decoding")+ }+ if !strings.Contains(err.Error(), "mem_limit") {+ t.Fatalf("expected error to reference mem_limit, got %v", err)+ }+}