Skip to content

Commit b8dbb41

Browse files
committed
fix(perf): harden platform and tarball paths
Normalize version-qualified Windows os.name values to win32 so native executable and package paths use the expected suffixes. Resolve relative pnpm pack filenames against the temporary destination while preserving the absolute paths emitted by current pnpm versions. Add regression coverage for both platform normalization and relative or absolute tarball filenames.
1 parent cf46b61 commit b8dbb41

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

‎apps/ccusage/scripts/compare-pr-performance_test.clj‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@
8181
(is (= :local (base-source-decision {:base-dir "/repo"})))
8282
(is (= :skip (base-source-decision {:base-package-url "https://example.test/pkg"}))))
8383

84+
(deftest platform-normalization
85+
(is (= "darwin" (normalize-platform-name "Mac OS X")))
86+
(is (= "linux" (normalize-platform-name "Linux")))
87+
(is (= "win32" (normalize-platform-name "Windows 11")))
88+
(is (= "freebsd" (normalize-platform-name "FreeBSD"))))
89+
90+
(deftest packed-tarball-path-resolution
91+
(is (= "/tmp/pack/ccusage.tgz"
92+
(packed-tarball-path "/tmp/pack" "ccusage.tgz")))
93+
(is (= "/var/tmp/ccusage.tgz"
94+
(packed-tarball-path "/tmp/pack" "/var/tmp/ccusage.tgz"))))
95+
8496
(deftest skipped-markdown-rendering
8597
(let [markdown (render-skipped-markdown
8698
{:base-package-url "https://pkg.pr.new/x/ccusage@abcdef0123456789"

‎apps/ccusage/scripts/compare_pr_performance/system.clj‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@
1616
{:kind :child-command-failed :argv argv :dir (:dir options)
1717
:exit (:exit result) :stderr (:err result)}))))
1818

19-
(defn platform-name [] ({"Mac OS X" "darwin" "Linux" "linux" "Windows" "win32"}
20-
(System/getProperty "os.name") (str/lower-case (System/getProperty "os.name"))))
19+
(defn normalize-platform-name [os-name]
20+
(cond
21+
(= os-name "Mac OS X") "darwin"
22+
(= os-name "Linux") "linux"
23+
(str/starts-with? os-name "Windows") "win32"
24+
:else (str/lower-case os-name)))
25+
(defn platform-name [] (normalize-platform-name (System/getProperty "os.name")))
2126
(defn arch-name [] ({"aarch64" "arm64" "x86_64" "x64" "amd64" "x64"}
2227
(System/getProperty "os.arch") (System/getProperty "os.arch")))
2328
(defn path [& parts] (str (apply fs/path parts)))
@@ -90,6 +95,9 @@
9095
(defn base-source-decision [{:keys [package-install base-dir base-package-url]}]
9196
(cond package-install :installed base-dir :local base-package-url :skip))
9297

98+
(defn packed-tarball-path [destination filename]
99+
(if (fs/absolute? filename) filename (path destination filename)))
100+
93101
(defn packed-tarball-size [repo-dir]
94102
(let [package-dir (path repo-dir "apps" "ccusage")
95103
package-json-path (path package-dir "package.json")
@@ -106,7 +114,7 @@
106114
filename (:filename pack-result)]
107115
(when-not filename
108116
(fail! "pnpm pack did not report a tarball filename" {:kind :malformed-pack-output}))
109-
(optional-file-size filename)))
117+
(optional-file-size (packed-tarball-path destination filename))))
110118
(finally (spit package-json-path original) (fs/delete-tree destination)))))
111119

112120
(defn remote-tarball-size [url]

0 commit comments

Comments
 (0)