From 9fa1fdd0cc3e4e1ff6a6fef024237cc0700ee924 Mon Sep 17 00:00:00 2001 From: Tsiry Sandratraina Date: Thu, 12 Nov 2026 07:45:16 +0300 Subject: [PATCH] feat(setup-uv): add Python and tools options in 0.3.0 --- fluentci.toml | 2 +- lib/setup/src/CI/Setup/UvEnvironment.purs | 99 +++++++++++++++++++++++ scripts/generate_components.py | 9 ++- scripts/generate_setup_tools.py | 24 +++++- setup/uv/COMPONENT.md | 4 +- setup/uv/README.md | 51 ++++++++++-- setup/uv/legacy-schema.json | 8 ++ setup/uv/schema.json | 10 ++- setup/uv/src/CI/Component.purs | 13 +-- setup/uv/src/CI/Setup/Uv.purs | 11 +-- setup/uv/test/environment.test.mjs | 64 +++++++++++++++ 11 files changed, 271 insertions(+), 24 deletions(-) create mode 100644 lib/setup/src/CI/Setup/UvEnvironment.purs create mode 100644 setup/uv/test/environment.test.mjs diff --git a/fluentci.toml b/fluentci.toml index deebed4..f900bac 100644 --- a/fluentci.toml +++ b/fluentci.toml @@ -1204,7 +1204,7 @@ runtime = "component" [[modules]] name = "setup-uv" -version = "0.2.1" +version = "0.3.0" path = "setup/uv" sdk = "purescript" runtime = "component" diff --git a/lib/setup/src/CI/Setup/UvEnvironment.purs b/lib/setup/src/CI/Setup/UvEnvironment.purs new file mode 100644 index 0000000..626a9a8 --- /dev/null +++ b/lib/setup/src/CI/Setup/UvEnvironment.purs @@ -0,0 +1,99 @@ +module CI.Setup.UvEnvironment (Config, defaultConfig, decodeConfig, setupWith, setup) where + +import Prelude +import CI.Setup.Host as H +import CI.Setup.Tools as Tools +import CI.Setup.Types as Types +import Data.Argonaut.Core (Json, isNull, stringify) +import Data.Argonaut.Decode (class DecodeJson, decodeJson, getFieldOptional) +import Data.Argonaut.Encode (encodeJson) +import Data.Argonaut.Parser (jsonParser) +import Data.Array as Array +import Data.Either (Either(..), either) +import Data.Foldable (traverse_) +import Data.Maybe (Maybe(..), fromMaybe) +import Data.String as String +import Data.String.Common (trim) +import Data.String.Pattern (Pattern(..)) +import Data.String.Regex as Regex +import Data.String.Regex.Flags (noFlags) +import Effect (Effect) +import Effect.Exception (throw) +import FluentCI.Plugin as P +import Foreign.Object as Object + +type Config = { base :: Types.Config, pythonVersion :: String, tools :: Array String } + +defaultConfig :: Config +defaultConfig = { base: Types.defaults "uv", pythonVersion: "", tools: [] } + +optional :: forall a. DecodeJson a => Object.Object Json -> String -> a -> Either String a +optional object key fallback = either (Left <<< show) (Right <<< fromMaybe fallback) (getFieldOptional object key) + +validate :: Config -> Either String Unit +validate config = do + Types.validateConfig "uv" config.base + python <- Regex.regex "^[A-Za-z0-9][A-Za-z0-9._+@-]*$" noFlags + unless (config.pythonVersion == "" || Regex.test python config.pythonVersion) $ Left "Invalid Python version selector" + package <- Regex.regex "^[A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?(\\[[A-Za-z0-9._-]+\\])?((===|==|~=|!=|<=|>=|<|>)[A-Za-z0-9.*+_-]+)?$" noFlags + traverse_ (\tool -> unless (Regex.test package tool) (Left "tools must contain package names or single version constraints, such as ruff==0.12.0, without empty entries or shell syntax")) config.tools + unless (Array.length (Array.nub config.tools) == Array.length config.tools) $ Left "Duplicate uv tools" + +decodeConfig :: Json -> Either String Config +decodeConfig json = do + object <- either (Left <<< show) pure (decodeJson json) + when (Array.any isNull (Object.values object)) $ Left "Setup arguments cannot be null" + pythonVersion <- optional object "pythonVersion" "" + text <- optional object "tools" "" + let tools = Types.commaSeparated text + base <- Types.decodeConfig "uv" (encodeJson (Object.delete "pythonVersion" (Object.delete "tools" object))) + let config = { base, pythonVersion, tools } + validate config + pure config + +setupWith :: Config -> Effect Types.Result +setupWith config = do + either throw pure (validate config) + host <- H.host + either throw pure (Types.hostSupported "uv" host) + when (Types.isBSD host.os && config.base.installDir /= "") $ throw "Native BSD packages use the system prefix; omit installDir" + installed <- Tools.install "uv" host (config.base { installDir = Types.cleanDirectory config.base.installDir }) + prepared <- if config.pythonVersion == "" && Array.null config.tools then pure installed else do + H.requireTools [ "mkdir", "ln", "test" ] + home <- H.userHome + let prefix = home <> "/.local/share/fluentci/uv-environments/" <> installed.version <> "/" <> if config.pythonVersion == "" then "default" else config.pythonVersion + pythonBin = prefix <> "/python-bin" + toolBin = prefix <> "/tool-bin" + uv = installed.binDir <> "/uv" + environment = Object.insert "UV_TOOL_DIR" (prefix <> "/tools") + (Object.insert "UV_TOOL_BIN_DIR" toolBin (Object.insert "UV_PYTHON_INSTALL_DIR" (prefix <> "/python") + (Object.insert "UV_PYTHON_BIN_DIR" pythonBin installed.environment))) + capture = H.captureWith environment false + bsdFlags = if Types.isBSD host.os then [ "--no-python-downloads" ] else [] + selected <- if config.pythonVersion == "" then pure environment else do + H.run [ "mkdir", "-p", pythonBin ] + unless (Types.isBSD host.os) $ void (capture [ uv, "python", "install", "--", config.pythonVersion ]) + python <- trim <$> capture ([ uv, "python", "find" ] <> (if Types.isBSD host.os then bsdFlags else [ "--managed-python" ]) <> [ "--", config.pythonVersion ]) + unless (Types.validDirectory python) $ throw "uv returned an invalid Python executable path" + H.run [ "test", "-x", python ] + void (capture [ python, "--version" ] >>= H.versionFrom "python") + H.run [ "ln", "-sf", python, pythonBin <> "/python" ] + H.run [ "ln", "-sf", python, pythonBin <> "/python3" ] + pure (Object.insert "UV_PYTHON" python environment) + let execute = H.captureWith selected false + traverse_ (\tool -> void (execute ([ uv, "tool", "install", "--force" ] <> bsdFlags + <> (if config.pythonVersion == "" then [] else [ "--python", fromMaybe "" (Object.lookup "UV_PYTHON" selected) ]) <> [ "--", tool ]))) config.tools + let paths = (if Array.null config.tools then [] else [ toolBin ]) <> (if config.pythonVersion == "" then [] else [ pythonBin ]) + path = String.joinWith ":" paths <> ":" <> fromMaybe "" (Object.lookup "PATH" installed.environment) + pure (installed { environment = Object.insert "PATH" path selected }) + H.activate prepared + pure prepared + +setup :: Effect Unit +setup = do + raw <- trim <$> (P.input >>= H.unwrap) + config <- if raw == "" then pure defaultConfig + else if String.startsWith (Pattern "{") raw then either throw pure (jsonParser raw >>= decodeConfig) + else pure (defaultConfig { base = (Types.defaults "uv") { version = raw } }) + result <- setupWith config + P.output (stringify (encodeJson result)) >>= H.unwrap diff --git a/scripts/generate_components.py b/scripts/generate_components.py index 060dbab..caaa896 100644 --- a/scripts/generate_components.py +++ b/scripts/generate_components.py @@ -80,6 +80,7 @@ def setup_props(name): props={k:{'type':t} for k,t in [('version','string'),('installDir','string'),('packageName','string'),('sudo','boolean')]} extras={'rust':{'toolchain':'string','components':'string','targets':'string','profile':'string'},'bun':{'baseline':'boolean','libc':'string'},'pkl':{'libc':'string'},'elixir':{'otpVersion':'string'},'nix':{'daemon':'boolean'},'determinate-nix':{'init':'string','trustedUsers':'array','extraConf':'array'},'extism':{k:'string' for k in ['cliVersion','jsVersion','pythonVersion','xtpVersion','binaryenVersion']},'purescript':{k:'string' for k in ['nodeVersion','bunVersion','npmVersion','spagoVersion','nodePackageName','bunPackageName']}} if name=='cachix':extras[name]={'cache':'string'} + if name=='uv':extras[name]={'pythonVersion':'string','tools':'string'} if name=='php':extras[name]={'tools':'string','miseVersion':'string'} if name in ['pkgx','mise','devbox','flox','macports','macports-rs']:extras[name]={'packages':'string'} if name in ['devbox','flox']:extras[name]['project']='string' @@ -95,8 +96,9 @@ def generated(): source=['-- Generated by scripts/generate_components.py.',f'module CI.Component ({", ".join(exports)}) where','', 'import Prelude','import CI.Contract as Contract','import Data.Either (either)','import Data.Maybe (Maybe(..))','import Effect (Effect)','import Effect.Exception (throw)'] if module['path'] in catalog:source+=['import '+('CI.NixPublish' if name=='nix-publish' else 'CI.CLI')+' as Native'] elif category=='setup': - if tool!='php':source+=['import CI.Setup as Setup','import CI.Setup.Types as Types'] + if tool not in ['php','uv']:source+=['import CI.Setup as Setup','import CI.Setup.Types as Types'] if tool=='purescript':source+=['import CI.Setup.PureScript as Native'] + if tool=='uv':source+=['import CI.Setup.UvEnvironment as Native'] if tool=='php':source+=['import CI.Setup.PHP as Native'] elif name=='buildx':source+=['import Buildx as B','import Buildx.Commands as C'] elif name in {'dpkg','rpmbuild'}:source+=['import CI.'+('Dpkg' if name=='dpkg' else 'Rpmbuild')+' as Native'] @@ -121,6 +123,11 @@ def generated(): returned='{ tool :: String, version :: String, binDir :: String, environment :: Array Contract.Variable, nodeVersion :: String, bunVersion :: String, npmVersion :: String, spagoVersion :: String }' for key in ['nodeVersion','bunVersion','npmVersion','spagoVersion']:output['properties'][key]={'type':'string'};output['required'].append(key) body=[' config <- either throw pure (Native.decodeConfig (Contract.input (Contract.encodeInput args)))',' result <- Native.setupWith config',' pure (result { environment = Contract.variables result.environment })'] + elif tool=='uv': + description='Install and verify uv, optionally configure a Python version and isolated tools, and publish their environment.' + properties['pythonVersion']['description']='Optional Python release or interpreter selector such as 3.13 or cpython-3.13.1; omit to retain uv-only setup. BSD selects an existing matching interpreter without downloads.' + properties['tools']['description']='Comma-separated Python CLI packages with optional single native version constraints, such as ruff==0.12.0,httpie. Blank or omitted values install no tools.' + body=[' config <- either throw pure (Native.decodeConfig (Contract.input (Contract.encodeInput args)))',' Contract.setupResult <$> Native.setupWith config'] elif tool=='php': description='Install and verify PHP and optional versioned CI tools, then publish their environment.' properties['tools'].update(default='composer',description='Comma-separated PHP tools, optionally name:version, such as composer:2,phpunit:11,phpstan. Blank or none skips module tool installation. Supports documented aliases and vendor/package:version with a matching executable name.') diff --git a/scripts/generate_setup_tools.py b/scripts/generate_setup_tools.py index a171856..cdbde25 100644 --- a/scripts/generate_setup_tools.py +++ b/scripts/generate_setup_tools.py @@ -16,7 +16,26 @@ def generated(): yield ROOT/'lib/setup/src/CI/Setup/ToolCatalog.purs',code for t in tools: name=t['name'];mod='CI.Setup.'+title(name);d=ROOT/'setup'/name - yield d/f'src/CI/Setup/{title(name)}.purs',f'''-- Generated by scripts/generate_setup_tools.py. + if name=='uv': + yield d/f'src/CI/Setup/{title(name)}.purs', '''-- Generated by scripts/generate_setup_tools.py. +module CI.Setup.Uv (setup, setupWith, defaultConfig) where + +import Prelude (Unit) +import Effect (Effect) +import CI.Setup.Types (Result) +import CI.Setup.UvEnvironment (Config) +import CI.Setup.UvEnvironment as Native + +defaultConfig :: Config +defaultConfig = Native.defaultConfig + +setupWith :: Config -> Effect Result +setupWith = Native.setupWith + +setup :: Effect Unit +setup = Native.setup +''' + else:yield d/f'src/CI/Setup/{title(name)}.purs',f'''-- Generated by scripts/generate_setup_tools.py. module {mod} (setup, setupWith, defaultConfig) where import Prelude (Unit) @@ -35,6 +54,9 @@ setup = Setup.setup "{name}" ''' yield d/'legacy-entry.mjs',f'export {{ setup }} from "./output/{mod}/index.js";\n' props={'version':{'type':'string','default':t['defaultVersion']},'installDir':{'type':'string'},'packageName':{'type':'string'},'sudo':{'type':'boolean','default':False}} + if name=='uv': + props['pythonVersion']={'type':'string','description':'Optional Python version to install or select; omit for uv-only setup.'} + props['tools']={'type':'string','description':'Comma-separated tools to install, optionally with native version constraints such as ruff==0.12.0.'} if name=='cachix':props['cache']={'type':'string','description':'Cachix cache name to enable with cachix use; omit for CLI-only setup.'} if name in ['pkgx','mise','devbox','flox','macports','macports-rs']:props['packages']={'type':'string','description':'Comma-separated packages to install, optionally with native version selectors.'} if name in ['devbox','flox']:props['project']={'type':'string','default':'.','description':'Project environment directory to initialize or update.'} diff --git a/setup/uv/COMPONENT.md b/setup/uv/COMPONENT.md index 7d22e79..5958426 100644 --- a/setup/uv/COMPONENT.md +++ b/setup/uv/COMPONENT.md @@ -5,7 +5,7 @@ and embedded help from these typed PureScript functions. Optional arguments may ## `setup` -Install and verify uv, select its version, and publish its environment for subsequent tasks. +Install and verify uv, optionally configure a Python version and isolated tools, and publish their environment. | Argument | Type | Required | Description | | --- | --- | --- | --- | @@ -13,5 +13,7 @@ Install and verify uv, select its version, and publish its environment for subse | `install-dir` | `string` | no | Absolute per-user installation prefix; omit for native package installations. | | `package-name` | `string` | no | Native package or port selector overriding the default repository package name. | | `sudo` | `boolean` | no | Use noninteractive sudo for native package or system installation; defaults to false. | +| `python-version` | `string` | no | Optional Python release or interpreter selector such as 3.13 or cpython-3.13.1; omit to retain uv-only setup. BSD selects an existing matching interpreter without downloads. | +| `tools` | `string` | no | Comma-separated Python CLI packages with optional single native version constraints, such as ruff==0.12.0,httpie. Blank or omitted values install no tools. | Returns `Contract.SetupResult`. diff --git a/setup/uv/README.md b/setup/uv/README.md index e0a7455..06457e8 100644 --- a/setup/uv/README.md +++ b/setup/uv/README.md @@ -7,7 +7,8 @@ source and are embedded in the component; no raw JSON plugin input is required. ## Usage ```sh -fluentci run setup-uv setup --version latest +fluentci run setup-uv setup --version latest \ + --python-version 3.13 --tools ruff==0.12.0,httpie ``` ```sh @@ -17,8 +18,7 @@ fluentci run setup-uv setup --help See [COMPONENT.md](./COMPONENT.md) for every named argument, description, required flag, and return type. The [schema](./schema.json) describes the same -contract. Optional values retain the native module defaults. Lists use JSON array -syntax; boolean arguments accept switches. Native function/flag names use kebab-case. +contract. Optional values retain the native module defaults. List arguments use comma-separated strings; boolean arguments accept switches. Native function/flag names use kebab-case. ## Requirements and behavior @@ -28,12 +28,47 @@ to later tasks in the same host session. Separate shell invocations must add the returned installation directory to PATH explicitly. +## Optional Python and tools -Linux/macOS use the configured upstream or ecosystem installer. JavaScript tools -are installed through Bun, bootstrapping Node.js/Bun when missing. Python, Go, -Ruby, and Java prerequisites depend on the selected tool. BSD uses native pkg, -pkg_add, or pkgin repositories; missing packages/versions fail clearly. Nix and -Determinate Nix support Linux/macOS only; dpkg/rpmbuild installers are Linux-only. +`--python-version` requests a Python release or interpreter selector, such as +`3.13`, `3.13.5`, or `cpython-3.13.5`. Linux/macOS install the managed interpreter +through `uv python install`, then verify its executable and expose `python` and +`python3` shims on PATH. `UV_PYTHON` selects that interpreter for later uv commands. +`--version` continues to select the uv release, not Python. + +`--tools` accepts a comma-separated list of Python CLI packages, optionally with +a single native version constraint: `ruff==0.12.0,httpie>=3`. Tools are installed +using `uv tool install` into isolated environments. Bare names, single extras +such as `mypy[faster-cache]`, and single comparison constraints are accepted; +compound constraints containing commas and direct URLs are not supported by this +list input. Tool requests are passed as literal arguments without shell expansion. +The requested Python is used for all tools when supplied; otherwise uv resolves +an interpreter using its normal rules. Repeated setup replaces the requested tool +installations in the module's own tool store using `--force`. + +Both options are optional. Omitted or blank tools install no tools; omitted or +empty Python version does not explicitly install/select Python. Supplying neither +retains uv-only setup. Entries are trimmed; malformed lists and empty entries are +rejected before any host command. Tool or interpreter failures fail setup before +publishing environment changes. Successful downloads can remain for retry. + +Managed environments are stored under +`$HOME/.local/share/fluentci/uv-environments/UV_VERSION/PYTHON_SELECTOR`, separate +from application environments. Returned environment values include the uv and +requested executable directories on PATH, plus uv's managed Python/tool storage +variables. Propagate the full returned environment between separate processes. + +Linux/macOS retain the existing per-user uv installer, which requires a bootstrap +`python3` with virtual-environment support. The optional managed Python is installed +after uv itself. FreeBSD, OpenBSD, and NetBSD use +native uv packages; missing packages/versions fail clearly. On BSD, a requested +Python must already be installed and discoverable by uv; automatic Python +downloads are disabled for both interpreter discovery and tool installation. +Unavailable or incompatible interpreters/tools fail clearly. Setup does not +change shell startup files or project dependency manifests. + +See uv's [Python guide](https://docs.astral.sh/uv/guides/install-python/) and +[tool guide](https://docs.astral.sh/uv/guides/tools/) for native behavior. ## Development diff --git a/setup/uv/legacy-schema.json b/setup/uv/legacy-schema.json index 4f389de..d1fb439 100644 --- a/setup/uv/legacy-schema.json +++ b/setup/uv/legacy-schema.json @@ -18,6 +18,14 @@ "sudo": { "type": "boolean", "default": false + }, + "pythonVersion": { + "type": "string", + "description": "Optional Python version to install or select; omit for uv-only setup." + }, + "tools": { + "type": "string", + "description": "Comma-separated tools to install, optionally with native version constraints such as ruff==0.12.0." } }, "additionalProperties": false diff --git a/setup/uv/schema.json b/setup/uv/schema.json index 1705ba7..380969d 100644 --- a/setup/uv/schema.json +++ b/setup/uv/schema.json @@ -3,7 +3,7 @@ "runtime": "component", "exports": { "setup": { - "description": "Install and verify uv, select its version, and publish its environment for subsequent tasks.", + "description": "Install and verify uv, optionally configure a Python version and isolated tools, and publish their environment.", "input": { "type": "object", "properties": { @@ -22,6 +22,14 @@ "sudo": { "type": "boolean", "description": "Use noninteractive sudo for native package or system installation; defaults to false." + }, + "pythonVersion": { + "type": "string", + "description": "Optional Python release or interpreter selector such as 3.13 or cpython-3.13.1; omit to retain uv-only setup. BSD selects an existing matching interpreter without downloads." + }, + "tools": { + "type": "string", + "description": "Comma-separated Python CLI packages with optional single native version constraints, such as ruff==0.12.0,httpie. Blank or omitted values install no tools." } }, "required": [], diff --git a/setup/uv/src/CI/Component.purs b/setup/uv/src/CI/Component.purs index 8f0434b..2033d01 100644 --- a/setup/uv/src/CI/Component.purs +++ b/setup/uv/src/CI/Component.purs @@ -7,15 +7,16 @@ import Data.Either (either) import Data.Maybe (Maybe) import Effect (Effect) import Effect.Exception (throw) -import CI.Setup as Setup -import CI.Setup.Types as Types +import CI.Setup.UvEnvironment as Native --- | Install and verify uv, select its version, and publish its environment for subsequent tasks. +-- | Install and verify uv, optionally configure a Python version and isolated tools, and publish their environment. -- | @param version Tool release or supported channel to install; omitted values use the documented default. -- | @param installDir Absolute per-user installation prefix; omit for native package installations. -- | @param packageName Native package or port selector overriding the default repository package name. -- | @param sudo Use noninteractive sudo for native package or system installation; defaults to false. -setup :: { version :: Maybe String, installDir :: Maybe String, packageName :: Maybe String, sudo :: Maybe Boolean } -> Effect Contract.SetupResult +-- | @param pythonVersion Optional Python release or interpreter selector such as 3.13 or cpython-3.13.1; omit to retain uv-only setup. BSD selects an existing matching interpreter without downloads. +-- | @param tools Comma-separated Python CLI packages with optional single native version constraints, such as ruff==0.12.0,httpie. Blank or omitted values install no tools. +setup :: { version :: Maybe String, installDir :: Maybe String, packageName :: Maybe String, sudo :: Maybe Boolean, pythonVersion :: Maybe String, tools :: Maybe String } -> Effect Contract.SetupResult setup args = do - config <- either throw pure (Types.decodeConfig "uv" (Contract.input (Contract.encodeInput args))) - Contract.setupResult <$> Setup.install "uv" config + config <- either throw pure (Native.decodeConfig (Contract.input (Contract.encodeInput args))) + Contract.setupResult <$> Native.setupWith config diff --git a/setup/uv/src/CI/Setup/Uv.purs b/setup/uv/src/CI/Setup/Uv.purs index 7ae259e..8e76d26 100644 --- a/setup/uv/src/CI/Setup/Uv.purs +++ b/setup/uv/src/CI/Setup/Uv.purs @@ -2,15 +2,16 @@ module CI.Setup.Uv (setup, setupWith, defaultConfig) where import Prelude (Unit) -import CI.Setup as Setup -import CI.Setup.Types (Config, Result, defaults) import Effect (Effect) +import CI.Setup.Types (Result) +import CI.Setup.UvEnvironment (Config) +import CI.Setup.UvEnvironment as Native defaultConfig :: Config -defaultConfig = defaults "uv" +defaultConfig = Native.defaultConfig setupWith :: Config -> Effect Result -setupWith = Setup.install "uv" +setupWith = Native.setupWith setup :: Effect Unit -setup = Setup.setup "uv" +setup = Native.setup diff --git a/setup/uv/test/environment.test.mjs b/setup/uv/test/environment.test.mjs new file mode 100644 index 0000000..31d67a5 --- /dev/null +++ b/setup/uv/test/environment.test.mjs @@ -0,0 +1,64 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {createRequire} from 'node:module'; +import {fixture} from '../../../test/setup/host.mjs'; +const {setup}=createRequire(import.meta.url)('../dist/plugin.cjs'); +function host(options={}){ + return fixture('uv',{os:options.os??'linux',input:{version:'0.11.0',...options.input},command:(args)=>{ + if(options.fail?.(args))throw Error('Injected uv environment failure'); + if(args[0].endsWith('/uv')&&args[1]==='--version')return 'uv 0.11.0'; + if(args[0].endsWith('/uv')&&args[1]==='python'&&args[2]==='find')return options.pythonPath??'/fixture/python/bin/python3.13'; + if(args[0]==='/fixture/python/bin/python3.13'&&args[1]==='--version')return 'Python 3.13.5'; + return undefined; + }}); +} +for(const os of ['linux','macos'])test(os+': optional Python is installed before tools and all executable paths are published',()=>{ + const f=host({os,input:{pythonVersion:'3.13',tools:' ruff==0.12.0, httpie '}});setup(); + const installed=f.calls.findIndex(a=>a[1]==='python'&&a[2]==='install'); + const found=f.calls.findIndex(a=>a[1]==='python'&&a[2]==='find'); + const tools=f.calls.filter(a=>a[1]==='tool'&&a[2]==='install'); + assert.ok(installed>=0&&found>installed);assert.equal(tools.length,2); + assert.deepEqual(tools.map(a=>a.at(-1)),['ruff==0.12.0','httpie']); + for(const a of tools){assert.ok(a.includes('--force'));assert.equal(a[a.indexOf('--python')+1],'/fixture/python/bin/python3.13');} + assert.equal(f.environment.UV_PYTHON,'/fixture/python/bin/python3.13'); + assert.ok(f.environment.PATH.includes('/tool-bin:'));assert.ok(f.environment.PATH.includes('/python-bin:')); + assert.equal(f.updates.length,1); + assert.ok(f.scopedCalls.filter(c=>c.args[1]==='tool').every(c=>c.environment.UV_TOOL_DIR.includes('uv-environments'))); +}); +test('omitted and blank optional fields preserve uv-only setup',()=>{ + for(const input of [{},{pythonVersion:'',tools:''},{tools:' '}]){ + const f=host({input});setup();assert.ok(!f.calls.some(a=>['python','tool'].includes(a[1])));assert.equal(f.environment.UV_PYTHON,undefined); + } +}); +test('tools can be installed without an explicitly requested Python',()=>{ + const f=host({input:{tools:'ruff,httpie>=3'}});setup(); + assert.ok(!f.calls.some(a=>a[1]==='python')); + const tools=f.calls.filter(a=>a[1]==='tool');assert.equal(tools.length,2);assert.ok(tools.every(a=>!a.includes('--python'))); +}); +test('invalid Python and tool fields fail before host commands',()=>{ + for(const input of [{pythonVersion:null},{pythonVersion:'../3.13'},{pythonVersion:'3.13;id'},{tools:['ruff']},{tools:'ruff,,httpie'},{tools:'ruff,'},{tools:'--help'},{tools:'ruff;id'},{tools:'ruff,ruff'},{tools:null}]){ + const f=host({input});assert.throws(setup,undefined,JSON.stringify(input));assert.equal(f.calls.length,0);assert.equal(f.updates.length,0); + } +}); +test('BSD selects an existing matching Python and disables downloads for tools',()=>{ + for(const os of ['freebsd','openbsd','netbsd']){ + const f=host({os,input:{pythonVersion:'3.13',tools:'ruff'}});setup(); + assert.ok(!f.calls.some(a=>a[1]==='python'&&a[2]==='install')); + for(const a of f.calls.filter(a=>a[1]==='tool'||(a[1]==='python'&&a[2]==='find')))assert.ok(a.includes('--no-python-downloads')); + assert.equal(f.updates.length,1); + } +}); +test('Python and tool failures never publish a successful setup',()=>{ + for(const options of [{pythonPath:'relative/python'},{fail:a=>a[1]==='python'&&a[2]==='install'},{fail:a=>a[1]==='python'&&a[2]==='find'},{fail:a=>a[1]==='tool'&&a[2]==='install'}]){ + const f=host({...options,input:{pythonVersion:'3.13',tools:'ruff'}});assert.throws(setup);assert.equal(f.updates.length,0);assert.equal(f.output.length,0); + } +}); +test('typed component forwards Python and CSV tools and returns the prepared environment',async()=>{ + const native=await import('../output/CI.Component/index.js'); + const {Just,Nothing}=await import('../output/Data.Maybe/index.js'); + const f=host(); + const result=native.setup({version:new Just('0.11.0'),installDir:Nothing.value,packageName:Nothing.value,sudo:Nothing.value,pythonVersion:new Just('3.13'),tools:new Just('ruff==0.12.0')})(); + assert.equal(result.tool,'uv');assert.equal(result.version,'0.11.0'); + assert.ok(result.environment.some(v=>v.name==='UV_PYTHON'&&v.value==='/fixture/python/bin/python3.13')); + assert.equal(f.output.length,0);assert.equal(f.updates.length,1); +}); -- knotmirror 0.0.1