🔧 Chore Description
log-viewer has five functions called createEvent, with five different signatures, across
252 call sites. One of them is the shared helper added in #1069.
| file |
line |
signature |
calls |
src/__tests__/helpers/events.ts |
49 |
({ text, self, total, … }) |
shared, 4 files |
features/call-tree/utils/__tests__/ExecutionHighlights.test.ts |
19 |
({ text, type, category, namespace, self, total, timestamp, exitStamp, parent, isTruncated }) |
56 |
features/timeline/__tests__/event-index.test.ts |
24 |
(timestamp, duration, children?) |
59 |
features/timeline/__tests__/tooltip.test.ts |
40 |
(timestamp, duration, type?, category?) |
54 |
features/timeline/optimised/__tests__/TemporalSegmentTree.test.ts |
26 |
(timestamp, duration, category, children?) |
48 |
features/timeline/optimised/__tests__/RectangleCache.bucket.test.ts |
25 |
byte-identical to the row above |
35 |
The cost is the name, more than the duplication. Someone in a timeline suite reads
createEvent(0, 100), greps for it, finds helpers/events.ts, and is reading the wrong
function. Only one function in log-viewer should carry that name.
Suggested shape
Three pieces, in value order. They can land separately.
-
Fold ExecutionHighlights.test.ts:19 into the shared helper. It is the shared helper plus
three fields — same options-object shape, same 'METHOD_ENTRY' / 'default' defaults, same
parent.children.push. It differs only by category, isTruncated and eventIndex. Add those
three to EventOptions, keeping eventIndex opt-in and undefaulted for the reason already
recorded at helpers/events.ts:45-48, then delete the local.
-
TemporalSegmentTree.test.ts and RectangleCache.bucket.test.ts are copies of each other.
Their createEvent, their createViewport and their getAllBuckets are all duplicated between
two sibling files in one directory. One module beside them covers all three.
-
event-index.test.ts and tooltip.test.ts are the timeline flavour — positional
(timestamp, duration, …), synthesising exitStamp and text. 113 calls. This wants its own
helper rather than folding into helpers/events.ts: the two serve different passes and the
field sets barely overlap.
Related, smaller
ev is six different functions across 99 call sites: core/log/__tests__/keyPathIds.test.ts:11,
components/__tests__/scopedCallTree.test.ts:17, components/__tests__/locatedRow.test.ts:51,
features/call-tree/utils/__tests__/bucketRows.test.ts:10,
components/__tests__/categoryTime.test.ts:20, and the exported one in
components/__tests__/fixtures/logEvents.ts:21. Only locatedRow and bucketRows are the same
builder (one optional argument apart) and worth merging; the rest want distinct names.
components/__tests__/limitsTestUtils.ts and sectionTestUtils.ts are each imported by suites
in other trees, so they belong in src/__tests__/helpers/ rather than under components/.
- The six shared helpers use four naming verbs between them (
create*, *Of, make*, verb-noun).
Worth settling on one rule and writing it down; makeViewport is the outlier.
🔧 Chore Description
log-viewerhas five functions calledcreateEvent, with five different signatures, across252 call sites. One of them is the shared helper added in #1069.
src/__tests__/helpers/events.ts({ text, self, total, … })features/call-tree/utils/__tests__/ExecutionHighlights.test.ts({ text, type, category, namespace, self, total, timestamp, exitStamp, parent, isTruncated })features/timeline/__tests__/event-index.test.ts(timestamp, duration, children?)features/timeline/__tests__/tooltip.test.ts(timestamp, duration, type?, category?)features/timeline/optimised/__tests__/TemporalSegmentTree.test.ts(timestamp, duration, category, children?)features/timeline/optimised/__tests__/RectangleCache.bucket.test.tsThe cost is the name, more than the duplication. Someone in a timeline suite reads
createEvent(0, 100), greps for it, findshelpers/events.ts, and is reading the wrongfunction. Only one function in
log-viewershould carry that name.Suggested shape
Three pieces, in value order. They can land separately.
Fold
ExecutionHighlights.test.ts:19into the shared helper. It is the shared helper plusthree fields — same options-object shape, same
'METHOD_ENTRY'/'default'defaults, sameparent.children.push. It differs only bycategory,isTruncatedandeventIndex. Add thosethree to
EventOptions, keepingeventIndexopt-in and undefaulted for the reason alreadyrecorded at
helpers/events.ts:45-48, then delete the local.TemporalSegmentTree.test.tsandRectangleCache.bucket.test.tsare copies of each other.Their
createEvent, theircreateViewportand theirgetAllBucketsare all duplicated betweentwo sibling files in one directory. One module beside them covers all three.
event-index.test.tsandtooltip.test.tsare the timeline flavour — positional(timestamp, duration, …), synthesisingexitStampandtext. 113 calls. This wants its ownhelper rather than folding into
helpers/events.ts: the two serve different passes and thefield sets barely overlap.
Related, smaller
evis six different functions across 99 call sites:core/log/__tests__/keyPathIds.test.ts:11,components/__tests__/scopedCallTree.test.ts:17,components/__tests__/locatedRow.test.ts:51,features/call-tree/utils/__tests__/bucketRows.test.ts:10,components/__tests__/categoryTime.test.ts:20, and the exported one incomponents/__tests__/fixtures/logEvents.ts:21. OnlylocatedRowandbucketRowsare the samebuilder (one optional argument apart) and worth merging; the rest want distinct names.
components/__tests__/limitsTestUtils.tsandsectionTestUtils.tsare each imported by suitesin other trees, so they belong in
src/__tests__/helpers/rather than undercomponents/.create*,*Of,make*, verb-noun).Worth settling on one rule and writing it down;
makeViewportis the outlier.