diff --git a/acceptance/bundle/resources/dashboards/generate_inplace/out.test.toml b/acceptance/bundle/resources/dashboards/generate_inplace/out.test.toml index bbcef543fa6..7edd52865f7 100644 --- a/acceptance/bundle/resources/dashboards/generate_inplace/out.test.toml +++ b/acceptance/bundle/resources/dashboards/generate_inplace/out.test.toml @@ -1,4 +1,4 @@ -Local = false +Local = true Cloud = true RequiresWarehouse = true RunsOnDbr = true diff --git a/acceptance/bundle/resources/dashboards/generate_inplace/test.toml b/acceptance/bundle/resources/dashboards/generate_inplace/test.toml index 731f8ff31b5..58053ece188 100644 --- a/acceptance/bundle/resources/dashboards/generate_inplace/test.toml +++ b/acceptance/bundle/resources/dashboards/generate_inplace/test.toml @@ -1,5 +1,5 @@ Cloud = true -Local = false +Local = true RecordRequests = false RunsOnDbr = true diff --git a/libs/testserver/dashboards.go b/libs/testserver/dashboards.go index 10cc03a477c..d29ff6f11d7 100644 --- a/libs/testserver/dashboards.go +++ b/libs/testserver/dashboards.go @@ -32,11 +32,18 @@ func transformSerializedDashboard(serializedDashboard, datasetCatalog, datasetSc return serializedDashboard } + // The real backend stores and returns the serialized dashboard verbatim, + // modulo the mutations applied below. Track whether any mutation actually + // happens so we can preserve the caller's original formatting (whitespace + // and key order) when it doesn't, matching cloud behavior. + mutated := false + // Add pageType to each page in the pages array (as of June 2025, this is an undocumented Lakeview API behaviour) if pages, ok := dashboardContent["pages"].([]any); ok { for _, page := range pages { if pageMap, ok := page.(map[string]any); ok { pageMap["pageType"] = "PAGE_TYPE_CANVAS" + mutated = true } } } @@ -47,21 +54,32 @@ func transformSerializedDashboard(serializedDashboard, datasetCatalog, datasetSc if datasetMap, ok := dataset.(map[string]any); ok { if datasetCatalog != "" { datasetMap["catalog"] = datasetCatalog + mutated = true } if datasetSchema != "" { datasetMap["schema"] = datasetSchema + mutated = true } } } } - updatedContent, err := json.Marshal(dashboardContent) - if err != nil { - return serializedDashboard + // Without mutations cloud preserves the caller's formatting verbatim; + // otherwise it re-marshals the content. + result := serializedDashboard + if mutated { + updatedContent, err := json.Marshal(dashboardContent) + if err != nil { + return serializedDashboard + } + result = string(updatedContent) } - // Add a newline to the end of the serialized dashboard. - return string(updatedContent) + "\n" + // Cloud always terminates the stored dashboard with a single trailing newline. + if !strings.HasSuffix(result, "\n") { + result += "\n" + } + return result } func (s *FakeWorkspace) DashboardCreate(req Request) Response {