Skip to content

Commit 14e6390

Browse files
committed
refactor: wip
1 parent f8f2847 commit 14e6390

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

packages/utils/src/lib/profiler/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ export const SHARDED_WAL_COORDINATOR_ID_ENV_VAR =
3131
* Used as the base name for sharded WAL files (e.g., "trace" in "trace.json").
3232
*/
3333
export const PROFILER_PERSIST_BASENAME = 'trace';
34+
35+
/**
36+
* Default base name for WAL files.
37+
* Used as the base name for sharded WAL files (e.g., "trace" in "trace.json").
38+
*/
39+
export const PROFILER_MEASURE_NAME = 'CP_PROFILER_MEASURE_NAME';

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import { vol } from 'memfs';
22
import { beforeEach, describe, expect, it } from 'vitest';
33
import { MEMFS_VOLUME, osAgnosticPath } from '@code-pushup/test-utils';
44
import { getUniqueInstanceId } from './process-id.js';
5-
import { SHARDED_WAL_COORDINATOR_ID_ENV_VAR } from './profiler/constants.js';
5+
import {
6+
PROFILER_MEASURE_NAME,
7+
SHARDED_WAL_COORDINATOR_ID_ENV_VAR,
8+
} from './profiler/constants.js';
69
import { ShardedWal } from './wal-sharded.js';
710
import {
811
type WalFormat,
@@ -43,7 +46,7 @@ describe('ShardedWal', () => {
4346
delete process.env[SHARDED_WAL_COORDINATOR_ID_ENV_VAR];
4447
// Clear measure name env var to avoid test pollution
4548
// eslint-disable-next-line functional/immutable-data
46-
delete process.env['CP_PROFILER_MEASURE_NAME'];
49+
delete process.env[PROFILER_MEASURE_NAME];
4750
});
4851

4952
describe('initialization', () => {
@@ -60,9 +63,9 @@ describe('ShardedWal', () => {
6063

6164
it('should use groupId from env var when measureNameEnvVar is set', () => {
6265
// eslint-disable-next-line functional/immutable-data
63-
process.env['CP_PROFILER_MEASURE_NAME'] = 'from-env';
66+
process.env[PROFILER_MEASURE_NAME] = 'from-env';
6467
const sw = getShardedWal({
65-
measureNameEnvVar: 'CP_PROFILER_MEASURE_NAME',
68+
measureNameEnvVar: PROFILER_MEASURE_NAME,
6669
});
6770
expect(sw.groupId).toBe('from-env');
6871
expect(process.env.CP_PROFILER_MEASURE_NAME).toBe('from-env');
@@ -72,7 +75,7 @@ describe('ShardedWal', () => {
7275
// eslint-disable-next-line functional/immutable-data
7376
delete process.env.CP_PROFILER_MEASURE_NAME;
7477
const sw = getShardedWal({
75-
measureNameEnvVar: 'CP_PROFILER_MEASURE_NAME',
78+
measureNameEnvVar: PROFILER_MEASURE_NAME,
7679
});
7780
expect(process.env.CP_PROFILER_MEASURE_NAME).toBe(sw.groupId);
7881
});
@@ -136,7 +139,7 @@ describe('ShardedWal', () => {
136139
process.env.CP_PROFILER_MEASURE_NAME = '../malicious';
137140
expect(() =>
138141
getShardedWal({
139-
measureNameEnvVar: 'CP_PROFILER_MEASURE_NAME',
142+
measureNameEnvVar: PROFILER_MEASURE_NAME,
140143
}),
141144
).toThrow('groupId cannot contain path separators');
142145
});

0 commit comments

Comments
 (0)