From f4018fe2411f8d24e9ef8bc789cd67f70d6a133d Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 17:35:11 +0800 Subject: [PATCH 01/12] feat(nushell): share pinned-version checks Expose a static module for grouped pin audits so repositories can use the same reporting, version ordering, and GitHub lookups with their own registries. Keep list available offline and report incomplete checks ahead of stale pins. --- docs/nushell.md | 55 ++++++ flake.nix | 2 + nix/lib.nix | 2 + src/pin-checks/pin-check.nu | 279 +++++++++++++++++++++++++++++ src/pin-checks/versions.nu | 36 ++++ tests/default.nix | 4 + tests/pin-checks/audit.testlib.nu | 79 ++++++++ tests/pin-checks/gh.stub.nu | 22 +++ tests/pin-checks/git.stub.nu | 6 + tests/pin-checks/pin-check.test.nu | 70 ++++++++ tests/pin-checks/versions.test.nu | 102 +++++++++++ 11 files changed, 657 insertions(+) create mode 100644 src/pin-checks/pin-check.nu create mode 100644 src/pin-checks/versions.nu create mode 100644 tests/pin-checks/audit.testlib.nu create mode 100644 tests/pin-checks/gh.stub.nu create mode 100644 tests/pin-checks/git.stub.nu create mode 100644 tests/pin-checks/pin-check.test.nu create mode 100644 tests/pin-checks/versions.test.nu diff --git a/docs/nushell.md b/docs/nushell.md index 1ff3dd2..00238d3 100644 --- a/docs/nushell.md +++ b/docs/nushell.md @@ -39,6 +39,61 @@ Nushell resolves named imports at parse time, so each environment needs the same The [package and test example](../tests/nu-tooling/lib-dirs/default.nix) shows how to share module directories. If a directory also contains files the package should exclude, pass a filtered source built with `lib.fileset.toSource`. +## Check pinned versions + +Add `dk.pinLibDir` to the dev shell's `NU_LIB_DIRS`, `hooks.nu-check.settings.libDirs`, and the `libDirs` passed to `dk.nuTests`. Each can then resolve the same static import. This example `check-pins.nu` reads a package definition from the checkout. + +```nu +use pin-check.nu + +def registry [] { + let root = (pin-check repo-root "my-project") + [ + { + title: "Packages" + pins: [ + { + pin: "nushell" + local: {|| pin-check nix-version $root "packages/nushell/default.nix" } + upstream: {|| pin-check gh-latest-release "nushell/nushell" | str replace -r "^v" "" } + } + ] + } + ] +} + +def "main list" [] { + let footer = "Renovate owns the flake.lock inputs and the GitHub Actions refs." + pin-check list {|| registry } --footer $footer +} + +def "main check" [] { pin-check check {|| registry } } +def main [] { main check } +``` + +Run `nu check-pins.nu list` from a prepared dev shell to list the groups and pins in registry order. Keep the registry itself local so listing works offline. The optional `--footer` appends the repository's message after the groups. Only `check` needs an authenticated GitHub CLI and runs the `local` and `upstream` closures. + +By default, matching values are current and different values are stale. To apply repository policy, give the row a `classify` closure that takes the pinned and upstream strings and returns a record such as `{status: "override redundant", outcome: "stale"}`. The table prints `status`. The summary counts rows by `outcome`, which must be `current`, `stale`, or `unknown`. + +A failed lookup or an empty group counts as unknown. A blank string produces a `no value found` warning. If the lookup has already reported the cause, return `null` to mark the pin unknown without a second warning. An incomplete check exits `2`, even if other pins are stale. A complete check exits `1` if any pins are stale and `0` otherwise. + +Use these [`pin-check` commands](../src/pin-checks/pin-check.nu) to build registry entries. GitHub queries take a repository in `owner/name` form. When a request fails, the checker prints a single warning with the pin name and the GitHub CLI error. + +| Command | Result | +| --------------------------------- | -------------------------------------------------------------------------- | +| `repo-root ` | Current Git root, or an error naming the expected checkout and exit code 2 | +| `nix-attr ` | First match of the named capture `v` | +| `nix-version ` | Value of a literal `version = "..."` in a Nix file | +| `gh-latest-release ` | Tag of GitHub's latest release | +| `gh-releases ` | Non-draft release records, including their assets | +| `gh-newest-release ` | Highest version-shaped release tag, including prereleases | +| `gh-newest-tag-head ` | Commit SHA of the highest stable version tag | +| `gh-default-head ` | Commit SHA at the tip of the default branch | +| `version-at-least ` | Whether the left version is at least the right one | +| `version-older ` | Whether the left version is older than the right one | +| `action-pins ` | Sorted, unique external refs from GitHub workflows and actions | +| `action-pin ` | Registry row delegating the ref to Renovate | + ## Pass application flags Both builders accept application defaults through `flags`, mapping each attribute name to `--`. diff --git a/flake.nix b/flake.nix index 449f9f9..7a90eb3 100644 --- a/flake.nix +++ b/flake.nix @@ -122,6 +122,7 @@ nu-check = { enable = true; settings.libDirs = [ + dk.pinLibDir ./tests/nu-tooling/lib-dirs/libs ./tests/nu-tooling/lib-dirs/extra ]; @@ -158,6 +159,7 @@ # ------------------------------------------------------------------------------------------ devShells.default = pkgs.mkShell { name = "devkit-dev"; + NU_LIB_DIRS = "${dk.pinLibDir}"; packages = [ dk.nushell dk.nu-test diff --git a/nix/lib.nix b/nix/lib.nix index ff6a713..c4bc523 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -88,4 +88,6 @@ in uvToolchain writeNuApplication ; + + pinLibDir = ../src/pin-checks; } diff --git a/src/pin-checks/pin-check.nu b/src/pin-checks/pin-check.nu new file mode 100644 index 0000000..06abca4 --- /dev/null +++ b/src/pin-checks/pin-check.nu @@ -0,0 +1,279 @@ +use ./versions.nu newest-version +export use ./versions.nu [version-at-least version-older] + +# -------------------------------------------------------------------------------------------------- +# Dispatch +# -------------------------------------------------------------------------------------------------- + +# List the groups and pin names without authenticating or running any row closures. +export def list [registry: closure, --footer: string]: nothing -> nothing { + print "Manual pins tracked by this script:" + for group in (do $registry) { + print $"\n($group.title)" + for row in $group.pins { + print $" ($row.pin)" + } + } + if ($footer | is-not-empty) { + print $"\n($footer)" + } +} + +def die [msg: string] { + print -e $"error: ($msg)" + exit 2 +} + +# Find the current Git checkout or report the expected checkout and exit 2. +export def repo-root [checkout: string]: nothing -> string { + try { + ^git rev-parse --show-toplevel | str trim + } catch { + die $"cannot find the repository root. Run inside the ($checkout) checkout." + } +} + +def require-gh [] { + if (which gh | is-empty) { + die "gh not found. Install GitHub CLI and authenticate to github.com." + } + if (^gh auth status --hostname github.com | complete).exit_code != 0 { + die "GitHub authentication check failed. Check credentials and network access." + } +} + +def warn [pin: string, message: string] { + print -e $" ($pin): ($message)" +} + +def query [pin: string, lookup: closure]: nothing -> string { + try { + let raw = (do $lookup) + if $raw == null { + return "" + } + let value = ($raw | into string | str trim) + if ($value | is-empty) { + warn $pin "no value found" + } + $value + } catch {|err| + warn $pin $err.msg + "" + } +} + +def classify [row: record, pinned: string, upstream: string]: nothing -> record { + if ($pinned | is-empty) or ($upstream | is-empty) { + { + status: "UNKNOWN" + outcome: "unknown" + } + + } else if ($row.classify? | is-not-empty) { + try { + let result = (do $row.classify $pinned $upstream) + if ($result.status | describe) != "string" or $result.outcome not-in [ + "current" "stale" "unknown" + ] { + error make {msg: "classifier must return a status string and a current, stale, or unknown outcome"} + } + $result + } catch {|err| + warn $row.pin $err.msg + { + status: "UNKNOWN" + outcome: "unknown" + } + } + + } else if ($row.delegated? | is-not-empty) { + { + status: $row.delegated + outcome: "current" + } + + } else if $pinned == $upstream { + { + status: "ok" + outcome: "current" + } + + } else { + { + status: "STALE" + outcome: "stale" + } + } +} + +def resolve-row [row: record]: nothing -> record { + let pinned = (query $row.pin $row.local) + let upstream = if ($row.delegated? | is-not-empty) { + $row.delegated + } else { + query $row.pin $row.upstream + } + let result = (classify $row $pinned $upstream) + + { + pin: $row.pin + pinned: ($pinned | default --empty "?") + upstream: ($upstream | default --empty "?") + status: $result.status + outcome: $result.outcome + } +} + +def resolve-group [group: record]: nothing -> record { + let rows = if ($group.pins | is-empty) { + warn $group.title "no pins matched" + [ + { + pin: $group.title + pinned: "?" + upstream: "?" + status: "UNKNOWN" + outcome: "unknown" + } + ] + } else { + $group.pins | par-each --keep-order {|row| resolve-row $row } + } + { + title: $group.title + rows: $rows + } +} + +# Audit the registry after authenticating. Exit 0 for current, 1 for stale, or 2 for incomplete. +export def check [registry: closure] { + require-gh + + let groups = (do $registry | par-each --keep-order {|group| resolve-group $group }) + for group in $groups { + print $"\n($group.title)" + print ($group.rows | reject outcome | table) + } + let rows = ($groups | each {|group| $group.rows } | flatten) + let stale = ($rows | where outcome == "stale" | length) + let unknown = ($rows | where outcome == "unknown" | length) + + print $"\n($stale) stale, ($unknown) unknown." + if $unknown > 0 { + print "UNKNOWN means a lookup failed. Rerun, and fix the printed cause if it persists." + exit 2 + } + if $stale > 0 { + exit 1 + } +} + +# -------------------------------------------------------------------------------------------------- +# GitHub queries +# -------------------------------------------------------------------------------------------------- + +def gh-api [path: string, jq: string, --paginate]: nothing -> string { + let args = if $paginate { ["--paginate"] } else { [] } + let result = ( + ^gh api $path + --hostname github.com + --jq $jq + ...$args + | complete + ) + if $result.exit_code != 0 { + error make {msg: ($result.stderr | str trim | default --empty "GitHub API request failed")} + } + $result.stdout | str trim +} + +# Read the tag GitHub marks as the latest release. +export def gh-latest-release [repo: string]: nothing -> string { + gh-api $"repos/($repo)/releases/latest" ".tag_name" +} + +# Read all published releases in GitHub's API order, including pre-releases. +export def gh-releases [repo: string]: nothing -> list { + let jq = ".[] | select(.draft == false) | @json" + gh-api $"repos/($repo)/releases?per_page=100" $jq --paginate + | from json --objects +} + +# Read the highest version-shaped release tag, allowing pre-releases. +export def gh-newest-release [repo: string]: nothing -> string { + newest-version (gh-releases $repo | get tag_name) --allow-pre-release +} + +# Resolve the highest stable version tag to its commit, including for annotated tags. +export def gh-newest-tag-head [repo: string]: nothing -> string { + let tags = (gh-api $"repos/($repo)/tags" ".[].name" --paginate | lines) + let tag = (newest-version $tags) + + if ($tag | is-empty) { + error make {msg: "no stable version tag found"} + } + gh-api $"repos/($repo)/commits/($tag)" ".sha" +} + +# Read the latest commit on the default branch. +export def gh-default-head [repo: string]: nothing -> string { + gh-api $"repos/($repo)/commits?per_page=1" ".[0].sha" +} + +# -------------------------------------------------------------------------------------------------- +# Source extraction +# -------------------------------------------------------------------------------------------------- + +# Extract the first match of the regex's named capture v from a file under root. +export def nix-attr [root: string, file: string, regex: string]: nothing -> string { + open --raw ($root | path join $file) + | parse --regex $regex + | get v.0 +} + +# Read the first literal version assignment from a Nix file. +export def nix-version [root: string, file: string]: nothing -> string { + nix-attr $root $file '(?m)^\s*version = "(?[^"]+)"' +} + +# Read the sorted, unique remote uses refs in workflows and composite actions. +export def action-pins [root: string]: nothing -> list { + [".github/workflows" ".github/actions"] + | each {|dir| glob ($root | path join $dir "**/*") } + | flatten + | where {|p| + ($p | path type) == "file" and ($p | path parse | get extension) in ["yml" "yaml"] + } + | each {|p| + let doc = (open $p) + let jobs = ($doc | get -o jobs | default {} | values) + [ + ($jobs | get -o uses) + ($jobs | each {|job| $job | get -o steps | default [] | get -o uses } | flatten) + ($doc | get -o runs.steps | default [] | get -o uses) + ] + | flatten + } + | flatten + | compact + | where {|pin| + ( + not ($pin | str starts-with "./") + and not ($pin | str starts-with "$/") + and not ($pin | str starts-with "docker://") + ) + } + | uniq + | sort +} + +# Turn a GitHub Actions uses ref into a row delegated to Renovate. +export def action-pin [ref: string]: nothing -> record { + let parts = ($ref | split row "@") + { + pin: ($parts | first) + local: {|| $parts | get 1 } + delegated: "renovate" + } +} diff --git a/src/pin-checks/versions.nu b/src/pin-checks/versions.nu new file mode 100644 index 0000000..354ac84 --- /dev/null +++ b/src/pin-checks/versions.nu @@ -0,0 +1,36 @@ +# Whether the left version is at or above the right one. The release core compares first, and a +# final release ranks above the same core's pre-release. +export def version-at-least [left: string, right: string]: nothing -> bool { + let left_core = ($left | split row "-" | first | str replace -r "^v" "") + let right_core = ($right | split row "-" | first | str replace -r "^v" "") + let left_suffix = ($left | split row "-" | skip 1 | str join "-") + let right_suffix = ($right | split row "-" | skip 1 | str join "-") + + if $left_core != $right_core { + ([$left_core $right_core] | sort --natural | last) == $left_core + } else if ($left_suffix | is-empty) != ($right_suffix | is-empty) { + $left_suffix | is-empty + } else { + ([$left_suffix $right_suffix] | sort --natural | last) == $left_suffix + } +} + +# Whether the left version is below the right one. +export def version-older [left: string, right: string]: nothing -> bool { + not (version-at-least $left $right) +} + +# The highest version-shaped tag, optionally including pre-releases. +export def newest-version [tags: list, --allow-pre-release]: nothing -> string { + let pattern = if $allow_pre_release { + '^v?[0-9]+(\.[0-9]+)*(-[0-9A-Za-z.]+)?$' + } else { + '^v?[0-9]+(\.[0-9]+)*$' + } + + $tags + | where {|tag| $tag =~ $pattern } + | reduce --fold "" {|tag, newest| + if ($newest | is-empty) or (version-at-least $tag $newest) { $tag } else { $newest } + } +} diff --git a/tests/default.nix b/tests/default.nix index bd653c8..2af08f9 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -16,6 +16,10 @@ in { actions = import ./actions { inherit pkgs dk repo; }; dprint-markdown = import ./dprint-markdown { inherit pkgs repo; }; + pin-check = dk.nuTests { + src = ./pin-checks; + libDirs = [ dk.pinLibDir ]; + }; skill-links = import ./skill-links { inherit pkgs skillSource; }; } // lib.mapAttrs' (name: lib.nameValuePair "nu-tooling-${name}") ( diff --git a/tests/pin-checks/audit.testlib.nu b/tests/pin-checks/audit.testlib.nu new file mode 100644 index 0000000..a0983b6 --- /dev/null +++ b/tests/pin-checks/audit.testlib.nu @@ -0,0 +1,79 @@ +use pin-check.nu + +def registry []: nothing -> list { + let sample = { + pin: "sample" + local: {|| "1.0"} + upstream: {|| "2.0"} + } + let pins = match $env.PIN_CASE { + "list" => [ + { + pin: "sample" + local: {|| error make {msg: "local lookup ran"} } + upstream: {|| error make {msg: "upstream lookup ran"} } + } + ] + "current" => [ + ($sample | merge { + classify: {|pinned, upstream| + { + status: $"tracks channel ($pinned) to ($upstream)" + outcome: "current" + } + } + }) + ] + "stale" => [ + ($sample | merge { + classify: {|_pinned, _upstream| + { + status: "pin superseded" + outcome: "stale" + } + } + }) + ] + "mixed" => [ + $sample + { + pin: "failed" + local: {|| "1.0"} + upstream: {|| error make {msg: "upstream unavailable"} } + } + { + pin: "missing" + local: {|| + print -e " cannot read missing version" + null + } + upstream: {|| "2.0"} + } + ] + "blank" => [ + ($sample | merge {upstream: {|| ""}}) + ] + "github" => [ + ($sample | merge {upstream: {|| pin-check gh-latest-release "example/sample"}}) + ] + "empty" => [] + } + [ + { + title: "Packages" + pins: $pins + } + ] +} + +def "main list" [--footer: string] { + pin-check list {|| registry } --footer $footer +} + +def "main root" [] { + pin-check repo-root "example" +} + +def main [] { + pin-check check {|| registry } +} diff --git a/tests/pin-checks/gh.stub.nu b/tests/pin-checks/gh.stub.nu new file mode 100644 index 0000000..21b7d4c --- /dev/null +++ b/tests/pin-checks/gh.stub.nu @@ -0,0 +1,22 @@ +def "main auth status" [--hostname: string] { + if $hostname != "github.com" { + exit 1 + } +} + +def "main api" [endpoint: string, --hostname: string, --jq: string] { + if ( + $endpoint != "repos/example/sample/releases/latest" + or $hostname != "github.com" + or $jq != ".tag_name" + ) { + print -e "unexpected GitHub API request" + } else { + print -e "gh: Service unavailable (HTTP 503)" + } + exit 1 +} + +def main [] { + exit 1 +} diff --git a/tests/pin-checks/git.stub.nu b/tests/pin-checks/git.stub.nu new file mode 100644 index 0000000..d37e582 --- /dev/null +++ b/tests/pin-checks/git.stub.nu @@ -0,0 +1,6 @@ +def main [command: string, --show-toplevel] { + if $command != "rev-parse" or not $show_toplevel { + print -e "unexpected git arguments" + } + exit 128 +} diff --git a/tests/pin-checks/pin-check.test.nu b/tests/pin-checks/pin-check.test.nu new file mode 100644 index 0000000..f68065e --- /dev/null +++ b/tests/pin-checks/pin-check.test.nu @@ -0,0 +1,70 @@ +use std/assert + +const SCRIPT = path self "audit.testlib.nu" + +def "test list is offline and leaves row closures lazy" [] { + let lib_dirs = ($env.NU_LIB_DIRS | str join (char esep)) + let results = (with-env {NU_LIB_DIRS: $lib_dirs, PIN_CASE: "list", PATH: []} { + [ + (^$nu.current-exe --no-config-file $SCRIPT list | complete) + (^$nu.current-exe --no-config-file $SCRIPT list --footer "See the project guide." | complete) + ] + }) + + let listing = "Manual pins tracked by this script:\n\nPackages\n sample\n" + assert equal $results [ + { + stdout: $listing + stderr: "" + exit_code: 0 + } + { + stdout: ($listing + "\nSee the project guide.\n") + stderr: "" + exit_code: 0 + } + ] +} + +def "test check derives exit code from outcomes and diagnoses incomplete groups" [] { + let lib_dirs = ($env.NU_LIB_DIRS | str join (char esep)) + let cases = [ + [name code summary label warnings]; + ["current" 0 "0 stale, 0 unknown." "tracks channel 1.0 to 2.0" []] + ["stale" 1 "1 stale, 0 unknown." "pin superseded" []] + ["mixed" 2 "1 stale, 2 unknown." "UNKNOWN" [" cannot read missing version" " failed: upstream unavailable"]] + ["blank" 2 "0 stale, 1 unknown." "UNKNOWN" [" sample: no value found"]] + ["github" 2 "0 stale, 1 unknown." "UNKNOWN" [" sample: gh: Service unavailable (HTTP 503)"]] + ["empty" 2 "0 stale, 1 unknown." "UNKNOWN" [" Packages: no pins matched"]] + ] + + for case in $cases { + let result = (with-env { + NU_LIB_DIRS: $lib_dirs + PIN_CASE: $case.name + PATH: [$env.NU_TEST_STUBS] + } { + ^$nu.current-exe --no-config-file $SCRIPT | complete + }) + + assert equal $result.exit_code $case.code $case.name + assert ($result.stdout | str contains $case.summary) $case.name + let table = ($result.stdout | split row $case.summary | first) + assert ($table | str contains $case.label) $case.name + assert (not ($table | str contains "outcome")) $case.name + assert equal ($result.stderr | lines | sort) $case.warnings $case.name + } +} + +def "test repo-root reports the expected checkout when Git fails" [] { + let lib_dirs = ($env.NU_LIB_DIRS | str join (char esep)) + let result = (with-env {NU_LIB_DIRS: $lib_dirs, PATH: [$env.NU_TEST_STUBS]} { + ^$nu.current-exe --no-config-file $SCRIPT root | complete + }) + + assert equal $result { + stdout: "" + stderr: "error: cannot find the repository root. Run inside the example checkout.\n" + exit_code: 2 + } +} diff --git a/tests/pin-checks/versions.test.nu b/tests/pin-checks/versions.test.nu new file mode 100644 index 0000000..ecf8cb2 --- /dev/null +++ b/tests/pin-checks/versions.test.nu @@ -0,0 +1,102 @@ +use std/assert + +use versions.nu * + +def "test version helpers compare naturally and select the newest valid tag" [] { + let selections = [ + { + name: "higher version in original order" + tags: ["1.2.0" "1.3.0"] + allow: false + expected: "1.3.0" + } + { + name: "higher version in reversed order" + tags: ["1.3.0" "1.2.0"] + allow: false + expected: "1.3.0" + } + { + name: "natural core comparison" + tags: ["1.9.0" "1.10.0"] + allow: false + expected: "1.10.0" + } + { + name: "final before same core pre-release" + tags: ["2.0.0" "2.0.0-rc.1"] + allow: true + expected: "2.0.0" + } + { + name: "final after same core pre-release" + tags: ["2.0.0-rc.1" "2.0.0"] + allow: true + expected: "2.0.0" + } + { + name: "pre-release allowed on higher core" + tags: ["1.4.0" "1.5.0-beta.1"] + allow: true + expected: "1.5.0-beta.1" + } + { + name: "later higher beta wins" + tags: ["2.2.0-beta.2" "3.0.0-beta.6"] + allow: true + expected: "3.0.0-beta.6" + } + { + name: "multi digit pre-release comparison" + tags: ["1.0.0-alpha.9" "1.0.0-alpha.10"] + allow: true + expected: "1.0.0-alpha.10" + } + { + name: "bare tags exclude pre-releases" + tags: ["1.9.0" "2.0.0-rc.1"] + allow: false + expected: "1.9.0" + } + { + name: "empty tags" + tags: [] + allow: false + expected: "" + } + { + name: "only non-version tags" + tags: ["release-notes" "macos-27-preview.5"] + allow: false + expected: "" + } + ] + + for case in $selections { + let actual = if $case.allow { + newest-version $case.tags --allow-pre-release + } else { + newest-version $case.tags + } + + assert equal $actual $case.expected $case.name + } + + let comparisons = [ + { + name: "compare numeric core components" + older: "1.9.0" + newer: "1.10.0" + } + { + name: "compare final with same core pre-release" + older: "2.0.0-rc.1" + newer: "2.0.0" + } + ] + + for case in $comparisons { + assert (version-at-least $case.newer $case.older) $case.name + assert (version-older $case.older $case.newer) $case.name + } +} From 8502306167cf3275c9deb8fdcba741150b758783 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 17:40:28 +0800 Subject: [PATCH 02/12] docs(nushell): remove pinned-version procedure --- docs/nushell.md | 55 ------------------------------------------------- 1 file changed, 55 deletions(-) diff --git a/docs/nushell.md b/docs/nushell.md index 00238d3..1ff3dd2 100644 --- a/docs/nushell.md +++ b/docs/nushell.md @@ -39,61 +39,6 @@ Nushell resolves named imports at parse time, so each environment needs the same The [package and test example](../tests/nu-tooling/lib-dirs/default.nix) shows how to share module directories. If a directory also contains files the package should exclude, pass a filtered source built with `lib.fileset.toSource`. -## Check pinned versions - -Add `dk.pinLibDir` to the dev shell's `NU_LIB_DIRS`, `hooks.nu-check.settings.libDirs`, and the `libDirs` passed to `dk.nuTests`. Each can then resolve the same static import. This example `check-pins.nu` reads a package definition from the checkout. - -```nu -use pin-check.nu - -def registry [] { - let root = (pin-check repo-root "my-project") - [ - { - title: "Packages" - pins: [ - { - pin: "nushell" - local: {|| pin-check nix-version $root "packages/nushell/default.nix" } - upstream: {|| pin-check gh-latest-release "nushell/nushell" | str replace -r "^v" "" } - } - ] - } - ] -} - -def "main list" [] { - let footer = "Renovate owns the flake.lock inputs and the GitHub Actions refs." - pin-check list {|| registry } --footer $footer -} - -def "main check" [] { pin-check check {|| registry } } -def main [] { main check } -``` - -Run `nu check-pins.nu list` from a prepared dev shell to list the groups and pins in registry order. Keep the registry itself local so listing works offline. The optional `--footer` appends the repository's message after the groups. Only `check` needs an authenticated GitHub CLI and runs the `local` and `upstream` closures. - -By default, matching values are current and different values are stale. To apply repository policy, give the row a `classify` closure that takes the pinned and upstream strings and returns a record such as `{status: "override redundant", outcome: "stale"}`. The table prints `status`. The summary counts rows by `outcome`, which must be `current`, `stale`, or `unknown`. - -A failed lookup or an empty group counts as unknown. A blank string produces a `no value found` warning. If the lookup has already reported the cause, return `null` to mark the pin unknown without a second warning. An incomplete check exits `2`, even if other pins are stale. A complete check exits `1` if any pins are stale and `0` otherwise. - -Use these [`pin-check` commands](../src/pin-checks/pin-check.nu) to build registry entries. GitHub queries take a repository in `owner/name` form. When a request fails, the checker prints a single warning with the pin name and the GitHub CLI error. - -| Command | Result | -| --------------------------------- | -------------------------------------------------------------------------- | -| `repo-root ` | Current Git root, or an error naming the expected checkout and exit code 2 | -| `nix-attr ` | First match of the named capture `v` | -| `nix-version ` | Value of a literal `version = "..."` in a Nix file | -| `gh-latest-release ` | Tag of GitHub's latest release | -| `gh-releases ` | Non-draft release records, including their assets | -| `gh-newest-release ` | Highest version-shaped release tag, including prereleases | -| `gh-newest-tag-head ` | Commit SHA of the highest stable version tag | -| `gh-default-head ` | Commit SHA at the tip of the default branch | -| `version-at-least ` | Whether the left version is at least the right one | -| `version-older ` | Whether the left version is older than the right one | -| `action-pins ` | Sorted, unique external refs from GitHub workflows and actions | -| `action-pin ` | Registry row delegating the ref to Renovate | - ## Pass application flags Both builders accept application defaults through `flags`, mapping each attribute name to `--`. From c7bfd40997f2baa78ce1fc044498f25b7aa39534 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 17:45:26 +0800 Subject: [PATCH 03/12] refactor(nushell): use pin-check source paths directly --- flake.nix | 4 ++-- nix/lib.nix | 2 -- tests/default.nix | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/flake.nix b/flake.nix index 7a90eb3..740e8ba 100644 --- a/flake.nix +++ b/flake.nix @@ -122,7 +122,7 @@ nu-check = { enable = true; settings.libDirs = [ - dk.pinLibDir + ./src/pin-checks ./tests/nu-tooling/lib-dirs/libs ./tests/nu-tooling/lib-dirs/extra ]; @@ -159,7 +159,7 @@ # ------------------------------------------------------------------------------------------ devShells.default = pkgs.mkShell { name = "devkit-dev"; - NU_LIB_DIRS = "${dk.pinLibDir}"; + NU_LIB_DIRS = "${./src/pin-checks}"; packages = [ dk.nushell dk.nu-test diff --git a/nix/lib.nix b/nix/lib.nix index c4bc523..ff6a713 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -88,6 +88,4 @@ in uvToolchain writeNuApplication ; - - pinLibDir = ../src/pin-checks; } diff --git a/tests/default.nix b/tests/default.nix index 2af08f9..f4346dd 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -18,7 +18,7 @@ in dprint-markdown = import ./dprint-markdown { inherit pkgs repo; }; pin-check = dk.nuTests { src = ./pin-checks; - libDirs = [ dk.pinLibDir ]; + libDirs = [ ../src/pin-checks ]; }; skill-links = import ./skill-links { inherit pkgs skillSource; }; } From b3fc0b29f6f88938f48b8c36395c4b28d299e6ae Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 17:47:07 +0800 Subject: [PATCH 04/12] style(nushell): align pinned-version file layout --- src/pin-checks/pin-check.nu | 16 +++++++++++----- src/pin-checks/versions.nu | 4 ++++ tests/pin-checks/gh.stub.nu | 6 ++++++ tests/pin-checks/git.stub.nu | 2 ++ tests/pin-checks/pin-check.test.nu | 6 +++++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/pin-checks/pin-check.nu b/src/pin-checks/pin-check.nu index 06abca4..e5bc3c8 100644 --- a/src/pin-checks/pin-check.nu +++ b/src/pin-checks/pin-check.nu @@ -1,3 +1,7 @@ +# ================================================================================================== +# Pinned Version Checks +# ================================================================================================== + use ./versions.nu newest-version export use ./versions.nu [version-at-least version-older] @@ -69,14 +73,15 @@ def classify [row: record, pinned: string, upstream: string]: nothing -> record status: "UNKNOWN" outcome: "unknown" } - } else if ($row.classify? | is-not-empty) { try { let result = (do $row.classify $pinned $upstream) if ($result.status | describe) != "string" or $result.outcome not-in [ "current" "stale" "unknown" ] { - error make {msg: "classifier must return a status string and a current, stale, or unknown outcome"} + error make { + msg: "classifier must return a status string and a current, stale, or unknown outcome" + } } $result } catch {|err| @@ -86,19 +91,16 @@ def classify [row: record, pinned: string, upstream: string]: nothing -> record outcome: "unknown" } } - } else if ($row.delegated? | is-not-empty) { { status: $row.delegated outcome: "current" } - } else if $pinned == $upstream { { status: "ok" outcome: "current" } - } else { { status: "STALE" @@ -237,6 +239,10 @@ export def nix-version [root: string, file: string]: nothing -> string { nix-attr $root $file '(?m)^\s*version = "(?[^"]+)"' } +# -------------------------------------------------------------------------------------------------- +# GitHub Actions +# -------------------------------------------------------------------------------------------------- + # Read the sorted, unique remote uses refs in workflows and composite actions. export def action-pins [root: string]: nothing -> list { [".github/workflows" ".github/actions"] diff --git a/src/pin-checks/versions.nu b/src/pin-checks/versions.nu index 354ac84..4246fac 100644 --- a/src/pin-checks/versions.nu +++ b/src/pin-checks/versions.nu @@ -1,3 +1,7 @@ +# ================================================================================================== +# Pinned Version Comparison +# ================================================================================================== + # Whether the left version is at or above the right one. The release core compares first, and a # final release ranks above the same core's pre-release. export def version-at-least [left: string, right: string]: nothing -> bool { diff --git a/tests/pin-checks/gh.stub.nu b/tests/pin-checks/gh.stub.nu index 21b7d4c..bda34ce 100644 --- a/tests/pin-checks/gh.stub.nu +++ b/tests/pin-checks/gh.stub.nu @@ -1,3 +1,9 @@ +#!/usr/bin/env nu + +# ================================================================================================== +# gh Stub +# ================================================================================================== + def "main auth status" [--hostname: string] { if $hostname != "github.com" { exit 1 diff --git a/tests/pin-checks/git.stub.nu b/tests/pin-checks/git.stub.nu index d37e582..81451bf 100644 --- a/tests/pin-checks/git.stub.nu +++ b/tests/pin-checks/git.stub.nu @@ -1,3 +1,5 @@ +#!/usr/bin/env nu + def main [command: string, --show-toplevel] { if $command != "rev-parse" or not $show_toplevel { print -e "unexpected git arguments" diff --git a/tests/pin-checks/pin-check.test.nu b/tests/pin-checks/pin-check.test.nu index f68065e..a108eff 100644 --- a/tests/pin-checks/pin-check.test.nu +++ b/tests/pin-checks/pin-check.test.nu @@ -28,11 +28,15 @@ def "test list is offline and leaves row closures lazy" [] { def "test check derives exit code from outcomes and diagnoses incomplete groups" [] { let lib_dirs = ($env.NU_LIB_DIRS | str join (char esep)) + let mixed_warnings = [ + " cannot read missing version" + " failed: upstream unavailable" + ] let cases = [ [name code summary label warnings]; ["current" 0 "0 stale, 0 unknown." "tracks channel 1.0 to 2.0" []] ["stale" 1 "1 stale, 0 unknown." "pin superseded" []] - ["mixed" 2 "1 stale, 2 unknown." "UNKNOWN" [" cannot read missing version" " failed: upstream unavailable"]] + ["mixed" 2 "1 stale, 2 unknown." "UNKNOWN" $mixed_warnings] ["blank" 2 "0 stale, 1 unknown." "UNKNOWN" [" sample: no value found"]] ["github" 2 "0 stale, 1 unknown." "UNKNOWN" [" sample: gh: Service unavailable (HTTP 503)"]] ["empty" 2 "0 stale, 1 unknown." "UNKNOWN" [" Packages: no pins matched"]] From 72df74972cf108813ee155eec851674703254c40 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 18:09:38 +0800 Subject: [PATCH 05/12] test(nushell): simplify the prior-warning fixture --- tests/pin-checks/audit.testlib.nu | 2 +- tests/pin-checks/pin-check.test.nu | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/pin-checks/audit.testlib.nu b/tests/pin-checks/audit.testlib.nu index a0983b6..a8bbf49 100644 --- a/tests/pin-checks/audit.testlib.nu +++ b/tests/pin-checks/audit.testlib.nu @@ -44,7 +44,7 @@ def registry []: nothing -> list { { pin: "missing" local: {|| - print -e " cannot read missing version" + print -e "cannot read missing version" null } upstream: {|| "2.0"} diff --git a/tests/pin-checks/pin-check.test.nu b/tests/pin-checks/pin-check.test.nu index a108eff..1389eac 100644 --- a/tests/pin-checks/pin-check.test.nu +++ b/tests/pin-checks/pin-check.test.nu @@ -29,8 +29,8 @@ def "test list is offline and leaves row closures lazy" [] { def "test check derives exit code from outcomes and diagnoses incomplete groups" [] { let lib_dirs = ($env.NU_LIB_DIRS | str join (char esep)) let mixed_warnings = [ - " cannot read missing version" " failed: upstream unavailable" + "cannot read missing version" ] let cases = [ [name code summary label warnings]; From e6a342d7f8a9fbed182ac2513a04c3062235cd08 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 18:17:14 +0800 Subject: [PATCH 06/12] fix(nushell): emit unindented pin warnings --- src/pin-checks/pin-check.nu | 2 +- tests/pin-checks/pin-check.test.nu | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pin-checks/pin-check.nu b/src/pin-checks/pin-check.nu index e5bc3c8..07cc00c 100644 --- a/src/pin-checks/pin-check.nu +++ b/src/pin-checks/pin-check.nu @@ -47,7 +47,7 @@ def require-gh [] { } def warn [pin: string, message: string] { - print -e $" ($pin): ($message)" + print -e $"($pin): ($message)" } def query [pin: string, lookup: closure]: nothing -> string { diff --git a/tests/pin-checks/pin-check.test.nu b/tests/pin-checks/pin-check.test.nu index 1389eac..b93b7c3 100644 --- a/tests/pin-checks/pin-check.test.nu +++ b/tests/pin-checks/pin-check.test.nu @@ -29,17 +29,17 @@ def "test list is offline and leaves row closures lazy" [] { def "test check derives exit code from outcomes and diagnoses incomplete groups" [] { let lib_dirs = ($env.NU_LIB_DIRS | str join (char esep)) let mixed_warnings = [ - " failed: upstream unavailable" "cannot read missing version" + "failed: upstream unavailable" ] let cases = [ [name code summary label warnings]; ["current" 0 "0 stale, 0 unknown." "tracks channel 1.0 to 2.0" []] ["stale" 1 "1 stale, 0 unknown." "pin superseded" []] ["mixed" 2 "1 stale, 2 unknown." "UNKNOWN" $mixed_warnings] - ["blank" 2 "0 stale, 1 unknown." "UNKNOWN" [" sample: no value found"]] - ["github" 2 "0 stale, 1 unknown." "UNKNOWN" [" sample: gh: Service unavailable (HTTP 503)"]] - ["empty" 2 "0 stale, 1 unknown." "UNKNOWN" [" Packages: no pins matched"]] + ["blank" 2 "0 stale, 1 unknown." "UNKNOWN" ["sample: no value found"]] + ["github" 2 "0 stale, 1 unknown." "UNKNOWN" ["sample: gh: Service unavailable (HTTP 503)"]] + ["empty" 2 "0 stale, 1 unknown." "UNKNOWN" ["Packages: no pins matched"]] ] for case in $cases { From 8db112763bc69748eee06200f1b73bb805687878 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 18:24:18 +0800 Subject: [PATCH 07/12] style(nushell): make pin-check output spacing explicit --- src/pin-checks/pin-check.nu | 12 ++++++---- tests/pin-checks/pin-check.test.nu | 35 ++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/pin-checks/pin-check.nu b/src/pin-checks/pin-check.nu index 07cc00c..73b8521 100644 --- a/src/pin-checks/pin-check.nu +++ b/src/pin-checks/pin-check.nu @@ -13,13 +13,15 @@ export use ./versions.nu [version-at-least version-older] export def list [registry: closure, --footer: string]: nothing -> nothing { print "Manual pins tracked by this script:" for group in (do $registry) { - print $"\n($group.title)" + print "" + print $group.title for row in $group.pins { print $" ($row.pin)" } } if ($footer | is-not-empty) { - print $"\n($footer)" + print "" + print $footer } } @@ -154,14 +156,16 @@ export def check [registry: closure] { let groups = (do $registry | par-each --keep-order {|group| resolve-group $group }) for group in $groups { - print $"\n($group.title)" + print "" + print $group.title print ($group.rows | reject outcome | table) } let rows = ($groups | each {|group| $group.rows } | flatten) let stale = ($rows | where outcome == "stale" | length) let unknown = ($rows | where outcome == "unknown" | length) - print $"\n($stale) stale, ($unknown) unknown." + print "" + print $"($stale) stale, ($unknown) unknown." if $unknown > 0 { print "UNKNOWN means a lookup failed. Rerun, and fix the printed cause if it persists." exit 2 diff --git a/tests/pin-checks/pin-check.test.nu b/tests/pin-checks/pin-check.test.nu index b93b7c3..97fa388 100644 --- a/tests/pin-checks/pin-check.test.nu +++ b/tests/pin-checks/pin-check.test.nu @@ -1,4 +1,5 @@ use std/assert +use std-rfc/str const SCRIPT = path self "audit.testlib.nu" @@ -11,7 +12,28 @@ def "test list is offline and leaves row closures lazy" [] { ] }) - let listing = "Manual pins tracked by this script:\n\nPackages\n sample\n" + let listing = ( + " + Manual pins tracked by this script: + + Packages + sample + + " + | str dedent + ) + let listing_with_footer = ( + " + Manual pins tracked by this script: + + Packages + sample + + See the project guide. + + " + | str dedent + ) assert equal $results [ { stdout: $listing @@ -19,7 +41,7 @@ def "test list is offline and leaves row closures lazy" [] { exit_code: 0 } { - stdout: ($listing + "\nSee the project guide.\n") + stdout: $listing_with_footer stderr: "" exit_code: 0 } @@ -28,15 +50,14 @@ def "test list is offline and leaves row closures lazy" [] { def "test check derives exit code from outcomes and diagnoses incomplete groups" [] { let lib_dirs = ($env.NU_LIB_DIRS | str join (char esep)) - let mixed_warnings = [ - "cannot read missing version" - "failed: upstream unavailable" - ] let cases = [ [name code summary label warnings]; ["current" 0 "0 stale, 0 unknown." "tracks channel 1.0 to 2.0" []] ["stale" 1 "1 stale, 0 unknown." "pin superseded" []] - ["mixed" 2 "1 stale, 2 unknown." "UNKNOWN" $mixed_warnings] + [ + "mixed" 2 "1 stale, 2 unknown." "UNKNOWN" + ["cannot read missing version" "failed: upstream unavailable"] + ] ["blank" 2 "0 stale, 1 unknown." "UNKNOWN" ["sample: no value found"]] ["github" 2 "0 stale, 1 unknown." "UNKNOWN" ["sample: gh: Service unavailable (HTTP 503)"]] ["empty" 2 "0 stale, 1 unknown." "UNKNOWN" ["Packages: no pins matched"]] From ef9b0dbd780dc99dcebf10c44a941b6f351e15af Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 18:27:58 +0800 Subject: [PATCH 08/12] style(nix): separate pin-check and fixture paths --- flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/flake.nix b/flake.nix index 740e8ba..7114b1c 100644 --- a/flake.nix +++ b/flake.nix @@ -123,6 +123,7 @@ enable = true; settings.libDirs = [ ./src/pin-checks + ./tests/nu-tooling/lib-dirs/libs ./tests/nu-tooling/lib-dirs/extra ]; From 2d4c6579aabc8aaab73b755ac0ad62dfd8e17386 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 18:34:19 +0800 Subject: [PATCH 09/12] refactor(nushell): put pin-check under the shared import root --- flake.nix | 4 ++-- src/{pin-checks/pin-check.nu => lib/pin-check/mod.nu} | 0 src/{pin-checks => lib/pin-check}/versions.nu | 0 tests/default.nix | 4 ++-- tests/{pin-checks => pin-check}/audit.testlib.nu | 2 +- tests/{pin-checks => pin-check}/gh.stub.nu | 0 tests/{pin-checks => pin-check}/git.stub.nu | 0 tests/{pin-checks => pin-check}/pin-check.test.nu | 0 tests/{pin-checks => pin-check}/versions.test.nu | 2 +- 9 files changed, 6 insertions(+), 6 deletions(-) rename src/{pin-checks/pin-check.nu => lib/pin-check/mod.nu} (100%) rename src/{pin-checks => lib/pin-check}/versions.nu (100%) rename tests/{pin-checks => pin-check}/audit.testlib.nu (98%) rename tests/{pin-checks => pin-check}/gh.stub.nu (100%) rename tests/{pin-checks => pin-check}/git.stub.nu (100%) rename tests/{pin-checks => pin-check}/pin-check.test.nu (100%) rename tests/{pin-checks => pin-check}/versions.test.nu (98%) diff --git a/flake.nix b/flake.nix index 7114b1c..93ac192 100644 --- a/flake.nix +++ b/flake.nix @@ -122,7 +122,7 @@ nu-check = { enable = true; settings.libDirs = [ - ./src/pin-checks + ./src/lib ./tests/nu-tooling/lib-dirs/libs ./tests/nu-tooling/lib-dirs/extra @@ -160,7 +160,7 @@ # ------------------------------------------------------------------------------------------ devShells.default = pkgs.mkShell { name = "devkit-dev"; - NU_LIB_DIRS = "${./src/pin-checks}"; + NU_LIB_DIRS = "${./src/lib}"; packages = [ dk.nushell dk.nu-test diff --git a/src/pin-checks/pin-check.nu b/src/lib/pin-check/mod.nu similarity index 100% rename from src/pin-checks/pin-check.nu rename to src/lib/pin-check/mod.nu diff --git a/src/pin-checks/versions.nu b/src/lib/pin-check/versions.nu similarity index 100% rename from src/pin-checks/versions.nu rename to src/lib/pin-check/versions.nu diff --git a/tests/default.nix b/tests/default.nix index f4346dd..50df147 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -17,8 +17,8 @@ in actions = import ./actions { inherit pkgs dk repo; }; dprint-markdown = import ./dprint-markdown { inherit pkgs repo; }; pin-check = dk.nuTests { - src = ./pin-checks; - libDirs = [ ../src/pin-checks ]; + src = ./pin-check; + libDirs = [ ../src/lib ]; }; skill-links = import ./skill-links { inherit pkgs skillSource; }; } diff --git a/tests/pin-checks/audit.testlib.nu b/tests/pin-check/audit.testlib.nu similarity index 98% rename from tests/pin-checks/audit.testlib.nu rename to tests/pin-check/audit.testlib.nu index a8bbf49..a30c3dc 100644 --- a/tests/pin-checks/audit.testlib.nu +++ b/tests/pin-check/audit.testlib.nu @@ -1,4 +1,4 @@ -use pin-check.nu +use pin-check def registry []: nothing -> list { let sample = { diff --git a/tests/pin-checks/gh.stub.nu b/tests/pin-check/gh.stub.nu similarity index 100% rename from tests/pin-checks/gh.stub.nu rename to tests/pin-check/gh.stub.nu diff --git a/tests/pin-checks/git.stub.nu b/tests/pin-check/git.stub.nu similarity index 100% rename from tests/pin-checks/git.stub.nu rename to tests/pin-check/git.stub.nu diff --git a/tests/pin-checks/pin-check.test.nu b/tests/pin-check/pin-check.test.nu similarity index 100% rename from tests/pin-checks/pin-check.test.nu rename to tests/pin-check/pin-check.test.nu diff --git a/tests/pin-checks/versions.test.nu b/tests/pin-check/versions.test.nu similarity index 98% rename from tests/pin-checks/versions.test.nu rename to tests/pin-check/versions.test.nu index ecf8cb2..3b067b6 100644 --- a/tests/pin-checks/versions.test.nu +++ b/tests/pin-check/versions.test.nu @@ -1,6 +1,6 @@ use std/assert -use versions.nu * +use pin-check/versions.nu * def "test version helpers compare naturally and select the newest valid tag" [] { let selections = [ From e5d202d0f51cb7d3533f823c695b113eebf91044 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 18:38:39 +0800 Subject: [PATCH 10/12] style(nix): keep Nushell hook paths consecutive --- flake.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/flake.nix b/flake.nix index 93ac192..f6a2d91 100644 --- a/flake.nix +++ b/flake.nix @@ -123,7 +123,6 @@ enable = true; settings.libDirs = [ ./src/lib - ./tests/nu-tooling/lib-dirs/libs ./tests/nu-tooling/lib-dirs/extra ]; From 211f604759dfdc38f4ee1db121aab2fd859cc8cf Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 18:39:54 +0800 Subject: [PATCH 11/12] style(nix): use singular lib for Nushell fixtures --- flake.nix | 2 +- tests/nu-tooling/lib-dirs/default.nix | 4 ++-- tests/nu-tooling/lib-dirs/{libs => lib}/shout.nu | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename tests/nu-tooling/lib-dirs/{libs => lib}/shout.nu (100%) diff --git a/flake.nix b/flake.nix index f6a2d91..4a5b74f 100644 --- a/flake.nix +++ b/flake.nix @@ -123,7 +123,7 @@ enable = true; settings.libDirs = [ ./src/lib - ./tests/nu-tooling/lib-dirs/libs + ./tests/nu-tooling/lib-dirs/lib ./tests/nu-tooling/lib-dirs/extra ]; }; diff --git a/tests/nu-tooling/lib-dirs/default.nix b/tests/nu-tooling/lib-dirs/default.nix index 19bf55a..62ed431 100644 --- a/tests/nu-tooling/lib-dirs/default.nix +++ b/tests/nu-tooling/lib-dirs/default.nix @@ -8,7 +8,7 @@ let libDirs = [ - ./libs + ./lib ./extra ]; @@ -23,7 +23,7 @@ let version = "0.1.0"; src = ./lib-app; libDirs = [ - ./libs + ./lib ]; }; in diff --git a/tests/nu-tooling/lib-dirs/libs/shout.nu b/tests/nu-tooling/lib-dirs/lib/shout.nu similarity index 100% rename from tests/nu-tooling/lib-dirs/libs/shout.nu rename to tests/nu-tooling/lib-dirs/lib/shout.nu From bed51c3b275dbb6a692b05d10f1fee33448ecd54 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sat, 28 Nov 2026 18:48:07 +0800 Subject: [PATCH 12/12] refactor(nushell): use a top-level module directory --- flake.nix | 8 ++++---- {src/lib => lib}/pin-check/mod.nu | 0 {src/lib => lib}/pin-check/versions.nu | 0 tests/default.nix | 2 +- tests/nu-tooling/lib-dirs/default.nix | 6 +++--- .../nu-tooling/lib-dirs/{lib => fixtures/first}/shout.nu | 0 .../lib-dirs/{extra => fixtures/second}/whisper.nu | 0 7 files changed, 8 insertions(+), 8 deletions(-) rename {src/lib => lib}/pin-check/mod.nu (100%) rename {src/lib => lib}/pin-check/versions.nu (100%) rename tests/nu-tooling/lib-dirs/{lib => fixtures/first}/shout.nu (100%) rename tests/nu-tooling/lib-dirs/{extra => fixtures/second}/whisper.nu (100%) diff --git a/flake.nix b/flake.nix index 4a5b74f..d02ce07 100644 --- a/flake.nix +++ b/flake.nix @@ -122,9 +122,9 @@ nu-check = { enable = true; settings.libDirs = [ - ./src/lib - ./tests/nu-tooling/lib-dirs/lib - ./tests/nu-tooling/lib-dirs/extra + ./lib + ./tests/nu-tooling/lib-dirs/fixtures/first + ./tests/nu-tooling/lib-dirs/fixtures/second ]; }; prettier.enable = true; @@ -159,7 +159,7 @@ # ------------------------------------------------------------------------------------------ devShells.default = pkgs.mkShell { name = "devkit-dev"; - NU_LIB_DIRS = "${./src/lib}"; + NU_LIB_DIRS = "${./lib}"; packages = [ dk.nushell dk.nu-test diff --git a/src/lib/pin-check/mod.nu b/lib/pin-check/mod.nu similarity index 100% rename from src/lib/pin-check/mod.nu rename to lib/pin-check/mod.nu diff --git a/src/lib/pin-check/versions.nu b/lib/pin-check/versions.nu similarity index 100% rename from src/lib/pin-check/versions.nu rename to lib/pin-check/versions.nu diff --git a/tests/default.nix b/tests/default.nix index 50df147..52c7296 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -18,7 +18,7 @@ in dprint-markdown = import ./dprint-markdown { inherit pkgs repo; }; pin-check = dk.nuTests { src = ./pin-check; - libDirs = [ ../src/lib ]; + libDirs = [ ../lib ]; }; skill-links = import ./skill-links { inherit pkgs skillSource; }; } diff --git a/tests/nu-tooling/lib-dirs/default.nix b/tests/nu-tooling/lib-dirs/default.nix index 62ed431..569f065 100644 --- a/tests/nu-tooling/lib-dirs/default.nix +++ b/tests/nu-tooling/lib-dirs/default.nix @@ -8,8 +8,8 @@ let libDirs = [ - ./lib - ./extra + ./fixtures/first + ./fixtures/second ]; lib-command = dk.writeNuApplication { @@ -23,7 +23,7 @@ let version = "0.1.0"; src = ./lib-app; libDirs = [ - ./lib + ./fixtures/first ]; }; in diff --git a/tests/nu-tooling/lib-dirs/lib/shout.nu b/tests/nu-tooling/lib-dirs/fixtures/first/shout.nu similarity index 100% rename from tests/nu-tooling/lib-dirs/lib/shout.nu rename to tests/nu-tooling/lib-dirs/fixtures/first/shout.nu diff --git a/tests/nu-tooling/lib-dirs/extra/whisper.nu b/tests/nu-tooling/lib-dirs/fixtures/second/whisper.nu similarity index 100% rename from tests/nu-tooling/lib-dirs/extra/whisper.nu rename to tests/nu-tooling/lib-dirs/fixtures/second/whisper.nu