amalgm 0.1.241 → 0.1.242
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const test = require('node:test');
|
|
4
4
|
const assert = require('node:assert/strict');
|
|
5
|
+
const crypto = require('crypto');
|
|
5
6
|
const fs = require('fs');
|
|
6
7
|
const os = require('os');
|
|
7
8
|
const path = require('path');
|
|
@@ -284,3 +285,44 @@ test('failed uploads yield the bulk lane to later durable objects', () => {
|
|
|
284
285
|
acknowledgeUpload(third.resourceId, third.sha256);
|
|
285
286
|
assert.equal(claimUpload(), null);
|
|
286
287
|
});
|
|
288
|
+
|
|
289
|
+
test('legacy shared-resource uploads can terminate without starving current projects', () => {
|
|
290
|
+
const legacyResourceId = 'shr_legacyobjectqueue0001';
|
|
291
|
+
const legacyBytes = Buffer.from('stale object from a legacy rail');
|
|
292
|
+
const legacyDigest = crypto.createHash('sha256').update(legacyBytes).digest('hex');
|
|
293
|
+
const objectRoot = path.join(process.env.AMALGM_DIR, 'state', 'repo-objects');
|
|
294
|
+
const manifests = path.join(objectRoot, 'manifests');
|
|
295
|
+
const chunks = path.join(objectRoot, 'chunks');
|
|
296
|
+
fs.writeFileSync(path.join(chunks, `${legacyDigest}.bin`), legacyBytes);
|
|
297
|
+
fs.writeFileSync(path.join(manifests, '000-legacy-shared-resource.json'), JSON.stringify({
|
|
298
|
+
contract: 'git-bundle-chunks@2',
|
|
299
|
+
resourceId: legacyResourceId,
|
|
300
|
+
repoKey: 'legacy-repo',
|
|
301
|
+
oid: '1'.repeat(40),
|
|
302
|
+
ref: `refs/amalgm/exports/${'1'.repeat(40)}`,
|
|
303
|
+
checksum: locatorChecksum([{ sha256: legacyDigest, bytes: legacyBytes.length }]),
|
|
304
|
+
bytes: legacyBytes.length,
|
|
305
|
+
chunks: [{ sha256: legacyDigest, bytes: legacyBytes.length, uploaded: false }],
|
|
306
|
+
createdAt: new Date().toISOString(),
|
|
307
|
+
}));
|
|
308
|
+
|
|
309
|
+
assert.equal(
|
|
310
|
+
publishPayload('current-after-legacy', Buffer.from('current project object'), REPO_KEY).kind,
|
|
311
|
+
'pending',
|
|
312
|
+
);
|
|
313
|
+
const legacy = claimUpload();
|
|
314
|
+
assert.equal(legacy.resourceId, legacyResourceId);
|
|
315
|
+
assert.equal(legacy.sha256, legacyDigest);
|
|
316
|
+
const terminal = failUpload(legacy.resourceId, legacy.sha256, {
|
|
317
|
+
retryable: false,
|
|
318
|
+
code: 'shared_resource_read_forbidden',
|
|
319
|
+
message: 'the legacy rail is no longer readable',
|
|
320
|
+
});
|
|
321
|
+
assert.equal(terminal.changed, true);
|
|
322
|
+
assert.equal(terminal.terminal, true);
|
|
323
|
+
|
|
324
|
+
const current = claimUpload();
|
|
325
|
+
assert.equal(current.resourceId, PROJECT);
|
|
326
|
+
assert.notEqual(current.sha256, legacy.sha256);
|
|
327
|
+
acknowledgeUpload(current.resourceId, current.sha256);
|
|
328
|
+
});
|
|
@@ -13,6 +13,7 @@ const crypto = require('crypto');
|
|
|
13
13
|
const fs = require('fs');
|
|
14
14
|
const path = require('path');
|
|
15
15
|
const { AMALGM_DIR } = require('../config');
|
|
16
|
+
const { isSharedResourceId } = require('../state/cloud-resource-id');
|
|
16
17
|
const { appendStateEvent } = require('../state/events');
|
|
17
18
|
const durable = require('./durable');
|
|
18
19
|
const transition = require('./transition');
|
|
@@ -288,7 +289,11 @@ function acknowledgeUpload(resourceId, digest) {
|
|
|
288
289
|
}
|
|
289
290
|
|
|
290
291
|
function failUpload(resourceId, digest, failure = {}) {
|
|
291
|
-
|
|
292
|
+
// Upload work is durable across protocol generations. Match the exact
|
|
293
|
+
// identity that was accepted when the work was queued, including legacy
|
|
294
|
+
// `shr_` rails, so stale historical work can reach a terminal state instead
|
|
295
|
+
// of monopolizing every newer code project behind it.
|
|
296
|
+
if (!isSharedResourceId(resourceId) || !/^[0-9a-f]{64}$/.test(String(digest || ''))) {
|
|
292
297
|
return { changed: false, terminal: false };
|
|
293
298
|
}
|
|
294
299
|
ensureDirs();
|