fix(n8n): make replacement replay idempotent

This commit is contained in:
Codex
2026-07-21 15:06:59 +03:00
parent bc23c550db
commit 358b259aac
10 changed files with 117 additions and 35 deletions
@@ -170,6 +170,39 @@ async function main() {
assert.equal(externalContract.validateDataProductPublish(replacement).ok, true);
assert.equal(replacement.batch.mode, 'replace');
assert.equal(replacement.batch.generationAt, zoneItems[0].json.observedAt);
const replacementReplay = contracts.buildPublishPayload(
zoneItems,
'execution-replay',
'workflow-other',
'node-other',
'map.zones.current.v1',
0,
'replace',
);
assert.equal(
replacementReplay.batch.runId,
replacement.batch.runId,
'the same complete generation must keep one run identity across executions',
);
assert.equal(
replacementReplay.batch.idempotencyKey,
replacement.batch.idempotencyKey,
'the same complete generation must replay through the data plane idempotently',
);
const changedReplacement = contracts.buildPublishPayload(
[{ json: { ...zoneItems[0].json, attributes: { display_name: 'Zone 42 changed' } } }],
'execution-replay',
'workflow-other',
'node-other',
'map.zones.current.v1',
0,
'replace',
);
assert.notEqual(
changedReplacement.batch.idempotencyKey,
replacement.batch.idempotencyKey,
'different content at one declared generation must not alias an accepted replay',
);
const replacementBatch = contracts.buildPublishPayload(
[{ json: { generationAt: zoneItems[0].json.observedAt, facts: zoneItems.map((item) => item.json) } }],
'execution-44',
@@ -181,6 +214,7 @@ async function main() {
);
assert.deepEqual(replacementBatch.facts, replacement.facts);
assert.equal(replacementBatch.batch.generationAt, zoneItems[0].json.observedAt);
assert.equal(replacementBatch.batch.idempotencyKey, replacement.batch.idempotencyKey);
const emptyReplacement = contracts.buildPublishPayload(
[{ json: { generationAt: '2026-07-15T13:00:00.000Z', facts: [] } }],
'execution-45',