Files
wekan/tests/databaseQueryBounds.test.cjs
T
Lauri Ojansivu 125e1659f8 Search: attachments are found again, by has:attachment, by their filename, and has:-attachment / has:-checklist work.
Found by the Haitian attachment-search browser test. Every attachment
lookup of the global search read the attachment's card from a top-level
cardId, which attachments do not have - they name it in meta.cardId - so
has:attachment, a free-text match on a filename and attachment:<name>
found no card at all; tests/databaseQueryBounds.test.cjs had pinned that
projection. The negated predicates (has:-attachment, has:-checklist)
were ignored and returned the cards WITH one. Soft-deleted attachments
do not count for has:attachment.

Thanks to xet7 !
2026-10-27 16:39:00 +02:00

64 lines
2.5 KiB
JavaScript

'use strict';
// Regression coverage for the high-volume query shapes used by search and the
// lazy card window. These assertions deliberately inspect the server query
// construction: a projection or board predicate applied after fetch is already
// too late to prevent database/network over-fetching.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const root = path.resolve(__dirname, '..');
const cardsPublication = fs.readFileSync(
path.join(root, 'server/publications/cards.js'),
'utf8',
);
const cardsModel = fs.readFileSync(path.join(root, 'server/models/cards.js'), 'utf8');
const dueCardsClient = fs.readFileSync(
path.join(root, 'client/components/main/dueCards.js'),
'utf8',
);
assert.match(
cardsPublication,
/const attachmentScope = Array\.isArray\(boardIds\)[\s\S]*?'meta\.boardId': \{ \$in: boardIds \}/,
'has:attachment must be restricted to the authorized card board scope',
);
assert.match(cardsPublication, /Meteor\.publish\('dueCards',[\s\S]*?limit: Math\.max\([\s\S]*?skip:/,
'Due Cards is database-paginated rather than an unlimited live cursor');
assert.match(dueCardsClient, /Meteor\.subscribe\([\s\S]*?'dueCards'[\s\S]*?page \* PAGE_SIZE/,
'the Due Cards client requests one database page at a time');
assert.match(dueCardsClient, /js-due-cards-previous-page/);
assert.match(dueCardsClient, /js-due-cards-next-page/);
assert.match(
cardsPublication,
/const checklistScope = Array\.isArray\(boardIds\)[\s\S]*?boardId: \{ \$in: boardIds \}/,
'has:checklist must be restricted to the authorized card board scope',
);
const filenameQueries = cardsPublication.match(
// meta.cardId: an attachment names its card there - the cardId this used
// to fetch was always empty, so a filename never found a card
// (tests/searchHasAttachmentPredicate.test.cjs).
/getAttachments\(\s*attachmentSelector,\s*\/\/[^\n]*\n\s*\{ fields: \{ 'meta\.cardId': 1 \} \},\s*\)/g,
) || [];
assert.strictEqual(
filenameQueries.length,
2,
'both free-text and attachment: filename searches fetch meta.cardId only',
);
assert.match(
cardsModel,
/ensureIndex\(Cards, \{\s*boardId: 1,\s*archived: 1,\s*listId: 1,\s*swimlaneId: 1,\s*sort: 1,\s*_id: 1,\s*\}\)/,
'the lazy window has equality keys followed by sort and its _id tie-breaker',
);
assert.match(
cardsModel,
/ensureIndex\(Cards, \{ boardId: 1, archived: 1, type: 1, dueAt: 1 \}\)/,
'Due Cards has an authorized-board/equality/date compound index',
);
console.log('database query bounds tests passed');