-
Notifications
You must be signed in to change notification settings - Fork 964
Expand file tree
/
Copy pathmerge-lanes-squash-diverge.e2e.ts
More file actions
309 lines (266 loc) · 13 KB
/
Copy pathmerge-lanes-squash-diverge.e2e.ts
File metadata and controls
309 lines (266 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import chai, { expect } from 'chai';
import { Helper } from '@teambit/legacy.e2e-helper';
import chaiFs from 'chai-fs';
chai.use(chaiFs);
describe('merge lanes - squash on diverged', function () {
this.timeout(0);
let helper: Helper;
before(() => {
helper = new Helper();
});
after(() => {
helper.scopeHelper.destroy();
});
describe('single scope: two diverged lanes, --squash on merge', () => {
let commonAncestor: string;
let headOnLaneA: string;
let headOnLaneB: string;
let mergeSnap: string;
before(() => {
helper.scopeHelper.setWorkspaceWithRemoteScope();
helper.fixtures.populateComponents(1);
helper.command.tagAllWithoutBuild();
commonAncestor = helper.command.getHead('comp1');
helper.command.export();
helper.command.createLane('lane-a');
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // A1
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // A2
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // A3
headOnLaneA = helper.command.getHeadOfLane('lane-a', 'comp1');
helper.command.export();
const laneAWorkspace = helper.scopeHelper.cloneWorkspace();
helper.command.switchLocalLane('main');
helper.command.createLane('lane-b');
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // B1
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // B2
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // B3
headOnLaneB = helper.command.getHeadOfLane('lane-b', 'comp1');
helper.command.export();
helper.scopeHelper.getClonedWorkspace(laneAWorkspace);
helper.command.import();
helper.command.mergeLane('lane-b', '--squash --auto-merge-resolve theirs');
mergeSnap = helper.command.getHeadOfLane('lane-a', 'comp1');
});
it('merge snap should have a single parent pointing to lane-a head', () => {
const snap = helper.command.catComponent(`comp1@${mergeSnap}`);
expect(snap.parents).to.have.lengthOf(1);
expect(snap.parents[0]).to.equal(headOnLaneA);
});
it('merge snap should record squash metadata with the dropped lane-b head', () => {
const snap = helper.command.catComponent(`comp1@${mergeSnap}`);
expect(snap).to.have.property('squashed');
const prevParents: string[] = snap.squashed.previousParents || snap.squashed.previousParentsRefs || [];
expect(prevParents).to.include(headOnLaneB);
});
it('bit log should show a clean history without lane-b intermediate snaps', () => {
const log = helper.command.logParsed('comp1');
const hashes = log.map((l: any) => l.hash);
expect(hashes).to.include(commonAncestor);
expect(hashes).to.include(headOnLaneA);
expect(hashes).to.include(mergeSnap);
// lane-b intermediates should not be reachable from lane-a's head chain
expect(hashes).to.not.include(headOnLaneB);
});
it('bit log should not throw', () => {
expect(() => helper.command.logParsed('comp1')).to.not.throw();
});
});
describe('multi scope: lane-a on scope-a, lane-b on scope-b, diverged, --squash', () => {
let scopeB: string;
let scopeBPath: string;
let headOnLaneA: string;
let headOnLaneB: string;
let mergeSnap: string;
let scopeAAfterExport: string;
before(() => {
helper.scopeHelper.setWorkspaceWithRemoteScope();
const newScope = helper.scopeHelper.getNewBareScope();
scopeB = newScope.scopeName;
scopeBPath = newScope.scopePath;
helper.scopeHelper.addRemoteScope(scopeBPath);
helper.scopeHelper.addRemoteScope(scopeBPath, helper.scopes.remotePath);
helper.scopeHelper.addRemoteScope(helper.scopes.remotePath, scopeBPath);
helper.fixtures.populateComponents(1);
helper.command.tagAllWithoutBuild();
helper.command.export();
helper.command.createLane('lane-a');
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // A1
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // A2
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // A3
headOnLaneA = helper.command.getHeadOfLane('lane-a', 'comp1');
helper.command.export();
const laneAWorkspace = helper.scopeHelper.cloneWorkspace();
helper.command.switchLocalLane('main');
helper.command.createLane('lane-b', `--scope ${scopeB} --fork-lane-new-scope`);
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // B1
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // B2
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // B3
headOnLaneB = helper.command.getHeadOfLane('lane-b', 'comp1');
helper.command.export('--fork-lane-new-scope');
helper.scopeHelper.getClonedWorkspace(laneAWorkspace);
helper.command.import();
helper.command.mergeLane(`${scopeB}/lane-b`, '--squash --auto-merge-resolve theirs');
mergeSnap = helper.command.getHeadOfLane('lane-a', 'comp1');
helper.command.export();
scopeAAfterExport = helper.scopeHelper.cloneWorkspace();
});
it('merge snap should have a single parent pointing to lane-a head', () => {
const snap = helper.command.catComponent(`comp1@${mergeSnap}`);
expect(snap.parents).to.have.lengthOf(1);
expect(snap.parents[0]).to.equal(headOnLaneA);
});
it('merge snap squash metadata should record the dropped lane-b head', () => {
const snap = helper.command.catComponent(`comp1@${mergeSnap}`);
expect(snap).to.have.property('squashed');
const prevParents: string[] = snap.squashed.previousParents || snap.squashed.previousParentsRefs || [];
expect(prevParents).to.include(headOnLaneB);
});
it('scope-a should NOT contain lane-b intermediate snaps after export', () => {
// Inspect scope-a's storage: lane-b's snaps should remain on scope-b only.
// catObject against the remote scope path; absence is signalled by throw.
expect(() => helper.command.catObject(headOnLaneB, false, helper.scopes.remotePath)).to.throw();
});
it('scope-a should contain the merge snap', () => {
expect(() => helper.command.catObject(mergeSnap, false, helper.scopes.remotePath)).to.not.throw();
});
it('scope-b should still contain lane-b intermediate snaps', () => {
expect(() => helper.command.catObject(headOnLaneB, false, scopeBPath)).to.not.throw();
});
describe('fresh consumer imports lane-a from scope-a', () => {
before(() => {
helper.scopeHelper.reInitWorkspace();
helper.scopeHelper.addRemoteScope();
helper.scopeHelper.addRemoteScope(scopeBPath);
helper.command.importLane('lane-a', '-x');
});
it('bit log should not throw on the merged component', () => {
expect(() => helper.command.logParsed('comp1')).to.not.throw();
});
it('bit log should show the merge snap and lane-a chain, not lane-b intermediates', () => {
const log = helper.command.logParsed('comp1');
const hashes = log.map((l: any) => l.hash);
expect(hashes).to.include(mergeSnap);
expect(hashes).to.include(headOnLaneA);
expect(hashes).to.not.include(headOnLaneB);
});
it('bit status should not throw', () => {
expect(() => helper.command.status()).to.not.throw();
});
});
describe('re-merge of lane-b after it advances with new snaps', () => {
let headOnLaneBAfter: string;
let secondMergeSnap: string;
before(() => {
// advance lane-b on a separate workspace tied to scope-b
helper.scopeHelper.reInitWorkspace();
helper.scopeHelper.addRemoteScope();
helper.scopeHelper.addRemoteScope(scopeBPath);
helper.command.runCmd(`bit lane import ${scopeB}/lane-b -x`);
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // B4
helper.command.snapAllComponentsWithoutBuild('--unmodified'); // B5
headOnLaneBAfter = helper.command.getHeadOfLane(`${scopeB}/lane-b`, 'comp1');
helper.command.export();
// return to the lane-a workspace and re-merge lane-b
helper.scopeHelper.getClonedWorkspace(scopeAAfterExport);
helper.command.import();
helper.command.mergeLane(`${scopeB}/lane-b`, '--squash --auto-merge-resolve theirs');
secondMergeSnap = helper.command.getHeadOfLane('lane-a', 'comp1');
});
it('second merge snap should have a single parent pointing to the previous merge snap', () => {
const snap = helper.command.catComponent(`comp1@${secondMergeSnap}`);
expect(snap.parents).to.have.lengthOf(1);
expect(snap.parents[0]).to.equal(mergeSnap);
});
it('second merge snap should record the new dropped lane-b head (B5), not B3', () => {
const snap = helper.command.catComponent(`comp1@${secondMergeSnap}`);
expect(snap).to.have.property('squashed');
const prevParents: string[] = snap.squashed.previousParents || snap.squashed.previousParentsRefs || [];
expect(prevParents).to.include(headOnLaneBAfter);
// crucially, should not re-include B3 (already merged previously)
expect(prevParents).to.not.include(headOnLaneB);
});
it('bit log after re-merge should not throw', () => {
expect(() => helper.command.logParsed('comp1')).to.not.throw();
});
it('bit log after re-merge should show two merge snaps in the chain, no lane-b intermediates', () => {
const log = helper.command.logParsed('comp1');
const hashes = log.map((l: any) => l.hash);
expect(hashes).to.include(mergeSnap);
expect(hashes).to.include(secondMergeSnap);
expect(hashes).to.not.include(headOnLaneB);
expect(hashes).to.not.include(headOnLaneBAfter);
});
it('re-merge should export to scope-a without errors', () => {
expect(() => helper.command.export()).to.not.throw();
});
});
});
describe('sanity: diverged merge without --squash still produces a two-parent merge snap', () => {
let headOnLaneA: string;
let headOnLaneB: string;
let mergeSnap: string;
before(() => {
helper.scopeHelper.setWorkspaceWithRemoteScope();
helper.fixtures.populateComponents(1);
helper.command.tagAllWithoutBuild();
helper.command.export();
helper.command.createLane('lane-a');
helper.command.snapAllComponentsWithoutBuild('--unmodified');
helper.command.snapAllComponentsWithoutBuild('--unmodified');
headOnLaneA = helper.command.getHeadOfLane('lane-a', 'comp1');
helper.command.export();
const laneAWorkspace = helper.scopeHelper.cloneWorkspace();
helper.command.switchLocalLane('main');
helper.command.createLane('lane-b');
helper.command.snapAllComponentsWithoutBuild('--unmodified');
helper.command.snapAllComponentsWithoutBuild('--unmodified');
headOnLaneB = helper.command.getHeadOfLane('lane-b', 'comp1');
helper.command.export();
helper.scopeHelper.getClonedWorkspace(laneAWorkspace);
helper.command.import();
helper.command.mergeLane('lane-b', '--auto-merge-resolve theirs');
mergeSnap = helper.command.getHeadOfLane('lane-a', 'comp1');
});
it('merge snap should have two parents (lane-a head and lane-b head)', () => {
const snap = helper.command.catComponent(`comp1@${mergeSnap}`);
expect(snap.parents).to.have.lengthOf(2);
expect(snap.parents).to.include(headOnLaneA);
expect(snap.parents).to.include(headOnLaneB);
});
it('merge snap should NOT have squash metadata', () => {
const snap = helper.command.catComponent(`comp1@${mergeSnap}`);
expect(snap).to.not.have.property('squashed');
});
});
describe('sanity: squash on non-diverged (fast-forward) lane-to-lane merge', () => {
let commonHead: string;
let mergeSnap: string;
before(() => {
helper.scopeHelper.setWorkspaceWithRemoteScope();
helper.fixtures.populateComponents(1);
helper.command.tagAllWithoutBuild();
commonHead = helper.command.getHead('comp1');
helper.command.export();
helper.command.createLane('lane-a');
// lane-a does NOT advance — stays at the common head
helper.command.export();
helper.command.switchLocalLane('main');
helper.command.createLane('lane-b');
helper.command.snapAllComponentsWithoutBuild('--unmodified');
helper.command.snapAllComponentsWithoutBuild('--unmodified');
helper.command.snapAllComponentsWithoutBuild('--unmodified');
helper.command.export();
helper.command.switchLocalLane('lane-a');
helper.command.mergeLane('lane-b', '--squash --auto-merge-resolve theirs');
mergeSnap = helper.command.getHeadOfLane('lane-a', 'comp1');
});
it('squashed snap on lane-a should have a single parent pointing to the common head', () => {
const snap = helper.command.catComponent(`comp1@${mergeSnap}`);
expect(snap.parents).to.have.lengthOf(1);
expect(snap.parents[0]).to.equal(commonHead);
});
it('bit log should not throw', () => {
expect(() => helper.command.logParsed('comp1')).to.not.throw();
});
});
});