From 24746adfda5d4c3d27368383374cdbebc56fcfcf Mon Sep 17 00:00:00 2001 From: Daniel Truong Date: Fri, 9 Oct 2026 23:36:37 +0000 Subject: [PATCH 1/2] feat(demi): log each landed DEMI push Only failed pushes wrote a log line, so a pod log could not show that the push landed before the write response was sent. Each landed push logs one info line: [demiPush] mirrored . --- api/helpers/actions.js | 4 +++ test/helpers/actions.test.js | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/api/helpers/actions.js b/api/helpers/actions.js index bc1d66d5..e216fae3 100644 --- a/api/helpers/actions.js +++ b/api/helpers/actions.js @@ -87,6 +87,10 @@ exports.sendMirrored = async function (res, code, data, pushes) { } try { if (result.mirrored) { + // Unlabelled values (null, a bare Promise.resolve(true) from pushIfMatched) are not pushes. + for (const { kind, id } of [].concat(pushes).filter(push => push && push.kind)) { + defaultLog.info(`[demiPush] mirrored ${kind} ${id}`, { kind, id }); + } return exports.sendResponse(res, code, data); } for (const { kind, id, reason } of result.failures) { diff --git a/test/helpers/actions.test.js b/test/helpers/actions.test.js index e80aef4c..6a4ff87c 100644 --- a/test/helpers/actions.test.js +++ b/test/helpers/actions.test.js @@ -423,6 +423,56 @@ describe('Actions Helper Functions', () => { expect(res.code).to.equal(200); expect(res.body).to.deep.equal({ ok: 1 }); }); + + it(`logs no mirrored line when the write had no push to wait for (${none})`, async () => { + const infoLog = sinon.stub(defaultLog, 'info'); + + await actions.sendMirrored(res, 200, { ok: 1 }, none); + + expect(infoLog.called).to.be.false; + }); + }); + + describe('mirrored log line', () => { + let infoLog; + const push = (kind, id) => Object.assign(Promise.resolve(true), { kind, id }); + + beforeEach(() => { + infoLog = sinon.stub(defaultLog, 'info'); + }); + + it('logs one info line naming kind and id when one push landed', async () => { + await actions.sendMirrored(res, 200, {}, push('document', 'd1')); + + expect(infoLog.calledOnce).to.be.true; + expect(infoLog.firstCall.args[0]).to.equal('[demiPush] mirrored document d1'); + expect(infoLog.firstCall.args[1]).to.deep.equal({ kind: 'document', id: 'd1' }); + }); + + it('logs one info line per landed push, in order', async () => { + await actions.sendMirrored(res, 200, {}, [push('organization', 'o1'), push('users', 'org:o1')]); + + expect(infoLog.args.map(args => args[0])).to.deep.equal([ + '[demiPush] mirrored organization o1', + '[demiPush] mirrored users org:o1' + ]); + }); + + it('logs no info line when a push failed', async () => { + const failed = Object.assign(Promise.resolve(false), { kind: 'document', id: 'd1' }); + + await actions.sendMirrored(res, 200, {}, failed); + + expect(res.code).to.equal(502); + expect(infoLog.called).to.be.false; + }); + + it('logs nothing for a value that is not a labelled push', async () => { + await actions.sendMirrored(res, 200, {}, Promise.resolve(true)); + + expect(res.code).to.equal(200); + expect(infoLog.called).to.be.false; + }); }); }); }); From ceaf3a4d8f89182d5aed99b7c3720900d26eb44f Mon Sep 17 00:00:00 2001 From: Daniel Truong Date: Fri, 9 Oct 2026 23:49:33 +0000 Subject: [PATCH 2/2] fix(demi): log landed pushes when a sibling fails The mirrored guard hid the info line for pushes that landed in the same write as a failed one. result.landed already holds only the pushes that landed. --- api/helpers/actions.js | 6 ++---- test/helpers/actions.test.js | 9 +++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/api/helpers/actions.js b/api/helpers/actions.js index ef05c665..e4d31bba 100644 --- a/api/helpers/actions.js +++ b/api/helpers/actions.js @@ -94,10 +94,8 @@ exports.sendMirrored = async function (res, code, data, pushes) { await demiPush.recordOutcome(result); const attempted = !result.mirrored || result.landed.length > 0; try { - if (result.mirrored) { - for (const { kind, id } of result.landed) { - defaultLog.info(`[demiPush] mirrored ${kind} ${id}`, { kind, id }); - } + for (const { kind, id } of result.landed) { + defaultLog.info(`[demiPush] mirrored ${kind} ${id}`, { kind, id }); } return exports.sendResponse(res, code, replyBody(data, attempted ? result.mirrored : undefined)); } catch (err) { diff --git a/test/helpers/actions.test.js b/test/helpers/actions.test.js index 94fcbb65..ac884d44 100644 --- a/test/helpers/actions.test.js +++ b/test/helpers/actions.test.js @@ -625,6 +625,15 @@ describe('Actions Helper Functions', () => { expect(infoLog.called).to.be.false; }); + it('logs the push that landed when a sibling push failed', async () => { + await actions.sendMirrored(res, 200, { _id: OID }, [push('organization', 'o1'), labelled(false)]); + + expect(res.body.mirrored).to.equal(false); + expect(infoLog.calledOnce).to.be.true; + expect(infoLog.firstCall.args[0]).to.equal('[demiPush] mirrored organization o1'); + expect(infoLog.firstCall.args[1]).to.deep.equal({ kind: 'organization', id: 'o1' }); + }); + it('logs nothing for a value that is not a labelled push', async () => { await actions.sendMirrored(res, 200, {}, Promise.resolve(true));