Uh oh!
There was an error while loading. Please reload this page.
refactor(learn): split src/learn.sh into a src/learn/ module - #938
Merged
Conversation
Fourth module under ADR-010. 1213 lines become 15 files behind a `source`-only entry point. learn/progress.sh LEARN_PROGRESS_FILE, mark_completed, is_completed, show_progress, reset_progress learn/session.sh LEARN_TEMP_DIR, init, cleanup, create_example_file, run_lesson_test learn/lessons/*.sh one file per lesson (10) learn/menu.sh print_menu, start Layering from all 37 internal call edges: progress <- session <- lessons <- menu. Every lesson calls exactly create_example_file and run_lesson_test and nothing else; no lesson calls another, so the ten are independent. `start` is the sole dispatcher and `bashunit::learn::start` remains the only external entry point. The issue's table lists this file as 82 functions. Only 20 are real -- the other 62 are sample code inside heredocs (the tutorial's example tests), counted because they sit at line-start in heredoc bodies. That distinction mattered: segmenting on a `^}$` closing brace, which worked for the previous three modules, terminates lesson bodies early here at a brace inside rendered sample code and would have split functions across files. Segment boundaries are taken from the next function's start instead, which heredocs cannot affect, and every new file is `bash -n` clean. `tests/unit/learn_test.sh` sources the module by path to get an isolated $HOME (LEARN_PROGRESS_FILE is a readonly resolved at source time), so its hardcoded `src/learn.sh` is repointed at `src/learn/index.sh`. BASHUNIT_ROOT_DIR is already exported in that sandbox, so the entry point's `source` lines resolve. A relocation: the non-blank line multiset differs only by the new shebangs, module headers and `source` lines; 20 functions before and after; the sorted code content of the built artifact is identical and `bash build.sh bin -v` prints "Build verified". The two file-scope globals do not reference each other, so their reordering across files is inert. The file-wide `# shellcheck disable=SC2016` moved to the seven lesson files that actually need it (their prose shows literal `$vars` in single quotes) rather than being applied to all fifteen. Lines over 120 *bytes* are box-drawing UTF-8 and under 120 characters, so no .editorconfig rule is needed. Related #931
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 Background
Related #931
Fourth module under ADR-010, after runner (#924), coverage (#925) and reports (#937).
src/learn.shwas the largest remaining flat file at 1213 lines. Responsibility map posted on #931 before any code moved.💡 Changes
learn/progress.shLEARN_PROGRESS_FILE,mark_completed,is_completed,show_progress,reset_progresslearn/session.shLEARN_TEMP_DIR,init,cleanup,create_example_file,run_lesson_testlearn/lessons/*.shlearn/menu.shprint_menu,startLayering from all 37 internal call edges:
progress ← session ← lessons ← menu. Every lesson calls exactlycreate_example_fileandrun_lesson_test; no lesson calls another, so the ten are independent and each is one file.bashunit::learn::startremains the only external entry point.lessons/as a subdirectory keeps the three plumbing files visible instead of buried among ten curriculum files. That makes this depth-3 — the first real use of the nesting #932 pinned with a regression test.The issue's table lists this file as 82 functions. Only 20 are real — the other 62 are sample code inside heredocs (the tutorial's example tests), counted because they sit at line-start in heredoc bodies.
That mattered. Segmenting on a
^}$closing brace — which worked for the previous three modules — terminates lesson bodies early here at a brace inside rendered sample code, and would have split functions across files. I caught it on a coverage check (large bogus gaps inside lesson bodies) and re-derived boundaries from the next function's start, which heredocs cannot affect. Every new file isbash -nclean.✅ Verification
A relocation: non-blank line multiset differs only by new shebangs, module headers and
sourcelines; 20 functions before and after; the sorted code content of the built artifact is identical;bash build.sh bin -v→✅ Build verified ✅.tests/unit/learn_test.shsources the module by path to isolate$HOME(LEARN_PROGRESS_FILEis a readonly resolved at source time). Its hardcodedsrc/learn.shis repointed atsrc/learn/index.sh— this surfaced as 14 red tests before the fix, not a behaviour break.The file-wide
# shellcheck disable=SC2016moved to the seven lesson files that actually need it. Lines over 120 bytes are box-drawing UTF-8 and under 120 characters, so no.editorconfigrule is needed.Green: sequential ·
--parallel·--parallel --simple --strict·make sa·make lint· CI-mode ShellCheck ·bashunit learnsmoke-tested end-to-end.