@decocms/blocks-cli 7.88.3 → 7.89.0
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 +2 -2
- package/scripts/fast-deploy-kv.test.ts +25 -2
- package/scripts/lib/kv-snapshot.ts +25 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/blocks-cli",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.89.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deco codegen (generate-blocks, generate-schema, generate-invoke) and Fresh-to-TanStack migration tooling",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"lint:unused": "knip"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@decocms/blocks": "7.
|
|
36
|
+
"@decocms/blocks": "7.89.0",
|
|
37
37
|
"ts-morph": "^27.0.0",
|
|
38
38
|
"tsx": "^4.22.5"
|
|
39
39
|
},
|
|
@@ -228,13 +228,36 @@ describe("kv-snapshot helpers", () => {
|
|
|
228
228
|
await expect(verifySnapshotInKv(client, snap.revision, ID)).resolves.toEqual({ ok: true });
|
|
229
229
|
});
|
|
230
230
|
|
|
231
|
-
it("verify fails when the revision
|
|
231
|
+
it("verify fails when the revision never matches", async () => {
|
|
232
232
|
const { client } = makeClient({
|
|
233
233
|
[snapshotKey(ID)]: "{}",
|
|
234
234
|
[revisionKey(ID)]: "other",
|
|
235
235
|
});
|
|
236
|
-
const
|
|
236
|
+
const slept: number[] = [];
|
|
237
|
+
const res = await verifySnapshotInKv(client, "expected", ID, {
|
|
238
|
+
attempts: 3,
|
|
239
|
+
delayMs: 5,
|
|
240
|
+
sleep: async (ms) => void slept.push(ms),
|
|
241
|
+
});
|
|
237
242
|
expect(res.ok).toBe(false);
|
|
243
|
+
expect(res.reason).toContain("after 3 reads");
|
|
244
|
+
expect(slept).toEqual([5, 5]);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("verify waits out a stale (eventually consistent) read", async () => {
|
|
248
|
+
const { client, store } = makeClient({
|
|
249
|
+
[snapshotKey(ID)]: "{}",
|
|
250
|
+
[revisionKey(ID)]: "old",
|
|
251
|
+
});
|
|
252
|
+
let reads = 0;
|
|
253
|
+
const res = await verifySnapshotInKv(client, "new", ID, {
|
|
254
|
+
sleep: async () => {
|
|
255
|
+
// The edge catches up after the second stale read.
|
|
256
|
+
if (++reads === 2) store.set(revisionKey(ID), "new");
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
expect(res).toEqual({ ok: true });
|
|
260
|
+
expect(reads).toBe(2);
|
|
238
261
|
});
|
|
239
262
|
|
|
240
263
|
it("setLiveDeployment writes index:live", async () => {
|
|
@@ -138,24 +138,37 @@ export async function writeSnapshotToKv(
|
|
|
138
138
|
await client.put(revisionKey(id), snap.revision);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
/**
|
|
141
|
+
/**
|
|
142
|
+
* Read both keys for deployment `id` back and confirm the revision matches.
|
|
143
|
+
*
|
|
144
|
+
* KV is eventually consistent: rewriting a key the edge has cached (every
|
|
145
|
+
* content push rewrites the live id's `index:revision`) can read back the OLD
|
|
146
|
+
* value for up to ~60 s. Failing on the first stale read made every sync pod
|
|
147
|
+
* exit 2 and the Job retry from scratch (about 3 pods per publish), so this
|
|
148
|
+
* re-reads until the write is visible or `attempts` run out (9 × 10 s ≈ 80 s,
|
|
149
|
+
* past the ~60 s propagation window).
|
|
150
|
+
*/
|
|
142
151
|
export async function verifySnapshotInKv(
|
|
143
152
|
client: KvRestClient,
|
|
144
153
|
expectedRevision: string,
|
|
145
154
|
id: string,
|
|
155
|
+
{
|
|
156
|
+
attempts = 9,
|
|
157
|
+
delayMs = 10_000,
|
|
158
|
+
sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms)),
|
|
159
|
+
}: { attempts?: number; delayMs?: number; sleep?: (ms: number) => Promise<void> } = {},
|
|
146
160
|
): Promise<{ ok: boolean; reason?: string }> {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
client.get(revisionKey(id))
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
161
|
+
let reason = "";
|
|
162
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
163
|
+
const [snapshot, revision] = await Promise.all([client.get(snapshotKey(id)), client.get(revisionKey(id))]);
|
|
164
|
+
if (snapshot !== null && revision === expectedRevision) return { ok: true };
|
|
165
|
+
reason =
|
|
166
|
+
snapshot === null
|
|
167
|
+
? `${snapshotKey(id)} missing`
|
|
168
|
+
: `${revisionKey(id)} is "${revision}", expected "${expectedRevision}"`;
|
|
169
|
+
if (attempt < attempts) await sleep(delayMs);
|
|
157
170
|
}
|
|
158
|
-
return { ok:
|
|
171
|
+
return { ok: false, reason: `${reason} (after ${attempts} reads)` };
|
|
159
172
|
}
|
|
160
173
|
|
|
161
174
|
/**
|