Skip to content

Commit 4eaabc4

Browse files
fix(shared): order native stacks from the best saved snapshot
1 parent a475c78 commit 4eaabc4

1 file changed

Lines changed: 24 additions & 55 deletions

File tree

‎packages/shared/src/threadPullRequests.test.ts‎

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,8 @@ describe("resolveThreadPullRequestChains", () => {
315315
});
316316
});
317317

318-
it.each(
319-
[
320-
[18, 20, 83, 84],
321-
[83, 18, 20, 84],
322-
].map((numbers) => ({ numbers })),
323-
)("orders inconsistent native snapshots with stored links $numbers", ({ numbers }) => {
324-
const links = numbers.map((number) =>
318+
it("uses a later complete native snapshot for layer order and the current pull request", () => {
319+
const links = [18, 20, 83, 84].map((number) =>
325320
link(number, {
326321
linkedAt: "2026-01-01T00:00:00.000Z",
327322
snapshot: snapshot(),
@@ -338,55 +333,27 @@ describe("resolveThreadPullRequestChains", () => {
338333
},
339334
}),
340335
);
341-
const chains = resolveThreadPullRequestChains(links);
342336
expect
343-
.soft(chains.map((chain) => chain.layers.map((layer) => layer.number)))
337+
.soft(
338+
resolveThreadPullRequestChains(links).map((chain) =>
339+
chain.layers.map((layer) => layer.number),
340+
),
341+
)
344342
.toEqual([[18, 20, 83, 84]]);
345-
expect(chains[0]?.depths).toEqual([0, 1, 2, 3]);
346-
const current = resolveThreadCurrentPullRequest(links);
347-
expect(current).toMatchObject({ kind: "stack", top: { number: 84 } });
348-
expect(current?.kind === "stack" ? current.open.map((entry) => entry.number) : null).toEqual([
349-
84, 83, 20, 18,
350-
]);
351-
expect(links.map((entry) => entry.number)).toEqual(numbers);
343+
expect(resolveThreadCurrentPullRequest(links)).toMatchObject({
344+
kind: "stack",
345+
top: { number: 84 },
346+
open: [{ number: 84 }, { number: 83 }, { number: 20 }, { number: 18 }],
347+
});
352348
});
353349

354-
it.each([
355-
{
356-
snapshots: [
357-
[9, 8, 7, 3],
358-
[1, 2],
359-
[1, 2],
360-
],
361-
expected: [1, 2, 3],
362-
},
363-
{
364-
snapshots: [
365-
[2, 1],
366-
[9, 1, 2],
367-
[9, 1, 2],
368-
],
369-
expected: [1, 2, 3],
370-
},
371-
{
372-
snapshots: [
373-
[2, 1],
374-
[1, 2],
375-
[1, 2],
376-
],
377-
expected: [2, 1, 3],
378-
},
379-
{
380-
snapshots: [
381-
[3, 2],
382-
[3, 2],
383-
[3, 2],
384-
[3, 2],
385-
],
386-
expected: [3, 2, 1, 4],
387-
},
388-
])("orders partial native snapshots $snapshots as $expected", ({ snapshots, expected }) => {
389-
const links = snapshots.map((numbers, index) =>
350+
it("uses the earliest longest partial snapshot and appends missing members in stored order", () => {
351+
const links = [
352+
[3, 2],
353+
[9, 2, 3],
354+
[9, 3, 2],
355+
[9, 3, 2],
356+
].map((numbers, index) =>
390357
link(index + 1, {
391358
stack: {
392359
kind: "native",
@@ -398,9 +365,11 @@ describe("resolveThreadPullRequestChains", () => {
398365
},
399366
}),
400367
);
401-
expect(resolveThreadPullRequestChains(links)[0]?.layers.map((layer) => layer.number)).toEqual(
402-
expected,
403-
);
368+
expect(
369+
resolveThreadPullRequestChains(links).map((chain) =>
370+
chain.layers.map((layer) => layer.number),
371+
),
372+
).toEqual([[2, 3, 1, 4]]);
404373
});
405374

406375
it("uses the native stack order when the host provides one", () => {

0 commit comments

Comments
 (0)