Skip to content

Commit fabbc25

Browse files
committed
test: split test into two
1 parent 92e7f6c commit fabbc25

File tree

3 files changed

+67
-34
lines changed

3 files changed

+67
-34
lines changed

test/integration/forcePush.integration.test.js

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,27 @@ describe('Force Push Integration Test', () => {
5757
});
5858

5959
describe('Complete force push pipeline', () => {
60-
it('should handle legitimate empty diff after rebase scenario', async function () {
60+
it('should handle valid diff after rebase scenario', async function () {
6161
this.timeout(5000); // eslint-disable-line no-invalid-this
6262

63-
// Create action simulating force push with old unreachable SHA
63+
// Create action simulating force push with valid SHAs that have actual changes
6464
const action = new Action(
65-
'force-push-integration',
65+
'valid-diff-integration',
6666
'push',
6767
'POST',
6868
Date.now(),
6969
'test/repo.git',
7070
);
7171
action.proxyGitPath = path.dirname(tempDir);
7272
action.repoName = path.basename(tempDir);
73-
action.commitFrom = initialCommitSHA; // Old SHA
74-
action.commitTo = rebasedCommitSHA; // New SHA after rebase
73+
74+
// Parent of initial commit to get actual diff content
75+
const parentSHA = '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
76+
action.commitFrom = parentSHA;
77+
action.commitTo = rebasedCommitSHA;
7578
action.commitData = [
7679
{
77-
parent: initialCommitSHA,
80+
parent: parentSHA,
7881
commit: rebasedCommitSHA,
7982
message: 'Add feature (rebased)',
8083
author: 'Test User',
@@ -86,33 +89,63 @@ describe('Force Push Integration Test', () => {
8689

8790
const diffStep = afterGetDiff.steps.find((s) => s.stepName === 'diff');
8891
expect(diffStep).to.exist;
92+
expect(diffStep.error).to.be.false;
93+
expect(diffStep.content).to.be.a('string');
94+
expect(diffStep.content.length).to.be.greaterThan(0);
8995

90-
// May produce empty diff or error - both should be handled
91-
if (diffStep.error) {
92-
console.log('getDiff failed as expected with unreachable commitFrom');
93-
expect(diffStep.errorMessage).to.be.a('string');
94-
} else {
95-
console.log('getDiff succeeded, checking content');
96-
expect(diffStep.content).to.satisfy(
97-
(content) => content === null || content === undefined || typeof content === 'string',
98-
);
99-
}
100-
101-
// scanDiff should not block on empty/missing diff
10296
const afterScanDiff = await scanDiff({}, afterGetDiff);
10397
const scanStep = afterScanDiff.steps.find((s) => s.stepName === 'scanDiff');
10498

10599
expect(scanStep).to.exist;
100+
expect(scanStep.error).to.be.false;
101+
});
102+
103+
it('should handle unreachable commit SHA error', async function () {
104+
this.timeout(5000); // eslint-disable-line no-invalid-this
106105

107-
// scanDiff should NOT error on empty diff
108-
if (diffStep.error || !diffStep.content) {
109-
expect(scanStep.error).to.be.false;
110-
console.log('scanDiff correctly allowed empty/missing diff');
111-
} else {
112-
// If diff exists, should process normally
113-
expect(scanStep.error).to.be.false;
114-
console.log('scanDiff processed valid diff content');
115-
}
106+
// Invalid SHA to trigger error
107+
const action = new Action(
108+
'unreachable-sha-integration',
109+
'push',
110+
'POST',
111+
Date.now(),
112+
'test/repo.git',
113+
);
114+
action.proxyGitPath = path.dirname(tempDir);
115+
action.repoName = path.basename(tempDir);
116+
action.commitFrom = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef'; // Invalid SHA
117+
action.commitTo = rebasedCommitSHA;
118+
action.commitData = [
119+
{
120+
parent: 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
121+
commit: rebasedCommitSHA,
122+
message: 'Add feature (rebased)',
123+
author: 'Test User',
124+
},
125+
];
126+
127+
const afterGetDiff = await getDiff({}, action);
128+
expect(afterGetDiff.steps).to.have.length.greaterThan(0);
129+
130+
const diffStep = afterGetDiff.steps.find((s) => s.stepName === 'diff');
131+
expect(diffStep).to.exist;
132+
expect(diffStep.error).to.be.true;
133+
expect(diffStep.errorMessage).to.be.a('string');
134+
expect(diffStep.errorMessage.length).to.be.greaterThan(0);
135+
expect(diffStep.errorMessage).to.satisfy(
136+
(msg) =>
137+
msg.includes('fatal:') ||
138+
msg.includes('unknown revision') ||
139+
msg.includes('bad revision'),
140+
'Error message should contain git-specific error patterns',
141+
);
142+
143+
// scanDiff should not block on missing diff due to error
144+
const afterScanDiff = await scanDiff({}, afterGetDiff);
145+
const scanStep = afterScanDiff.steps.find((s) => s.stepName === 'scanDiff');
146+
147+
expect(scanStep).to.exist;
148+
expect(scanStep.error).to.be.false;
116149
});
117150

118151
it('should handle missing diff step gracefully', async function () {

test/scanDiff.emptyDiff.test.js renamed to test/processors/scanDiff.emptyDiff.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const { Action } = require('../src/proxy/actions');
2-
const { exec } = require('../src/proxy/processors/push-action/scanDiff');
1+
const { Action } = require('../../src/proxy/actions');
2+
const { exec } = require('../../src/proxy/processors/push-action/scanDiff');
33

44
const chai = require('chai');
55
const expect = chai.expect;

test/scanDiff.test.js renamed to test/processors/scanDiff.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const chai = require('chai');
22
const crypto = require('crypto');
3-
const processor = require('../src/proxy/processors/push-action/scanDiff');
4-
const { Action } = require('../src/proxy/actions/Action');
3+
const processor = require('../../src/proxy/processors/push-action/scanDiff');
4+
const { Action } = require('../../src/proxy/actions/Action');
55
const { expect } = chai;
6-
const config = require('../src/config');
7-
const db = require('../src/db');
6+
const config = require('../../src/config');
7+
const db = require('../../src/db');
88
chai.should();
99

1010
// Load blocked literals and patterns from configuration...
11-
const commitConfig = require('../src/config/index').getCommitConfig();
11+
const commitConfig = require('../../src/config/index').getCommitConfig();
1212
const privateOrganizations = config.getPrivateOrganizations();
1313

1414
const blockedLiterals = commitConfig.diff.block.literals;

0 commit comments

Comments
 (0)