amalgm 0.1.160 → 0.1.161
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
|
@@ -613,7 +613,15 @@ function installCookieCloudBootstrap(input = {}, options = {}) {
|
|
|
613
613
|
const remote = normalizeCloudSnapshot(JSON.parse(bytes.toString('utf8')));
|
|
614
614
|
const pending = require('../state/mutations').listPendingCloudMutations(replica.resourceId, { database });
|
|
615
615
|
const pendingKeys = new Set(pending.map((mutation) => mutation.operation?.key).filter(Boolean));
|
|
616
|
-
|
|
616
|
+
// A base snapshot behind the official head is not the current cloud jar.
|
|
617
|
+
// Comparing local state against it would misclassify already-synced values
|
|
618
|
+
// as pre-cloud work and create an echo loop on every reconnect. The gateway
|
|
619
|
+
// normally compacts private resources to head before bootstrap; this guard
|
|
620
|
+
// makes the runtime fail closed if an older gateway sends a stale base.
|
|
621
|
+
const snapshotIsCurrent = Number(input.snapshotVersion) >= Number(input.headVersion);
|
|
622
|
+
const bootstrapOperations = snapshotIsCurrent
|
|
623
|
+
? localBootstrapOperations(local, remote, pendingKeys)
|
|
624
|
+
: [];
|
|
617
625
|
|
|
618
626
|
persistCloudSnapshot({
|
|
619
627
|
schemaVersion: COOKIE_JAR_SCHEMA_VERSION,
|
|
@@ -645,7 +653,12 @@ function installCookieCloudBootstrap(input = {}, options = {}) {
|
|
|
645
653
|
commitCookieOperation(operation, currentReplica, { database });
|
|
646
654
|
currentReplica = cookieCloudReplica({ database });
|
|
647
655
|
}
|
|
648
|
-
return {
|
|
656
|
+
return {
|
|
657
|
+
replica: currentReplica,
|
|
658
|
+
jar: readCookieJar(),
|
|
659
|
+
bootstrappedMutations: bootstrapOperations.length,
|
|
660
|
+
bootstrapDeferred: !snapshotIsCurrent,
|
|
661
|
+
};
|
|
649
662
|
}
|
|
650
663
|
|
|
651
664
|
function applyCloudCookieMutation(input = {}, options = {}) {
|
|
@@ -27,6 +27,7 @@ const {
|
|
|
27
27
|
COOKIE_CLOUD_CONTRACT,
|
|
28
28
|
applyCloudCookieMutation,
|
|
29
29
|
getCookieCloudBootstrap,
|
|
30
|
+
installCookieCloudBootstrap,
|
|
30
31
|
mergeCookieJar,
|
|
31
32
|
privateCookieResourceId,
|
|
32
33
|
readCookieJar,
|
|
@@ -150,3 +151,31 @@ test('the private resource is deterministic per user and bootstrap is automatic'
|
|
|
150
151
|
);
|
|
151
152
|
assert.equal(JSON.parse(Buffer.from(bootstrap.snapshotBase64, 'base64').toString('utf8')).schemaVersion, 1);
|
|
152
153
|
});
|
|
154
|
+
|
|
155
|
+
test('a stale cloud base never re-emits local cookies as bootstrap mutations', () => {
|
|
156
|
+
mergeCookieJar({ sourceId: 'machine-a', upserts: [cookie('already-synced', 'local-secret')] });
|
|
157
|
+
const db = openLocalDb();
|
|
158
|
+
db.prepare('DELETE FROM mutation_journal').run();
|
|
159
|
+
const resourceId = privateCookieResourceId(userId);
|
|
160
|
+
const bytes = Buffer.from(JSON.stringify({
|
|
161
|
+
schemaVersion: 1,
|
|
162
|
+
version: 0,
|
|
163
|
+
updatedAt: '2026-07-20T19:00:00.000Z',
|
|
164
|
+
records: [],
|
|
165
|
+
tombstones: [],
|
|
166
|
+
}), 'utf8');
|
|
167
|
+
const result = installCookieCloudBootstrap({
|
|
168
|
+
resourceId,
|
|
169
|
+
authorityEpoch: 1,
|
|
170
|
+
headVersion: 7,
|
|
171
|
+
snapshotVersion: 0,
|
|
172
|
+
snapshotChecksum: require('crypto').createHash('sha256').update(bytes).digest('hex'),
|
|
173
|
+
snapshotBase64: bytes.toString('base64'),
|
|
174
|
+
contract: COOKIE_CLOUD_CONTRACT,
|
|
175
|
+
schemaVersion: 1,
|
|
176
|
+
}, { database: db });
|
|
177
|
+
|
|
178
|
+
assert.equal(result.bootstrapDeferred, true);
|
|
179
|
+
assert.equal(result.bootstrappedMutations, 0);
|
|
180
|
+
assert.equal(db.prepare('SELECT COUNT(*) AS count FROM mutation_journal').get().count, 0);
|
|
181
|
+
});
|