mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Sync and the stored rule archive runner fixed each History row's previousHash and integrityHash when they PLANNED a batch, so the board's History chain had to stay unchanged from planning until the last row was written - which needed a multi-row History reservation that would block or queue ordinary edits, and made a coordinated board refuse Sync. Maintainer decision of 2026-09-30: plans are content only, and each row is linked when it is appended, like an ordinary edit. On a board still on the legacy path, the batch holds one writer token (so a chain migration drains it) and each row is linked after the chain's tip - the newest hashed row, then its successors, since the rows of one batch share a planned createdAt and "newest" alone is a tie that forks the chain. On a coordinated board each row goes through the chain head. Appends are idempotent by row _id, and a replay accepts only the planned content. The archive runner needs no reservation any more; it captures the actor's redo candidates when it plans. Plans in the old chained format are refused. An index on (boardId, previousHash) serves the tip walk. Unit and MongoDB tests: plans carry no link; rows chain correctly in both modes and replay once; ordinary History written between planning and writing is neither blocked nor forked; a coordinated board appends through the head; old-format plans and adapters without admission or linking are refused. The full-app archive case now runs without a reservation and verifies the resulting chain. 561 server tests pass; the one other failure in that run, the activity notification recovery scan, is intermittent and passes on its own. Thanks to xet7 !
29 lines
1.6 KiB
JavaScript
29 lines
1.6 KiB
JavaScript
'use strict';
|
|
// A History adapter for the Sync integration tests that behaves like the
|
|
// production legacy path (server/lib/storedHistoryChain.js): one writer, and
|
|
// each appended row linked after the chain's TIP - the newest hashed row, then
|
|
// its successors, because the rows of one Sync batch share a planned createdAt.
|
|
const { hashHistoryRow } = require('../../models/lib/changeHistoryIntegrity');
|
|
function linkingHistory(events, extra = {}) {
|
|
const history = {
|
|
admitHistoryWriter: ({ work }) => work({ mode: 'legacy', assertCurrent: async () => {} }),
|
|
// `this` is the adapter the caller built, so its own insertAsync (which a
|
|
// test may make fail or lose its reply) is the one used.
|
|
async appendSyncHistoryRow({ row }) {
|
|
if (await events.findOne({ _id: row._id })) return row._id;
|
|
let previous = await events.findOne({ boardId: row.boardId, integrityHash: { $nin: [null, ''] } }, { sort: { createdAt: -1 } });
|
|
for (let next; previous && (next = await events.findOne({ boardId: row.boardId, previousHash: previous.integrityHash }));) previous = next;
|
|
const saved = { ...row, previousHash: previous ? previous.integrityHash : null };
|
|
saved.integrityHash = hashHistoryRow(saved);
|
|
await this.insertAsync(saved);
|
|
return row._id;
|
|
},
|
|
findOneAsync: query => events.findOne(typeof query === 'string' ? { _id: query } : query),
|
|
insertAsync: async row => { await events.insertOne(row); return row._id; },
|
|
updateAsync: async (selector, modifier) => (await events.updateOne(selector, modifier)).modifiedCount,
|
|
...extra,
|
|
};
|
|
return history;
|
|
}
|
|
module.exports = { linkingHistory };
|