amalgm 0.1.181 → 0.1.183

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.181",
3
+ "version": "0.1.183",
4
4
  "description": "Amalgm local computer runtime: login, MCP, chat, events, previews, and tunnels.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -164,7 +164,7 @@ test('checkpoint captures are local cache; their operations travel on the one wa
164
164
  assert.equal(first, checkpointFile('m1', 'https://github.com/a/b'));
165
165
  assert.notEqual(first, checkpointFile('m2', 'https://github.com/a/b'));
166
166
  assert.notEqual(first, checkpointFile('m1', 'https://github.com/a/c'));
167
- assert.match(first, /repo-checkpoints-v5/);
167
+ assert.match(first, /repo-checkpoints-v6/);
168
168
  });
169
169
 
170
170
  test('an uploading checkpoint payload is not published as a transition', () => {
@@ -21,7 +21,7 @@ fs.writeFileSync(
21
21
  );
22
22
 
23
23
  const { closeLocalDb } = require('../state/db');
24
- const { revisionOf } = require('../workspace/checkpoint');
24
+ const { CHECKPOINT_CONTRACT, revisionOf } = require('../workspace/checkpoint');
25
25
  const {
26
26
  captureIsOnRail,
27
27
  hydrateRepo,
@@ -73,7 +73,7 @@ function value(baseOid, diff) {
73
73
 
74
74
  function transition(machine, version, baseOid, from, to) {
75
75
  return {
76
- checkpoint: 'repo-checkpoint@5',
76
+ checkpoint: CHECKPOINT_CONTRACT,
77
77
  machine,
78
78
  repoKey: 'root:test',
79
79
  branch: 'main',
@@ -130,6 +130,18 @@ test('a stale lower rail card cannot roll back a newer branch and commit', () =>
130
130
  assert.equal(plan.card.positionVersion, 12);
131
131
  });
132
132
 
133
+ test('checkpoint reduction reads only the current rail contract', () => {
134
+ const current = card('/current-contract', 'a'.repeat(40), 1);
135
+ const stale = transition('machine-local', 2, current.head.oid, '', 'stale');
136
+ stale.checkpoint = 'repo-checkpoint@5';
137
+ current.checkpoints = [
138
+ stale,
139
+ transition('machine-local', 3, current.head.oid, '', 'current'),
140
+ ];
141
+ const plan = reduceWall([{ machine: 'machine-local', cards: [current] }]).get('root:test');
142
+ assert.deepEqual(plan.transitions.map((item) => item.version), [3]);
143
+ });
144
+
133
145
  test('an old pending payload does not block the later complete checkpoint transition', async () => {
134
146
  const { repo, oid } = await makeRepo('pending-payload');
135
147
  const diff = await patchFor(repo, { 'a.txt': 'a1\n' });
@@ -403,6 +415,41 @@ test('a losing commit is parked, the winning card lands exactly, and losing work
403
415
  assert.deepEqual(readRepoState('root:test').parked.map((entry) => entry.oid), [losingOid]);
404
416
  });
405
417
 
418
+ test('a new card folds checkpoint work already on the rail instead of replaying it as local work', async () => {
419
+ const { repo, oid: baseOid } = await makeRepo('card-folds-shared-checkpoint');
420
+ const sharedPatch = await patchFor(repo, { 'a.txt': 'shared checkpoint\n' });
421
+
422
+ await git(repo, 'switch', '-c', 'target');
423
+ fs.writeFileSync(path.join(repo, 'a.txt'), 'shared checkpoint\n');
424
+ await git(repo, 'add', 'a.txt');
425
+ await git(repo, 'commit', '-m', 'commit shared checkpoint');
426
+ const targetOid = (await git(repo, 'rev-parse', 'HEAD')).trim();
427
+ await git(repo, 'switch', 'main');
428
+
429
+ const oldCard = card(repo, baseOid, 1);
430
+ await materializeRepo(oldCard, {
431
+ repoKey: 'root:test',
432
+ card: oldCard,
433
+ transitions: [transition('machine-remote', 2, baseOid, '', sharedPatch)],
434
+ });
435
+ assert.notEqual((await git(repo, 'status', '--porcelain')).trim(), '');
436
+
437
+ const outcome = await materializeRepo(oldCard, {
438
+ repoKey: 'root:test',
439
+ card: {
440
+ ...oldCard,
441
+ head: { branch: 'main', oid: targetOid, detached: false },
442
+ positionVersion: 3,
443
+ positionMutationId: 'mut_card_shared_fold',
444
+ },
445
+ transitions: [],
446
+ parked: [],
447
+ });
448
+ assert.equal(outcome.state, 'in-sync');
449
+ assert.equal((await git(repo, 'rev-parse', 'HEAD')).trim(), targetOid);
450
+ assert.equal((await git(repo, 'status', '--porcelain')).trim(), '');
451
+ });
452
+
406
453
  test('checkpoint then commit folds through the same card movement and unrelated local work stays', async () => {
407
454
  const { repo, oid: baseOid } = await makeRepo('checkpoint-commit-fold');
408
455
  await git(repo, 'switch', '-c', 'target');
@@ -155,7 +155,7 @@ test('checkpoint transitions append until the next card and carry their official
155
155
  const file = checkpointFile('machine-a', repoKey);
156
156
  fs.mkdirSync(path.dirname(file), { recursive: true });
157
157
  const firstCheckpoint = {
158
- checkpoint: 'repo-checkpoint@5',
158
+ checkpoint: 'repo-checkpoint@6',
159
159
  machine: 'machine-a',
160
160
  repoKey,
161
161
  branch: card.head.branch,
@@ -25,7 +25,7 @@ const { machineId } = require('./identity');
25
25
  const { listRepoCards } = require('./cards');
26
26
  const { captureCheckpoint } = require('./git');
27
27
 
28
- const CHECKPOINT_CONTRACT = 'repo-checkpoint@5';
28
+ const CHECKPOINT_CONTRACT = 'repo-checkpoint@6';
29
29
  const MAX_INLINE_DIFF_BYTES = 512 * 1024;
30
30
  const PUBLISH_QUIET_MS = 25;
31
31
  const RECONCILE_INTERVAL_MS = 30_000;
@@ -54,7 +54,7 @@ function checkpointFile(machine, repoKey) {
54
54
  .update(`${CHECKPOINT_CONTRACT}|${machine}|${repoKey}`)
55
55
  .digest('hex')
56
56
  .slice(0, 24);
57
- return path.join(AMALGM_DIR, 'state', 'repo-checkpoints-v5', `${digest}.json`);
57
+ return path.join(AMALGM_DIR, 'state', 'repo-checkpoints-v6', `${digest}.json`);
58
58
  }
59
59
 
60
60
  function revisionOf(baseOid, indexDiff, worktreeDiff = '') {
@@ -28,6 +28,7 @@ const {
28
28
  operationState,
29
29
  } = require('./git');
30
30
  const {
31
+ CHECKPOINT_CONTRACT,
31
32
  readCheckpointValue,
32
33
  repoKeyOfCard,
33
34
  revisionOf,
@@ -106,7 +107,8 @@ function reduceWall(entries) {
106
107
  }
107
108
  for (const checkpoint of card.checkpoints || []) {
108
109
  if (
109
- validVersion(checkpoint.version)
110
+ checkpoint.checkpoint === CHECKPOINT_CONTRACT
111
+ && validVersion(checkpoint.version)
110
112
  && checkpoint.machine === wallEntry.machine
111
113
  ) {
112
114
  repo.transitions.push(checkpoint);
@@ -228,6 +230,15 @@ async function moveToWinningCard(localCard, targetCard) {
228
230
  return { state: 'waiting', reason: 'local-state-moving' };
229
231
  }
230
232
  const repoKey = repoKeyOfCard(localCard);
233
+ const reducedState = readRepoState(repoKey);
234
+ const capturedOnRail = reducedState?.baseOid === current.head.oid
235
+ && reducedState.checkpointRevision === revisionOf(
236
+ current.head.oid,
237
+ captured.indexDiff,
238
+ captured.worktreeDiff,
239
+ );
240
+ const movingIndexDiff = capturedOnRail ? '' : captured.indexDiff;
241
+ const movingWorktreeDiff = capturedOnRail ? '' : captured.worktreeDiff;
231
242
  const parked = [];
232
243
  if (!forward && current.head.oid !== targetCard.head.oid) {
233
244
  const parkedRef = await transition.parkCommit(localCard.path, current.head.oid);
@@ -255,7 +266,7 @@ async function moveToWinningCard(localCard, targetCard) {
255
266
  oldTree,
256
267
  { label: `parked-${current.head.oid.slice(0, 12)}` },
257
268
  );
258
- const oldIndexTree = await merge.treeOfPatch(localCard.path, current.head.oid, captured.indexDiff);
269
+ const oldIndexTree = await merge.treeOfPatch(localCard.path, current.head.oid, movingIndexDiff);
259
270
  const staged = await merge.reduceTree(
260
271
  localCard.path,
261
272
  committed.tree,
@@ -263,7 +274,7 @@ async function moveToWinningCard(localCard, targetCard) {
263
274
  oldIndexTree,
264
275
  { label: `staged-${current.head.oid.slice(0, 12)}` },
265
276
  );
266
- const oldWorktree = await merge.treeOfPatch(localCard.path, oldIndexTree, captured.worktreeDiff);
277
+ const oldWorktree = await merge.treeOfPatch(localCard.path, oldIndexTree, movingWorktreeDiff);
267
278
  const working = await merge.reduceTree(
268
279
  localCard.path,
269
280
  staged.tree,