[CSM-540]: Add unit tests for component - #1
Open
oykukurtgoz wants to merge 1 commit into
Open
Conversation
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: Comment |
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 free
to 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.
Closes CSM-540.
Adds unit tests for
main.rb.The whole PR is 462 added lines and 12 deleted ones;
main.rbaccounts for 17 added and 12 deleted. Nothing in the install logic was moved or reworded — the version selection, theSelected node version is …line, then/sudo ncommands and theUnexpected OSabort are byte-for-byte what they were.Changes to
main.rbTwo, both driven by the issue's prerequisite refactor.
Top-level side effects are guarded. The version-selection lines that used to sit between
get_versionandrun_command, and the OS branch at the bottom of the file, now sit together inside a singleif __FILE__ == $PROGRAM_NAME ... endblock, in their original order. Appcircle runs the step withruby main.rb, so the guard is true there and the body executes exactly as before.require-ing the file only definesenv_has_key,get_versionandrun_command.osis loaded insidebegin/rescue LoadError. It is a gem rather than stdlib, so a bare test environment may not have it. When it is installed nothing changes; when it is not, the file still loads and the tests supply a stubOSmodule.open3is stdlib and is left as a plainrequire.No nil-unsafe access surfaced in the real flow, so no explicit
raisewas added.env_has_key(nil)andrun_command(nil)are never reached by the script; the tests pin their currentTypeErrorbehaviour rather than change it.Tests (
test/test_main.rb)Self-executing, 28 examples, no Gemfile / Bundler —
rspecgem + Ruby stdlib only.main.rbexposes three functions plus the script as a whole, and the tests cover all four surfaces:env_has_key, in-process — returns the value when set, returnsnilfor a missing key, an empty string and an empty key name, raisesTypeErrorfor anilkey.get_version, in-process — returns the config version when set, falls back to the component version when the config version isnil, returns an empty config version as-is, returnsnilwhen both arenil.run_command, in-process —Open3.popen3is stubbed withStringIOstreams and a fakewait_thr, so no real command runs. Happy path, the echoed@@[command]line and forwarded stdout lines, the exact command string handed topopen3, the failure branch (SystemExitstatus 1 carrying the child's stderr, and an empty stderr), plusniland empty commands. Two further cases run a realechoand a realsh -c "exit 1"the same way the reference PRs do.$PROGRAM_NAMEis pointed atmain.rband the file isload-ed withOpen3.popen3stubbed andOS.linux?/OS.mac?stubbed per case. This asserts the composed command string end to end:n ltsby default,n 18fromAC_SELECTED_NODE_VERSION,AC_NODE_JS_VERSIONoverriding it, empty values of either being ignored,sudo n …on macOS,Unexpected OSabort with no command on any other OS, and the stderr of a failing install being propagated throughabort.require-ingmain.rbin a fresh process throughOpen3.capture3exits 0 and prints noSelected node versionline.The script declares no required environment variables, so there are no missing-and-empty validation subprocess cases; the empty-value behaviour of the two optional variables is covered by the in-process step cases above.
No real toolchain (
n,sudo), network, or filesystem writes.Coverage
One detail worth knowing: Ruby's
Coverageresets a file's counters every time that file isload-ed again. Since the step-level casesloadmain.rbonce each, the test file takes aCoverage.peek_resultsnapshot before everyloadand sums the snapshots into the final report. Without that the report would only reflect the lastload.Docs
README.mdgains a## Running testssection.🤖 Generated with Claude Code