Repository navigation
fix(github-actions): harden google-internal-tests against SHA status overwrite and 3000-file truncation #4027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alan-agius4
merged 2 commits into
angular:main
from
josephperrott:fix/google-internal-tests-hardening
Oct 12, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| import {context} from '@actions/github'; | ||
| import {Octokit} from '@octokit/rest'; | ||
| import {main} from './main.js'; | ||
|
|
||
| describe('google-internal-tests action', () => { | ||
| let mockGit: jasmine.SpyObj<Octokit>; | ||
| let existingStatuses: Array<{context: string; state: string; target_url?: string | null}>; | ||
| let prFiles: Array<{filename: string; status?: string; previous_filename?: string}>; | ||
| const mockSyncConfig = { | ||
| config: { | ||
| syncedFilePatterns: ['packages/**'], | ||
| alwaysExternalFilePatterns: [], | ||
| separateFilePatterns: ['goldens/**'], | ||
| }, | ||
| ngMatchFn: (p: string) => p.startsWith('packages/'), | ||
| separateMatchFn: (p: string) => p.startsWith('goldens/'), | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| process.env['INPUT_RUN-TESTS-GUIDE-URL'] = 'https://goo.gle/angular-internal-presubmit'; | ||
| existingStatuses = []; | ||
| prFiles = []; | ||
|
|
||
| context.eventName = 'pull_request_target'; | ||
| context.payload = { | ||
| pull_request: { | ||
| number: 100, | ||
| head: {sha: 'deadbeef1234567890'}, | ||
| base: {ref: 'main'}, | ||
| }, | ||
| }; | ||
| spyOnProperty(context, 'repo', 'get').and.returnValue({ | ||
| owner: 'angular', | ||
| repo: 'angular', | ||
| }); | ||
|
|
||
| mockGit = jasmine.createSpyObj('Octokit', ['paginate', 'repos', 'pulls']); | ||
| mockGit.repos = jasmine.createSpyObj('repos', [ | ||
| 'createCommitStatus', | ||
| 'getCombinedStatusForRef', | ||
| ]); | ||
| mockGit.pulls = jasmine.createSpyObj('pulls', ['listFiles']); | ||
|
|
||
| (mockGit.repos.createCommitStatus as unknown as jasmine.Spy).and.resolveTo({}); | ||
| (mockGit.paginate as jasmine.Spy).and.callFake((fn: unknown) => { | ||
| if (fn === mockGit.repos.getCombinedStatusForRef) { | ||
| return Promise.resolve(existingStatuses); | ||
| } | ||
| if (fn === mockGit.pulls.listFiles) { | ||
| return Promise.resolve(prFiles); | ||
| } | ||
| return Promise.resolve([]); | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| delete process.env['INPUT_RUN-TESTS-GUIDE-URL']; | ||
| }); | ||
|
|
||
| it('should post pending status when a PR targeting main touches synced files', async () => { | ||
| prFiles = [{filename: 'packages/core/src/index.ts'}]; | ||
|
|
||
| await main(mockGit as unknown as Octokit, mockSyncConfig); | ||
|
|
||
| expect(mockGit.repos.createCommitStatus).toHaveBeenCalledOnceWith({ | ||
| owner: 'angular', | ||
| repo: 'angular', | ||
| state: 'pending', | ||
| description: 'Waiting for tests to start. @Googlers: Initiate a presubmit. See -->', | ||
| target_url: 'https://goo.gle/angular-internal-presubmit', | ||
| context: 'google-internal-tests', | ||
| sha: 'deadbeef1234567890', | ||
| }); | ||
| }); | ||
|
|
||
| it('should post success status when a PR targeting main does not touch synced files', async () => { | ||
| prFiles = [{filename: 'docs/README.md'}]; | ||
|
|
||
| await main(mockGit as unknown as Octokit, mockSyncConfig); | ||
|
|
||
| expect(mockGit.repos.createCommitStatus).toHaveBeenCalledOnceWith({ | ||
| owner: 'angular', | ||
| repo: 'angular', | ||
| state: 'success', | ||
| description: 'Does not affect Google.', | ||
| context: 'google-internal-tests', | ||
| sha: 'deadbeef1234567890', | ||
| }); | ||
| }); | ||
|
|
||
| it('should post skipped success status for PR targeting non-main branch when no status exists', async () => { | ||
| context.payload.pull_request!.base.ref = '18.2.x'; | ||
|
|
||
| await main(mockGit as unknown as Octokit, mockSyncConfig); | ||
|
|
||
| expect(mockGit.repos.createCommitStatus).toHaveBeenCalledOnceWith({ | ||
| owner: 'angular', | ||
| repo: 'angular', | ||
| state: 'success', | ||
| description: 'Skipped. PR does not target `main` branch', | ||
| context: 'google-internal-tests', | ||
| sha: 'deadbeef1234567890', | ||
| }); | ||
| }); | ||
|
|
||
| it('should not overwrite an existing status pointing to an internal CL', async () => { | ||
| context.payload.pull_request!.base.ref = '18.2.x'; | ||
| existingStatuses = [ | ||
| { | ||
| context: 'google-internal-tests', | ||
| state: 'success', | ||
| target_url: 'http://cl/123456789', | ||
| }, | ||
| ]; | ||
|
|
||
| await main(mockGit as unknown as Octokit, mockSyncConfig); | ||
|
|
||
| expect(mockGit.repos.createCommitStatus).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should not overwrite an existing pending status when triggered on a non-main branch with the same head SHA', async () => { | ||
| context.payload.pull_request!.base.ref = '18.2.x'; | ||
| existingStatuses = [ | ||
| { | ||
| context: 'google-internal-tests', | ||
| state: 'pending', | ||
| target_url: 'https://goo.gle/angular-internal-presubmit', | ||
| }, | ||
| ]; | ||
|
|
||
| await main(mockGit as unknown as Octokit, mockSyncConfig); | ||
|
|
||
| expect(mockGit.repos.createCommitStatus).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should overwrite a non-CL skipped success status when a PR targeting main with the same SHA touches synced files', async () => { | ||
| context.payload.pull_request!.base.ref = 'main'; | ||
| existingStatuses = [ | ||
| { | ||
| context: 'google-internal-tests', | ||
| state: 'success', | ||
| target_url: null, | ||
| }, | ||
| ]; | ||
| prFiles = [{filename: 'packages/core/src/index.ts'}]; | ||
|
|
||
| await main(mockGit as unknown as Octokit, mockSyncConfig); | ||
|
|
||
| expect(mockGit.repos.createCommitStatus).toHaveBeenCalledOnceWith({ | ||
| owner: 'angular', | ||
| repo: 'angular', | ||
| state: 'pending', | ||
| description: 'Waiting for tests to start. @Googlers: Initiate a presubmit. See -->', | ||
| target_url: 'https://goo.gle/angular-internal-presubmit', | ||
| context: 'google-internal-tests', | ||
| sha: 'deadbeef1234567890', | ||
| }); | ||
| }); | ||
|
|
||
| it('should fail closed with pending status when returned file list reaches 3000-file pagination limit', async () => { | ||
| prFiles = Array.from({length: 3000}, (_, i) => ({ | ||
| filename: `docs/dummy-${i}.md`, | ||
| })); | ||
|
|
||
| await main(mockGit as unknown as Octokit, mockSyncConfig); | ||
|
|
||
| expect(mockGit.repos.createCommitStatus).toHaveBeenCalledOnceWith({ | ||
| owner: 'angular', | ||
| repo: 'angular', | ||
| state: 'pending', | ||
| description: 'Waiting for tests to start. @Googlers: Initiate a presubmit. See -->', | ||
| target_url: 'https://goo.gle/angular-internal-presubmit', | ||
| context: 'google-internal-tests', | ||
| sha: 'deadbeef1234567890', | ||
| }); | ||
| }); | ||
|
|
||
| it('should fail closed with pending status when returned file count is less than pull_request.changed_files', async () => { | ||
| context.payload.pull_request!['changed_files'] = 3005; | ||
| prFiles = [{filename: 'docs/README.md'}]; | ||
|
|
||
| await main(mockGit as unknown as Octokit, mockSyncConfig); | ||
|
|
||
| expect(mockGit.repos.createCommitStatus).toHaveBeenCalledOnceWith({ | ||
| owner: 'angular', | ||
| repo: 'angular', | ||
| state: 'pending', | ||
| description: 'Waiting for tests to start. @Googlers: Initiate a presubmit. See -->', | ||
| target_url: 'https://goo.gle/angular-internal-presubmit', | ||
| context: 'google-internal-tests', | ||
| sha: 'deadbeef1234567890', | ||
| }); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.