refactor(action): replace mock.module with dependency injection in tests#780
Merged
Conversation
…ests Refactor shared/s3 to a factory pattern and inject dependencies explicitly into app/backend modules so tests can pass fakes without mutating the global module registry via mock.module. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Rename deps.ts→dependencies.ts and Deps interface→Dependencies.
Expand deps.context from { runAttempt } to the full shape needed from
@actions/github (runId, serverUrl, repo, issue), so tests no longer
need GITHUB_* env vars — all context is supplied via deps.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…encies Export defaultS3Operations from shared/s3 and use it as the deps.s3 default. The s3 type in Dependencies is now S3Operations rather than a manual Pick of the methods the action uses. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
🎉 This PR is included in version 1.44.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
Summary
mock.modulecalls from the action test suite, following the same pattern established for the backend in refactor(backend): replace mock.module with dependency injection in tests #778Depsinterface with amakeDefaultDeps()factory, so production code runs unchanged while tests inject fakes directlygetInput,getBooleanInput,getMultilineInput) are now driven viaINPUT_*environment variables in tests, exercising the real@actions/coreimplementationrepo,runId,serverUrl) are driven viaGITHUB_*environment variables;runAttemptis part ofdepssince thecontextsingleton is frozen at import timeoctokit.tsis deleted —octokitis now created lazily insidemakeDefaultDeps()and injected wherever neededChanges
action/src/deps.ts— definesDepsandmakeDefaultDeps()run(),downloadBaseImages(),uploadAllImages(),uploadOriginalNewImages(),deleteHashImages(),uploadBaseImages()all accept adepsparameter threaded through from the topcreateGithubComment()accepts anoctokitparameterdisableAutoMerge()andgetLatestVisualRegressionStatus()acceptdeps/octokitresizeImageIfNeeded()accepts ajimpparameterrun.test.tsandcomment.test.tsrewritten: zeromock.modulecalls, fakedepsconstructed inline and passed directly to tested functionsTest plan
cd action && bun test— all 69 tests passmock.modulecalls remain:grep -r "mock.module" action/test/returns nothingGenerated with Claude Code