amalgm 0.1.186 → 0.1.188
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 +1 -1
- package/runtime/scripts/amalgm-mcp/state/docs.js +1 -1
- package/runtime/scripts/amalgm-mcp/state/promotions.js +1 -1
- package/runtime/scripts/amalgm-mcp/tests/state-shared-replica.test.js +6 -1
- package/runtime/scripts/amalgm-mcp/tests/workspace-reducer.test.js +28 -0
- package/runtime/scripts/amalgm-mcp/tests/workspace-wall.test.js +3 -2
- package/runtime/scripts/amalgm-mcp/workspace/reducer.js +5 -1
- package/runtime/scripts/amalgm-mcp/workspace/tree-store.js +1 -1
- package/runtime/scripts/amalgm-mcp/workspace/wall.js +2 -19
package/package.json
CHANGED
|
@@ -341,7 +341,7 @@ function commitDocMutation(Y, entry, { mutationId, update, bytes }, source) {
|
|
|
341
341
|
localResource: entry.resource,
|
|
342
342
|
sharedResourceId: replica?.resourceId,
|
|
343
343
|
mutationId,
|
|
344
|
-
deviceId: replica ?
|
|
344
|
+
deviceId: replica ? require('../workspace/identity').machineId() : null,
|
|
345
345
|
authorityEpoch: replica?.authorityEpoch || 0,
|
|
346
346
|
baseCloudVersion: replica?.appliedVersion || 0,
|
|
347
347
|
contract: replica?.contract || 'text-yjs@1',
|
|
@@ -248,7 +248,7 @@ function acknowledgePromotion(promotionIdInput, acknowledgement, options = {}) {
|
|
|
248
248
|
`).run(
|
|
249
249
|
`resource:${replica.resourceId}`,
|
|
250
250
|
replica.resourceId,
|
|
251
|
-
|
|
251
|
+
require('../workspace/identity').machineId(),
|
|
252
252
|
replica.authorityEpoch,
|
|
253
253
|
replica.snapshotVersion,
|
|
254
254
|
now,
|
|
@@ -8,6 +8,7 @@ const path = require('path');
|
|
|
8
8
|
|
|
9
9
|
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'amalgm-shared-replica-test-'));
|
|
10
10
|
process.env.AMALGM_DIR = path.join(tempRoot, '.amalgm');
|
|
11
|
+
process.env.AMALGM_COMPUTER_ID = 'computer-shared-replica-test';
|
|
11
12
|
process.env.AMALGM_DEVICE_ID = 'device-shared-replica-test';
|
|
12
13
|
process.env.AMALGM_EVENT_LOG_PRUNE_INTERVAL_MS = '0';
|
|
13
14
|
|
|
@@ -142,6 +143,10 @@ test('batched surface edits retain separate IDs/versions and recipient file prec
|
|
|
142
143
|
'mut_shared_batch_001',
|
|
143
144
|
'mut_shared_batch_002',
|
|
144
145
|
]);
|
|
146
|
+
assert.deepEqual(claims.map((claim) => claim.envelope.deviceId), [
|
|
147
|
+
process.env.AMALGM_COMPUTER_ID,
|
|
148
|
+
process.env.AMALGM_COMPUTER_ID,
|
|
149
|
+
]);
|
|
145
150
|
acknowledgeCloudMutation(resourceId, 'mut_shared_batch_001', {
|
|
146
151
|
version: 1,
|
|
147
152
|
committedAt: '2026-07-14T20:00:00.000Z',
|
|
@@ -378,7 +383,7 @@ test('edits journaled during the promotion window are re-homed into the outbox',
|
|
|
378
383
|
assert.equal(rehomed.sharedResourceId, fenceResourceId);
|
|
379
384
|
assert.equal(rehomed.authorityEpoch, 1);
|
|
380
385
|
assert.equal(rehomed.baseCloudVersion, 0);
|
|
381
|
-
assert.equal(rehomed.deviceId, process.env.
|
|
386
|
+
assert.equal(rehomed.deviceId, process.env.AMALGM_COMPUTER_ID);
|
|
382
387
|
const claims = claimCloudMutations().filter((claim) => claim.envelope.resourceId === fenceResourceId);
|
|
383
388
|
assert.deepEqual(claims.map((claim) => claim.envelope.mutationId), ['mut_during_promotion1']);
|
|
384
389
|
});
|
|
@@ -116,6 +116,34 @@ test('wall reduction chooses one rail winner and orders checkpoint transitions b
|
|
|
116
116
|
assert.deepEqual(plan.transitions.map((item) => item.version), [8]);
|
|
117
117
|
});
|
|
118
118
|
|
|
119
|
+
test('a ready parked bundle never regresses to pending', () => {
|
|
120
|
+
const oid = 'c'.repeat(40);
|
|
121
|
+
const ready = card('/ready', 'a'.repeat(40), 1);
|
|
122
|
+
const readyCheckpoint = transition('machine-ready', 2, ready.head.oid, '', '');
|
|
123
|
+
readyCheckpoint.parked = [{
|
|
124
|
+
oid,
|
|
125
|
+
ref: `refs/amalgm/parked/${oid}`,
|
|
126
|
+
objects: { kind: 'bundle', checksum: 'd'.repeat(64) },
|
|
127
|
+
}];
|
|
128
|
+
ready.checkpoints = [readyCheckpoint];
|
|
129
|
+
|
|
130
|
+
const pending = card('/pending', ready.head.oid, 3);
|
|
131
|
+
const pendingCheckpoint = transition('machine-pending', 4, pending.head.oid, '', '');
|
|
132
|
+
pendingCheckpoint.parked = [{
|
|
133
|
+
oid,
|
|
134
|
+
ref: `refs/amalgm/parked/${oid}`,
|
|
135
|
+
objects: { kind: 'pending' },
|
|
136
|
+
}];
|
|
137
|
+
pending.checkpoints = [pendingCheckpoint];
|
|
138
|
+
|
|
139
|
+
const plan = reduceWall([
|
|
140
|
+
{ machine: 'machine-ready', cards: [ready] },
|
|
141
|
+
{ machine: 'machine-pending', cards: [pending] },
|
|
142
|
+
]).get('root:test');
|
|
143
|
+
assert.equal(plan.parked.length, 1);
|
|
144
|
+
assert.equal(plan.parked[0].objects.kind, 'bundle');
|
|
145
|
+
});
|
|
146
|
+
|
|
119
147
|
test('a stale lower rail card cannot roll back a newer branch and commit', () => {
|
|
120
148
|
const newer = card('/newer', 'b'.repeat(40), 12);
|
|
121
149
|
newer.head.branch = 'feature';
|
|
@@ -128,7 +128,8 @@ test('a repo project carries exactly one line per machine, replaced in place', a
|
|
|
128
128
|
committedAt: '2026-07-23T00:00:00.000Z',
|
|
129
129
|
});
|
|
130
130
|
const sealed = publishWall(repoKey);
|
|
131
|
-
assert.equal(sealed.published,
|
|
131
|
+
assert.equal(sealed.published, false);
|
|
132
|
+
assert.equal(sealed.reason, 'unchanged');
|
|
132
133
|
const sealedCard = readWall(repoKey)[0].cards[0];
|
|
133
134
|
assert.equal(sealedCard.positionMutationId, first.mutationId);
|
|
134
135
|
assert.equal(sealedCard.positionVersion, 1);
|
|
@@ -176,7 +177,7 @@ test('checkpoint transitions append until the next card and carry their official
|
|
|
176
177
|
committedAt: '2026-07-23T00:00:02.000Z',
|
|
177
178
|
});
|
|
178
179
|
assert.equal(readWall(repoKey)[0].cards[0].checkpoints[0].version, 2);
|
|
179
|
-
assert.equal(publishWall(repoKey).published,
|
|
180
|
+
assert.equal(publishWall(repoKey).published, false);
|
|
180
181
|
|
|
181
182
|
fs.writeFileSync(file, `${JSON.stringify({
|
|
182
183
|
...firstCheckpoint,
|
|
@@ -124,6 +124,7 @@ function reduceWall(entries) {
|
|
|
124
124
|
&& entry.branch === repo.card.head?.branch
|
|
125
125
|
))
|
|
126
126
|
.sort((left, right) => left.version - right.version);
|
|
127
|
+
repo.parked = uniqueParked(repo.parked);
|
|
127
128
|
if (repo.card.head?.branch) {
|
|
128
129
|
const held = repo.branchMap.get(repo.card.head.branch);
|
|
129
130
|
if (!held || repo.card.positionVersion > held.version) {
|
|
@@ -146,7 +147,10 @@ function uniqueParked(entries) {
|
|
|
146
147
|
const byOid = new Map();
|
|
147
148
|
for (const entry of entries || []) {
|
|
148
149
|
if (typeof entry?.oid === 'string' && /^[0-9a-f]{40,64}$/.test(entry.oid)) {
|
|
149
|
-
byOid.
|
|
150
|
+
const held = byOid.get(entry.oid);
|
|
151
|
+
if (!held || held.objects?.kind !== 'bundle' || entry.objects?.kind === 'bundle') {
|
|
152
|
+
byOid.set(entry.oid, entry);
|
|
153
|
+
}
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
return [...byOid.values()].sort((left, right) => left.oid.localeCompare(right.oid));
|
|
@@ -372,7 +372,7 @@ function commitTreeOperation(input, options = {}) {
|
|
|
372
372
|
localResource,
|
|
373
373
|
sharedResourceId: replica?.resourceId,
|
|
374
374
|
mutationId,
|
|
375
|
-
deviceId: replica ?
|
|
375
|
+
deviceId: replica ? require('./identity').machineId() : null,
|
|
376
376
|
authorityEpoch: replica?.authorityEpoch || 0,
|
|
377
377
|
baseCloudVersion: replica?.appliedVersion || 0,
|
|
378
378
|
contract: 'workspace-tree@1',
|
|
@@ -249,15 +249,11 @@ function stampBranches(refs, previousBranches, mutationId, resourceId) {
|
|
|
249
249
|
&& before.mutationId
|
|
250
250
|
&& (validVersion(before.version) || knownMutation(resourceId, before.mutationId));
|
|
251
251
|
const mutation = reusable ? before.mutationId : mutationId;
|
|
252
|
-
const version = reusable
|
|
253
|
-
? (validVersion(before.version) ? before.version : officialVersion(resourceId, mutation))
|
|
254
|
-
: null;
|
|
255
252
|
return {
|
|
256
253
|
name,
|
|
257
254
|
oid,
|
|
258
255
|
...(observed?.objects ? { objects: observed.objects } : {}),
|
|
259
256
|
mutationId: mutation,
|
|
260
|
-
...(validVersion(version) ? { version } : {}),
|
|
261
257
|
};
|
|
262
258
|
});
|
|
263
259
|
}
|
|
@@ -294,15 +290,8 @@ function stampCards(cards, previousCards, mutationId, project) {
|
|
|
294
290
|
&& (
|
|
295
291
|
validVersion(previous.positionVersion)
|
|
296
292
|
|| knownMutation(project.resourceId, previous.positionMutationId)
|
|
297
|
-
|
|
293
|
+
);
|
|
298
294
|
const positionMutationId = reusablePosition ? previous.positionMutationId : mutationId;
|
|
299
|
-
const positionVersion = reusablePosition
|
|
300
|
-
? (
|
|
301
|
-
validVersion(previous.positionVersion)
|
|
302
|
-
? previous.positionVersion
|
|
303
|
-
: officialVersion(project.resourceId, positionMutationId)
|
|
304
|
-
)
|
|
305
|
-
: null;
|
|
306
295
|
const checkpoint = readCheckpoint(machineId(), project.repoKey);
|
|
307
296
|
const currentCheckpoint = checkpoint
|
|
308
297
|
&& checkpoint.baseOid === card.head?.oid
|
|
@@ -312,12 +301,7 @@ function stampCards(cards, previousCards, mutationId, project) {
|
|
|
312
301
|
const sameBase = previous?.head?.oid === card.head?.oid
|
|
313
302
|
&& previous?.head?.branch === card.head?.branch;
|
|
314
303
|
const history = sameBase && Array.isArray(previous?.checkpoints)
|
|
315
|
-
? previous.checkpoints.map((entry) =>
|
|
316
|
-
const version = validVersion(entry.version)
|
|
317
|
-
? entry.version
|
|
318
|
-
: officialVersion(project.resourceId, entry.mutationId);
|
|
319
|
-
return validVersion(version) ? { ...entry, version } : entry;
|
|
320
|
-
})
|
|
304
|
+
? previous.checkpoints.map(({ version: _version, ...entry }) => entry)
|
|
321
305
|
: [];
|
|
322
306
|
const last = history.at(-1);
|
|
323
307
|
const checkpoints = currentCheckpoint
|
|
@@ -328,7 +312,6 @@ function stampCards(cards, previousCards, mutationId, project) {
|
|
|
328
312
|
return {
|
|
329
313
|
...sharedCard(card),
|
|
330
314
|
positionMutationId,
|
|
331
|
-
...(validVersion(positionVersion) ? { positionVersion } : {}),
|
|
332
315
|
branches: stampBranches(
|
|
333
316
|
card.refs,
|
|
334
317
|
sameBase ? previous?.branches : [],
|