diff --git a/frontend/performance/benches/render_wasm/node/feature_comparison.cljs b/frontend/performance/benches/render_wasm/node/feature_comparison.cljs index 8f24fc83a8..4dcdfed6e1 100644 --- a/frontend/performance/benches/render_wasm/node/feature_comparison.cljs +++ b/frontend/performance/benches/render_wasm/node/feature_comparison.cljs @@ -36,16 +36,6 @@ :create-run-home runs/create-home :execute-run run/execute}) -(defn- invalid-home - [message data] - (throw (ex-info message (assoc data :type ::invalid-home)))) - -(defn- check-id - [id] - (when-not (files/valid-id? id) - (invalid-home "invalid feature comparison id" {:id id})) - id) - (defn create-home "Creates the feature-comparison home directory @@ -53,12 +43,12 @@ An explicit directory resolves from the caller's cwd and must not exist. Paths inside the managed builds tree are rejected." [root comparison-id output-dir] - (check-id comparison-id) + (files/check-id comparison-id) (let [default-dir (path/join (artifacts/managed-root root) "feature-comparisons" comparison-id) dir (runs/check-output-dir (or output-dir default-dir))] (when (artifacts/inside-builds? root dir) - (invalid-home "feature comparison cannot use a directory inside builds" {:path dir})) + (files/invalid-home "feature comparison cannot use a directory inside builds" {:path dir})) (try (files/create-home dir "feature-comparison") (catch :default cause diff --git a/frontend/performance/benches/render_wasm/node/files.cljs b/frontend/performance/benches/render_wasm/node/files.cljs index c1ed81cd6d..551581ba78 100644 --- a/frontend/performance/benches/render_wasm/node/files.cljs +++ b/frontend/performance/benches/render_wasm/node/files.cljs @@ -37,6 +37,16 @@ :log-path log-path :record-path (path/join dir (str stem ".transit"))})) +(defn invalid-home + [message data] + (throw (ex-info message (assoc data :type ::invalid-home)))) + +(defn check-id + [id] + (when-not (valid-id? id) + (invalid-home "invalid id" {:id id})) + id) + (defn get-real-path "Resolves symlink ancestors even when the final path does not exist yet." [file] diff --git a/frontend/performance/benches/render_wasm/node/runs.cljs b/frontend/performance/benches/render_wasm/node/runs.cljs index 7450a30d4e..408a53ece3 100644 --- a/frontend/performance/benches/render_wasm/node/runs.cljs +++ b/frontend/performance/benches/render_wasm/node/runs.cljs @@ -20,26 +20,16 @@ [benches.render-wasm.result :as result] [clojure.string :as str])) -(defn- invalid-home - [message data] - (throw (ex-info message (assoc data :type ::invalid-home)))) - -(defn- check-id - [id] - (when-not (files/valid-id? id) - (invalid-home "invalid run id" {:id id})) - id) - (defn check-output-dir "Resolves an explicit user directory from the caller's cwd and checks that it does not exist. Nil selects the managed default. Does not create anything." [dir] (when (some? dir) (when (str/blank? dir) - (invalid-home "output directory requires a nonempty path" {})) + (files/invalid-home "output directory requires a nonempty path" {})) (let [resolved (path/resolve dir)] (when (fs/lstatSync resolved #js {:throwIfNoEntry false}) - (invalid-home "output directory already exists" {:path resolved})) + (files/invalid-home "output directory already exists" {:path resolved})) resolved))) (defn create-home @@ -47,11 +37,11 @@ after the plan exists. An explicit directory must not exist; a managed home uses the frontend root regardless of cwd." [{:keys [root run-id output-dir remove]}] - (check-id run-id) + (files/check-id run-id) (let [dir (check-output-dir (or output-dir (path/join (artifacts/managed-root root) "runs" run-id)))] (when (and remove (artifacts/inside-builds? root dir)) - (invalid-home "--remove cannot use an output directory inside builds" {:path dir})) + (files/invalid-home "--remove cannot use an output directory inside builds" {:path dir})) (try (assoc (files/create-home dir "run") :run-id run-id) (catch :default cause diff --git a/frontend/test/performance_tests/render_wasm/feature_comparison_test.cljs b/frontend/test/performance_tests/render_wasm/feature_comparison_test.cljs index 95806ab898..b7dd904586 100644 --- a/frontend/test/performance_tests/render_wasm/feature_comparison_test.cljs +++ b/frontend/test/performance_tests/render_wasm/feature_comparison_test.cljs @@ -783,7 +783,7 @@ (:dir home))) (t/is (= "" (fs/readFileSync (:log-path home) "utf8")))) (doseq [id [nil "" "../escape" "a/b" "a\\b"]] - (t/is (thrown-with-msg? js/Error #"invalid feature comparison id" + (t/is (thrown-with-msg? js/Error #"invalid id" (feature-comparison/create-home (frontend-root) id nil)))) (let [existing (path/join @temporary-root "existing")] (fs/mkdirSync existing) diff --git a/frontend/test/performance_tests/render_wasm/runs_test.cljs b/frontend/test/performance_tests/render_wasm/runs_test.cljs index da5f810aae..97c45bea94 100644 --- a/frontend/test/performance_tests/render_wasm/runs_test.cljs +++ b/frontend/test/performance_tests/render_wasm/runs_test.cljs @@ -10,6 +10,7 @@ ["os" :as os] ["path" :as path] [benches.render-wasm.node.artifacts :as artifacts] + [benches.render-wasm.node.files :as files] [benches.render-wasm.node.runs :as runs] [benches.render-wasm.result :as result] [cljs.test :as t :include-macros true] @@ -71,7 +72,7 @@ (let [error (failure #(runs/create-home {:root @temporary-root :run-id "run-3" :output-dir directory}))] - (t/is (= ::runs/invalid-home (:type (ex-data error)))) + (t/is (= ::files/invalid-home (:type (ex-data error)))) (t/is (= "output directory already exists" (ex-message error))) (t/is (= "keep" (fs/readFileSync (path/join directory "sentinel") "utf8")))))) @@ -95,7 +96,7 @@ (t/deftest malformed-ids-and-empty-paths-fail-at-the-home-boundary (doseq [id ["../escape" "" "a/b" "a\\b"]] - (t/is (thrown-with-msg? js/Error #"invalid run id" + (t/is (thrown-with-msg? js/Error #"invalid id" (runs/create-home {:root @temporary-root :run-id id})))) (t/is (thrown-with-msg? js/Error #"nonempty path" (runs/check-output-dir " "))))