fix: defer cache key generation to pre-command and fix stdout log pollution#11
Open
karlchu wants to merge 1 commit into
Open
fix: defer cache key generation to pre-command and fix stdout log pollution#11karlchu wants to merge 1 commit into
karlchu wants to merge 1 commit into
Conversation
karlchu
marked this pull request as ready for review
July 17, 2026 10:31
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.
This pull request resolves two critical bugs in the plugin's cache-key generation lifecycle and logging mechanism, and introduces fail-fast configuration validation.
The Bugs Resolved
Incorrect Lifecycle Timing (Environment Hook)
environmenthook (hooks/environment). In Buildkite's lifecycle, theenvironmenthook executes before repository checkout. As a result, the plugin was looking for local files (like a customcache-keyDockerfile or lockfiles) before they were cloned onto the runner.Stdout Log Contamination
log_info,log_success, andlog_warningwere printing tostdout.generate_cache_key(), the loop output is piped directly tosha1sum(done | sha1sum). When a file was missing, the warning message[WARNING]: Cache key file not found <file>was written to stdout, polluting the pipe. This resulted in the plugin generating a constant cache key hash offaad270761e3125b46cc97fbde55722f536114f1(the SHA-1 of the warning string itself).Key Changes
Deferred Key Generation
hooks/environment. The plugin now generates the key on-demand in thepre-commandhook, which executes safely after checkout.Diagnostic Log Redirection to Stderr
log_info,log_success, andlog_warninginlib/shared.bashto write tostderr(>&2). This adheres to standard Unix logging practices and keeps diagnostic logs from contaminating functionalstdoutstreams used in command substitutions and pipelines.Fail-Fast Validation
generate_cache_keyinlib/plugin.bash. If a user explicitly configures acache-keypointing to file paths, the plugin now verifies their existence in the main shell context before hashing. If any file is missing, the plugin fails-fast immediately with a clear error (exit 1) instead of silently building using a corrupted/empty hash.Added Test Cases
tests/pre-command.bats:"Pre-command hook generates cache key on demand after checkout": Verifies correct key generation from workspace files."Pre-command hook fails fast if cache key file is missing": Verifies that missing files trigger an immediate build step failure."Pre-command hook treats cache key without slash as a literal string": Verifies string-literal cache key treatment and hashing when no slash is present in the value.How This Was Tested
The entire Bats test suite was executed locally using the official Docker
plugin-testerimage:docker run --rm -v "$PWD:/plugin" buildkite/plugin-testerAll 69 tests passed successfully (including the 3 new test cases).