Skip to content

fix: accept Graphsync measurements without HEAD status #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,14 @@ export const assertValidMeasurement = measurement => {
assert(measurement.end_at >= measurement.first_byte_at, 'end_at must be greater than or equal to first_byte_at')
assert(measurement.first_byte_at >= measurement.start_at, 'first_byte_at must be greater than or equal to start_at')

assert.strictEqual(typeof measurement.head_status_code, 'number', '`head_status_code` must be a number')
if (measurement.protocol === 'http') {
assert.strictEqual(typeof measurement.head_status_code, 'number', '`head_status_code` must be a number')
} else {
assert(
measurement.head_status_code === undefined || measurement.head_status_code === null,
'`head_status_code` must be undefined or null for non-HTTP retrievals'
)
}
}
}

Expand Down
29 changes: 29 additions & 0 deletions test/preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,19 +314,48 @@ describe('assertValidMeasurement', () => {
assert.throws(
() => assertValidMeasurement({
...VALID_MEASUREMENT,
protocol: 'http',
head_status_code: null
}),
/`head_status_code` must be a number/
)
assert.throws(
() => assertValidMeasurement({
...VALID_MEASUREMENT,
protocol: 'http',
head_status_code: /** @type {any} */ ('200')
}),
/`head_status_code` must be a number/
)
})

it('accepts Graphsync measurements with OK retrieval result and head_status_code is null', () => {
assertValidMeasurement({
...VALID_MEASUREMENT,
protocol: 'graphsync',
head_status_code: null

})
})

it('accepts Graphsync measurements with OK retrieval result and head_status_code is undefined', () => {
assertValidMeasurement({
...VALID_MEASUREMENT,
protocol: 'graphsync',
head_status_code: undefined
})
})

it('rejects Graphsync measurements with head_status_code not null/undefined ', () => {
assert.throws(
() => assertValidMeasurement({
...VALID_MEASUREMENT,
head_status_code: /** @type {any} */ ('200')
}),
/`head_status_code` must be undefined/
)
})

it('should throw an error for invalid start_at', () => {
const measurement = {
...VALID_MEASUREMENT,
Expand Down