Support multi-screenshot calibration and cached shop context

This commit is contained in:
2026-08-11 17:43:32 +03:00
parent f87a65bb04
commit cf1cb41f04
8 changed files with 507 additions and 84 deletions
+22
View File
@@ -11,6 +11,7 @@ test("keeps the same batch across retries and deletes only after acknowledgement
const send = async (batch) => {
sent.push(batch);
if (fail) throw new Error("offline");
return { batchId: batch.batchId };
};
const options = { now: () => "2026-08-11T12:00:00.000Z", uuid: () => "batch-one" };
@@ -24,6 +25,27 @@ test("keeps the same batch across retries and deletes only after acknowledgement
assert.deepEqual(await store.list(200), []);
});
test("keeps rows pending for a wrong acknowledgement and caps encoded batch size", async () => {
const store = memoryStore();
for (let index = 0; index < 80; index += 1) {
await store.add({ observationId: `observation-${index}`, rawText: "x".repeat(4096), storeRawText: "y".repeat(4096) });
}
let sent;
const outbox = new MarketOutbox(
store,
async (batch) => {
sent = batch;
return { batchId: "wrong" };
},
{ now: () => "2026-08-11T12:00:00.000Z", uuid: () => "batch-two" },
);
await assert.rejects(outbox.flush(), /другой пакет/);
assert.ok(sent.observations.length < 80);
assert.ok(new TextEncoder().encode(JSON.stringify(sent)).byteLength <= 80 * 1024);
assert.equal((await store.list(200)).length, 80);
});
function memoryStore() {
const observations = new Map();
let batch = null;