Skip to content

Commit 8f812c5

Browse files
committed
refactor: wip
1 parent e20e804 commit 8f812c5

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

packages/utils/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ export {
114114
settlePromise,
115115
} from './lib/promises.js';
116116
export { generateRandomId } from './lib/random.js';
117-
// export { profiler } from './lib/profiler/profiler.js'; // Disabled - requires WAL functionality
118117
export {
119118
CODE_PUSHUP_DOMAIN,
120119
CODE_PUSHUP_UNICODE_LOGO,

packages/utils/src/lib/performance-observer.unit.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('PerformanceObserverSink', () => {
2929
options = {
3030
sink,
3131
encode,
32-
// we test buffered behavior separately
32+
3333
flushThreshold: 1,
3434
};
3535

@@ -51,24 +51,21 @@ describe('PerformanceObserverSink', () => {
5151
}),
5252
).not.toThrow();
5353
expect(MockPerformanceObserver.instances).toHaveLength(0);
54-
// Instance creation covers the default flushThreshold assignment
5554
});
5655

5756
it('automatically flushes when pendingCount reaches flushThreshold', () => {
5857
const observer = new PerformanceObserverSink({
5958
sink,
6059
encode,
61-
flushThreshold: 2, // Set threshold to 2
60+
flushThreshold: 2,
6261
});
6362
observer.subscribe();
6463

6564
const mockObserver = MockPerformanceObserver.lastInstance();
6665

67-
// Emit 1 entry - should not trigger flush yet (pendingCount = 1 < 2)
6866
mockObserver?.emitMark('first-mark');
6967
expect(sink.getWrittenItems()).toStrictEqual([]);
7068

71-
// Emit 1 more entry - should trigger flush (pendingCount = 2 >= 2)
7269
mockObserver?.emitMark('second-mark');
7370
expect(sink.getWrittenItems()).toStrictEqual([
7471
'first-mark:mark',
@@ -143,7 +140,7 @@ describe('PerformanceObserverSink', () => {
143140
it('internal PerformanceObserver should process observed entries', () => {
144141
const observer = new PerformanceObserverSink({
145142
...options,
146-
flushThreshold: 20, // Disable automatic flushing for this test
143+
flushThreshold: 20,
147144
});
148145
observer.subscribe();
149146

@@ -318,7 +315,6 @@ describe('PerformanceObserverSink', () => {
318315
});
319316

320317
it('accepts custom sinks with append method', () => {
321-
// Create a simple in-memory sink that just collects items
322318
const collectedItems: string[] = [];
323319
const customSink = {
324320
append: (item: string) => collectedItems.push(item),

packages/utils/src/lib/wal.unit.test.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('createTolerantCodec', () => {
5151
},
5252
});
5353
expect(c.decode(c.encode(42))).toBe(42);
54-
// Invalid decode should return InvalidEntry, and encoding that should return the raw value
54+
5555
const invalid = c.decode('x');
5656
expect(invalid).toStrictEqual({ __invalid: true, raw: 'x' });
5757
expect(c.encode(invalid)).toBe('x');
@@ -188,11 +188,9 @@ describe('WriteAheadLogFile', () => {
188188
const w = wal('/test/a.log');
189189
expect(w.isClosed()).toBe(true);
190190

191-
// First open should open the file
192191
w.open();
193192
expect(w.isClosed()).toBe(false);
194193

195-
// Subsequent opens should be no-ops
196194
w.open();
197195
expect(w.isClosed()).toBe(false);
198196
w.open();
@@ -221,7 +219,6 @@ describe('WriteAheadLogFile', () => {
221219
});
222220

223221
it('returns empty result when file does not exist', () => {
224-
// File '/test/nonexistent.log' does not exist
225222
const w = wal('/test/nonexistent.log');
226223
const result = w.recover();
227224

@@ -236,7 +233,7 @@ describe('WriteAheadLogFile', () => {
236233
vol.mkdirSync('/test', { recursive: true });
237234
write('/test/a.log', 'line1\nline2\n');
238235
const w = wal('/test/a.log');
239-
// Profiler WAL can recover without opening - it reads the file directly
236+
240237
const result = w.recover();
241238
expect(result.records).toEqual(['line1', 'line2']);
242239
expect(result.errors).toEqual([]);
@@ -292,7 +289,6 @@ describe('WriteAheadLogFile', () => {
292289
},
293290
});
294291

295-
// With tolerant codec, repack should succeed and preserve all entries (valid and invalid)
296292
wal('/test/a.log', tolerantCodec).repack();
297293
expect(read('/test/a.log')).toBe('ok\nbad\n');
298294
});
@@ -309,7 +305,6 @@ describe('WriteAheadLogFile', () => {
309305
const content = 'good\nbad\ngood\n';
310306
const result = recoverFromContent(content, failingCodec.decode);
311307

312-
// Should have decode errors
313308
expect(result.errors).toHaveLength(1);
314309
expect(result.errors[0].error.message).toBe('Bad record during recovery');
315310
expect(result.records).toEqual(['good', 'good']);
@@ -390,17 +385,14 @@ describe('stringCodec', () => {
390385
});
391386

392387
it('should maintain type safety with generics', () => {
393-
// Test with string type
394388
const stringCodecInstance = stringCodec<string>();
395389
const str: string = stringCodecInstance.decode('test');
396390
expect(typeof str).toBe('string');
397391

398-
// Test with object type
399392
const objectCodecInstance = stringCodec<{ id: number; name: string }>();
400393
const obj = objectCodecInstance.decode('{"id":1,"name":"test"}');
401394
expect(obj).toEqual({ id: 1, name: 'test' });
402395

403-
// Test with union type
404396
const unionCodecInstance = stringCodec<string | number[]>();
405397
expect(unionCodecInstance.decode('string')).toBe('string');
406398
expect(unionCodecInstance.decode('[1,2,3]')).toEqual([1, 2, 3]);
@@ -474,7 +466,6 @@ describe('getShardedGroupId', () => {
474466
const originalTimeOrigin = performance.timeOrigin;
475467

476468
afterEach(() => {
477-
// Restore original timeOrigin
478469
Object.defineProperty(performance, 'timeOrigin', {
479470
value: originalTimeOrigin,
480471
writable: true,
@@ -549,6 +540,6 @@ describe('getShardedGroupId', () => {
549540

550541
const result = getShardedGroupId();
551542

552-
expect(result).toBe('-124'); // Math.floor(-123.456) = -124
543+
expect(result).toBe('-124');
553544
});
554545
});

0 commit comments

Comments
 (0)