From b3f9ed628997d3551880db385536478ae560e68e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 29 Oct 2026 15:33:17 +0000 Subject: [PATCH] :bug: Validate debug files with their own pointer loader The `/dbg/actions` file validation passed the file id where `get-resolved-file-libraries` expects the file map, so the library map was seeded with a nil key. It also validated a file read without realizing it, so the first page lookup of a pointer-mapped file raised "load is not supported when *load-fn* is not bind" and the endpoint could not validate exactly the files the feature touches. Read the file realized (validation walks every page and component anyway) and build the library map from the file. The library loader already resolves each library's pointers with its own id, so the realized file and its libraries validate as plain data. Covered by a handler-level test that fails before the change. AI-assisted-by: deepseek-v4.1-flash --- backend/src/app/http/debug.clj | 8 +++-- .../test/backend_tests/http_debug_test.clj | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 backend/test/backend_tests/http_debug_test.clj diff --git a/backend/src/app/http/debug.clj b/backend/src/app/http/debug.clj index 6995464290..145737280a 100644 --- a/backend/src/app/http/debug.clj +++ b/backend/src/app/http/debug.clj @@ -784,8 +784,12 @@ (db/tx-run! (assoc cfg ::db/rollback true) (fn [cfg] - (let [file (bfc/get-file cfg file-id) - libs (bfc/get-resolved-file-libraries cfg file-id)] + ;; Validation walks every page and component, so the + ;; file is read realized; the library map is built + ;; from the file (not its id) and its own loader + ;; resolves each library's pointers. + (let [file (bfc/get-file cfg file-id :realize? true) + libs (bfc/get-resolved-file-libraries cfg file)] (if file (let [errors (cfv/validate-file file libs)] {::yres/status 200 diff --git a/backend/test/backend_tests/http_debug_test.clj b/backend/test/backend_tests/http_debug_test.clj new file mode 100644 index 0000000000..9c874601f4 --- /dev/null +++ b/backend/test/backend_tests/http_debug_test.clj @@ -0,0 +1,29 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS SUBSIDIARY SL + +(ns backend-tests.http-debug-test + "The /dbg validate action walks the whole file and its libraries: it + must hand `get-resolved-file-libraries` the file (not its id) and + resolve the pointer-mapped pages with the file's own loader." + (:require + [app.http.debug :as debug] + [backend-tests.helpers :as th] + [clojure.test :as t] + [yetti.response :as-alias yres])) + +(t/use-fixtures :once th/state-init) +(t/use-fixtures :each th/database-reset) + +(t/deftest validate-file-action-resolves-pointer-mapped-data + (let [profile (th/create-profile* 1) + file (th/create-file* 1 {:profile-id (:id profile) + :project-id (:default-project-id profile) + :is-shared false}) + handler (deref #'debug/validate-file) + result (handler th/*system* {:params {:file-id (str (:id file))}})] + + (t/is (= 200 (::yres/status result))) + (t/is (= "NO VALIDATION ERRORS FOUND" (::yres/body result)))))