@@ -1970,14 +1970,123 @@ buffer and hand nil to the native module."
19701970; ; -----------------------------------------------------------------------
19711971
19721972; ; -----------------------------------------------------------------------
1973- ; ; Test: module version check
1974- ; ; -----------------------------------------------------------------------
1975-
1976- (ert-deftest ghostel-test-package-version ()
1977- " Test that `ghostel--package-version' returns a version string."
1978- (let ((ver (ghostel--package-version)))
1979- (should (stringp ver))
1980- (should (string-match-p " ^[0-9]+\\ .[0-9]+\\ .[0-9]+" ver))))
1973+ ; ; Test: module download version selection
1974+ ; ; -----------------------------------------------------------------------
1975+
1976+ (ert-deftest ghostel-test-module-download-url-uses-requested-version ()
1977+ " Requested download versions are decoupled from the package version."
1978+ (let ((ghostel-github-release-url " https://example.invalid/releases" ))
1979+ (cl-letf (((symbol-function 'ghostel--module-asset-name )
1980+ (lambda () " ghostel-module-x86_64-linux.so" )))
1981+ (should (equal " https://example.invalid/releases/download/v0.7.1/ghostel-module-x86_64-linux.so"
1982+ (ghostel--module-download-url " 0.7.1" ))))))
1983+
1984+ (ert-deftest ghostel-test-module-download-url-uses-latest-release ()
1985+ " A nil download version uses the latest release asset."
1986+ (let ((ghostel-github-release-url " https://example.invalid/releases" ))
1987+ (cl-letf (((symbol-function 'ghostel--module-asset-name )
1988+ (lambda () " ghostel-module-x86_64-linux.so" )))
1989+ (should (equal " https://example.invalid/releases/latest/download/ghostel-module-x86_64-linux.so"
1990+ (ghostel--module-download-url nil ))))))
1991+
1992+ (ert-deftest ghostel-test-download-module-defaults-to-minimum-version ()
1993+ " Automatic downloads pin to the minimum supported native module version."
1994+ (let ((ghostel--minimum-module-version " 0.7.1" )
1995+ (captured-version :unset )
1996+ (download-dest nil ))
1997+ (cl-letf (((symbol-function 'ghostel--module-download-url )
1998+ (lambda (&optional version )
1999+ (setq captured-version version)
2000+ " https://example.invalid/releases/download/v0.7.1/ghostel-module-x86_64-linux.so" ))
2001+ ((symbol-function 'ghostel--download-file )
2002+ (lambda (_url dest )
2003+ (setq download-dest dest)
2004+ t ))
2005+ ((symbol-function 'message )
2006+ (lambda (&rest _ ))))
2007+ (should (ghostel--download-module " C:/ghostel/" ))
2008+ (should (equal " 0.7.1" captured-version))
2009+ (should (equal (downcase (expand-file-name
2010+ (concat " ghostel-module" module-file-suffix)
2011+ " C:/ghostel/" ))
2012+ (downcase download-dest))))))
2013+
2014+ (ert-deftest ghostel-test-download-module-prefix-uses-requested-version ()
2015+ " Prefix downloads pass the requested release version through unchanged."
2016+ (let ((ghostel--minimum-module-version " 0.7.1" )
2017+ (captured-version :unset )
2018+ (captured-latest nil )
2019+ (loaded-module nil ))
2020+ (let ((comp-enable-subr-trampolines nil )
2021+ (native-comp-enable-subr-trampolines nil ))
2022+ (cl-letf (((symbol-function 'locate-library )
2023+ (lambda (_ ) " C:/ghostel/ghostel.el" ))
2024+ ((symbol-function 'file-exists-p )
2025+ (lambda (_ ) nil ))
2026+ ((symbol-function 'read-string )
2027+ (lambda (&rest _ ) " 0.8.0" ))
2028+ ((symbol-function 'ghostel--download-module )
2029+ (lambda (_dir &optional version latest-release )
2030+ (setq captured-version version
2031+ captured-latest latest-release)
2032+ t ))
2033+ ((symbol-function 'module-load )
2034+ (lambda (path )
2035+ (setq loaded-module path)))
2036+ ((symbol-function 'message )
2037+ (lambda (&rest _ ))))
2038+ (ghostel-download-module '(4 ))
2039+ (should (equal " 0.8.0" captured-version))
2040+ (should-not captured-latest)
2041+ (should (equal (downcase (expand-file-name
2042+ (concat " ghostel-module" module-file-suffix)
2043+ " C:/ghostel/" ))
2044+ (downcase loaded-module)))))))
2045+
2046+ (ert-deftest ghostel-test-download-module-prefix-empty-uses-latest ()
2047+ " Prefix download treats blank input as a request for the latest release."
2048+ (let ((captured-version :unset )
2049+ (captured-latest nil )
2050+ (loaded-module nil ))
2051+ (let ((comp-enable-subr-trampolines nil )
2052+ (native-comp-enable-subr-trampolines nil ))
2053+ (cl-letf (((symbol-function 'locate-library )
2054+ (lambda (_ ) " C:/ghostel/ghostel.el" ))
2055+ ((symbol-function 'file-exists-p )
2056+ (lambda (_ ) nil ))
2057+ ((symbol-function 'read-string )
2058+ (lambda (&rest _ ) " " ))
2059+ ((symbol-function 'ghostel--download-module )
2060+ (lambda (_dir &optional version latest-release )
2061+ (setq captured-version version
2062+ captured-latest latest-release)
2063+ t ))
2064+ ((symbol-function 'module-load )
2065+ (lambda (path )
2066+ (setq loaded-module path)))
2067+ ((symbol-function 'message )
2068+ (lambda (&rest _ ))))
2069+ (ghostel-download-module '(4 ))
2070+ (should (null captured-version))
2071+ (should captured-latest)
2072+ (should (equal (downcase (expand-file-name
2073+ (concat " ghostel-module" module-file-suffix)
2074+ " C:/ghostel/" ))
2075+ (downcase loaded-module)))))))
2076+
2077+ (ert-deftest ghostel-test-download-module-prefix-rejects-too-old-version ()
2078+ " Prefix download rejects versions below the minimum supported version."
2079+ (let ((ghostel--minimum-module-version " 0.7.1" ))
2080+ (let ((comp-enable-subr-trampolines nil )
2081+ (native-comp-enable-subr-trampolines nil ))
2082+ (cl-letf (((symbol-function 'locate-library )
2083+ (lambda (_ ) " C:/ghostel/ghostel.el" ))
2084+ ((symbol-function 'file-exists-p )
2085+ (lambda (_ ) nil ))
2086+ ((symbol-function 'read-string )
2087+ (lambda (&rest _ ) " 0.7.0" )))
2088+ (should-error (ghostel-download-module '(4 ))
2089+ :type 'user-error )))))
19812090
19822091(ert-deftest ghostel-test-compile-module-invokes-zig-build ()
19832092 " Source compilation runs zig build directly."
@@ -2787,9 +2896,14 @@ while :; do sleep 0.1; done'\n")
27872896 ghostel-test-project-universal-arg
27882897 ghostel-test-copy-all
27892898 ghostel-test-copy-mode-buffer-navigation
2790- ghostel-test-package-version
27912899 ghostel-test-compile-module-invokes-zig-build
27922900 ghostel-test-module-compile-command-uses-zig-build
2901+ ghostel-test-module-download-url-uses-requested-version
2902+ ghostel-test-module-download-url-uses-latest-release
2903+ ghostel-test-download-module-defaults-to-minimum-version
2904+ ghostel-test-download-module-prefix-uses-requested-version
2905+ ghostel-test-download-module-prefix-empty-uses-latest
2906+ ghostel-test-download-module-prefix-rejects-too-old-version
27932907 ghostel-test-module-version-match
27942908 ghostel-test-module-version-mismatch
27952909 ghostel-test-module-version-newer-than-minimum
0 commit comments