From 33e0fe13c5476694dc0ec81d7bd53fc40874e1e4 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Sat, 1 Aug 2026 15:17:35 +0200 Subject: [PATCH] refactor(system): group the capability probes into a src/system/ module First group under #949. src/ held eleven modules and fifteen loose files; individually each was small and well named, but as a listing they read as leftovers and the root stopped conveying structure. src/check_os.sh -> src/system/check_os.sh src/dependencies.sh -> src/system/dependencies.sh src/io.sh -> src/system/io.sh The bottom layer: what this machine is and what it has. Nothing in it touches config, test state, console or the runner. The issue proposed putting clock.sh here too. That would have created a cross-module cycle -- system/clock.sh -> util/math.sh -> system/dependencies.sh. Harmless at load time, since both crossings are inside function bodies and clock.sh's only file-scope statements are two variable initialisers, but not worth shipping. clock.sh goes to src/util/ with math.sh instead: both compute something and both probe via dependencies, so the edge runs util -> system in one direction only. Two callers reach these files by path rather than through the entrypoint: build.sh sources check_os.sh and calls check_os::init at line 4, before it sets BASHUNIT_ROOT_DIR, so it points at the file rather than the module index; and tests/unit/check_os_test.sh sources it relative to the test file. A relocation: git records all three as renames with a zero-line diff, and the built artifact's code content is identical. Related #949 --- .claude/rules/architecture-map.md | 4 +++- bashunit | 4 +--- build.sh | 2 +- src/{ => system}/check_os.sh | 0 src/{ => system}/dependencies.sh | 0 src/system/index.sh | 12 ++++++++++++ src/{ => system}/io.sh | 0 tests/unit/check_os_test.sh | 2 +- 8 files changed, 18 insertions(+), 6 deletions(-) rename src/{ => system}/check_os.sh (100%) rename src/{ => system}/dependencies.sh (100%) create mode 100644 src/system/index.sh rename src/{ => system}/io.sh (100%) diff --git a/.claude/rules/architecture-map.md b/.claude/rules/architecture-map.md index e252ef26..2c2677a7 100644 --- a/.claude/rules/architecture-map.md +++ b/.claude/rules/architecture-map.md @@ -101,7 +101,9 @@ shell (or, in parallel, in per-test `.result` files aggregated at the end). | `coverage/html_index.sh` / `html_file.sh` | HTML page emitters; the only two files exempt from `max_line_length` | | `rerun.sh` | `.bashunit/last-failed` cache for `--rerun-failed` | | `reports.sh` | JUnit/HTML/TAP/JSON writers | -| `check_os.sh` / `dependencies.sh` | one-fork OS detect; `command -v` probes (builtins, not forks) | +| `system/index.sh` | aggregator only — sources the `src/system/` module below | +| `system/check_os.sh` / `system/dependencies.sh` | one-fork OS detect; `command -v` probes (builtins, not forks) | +| `system/io.sh` | small I/O helpers | | `cli/index.sh` | aggregator only — sources the `src/cli/` module below | | `cli/{upgrade,watch,doc,init}.sh` | the non-`test` subcommand implementations; `main.sh` is their only caller | | `learn/index.sh` `benchmark.sh` | the remaining non-`test` subcommands; benchmark is shared with `runner/bench.sh` | diff --git a/bashunit b/bashunit index 029f1934..55e269fa 100755 --- a/bashunit +++ b/bashunit @@ -65,11 +65,9 @@ for arg in "$@"; do done source "$BASHUNIT_ROOT_DIR/src/dev/debug.sh" -source "$BASHUNIT_ROOT_DIR/src/check_os.sh" +source "$BASHUNIT_ROOT_DIR/src/system/index.sh" source "$BASHUNIT_ROOT_DIR/src/str.sh" source "$BASHUNIT_ROOT_DIR/src/globals.sh" -source "$BASHUNIT_ROOT_DIR/src/dependencies.sh" -source "$BASHUNIT_ROOT_DIR/src/io.sh" source "$BASHUNIT_ROOT_DIR/src/math.sh" source "$BASHUNIT_ROOT_DIR/src/parallel.sh" source "$BASHUNIT_ROOT_DIR/src/env.sh" diff --git a/build.sh b/build.sh index 185f1a9e..aaa56792 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -source src/check_os.sh +source src/system/check_os.sh bashunit::check_os::init BASHUNIT_ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" diff --git a/src/check_os.sh b/src/system/check_os.sh similarity index 100% rename from src/check_os.sh rename to src/system/check_os.sh diff --git a/src/dependencies.sh b/src/system/dependencies.sh similarity index 100% rename from src/dependencies.sh rename to src/system/dependencies.sh diff --git a/src/system/index.sh b/src/system/index.sh new file mode 100644 index 00000000..a1c78417 --- /dev/null +++ b/src/system/index.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# Entry point for the src/system/ module: only `source` lines and comments belong +# here. build.sh emits a file's body before recursing into its `source` lines, so +# any statement here would run before its dependencies in the built binary +# (adrs/adr-010-src-module-directories.md). +# +# Capability probing: what this machine is and what it has. The bottom layer -- +# nothing here touches config, test state, console or the runner. +source "$BASHUNIT_ROOT_DIR/src/system/check_os.sh" +source "$BASHUNIT_ROOT_DIR/src/system/dependencies.sh" +source "$BASHUNIT_ROOT_DIR/src/system/io.sh" diff --git a/src/io.sh b/src/system/io.sh similarity index 100% rename from src/io.sh rename to src/system/io.sh diff --git a/tests/unit/check_os_test.sh b/tests/unit/check_os_test.sh index 8cd9c5c3..84ea08f4 100644 --- a/tests/unit/check_os_test.sh +++ b/tests/unit/check_os_test.sh @@ -85,7 +85,7 @@ function test_module_load_detects_os_with_a_single_uname_call() { # under `build.sh --verify` the built bashunit lives in a folder # without src/, and sourcing through $BASHUNIT_ROOT_DIR crashed # the whole verification run (silently, until #834 gated it). - source "$(dirname "${BASH_SOURCE[0]}")/../../src/check_os.sh" + source "$(dirname "${BASH_SOURCE[0]}")/../../src/system/check_os.sh" assert_have_been_called_times 1 uname }