[CSM-439]: Add unit tests for cache pull component - #5
Open
boztopuz wants to merge 1 commit into
Open
Conversation
Add test/test_main.rb covering every function in main.rb plus the script's env-var validation and download/restore flow. - get_env_variable, run_command, run_command_with_log and abort_with0 are tested in-process with Kernel#system stubbed, on both the happy path and the error branch (empty/nil input, non-zero child status, SystemExit). - The full script runs in a subprocess with Kernel#system and Net::HTTP.get replaced through a RUBYOPT-preloaded stub, so no unzip/curl/rm/mkdir is ever executed, no network connection is opened and nothing is written outside a tmpdir. Stubbed calls are echoed so the composed command strings can be asserted. - AC_CACHE_LABEL, AC_TOKEN_ID and AC_CALLBACK_URL each have a missing and an empty validation test; AC_CACHE_GET_URL is covered through the curl target it produces for both cache providers. - A merged (in-process + subprocess) coverage report is printed after the run. main.rb only gains the `if __FILE__ == $PROGRAM_NAME` guard around the top-level script body so the file can be required; no logic is changed. Co-Authored-By: Claude Opus 5 <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: Advanced 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.
Linear: CSM-439
Adds a unit test suite for
appcircle-cache-pull-component, following the conventions established in CSM-230, CSM-231 and the sibling CSM-417 cache push PR: a single self-executingtest/test_main.rb, RSpec + Ruby stdlib only (no Gemfile/Bundler), the sharedReadableFormatter, and a coverage report printed after the run.Results
What is covered
Both the positive and the negative path for every function in scope.
get_env_variablenilrun_commandsystemuntouched, silent on success@@[error] Unexpected exit with code N+SystemExit(0);nil→TypeErrorrun_command_with_log@@[command], runs, printstook Nstook;nil→TypeErrorafter logging; empty stringabort_with0@@[error] <msg>, exits 0nilmessage still exit 0Script-level behaviour, exercised by running
main.rbin a subprocess:AC_CACHE_LABEL,AC_TOKEN_IDandAC_CALLBACK_URLeach have a missing and an empty test, asserting the@@[error]line, the deliberate exit code 0, and that the script stopped before doing any work.AC_REPOSITORY_DIRis asserted to be genuinely optional.AC_CACHE_GET_URL— this variable is set bymain.rbfrom thegetUrlfield of the signed-URL response rather than supplied by the user, so it is covered through the curl target it produces: value present,getUrlabsent from the JSON,getUrlempty, and a stale pre-set value being overwritten. Both provider branches are covered, includingAC_CACHE_PROVIDERunset (confirmingnil.eql?is safe here).?action=getCacheUrls&cacheKey=…&tokenId=…query, empty response body skipping the download, and malformed JSON failing with a non-zero exit.exit 0when the archive is absent or zero bytes, the MD5 digest and its appended.md5sidecar, the top-levelunzip, and the nested-archive loop that maps a cached folder named after anAC_directory variable back to that path.No real side effects
Kernel#systemandNet::HTTP.getare replaced in the child through aRUBYOPT-preloaded stub, so nounzip,curl,rmormkdiris ever executed and no socket is opened. Stubbed calls are echoed to stdout, which is what lets the tests assert the exact composed command strings. All fixtures live inDir.mktmpdirand the script is run withchdirpointed at it, so nothing is written outside a temp directory.Every mutation tried against
main.rbwhile validating the suite (exit 0→exit 1, dropping--fail, loosening the label sanitizer, removing.strip,'a'→'w'on the sidecar) was caught by at least one test.Changes to
main.rbOnly the
if __FILE__ == $PROGRAM_NAMEguard around the top-level script body, so the file can berequired from the test. Reviewing withgit diff -wshows the guard is the entire change — no logic, ordering or behaviour was touched. All fourrequires are stdlib, so noLoadErrorguards were needed.Notes for the reviewer
Two pre-existing behaviours were found while writing the tests. Per the issue scope they are documented by the tests rather than changed, and are worth a look:
ac_cache/<label>/foo.zip, no folder segment) resolvesbase_pathto"", so the restore runsunzip … -d /andmkdir -pwith no operand. Same for a folder that is not a knownAC_variable, which resolves to an absolute/<name>/.unless ac_token_id.empty?(main.rb:66) can never be false —get_env_variablereturnsnilfor an empty value andabort_with0has already exited by that point.How to run
gem install rspec # once ruby test/test_main.rb🤖 Generated with Claude Code