-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: libnpmpublish will no longer attempt a single automatic retry on 409 responses during publish.
- Loading branch information
1 parent
d2c3712
commit 0a71ebb
Showing
2 changed files
with
9 additions
and
341 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
'use strict' | ||
|
||
const cloneDeep = require('lodash.clonedeep') | ||
const crypto = require('crypto') | ||
const fs = require('fs') | ||
const npa = require('npm-package-arg') | ||
|
@@ -180,266 +179,6 @@ t.test('scoped publish - restricted access', async t => { | |
t.ok(ret, 'publish succeeded') | ||
}) | ||
|
||
t.test('retry after a conflict', async t => { | ||
const { publish } = t.mock('..') | ||
const registry = new MockRegistry({ | ||
tap: t, | ||
registry: opts.registry, | ||
authorization: token, | ||
}) | ||
const REV = '72-47f2986bfd8e8b55068b204588bbf484' | ||
const manifest = { | ||
name: 'libnpmpublish', | ||
version: '1.0.0', | ||
description: 'some stuff', | ||
} | ||
|
||
const basePackument = { | ||
name: 'libnpmpublish', | ||
description: 'some stuff', | ||
access: 'public', | ||
_id: 'libnpmpublish', | ||
'dist-tags': {}, | ||
versions: {}, | ||
_attachments: {}, | ||
} | ||
const currentPackument = cloneDeep({ | ||
...basePackument, | ||
time: { | ||
modified: new Date().toISOString(), | ||
created: new Date().toISOString(), | ||
'1.0.1': new Date().toISOString(), | ||
}, | ||
'dist-tags': { latest: '1.0.1' }, | ||
versions: { | ||
'1.0.1': { | ||
_id: '[email protected]', | ||
_nodeVersion: process.versions.node, | ||
_npmVersion: opts.npmVersion, | ||
name: 'libnpmpublish', | ||
version: '1.0.1', | ||
description: 'some stuff', | ||
dist: { | ||
shasum, | ||
integrity: integrity.toString(), | ||
tarball: 'http://mock.reg/libnpmpublish/-/libnpmpublish-1.0.1.tgz', | ||
}, | ||
}, | ||
}, | ||
_attachments: { | ||
'libnpmpublish-1.0.1.tgz': { | ||
content_type: 'application/octet-stream', | ||
data: tarData.toString('base64'), | ||
length: tarData.length, | ||
}, | ||
}, | ||
}) | ||
const newPackument = cloneDeep({ | ||
...basePackument, | ||
'dist-tags': { latest: '1.0.0' }, | ||
versions: { | ||
'1.0.0': { | ||
_id: '[email protected]', | ||
_nodeVersion: process.versions.node, | ||
_npmVersion: opts.npmVersion, | ||
name: 'libnpmpublish', | ||
version: '1.0.0', | ||
description: 'some stuff', | ||
dist: { | ||
shasum, | ||
integrity: integrity.toString(), | ||
tarball: 'http://mock.reg/libnpmpublish/-/libnpmpublish-1.0.0.tgz', | ||
}, | ||
}, | ||
}, | ||
_attachments: { | ||
'libnpmpublish-1.0.0.tgz': { | ||
content_type: 'application/octet-stream', | ||
data: tarData.toString('base64'), | ||
length: tarData.length, | ||
}, | ||
}, | ||
}) | ||
const mergedPackument = cloneDeep({ | ||
...basePackument, | ||
time: currentPackument.time, | ||
'dist-tags': { latest: '1.0.0' }, | ||
versions: { ...currentPackument.versions, ...newPackument.versions }, | ||
_attachments: { ...currentPackument._attachments, ...newPackument._attachments }, | ||
}) | ||
|
||
registry.nock.put('/libnpmpublish', body => { | ||
t.notOk(body._rev, 'no _rev in initial post') | ||
t.same(body, newPackument, 'got conflicting packument') | ||
return true | ||
}).reply(409, { error: 'gimme _rev plz' }) | ||
|
||
registry.nock.get('/libnpmpublish?write=true').reply(200, { | ||
_rev: REV, | ||
...currentPackument, | ||
}) | ||
|
||
registry.nock.put('/libnpmpublish', body => { | ||
t.same(body, { | ||
_rev: REV, | ||
...mergedPackument, | ||
}, 'posted packument includes _rev and a merged version') | ||
return true | ||
}).reply(201, {}) | ||
|
||
const ret = await publish(manifest, tarData, opts) | ||
t.ok(ret, 'publish succeeded') | ||
}) | ||
|
||
t.test('retry after a conflict -- no versions on remote', async t => { | ||
const { publish } = t.mock('..') | ||
const registry = new MockRegistry({ | ||
tap: t, | ||
registry: opts.registry, | ||
authorization: token, | ||
}) | ||
const REV = '72-47f2986bfd8e8b55068b204588bbf484' | ||
const manifest = { | ||
name: 'libnpmpublish', | ||
version: '1.0.0', | ||
description: 'some stuff', | ||
} | ||
|
||
const basePackument = { | ||
name: 'libnpmpublish', | ||
description: 'some stuff', | ||
access: 'public', | ||
_id: 'libnpmpublish', | ||
} | ||
const currentPackument = { ...basePackument } | ||
const newPackument = cloneDeep({ | ||
...basePackument, | ||
'dist-tags': { latest: '1.0.0' }, | ||
versions: { | ||
'1.0.0': { | ||
_id: '[email protected]', | ||
_nodeVersion: process.versions.node, | ||
_npmVersion: opts.npmVersion, | ||
name: 'libnpmpublish', | ||
version: '1.0.0', | ||
description: 'some stuff', | ||
dist: { | ||
shasum, | ||
integrity: integrity.toString(), | ||
tarball: 'http://mock.reg/libnpmpublish/-/libnpmpublish-1.0.0.tgz', | ||
}, | ||
}, | ||
}, | ||
_attachments: { | ||
'libnpmpublish-1.0.0.tgz': { | ||
content_type: 'application/octet-stream', | ||
data: tarData.toString('base64'), | ||
length: tarData.length, | ||
}, | ||
}, | ||
}) | ||
const mergedPackument = cloneDeep({ | ||
...basePackument, | ||
'dist-tags': { latest: '1.0.0' }, | ||
versions: { ...newPackument.versions }, | ||
_attachments: { ...newPackument._attachments }, | ||
}) | ||
|
||
registry.nock.put('/libnpmpublish', body => { | ||
t.notOk(body._rev, 'no _rev in initial post') | ||
t.same(body, newPackument, 'got conflicting packument') | ||
return true | ||
}).reply(409, { error: 'gimme _rev plz' }) | ||
|
||
registry.nock.get('/libnpmpublish?write=true').reply(200, { | ||
_rev: REV, | ||
...currentPackument, | ||
}) | ||
|
||
registry.nock.put('/libnpmpublish', body => { | ||
t.same(body, { | ||
_rev: REV, | ||
...mergedPackument, | ||
}, 'posted packument includes _rev and a merged version') | ||
return true | ||
}).reply(201, {}) | ||
|
||
const ret = await publish(manifest, tarData, opts) | ||
|
||
t.ok(ret, 'publish succeeded') | ||
}) | ||
|
||
t.test('version conflict', async t => { | ||
const { publish } = t.mock('..') | ||
const registry = new MockRegistry({ | ||
tap: t, | ||
registry: opts.registry, | ||
authorization: token, | ||
}) | ||
const REV = '72-47f2986bfd8e8b55068b204588bbf484' | ||
const manifest = { | ||
name: 'libnpmpublish', | ||
version: '1.0.0', | ||
description: 'some stuff', | ||
} | ||
|
||
const basePackument = { | ||
name: 'libnpmpublish', | ||
description: 'some stuff', | ||
access: 'public', | ||
_id: 'libnpmpublish', | ||
'dist-tags': {}, | ||
versions: {}, | ||
_attachments: {}, | ||
} | ||
const newPackument = cloneDeep(Object.assign({}, basePackument, { | ||
'dist-tags': { latest: '1.0.0' }, | ||
versions: { | ||
'1.0.0': { | ||
_id: '[email protected]', | ||
_nodeVersion: process.versions.node, | ||
_npmVersion: '6.13.7', | ||
name: 'libnpmpublish', | ||
version: '1.0.0', | ||
description: 'some stuff', | ||
dist: { | ||
shasum, | ||
integrity: integrity.toString(), | ||
tarball: 'http://mock.reg/libnpmpublish/-/libnpmpublish-1.0.0.tgz', | ||
}, | ||
}, | ||
}, | ||
_attachments: { | ||
'libnpmpublish-1.0.0.tgz': { | ||
content_type: 'application/octet-stream', | ||
data: tarData.toString('base64'), | ||
length: tarData.length, | ||
}, | ||
}, | ||
})) | ||
|
||
registry.nock.put('/libnpmpublish', body => { | ||
t.notOk(body._rev, 'no _rev in initial post') | ||
t.same(body, newPackument, 'got conflicting packument') | ||
return true | ||
}).reply(409, { error: 'gimme _rev plz' }) | ||
|
||
registry.nock.get('/libnpmpublish?write=true').reply(200, { | ||
_rev: REV, | ||
...newPackument, | ||
}) | ||
|
||
try { | ||
await publish(manifest, tarData, { | ||
...opts, | ||
npmVersion: '6.13.7', | ||
token: 'deadbeef', | ||
}) | ||
} catch (err) { | ||
t.equal(err.code, 'EPUBLISHCONFLICT', 'got publish conflict code') | ||
} | ||
}) | ||
|
||
t.test('refuse if package marked private', async t => { | ||
const { publish } = t.mock('..') | ||
const registry = new MockRegistry({ | ||
|