amalgm 0.1.190 → 0.1.191

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amalgm",
3
- "version": "0.1.190",
3
+ "version": "0.1.191",
4
4
  "description": "Amalgm local computer runtime: login, MCP, chat, events, previews, and tunnels.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -38,6 +38,7 @@ const {
38
38
  publishedCardFor,
39
39
  publishWall,
40
40
  readWall,
41
+ stampCards,
41
42
  wallStats,
42
43
  } = require('../workspace/wall');
43
44
 
@@ -126,6 +127,61 @@ test('only a value different from both the materialized baseline and the rail is
126
127
  }), true);
127
128
  });
128
129
 
130
+ test('checkpoint work on the materialized baseline keeps the baseline card and branch numbers', () => {
131
+ const baselineOid = 'a'.repeat(40);
132
+ const railOid = 'b'.repeat(40);
133
+ const card = {
134
+ card: 'repo-card@2',
135
+ machine: 'machine-a',
136
+ replica: 'rpl_baseline',
137
+ kind: 'primary',
138
+ head: { branch: 'main', oid: baselineOid, detached: false },
139
+ refs: [{ name: 'main', oid: baselineOid }],
140
+ health: 'healthy',
141
+ };
142
+ const stamped = stampCards(
143
+ [card],
144
+ [{
145
+ ...card,
146
+ head: { branch: 'old', oid: 'c'.repeat(40), detached: false },
147
+ positionMutationId: 'mut_stale_card_01',
148
+ positionVersion: 8,
149
+ branches: [],
150
+ }],
151
+ {
152
+ card: {
153
+ ...card,
154
+ head: { branch: 'main', oid: railOid, detached: false },
155
+ positionMutationId: 'mut_winning_card1',
156
+ positionVersion: 12,
157
+ },
158
+ branches: [{
159
+ name: 'main',
160
+ oid: railOid,
161
+ mutationId: 'mut_winning_ref01',
162
+ version: 12,
163
+ }],
164
+ },
165
+ {
166
+ branch: 'main',
167
+ baseOid: baselineOid,
168
+ cardMutationId: 'mut_baseline_card',
169
+ cardVersion: 9,
170
+ branches: [{
171
+ name: 'main',
172
+ oid: baselineOid,
173
+ mutationId: 'mut_baseline_ref1',
174
+ version: 9,
175
+ }],
176
+ },
177
+ 'mut_checkpoint_only',
178
+ { repoKey: 'root:baseline-stamp', resourceId: 'shr_baseline_stamp_test' },
179
+ )[0];
180
+
181
+ assert.equal(stamped.positionMutationId, 'mut_baseline_card');
182
+ assert.equal(stamped.branches[0].mutationId, 'mut_baseline_ref1');
183
+ });
184
+
129
185
  test('a collaborator binds the same repo to the owner project, not a parallel project', () => {
130
186
  const shared = projectResourceId('repo-shared', '22222222-2222-4222-8222-222222222222');
131
187
  const localPath = path.join(tempRoot, 'projects/shared');
@@ -281,15 +281,24 @@ function officialVersion(resourceId, mutationId) {
281
281
  return Number.isInteger(mutation?.officialCloudVersion) ? mutation.officialCloudVersion : null;
282
282
  }
283
283
 
284
- function stampBranches(refs, previousBranches, sharedBranches, mutationId, resourceId) {
284
+ function stampBranches(
285
+ refs,
286
+ previousBranches,
287
+ sharedBranches,
288
+ baselineBranches,
289
+ mutationId,
290
+ resourceId,
291
+ ) {
285
292
  const current = new Map((refs || []).map((ref) => [ref.name, ref]));
286
293
  const previous = new Map((previousBranches || []).map((ref) => [ref.name, ref]));
287
294
  const shared = new Map((sharedBranches || []).map((ref) => [ref.name, ref]));
295
+ const baseline = new Map((baselineBranches || []).map((ref) => [ref.name, ref]));
288
296
  const names = [...new Set([...current.keys(), ...previous.keys()])].sort();
289
297
  return names.map((name) => {
290
298
  const observed = current.get(name);
291
299
  const before = previous.get(name);
292
300
  const onRail = shared.get(name);
301
+ const materialized = baseline.get(name);
293
302
  const oid = observed?.oid ?? null;
294
303
  const unchanged = before && (before.oid ?? null) === oid;
295
304
  const previousReusable = unchanged
@@ -299,9 +308,15 @@ function stampBranches(refs, previousBranches, sharedBranches, mutationId, resou
299
308
  && (onRail.oid ?? null) === oid
300
309
  && onRail.mutationId
301
310
  && validVersion(onRail.version);
311
+ const baselineReusable = materialized
312
+ && (materialized.oid ?? null) === oid
313
+ && materialized.mutationId
314
+ && validVersion(materialized.version);
302
315
  const mutation = previousReusable
303
316
  ? before.mutationId
304
- : railReusable ? onRail.mutationId : mutationId;
317
+ : railReusable
318
+ ? onRail.mutationId
319
+ : baselineReusable ? materialized.mutationId : mutationId;
305
320
  return {
306
321
  name,
307
322
  oid,
@@ -332,7 +347,7 @@ function isCommittedCard(card) {
332
347
  return typeof card?.head?.oid === 'string' && /^[0-9a-f]{40,64}$/.test(card.head.oid);
333
348
  }
334
349
 
335
- function stampCards(cards, previousCards, sharedPlan, mutationId, project) {
350
+ function stampCards(cards, previousCards, sharedPlan, baseline, mutationId, project) {
336
351
  const previousByReplica = new Map(
337
352
  (previousCards || []).filter((card) => card?.replica).map((card) => [card.replica, card]),
338
353
  );
@@ -347,9 +362,16 @@ function stampCards(cards, previousCards, sharedPlan, mutationId, project) {
347
362
  const reusableRailPosition = samePosition(sharedPlan?.card, card)
348
363
  && sharedPlan.card.positionMutationId
349
364
  && validVersion(sharedPlan.card.positionVersion);
365
+ const reusableBaselinePosition = baseline
366
+ && card.head?.branch === baseline.branch
367
+ && card.head?.oid === baseline.baseOid
368
+ && baseline.cardMutationId
369
+ && validVersion(baseline.cardVersion);
350
370
  const positionMutationId = reusablePosition
351
371
  ? previous.positionMutationId
352
- : reusableRailPosition ? sharedPlan.card.positionMutationId : mutationId;
372
+ : reusableRailPosition
373
+ ? sharedPlan.card.positionMutationId
374
+ : reusableBaselinePosition ? baseline.cardMutationId : mutationId;
353
375
  const checkpoint = readCheckpoint(machineId(), project.repoKey);
354
376
  const currentCheckpoint = checkpoint
355
377
  && checkpoint.baseOid === card.head?.oid
@@ -374,6 +396,7 @@ function stampCards(cards, previousCards, sharedPlan, mutationId, project) {
374
396
  card.refs,
375
397
  previous?.branches,
376
398
  sharedPlan?.branches,
399
+ baseline?.branches,
377
400
  mutationId,
378
401
  project.resourceId,
379
402
  ),
@@ -437,7 +460,14 @@ function publishProject(project, rawCards) {
437
460
  return { published: false, reason: 'shared-state-covered', repoKey: project.repoKey };
438
461
  }
439
462
  const mutationId = `mut_project_${crypto.randomBytes(16).toString('base64url')}`;
440
- const cards = stampCards(rawCards, previousEntry?.cards, sharedPlan, mutationId, project);
463
+ const cards = stampCards(
464
+ rawCards,
465
+ previousEntry?.cards,
466
+ sharedPlan,
467
+ baseline,
468
+ mutationId,
469
+ project,
470
+ );
441
471
  const mine = JSON.stringify({
442
472
  wall: WALL_CONTRACT,
443
473
  project: project.repoKey,
@@ -648,6 +678,7 @@ module.exports = {
648
678
  publishedCardFor,
649
679
  publishWall,
650
680
  readWall,
681
+ stampCards,
651
682
  startWallService,
652
683
  stopWallService,
653
684
  wallStats,