Skip to content

Commit e6f0071

Browse files
authored
Merge pull request #1409 from qtomlinson/qt/add_logging
Add logging to harvest filter initialization
2 parents aae1a0b + a1368b2 commit e6f0071

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

providers/harvest/throttling/listBasedFilter.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class ListBasedFilter {
2525
// Store as a Set for quick type lookup
2626
this._targetTypes = new Set(versionlessCoordinates.map(c => c.type))
2727
this._blacklist = new Set(versionlessCoordinates.map(c => c.toString()))
28+
this.logger.info('ListBasedFilter initialized', {
29+
blockedCount: this._blacklist.size,
30+
blockedCoordinates: [...this._blacklist].sort(),
31+
targetTypes: [...this._targetTypes].sort()
32+
})
2833
}
2934

3035
/**

test/providers/harvest/throttling/listBasedFilterConfigTest.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ const EntityCoordinates = require('../../../../lib/entityCoordinates')
66
const proxyquire = require('proxyquire')
77

88
describe('ListBasedFilterConfig', () => {
9-
// Stub the logger used by the module to avoid initialization issues
10-
const factory = proxyquire('../../../../providers/harvest/throttling/listBasedFilterConfig', {
11-
'../../logging/logger': () => ({
12-
debug: () => {},
13-
error: () => {},
14-
warn: () => {}
9+
// Helper to create a factory with shared logger stub and optional overrides
10+
const makeFactory = overrides =>
11+
proxyquire('../../../../providers/harvest/throttling/listBasedFilterConfig', {
12+
'../../logging/logger': () => ({
13+
info: () => {},
14+
debug: () => {},
15+
error: () => {},
16+
warn: () => {}
17+
}),
18+
...(overrides || {})
1519
})
16-
})
20+
21+
// Stub the logger used by the module to avoid initialization issues
22+
const factory = makeFactory()
1723

1824
function createCoord(coordString) {
1925
return EntityCoordinates.fromString(coordString)
@@ -85,14 +91,6 @@ describe('ListBasedFilterConfig', () => {
8591

8692
describe('with mixed-type array', () => {
8793
it('filters out non-string entries and blocks only string coordinates', () => {
88-
const factory = proxyquire('../../../../providers/harvest/throttling/listBasedFilterConfig', {
89-
'../../logging/logger': () => ({
90-
debug: () => {},
91-
error: () => {},
92-
warn: () => {}
93-
})
94-
})
95-
9694
const mixed = JSON.stringify(['npm/npmjs/-/left-pad', 123, null, {}, 'git/github/org/name'])
9795
const filter = factory(mixed)
9896

@@ -104,15 +102,10 @@ describe('ListBasedFilterConfig', () => {
104102

105103
describe('environment config', () => {
106104
it('reads HARVEST_THROTTLER_BLACKLIST from config and blocks', () => {
107-
const factoryFromEnv = proxyquire('../../../../providers/harvest/throttling/listBasedFilterConfig', {
105+
const factoryFromEnv = makeFactory({
108106
'painless-config': {
109107
get: key => (key === 'HARVEST_THROTTLER_BLACKLIST' ? JSON.stringify(['git/github/org/name']) : undefined)
110-
},
111-
'../../logging/logger': () => ({
112-
debug: () => {},
113-
error: () => {},
114-
warn: () => {}
115-
})
108+
}
116109
})
117110

118111
const filter = factoryFromEnv()

test/providers/harvest/throttling/listBasedFilterTest.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const EntityCoordinates = require('../../../../lib/entityCoordinates')
77

88
describe('ListBasedFilter', () => {
99
const logger = {
10+
info: () => {},
1011
debug: () => {},
1112
error: () => {},
1213
warn: () => {}
@@ -116,6 +117,7 @@ describe('ListBasedFilter', () => {
116117
it('should log warnings for invalid coordinates', () => {
117118
const warnings = []
118119
const mockLogger = {
120+
info: () => {},
119121
debug: () => {},
120122
error: () => {},
121123
warn: msg => warnings.push(msg)

test/routes/harvest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const utils = require('../../lib/utils')
1111

1212
// Shared noop logger for tests
1313
const logger = {
14+
info: () => {},
1415
debug: () => {},
1516
error: () => {},
1617
warn: () => {}

0 commit comments

Comments
 (0)