Skip to content

Commit b0e781b

Browse files
kptdobeclaude
andauthored
fix: keep audit entries in separate groups when split by a labelled version (#931)
Audit entries on the same day were incorrectly merged into one group even when a labelled version sat between them. Now grouping only applies to consecutive audits with no version boundary in between. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 04febaf commit b0e781b

2 files changed

Lines changed: 59 additions & 17 deletions

File tree

blocks/edit/da-versions/helpers.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@ export function formatVersions(json) {
2020
};
2121
});
2222

23-
// Group everything by date
23+
// Group consecutive audit entries by date, but never across a version boundary
2424
return ungrouped.reduce((acc, entry) => {
25-
// Elevate versions to the top
2625
if (entry.isVersion) {
2726
acc.push(entry);
2827
} else {
29-
// Group audits by date
30-
const notVerSameDate = acc.find(
31-
(accEntry) => !accEntry.isVersion && accEntry.date === entry.date,
32-
);
33-
if (!notVerSameDate) {
34-
acc.push({ date: entry.date, audits: [entry] });
28+
const last = acc[acc.length - 1];
29+
if (last && !last.isVersion && last.date === entry.date) {
30+
last.audits.push(entry);
3531
} else {
36-
notVerSameDate.audits.push(entry);
32+
acc.push({ date: entry.date, audits: [entry] });
3733
}
3834
}
3935
return acc;

test/unit/blocks/edit/da-versions/helpers.test.js

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('Versions helper', () => {
6565
const formatted = formatVersions(versions);
6666

6767
const expected = [{
68+
// Audit AFTER the version (newer, same day)
6869
date: new Date(1715766906908).toLocaleDateString([], DATE_OPTS),
6970
audits: [{
7071
date: new Date(1715766906908).toLocaleDateString([], DATE_OPTS),
@@ -73,14 +74,6 @@ describe('Versions helper', () => {
7374
timestamp: 1715766906908,
7475
path: 'da-aem-boilerplate/blah7.html',
7576
isVersion: false,
76-
},
77-
{
78-
date: new Date(1715766405165).toLocaleDateString([], DATE_OPTS),
79-
time: new Date(1715766405165).toLocaleTimeString([], TIME_OPTS),
80-
users: [{ email: 'joe@acme.com' }],
81-
timestamp: 1715766405165,
82-
path: 'da-aem-boilerplate/blah7.html',
83-
isVersion: false,
8477
}],
8578
}, {
8679
date: new Date(1715766894180).toLocaleDateString([], DATE_OPTS),
@@ -91,6 +84,17 @@ describe('Versions helper', () => {
9184
path: 'da-aem-boilerplate/blah7.html',
9285
label: 'hello',
9386
isVersion: true,
87+
}, {
88+
// Audit BEFORE the version (older, same day — separate group)
89+
date: new Date(1715766405165).toLocaleDateString([], DATE_OPTS),
90+
audits: [{
91+
date: new Date(1715766405165).toLocaleDateString([], DATE_OPTS),
92+
time: new Date(1715766405165).toLocaleTimeString([], TIME_OPTS),
93+
users: [{ email: 'joe@acme.com' }],
94+
timestamp: 1715766405165,
95+
path: 'da-aem-boilerplate/blah7.html',
96+
isVersion: false,
97+
}],
9498
}, {
9599
date: new Date(1715701875589).toLocaleDateString([], DATE_OPTS),
96100
audits: [{
@@ -121,4 +125,46 @@ describe('Versions helper', () => {
121125

122126
expect(formatted).to.deep.equal(expected);
123127
});
128+
129+
it('Does not group audit entries across a labelled version on the same day', () => {
130+
// All three entries are on 2024-05-18 UTC, but the version sits between the two audits:
131+
// ts_after (12:00) | ts_version (11:00, labelled) | ts_before (10:00)
132+
const TS_AFTER = 1716033600000;
133+
const TS_VERSION = 1716030000000;
134+
const TS_BEFORE = 1716026400000;
135+
136+
const versions = [{
137+
users: [{ email: 'after@acme.com' }],
138+
timestamp: TS_AFTER,
139+
path: 'org/repo/doc.html',
140+
}, {
141+
url: '/versionsource/org/v1.html',
142+
users: [{ email: 'tagger@acme.com' }],
143+
timestamp: TS_VERSION,
144+
path: 'org/repo/doc.html',
145+
label: 'v1',
146+
}, {
147+
users: [{ email: 'before@acme.com' }],
148+
timestamp: TS_BEFORE,
149+
path: 'org/repo/doc.html',
150+
}];
151+
152+
const formatted = formatVersions(versions);
153+
154+
expect(formatted).to.have.length(3);
155+
156+
// First block: audit group AFTER the version
157+
expect(formatted[0].isVersion).to.be.undefined;
158+
expect(formatted[0].audits).to.have.length(1);
159+
expect(formatted[0].audits[0].users[0].email).to.equal('after@acme.com');
160+
161+
// Second block: the labelled version
162+
expect(formatted[1].isVersion).to.be.true;
163+
expect(formatted[1].label).to.equal('v1');
164+
165+
// Third block: audit group BEFORE the version (same date, but separate group)
166+
expect(formatted[2].isVersion).to.be.undefined;
167+
expect(formatted[2].audits).to.have.length(1);
168+
expect(formatted[2].audits[0].users[0].email).to.equal('before@acme.com');
169+
});
124170
});

0 commit comments

Comments
 (0)