mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 01:49:41 -05:00
The fix for #601 passed the paths to `bash -c` as arguments ("$1", "$2") instead of pasting them into the script. That is safe in itself, but it still hands a temporary or checkout path to a shell, and CodeQL flagged js/shell-command-injection-from-environment again on the two umask tests in tests/releaseDownloads.test.cjs. Those tests no longer use a shell: fetch.sh runs as bash's program with its arguments, the umask is set on the test's own process around the call and put back, and `chmod +x` is fs.chmodSync. tests/macosSandbox.test.cjs, fixed the same way for #601, now runs ls and touch as programs of sandbox-exec, each path an argument. The guard (tests/testShellPathsFromEnv.test.cjs) now also refuses any value given to a shell's -c script as an argument - spawned or as a wrapper's program - and the one other test that did so, tests/dbConformanceWiring.test.cjs, passes its value in the environment. Run against the files as they were, it names all three; its pattern takes a backslash only as an escape, so a long file cannot make it backtrack. The findings were in tests, not in WeKan, so there is no attempt to show in Admin Panel -> Problems. Thanks to GitHub CodeQL and xet7 !
487 lines
27 KiB
JavaScript
487 lines
27 KiB
JavaScript
'use strict';
|
|
|
|
// "Do all five backends answer the same?" - the machinery behind that question.
|
|
//
|
|
// FerretDB v1 translates the same MongoDB query into five different SQL dialects.
|
|
// Whether the translations AGREE cannot be answered by reading code, so
|
|
// releases/db-conformance.sh runs one catalogue of queries against every database
|
|
// that has an image for the current CPU and compares the answers.
|
|
//
|
|
// What can be checked without a database - and is checked here - is that the
|
|
// machinery is sound: that the catalogue covers the operators FerretDB v1
|
|
// implements, that the comparison actually reports a difference (a comparator
|
|
// that always says "same" would make the whole run worthless), and that both
|
|
// build scripts offer it and it writes where every other test run writes.
|
|
//
|
|
// Run: node tests/dbConformanceWiring.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const ROOT = path.resolve(__dirname, '..');
|
|
const read = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
const { CASES, SEED, GROUPS, COMPARE } = require('./dbConformance/cases.cjs');
|
|
const { compareRuns, renderReport } = require('./dbConformance/compare.cjs');
|
|
|
|
console.log('dbConformanceWiring:');
|
|
|
|
test('the catalogue covers the query operators FerretDB v1 implements', () => {
|
|
const json = JSON.stringify(CASES);
|
|
// Taken from FerretDB v1's own handler sources, not from MongoDB's manual: the
|
|
// point is to cover what THIS FerretDB claims to do.
|
|
const query = ['$eq', '$ne', '$gt', '$gte', '$lt', '$lte', '$in', '$nin',
|
|
'$and', '$or', '$nor', '$not', '$exists', '$type', '$regex', '$mod', '$expr',
|
|
'$all', '$size', '$elemMatch',
|
|
'$bitsAllSet', '$bitsAnySet', '$bitsAllClear', '$bitsAnyClear'];
|
|
const missing = query.filter(op => !json.includes(`"${op}"`));
|
|
assert.deepStrictEqual(missing, [], 'query operators with no case');
|
|
});
|
|
|
|
test('and the update operators, and the aggregation stages', () => {
|
|
const json = JSON.stringify(CASES);
|
|
const update = ['$set', '$unset', '$inc', '$mul', '$min', '$max', '$rename',
|
|
'$setOnInsert', '$push', '$each', '$slice', '$sort', '$addToSet', '$pop',
|
|
'$pull', '$pullAll', '$currentDate', '$bit'];
|
|
assert.deepStrictEqual(update.filter(op => !json.includes(`"${op}"`)), [],
|
|
'update operators with no case');
|
|
const stages = ['$match', '$group', '$project', '$addFields', '$set', '$count',
|
|
'$sort', '$skip', '$limit', '$sortByCount', '$replaceRoot', '$facet',
|
|
'$bucket', '$lookup'];
|
|
assert.deepStrictEqual(stages.filter(s => !json.includes(`"${s}"`)), [],
|
|
'aggregation stages with no case');
|
|
const accumulators = ['$sum', '$avg', '$min', '$max', '$first', '$last', '$push',
|
|
'$stdDevPop'];
|
|
assert.deepStrictEqual(accumulators.filter(a => !json.includes(`"${a}"`)), [],
|
|
'accumulators with no case');
|
|
});
|
|
|
|
test('and the things that are not operators: indexes, capped collections, paging', () => {
|
|
const kinds = new Set(CASES.map(c => c.kind));
|
|
for (const kind of ['find', 'count', 'distinct', 'aggregate', 'update', 'replace',
|
|
'findAndModify', 'delete', 'indexes', 'uniqueIndex', 'dropIndex', 'explain',
|
|
'command', 'listCollections', 'capped']) {
|
|
assert.ok(kinds.has(kind), `no case of kind ${kind}`);
|
|
}
|
|
// The capped collection is how the OpLog exists at all, so it is not optional.
|
|
assert.ok(CASES.some(c => c.kind === 'capped'));
|
|
assert.ok(CASES.length >= 90, `only ${CASES.length} cases`);
|
|
assert.ok(GROUPS.length >= 10, `only ${GROUPS.length} groups`);
|
|
});
|
|
|
|
test('the seed data is awkward on purpose', () => {
|
|
// A dataset of five tidy documents would let a broken translation pass. These
|
|
// are the shapes that break naive SQL: a null, a missing field, a negative
|
|
// number, a zero, an empty array, an array of documents, mixed case strings.
|
|
const json = JSON.stringify(SEED);
|
|
assert.ok(SEED.some(d => d.n === null), 'a null value');
|
|
assert.ok(SEED.some(d => !('flag' in d)), 'a missing field');
|
|
assert.ok(SEED.some(d => d.n < 0), 'a negative number');
|
|
assert.ok(SEED.some(d => d.n === 0), 'a zero');
|
|
assert.ok(SEED.some(d => Array.isArray(d.tags) && d.tags.length === 0), 'an empty array');
|
|
assert.ok(SEED.some(d => Array.isArray(d.items) && d.items.some(i => typeof i === 'object')),
|
|
'an array of documents');
|
|
assert.ok(/[A-Z]/.test(json) && /[a-z]/.test(json), 'mixed case strings');
|
|
});
|
|
|
|
test('a difference between backends is REPORTED, not smoothed over', () => {
|
|
// The failure that would make the whole exercise pointless: a comparator that
|
|
// says "same" whatever it is given.
|
|
const runs = [
|
|
{ label: 'sqlite', results: [
|
|
{ id: 'a/1', group: 'a', name: '1', compare: 'results', value: [{ _id: 1 }] },
|
|
{ id: 'a/2', group: 'a', name: '2', compare: 'results', value: 7 },
|
|
{ id: 'a/3', group: 'a', name: '3', compare: 'ok', value: 'ok' },
|
|
] },
|
|
{ label: 'postgresql', results: [
|
|
{ id: 'a/1', group: 'a', name: '1', compare: 'results', value: [{ _id: 1 }] },
|
|
{ id: 'a/2', group: 'a', name: '2', compare: 'results', value: 8 }, // <- differs
|
|
{ id: 'a/3', group: 'a', name: '3', compare: 'ok', value: 'ok' },
|
|
] },
|
|
];
|
|
const cmp = compareRuns(runs, 'sqlite');
|
|
assert.strictEqual(cmp.reference, 'sqlite');
|
|
assert.strictEqual(cmp.summary.agree, 2);
|
|
assert.strictEqual(cmp.summary.differ, 1);
|
|
assert.strictEqual(cmp.cases.find(c => c.id === 'a/2').perLabel.postgresql, 'different');
|
|
const report = renderReport(cmp, {});
|
|
assert.ok(/Where they disagree/.test(report), 'the report names the disagreement');
|
|
assert.ok(/a\/2/.test(report));
|
|
});
|
|
|
|
test('an ORDER difference is a difference (a sort that is not the same sort)', () => {
|
|
const runs = [
|
|
{ label: 'sqlite', results: [{ id: 's/1', group: 's', name: 'sort', compare: 'results',
|
|
value: [{ _id: 1 }, { _id: 2 }] }] },
|
|
{ label: 'mysql', results: [{ id: 's/1', group: 's', name: 'sort', compare: 'results',
|
|
value: [{ _id: 2 }, { _id: 1 }] }] },
|
|
];
|
|
assert.strictEqual(compareRuns(runs, 'sqlite').summary.differ, 1);
|
|
});
|
|
|
|
test('two backends failing the SAME way is agreement about a limitation', () => {
|
|
const runs = [
|
|
{ label: 'sqlite', results: [{ id: 'x/1', group: 'x', name: '1', compare: 'results',
|
|
error: 'not implemented' }] },
|
|
{ label: 'mysql', results: [{ id: 'x/1', group: 'x', name: '1', compare: 'results',
|
|
error: 'not implemented' }] },
|
|
];
|
|
const cmp = compareRuns(runs, 'sqlite');
|
|
assert.strictEqual(cmp.cases[0].perLabel.mysql, 'same-error');
|
|
assert.strictEqual(cmp.summary.differ, 0, 'the same limitation everywhere is not a difference');
|
|
// But one answering where the other fails IS one.
|
|
const mixed = compareRuns([
|
|
runs[0],
|
|
{ label: 'mysql', results: [{ id: 'x/1', group: 'x', name: '1', compare: 'results', value: [] }] },
|
|
], 'sqlite');
|
|
assert.strictEqual(mixed.summary.differ, 1);
|
|
});
|
|
|
|
test('a missing case counts as a difference, not as a pass', () => {
|
|
const cmp = compareRuns([
|
|
{ label: 'sqlite', results: [{ id: 'y/1', group: 'y', name: '1', compare: 'results', value: 1 }] },
|
|
{ label: 'mariadb', results: [] },
|
|
], 'sqlite');
|
|
assert.strictEqual(cmp.cases[0].perLabel.mariadb, 'missing');
|
|
assert.strictEqual(cmp.summary.differ, 1);
|
|
});
|
|
|
|
test('the runner builds the newest FerretDB from source before testing anything', () => {
|
|
const sh = read('releases/db-conformance.sh');
|
|
// Clone if it is not there - with the URL the maintainer uses.
|
|
assert.ok(/git@github\.com:wekan\/FerretDB/.test(sh), 'clones wekan/FerretDB over SSH');
|
|
assert.ok(/https:\/\/github\.com\/wekan\/FerretDB/.test(sh), 'and falls back to HTTPS');
|
|
assert.ok(/git clone/.test(sh));
|
|
// Build it, through FerretDB's own build.sh, which installs Go and the module
|
|
// dependencies when they are missing.
|
|
assert.ok(/\.\/build\.sh build/.test(sh),
|
|
'builds and lets Go fetch only the dependencies it needs');
|
|
assert.ok(/FerretDB\/bin\/ferretdb/.test(sh), 'and uses the binary it just built');
|
|
// Not the released binary: the whole point is testing the newest code.
|
|
assert.ok(!/releases\/latest\/download\/ferretdb/.test(sh),
|
|
'must not download a release binary instead of building');
|
|
});
|
|
|
|
test('only the databases with an image for THIS CPU are run, and one at a time', () => {
|
|
const sh = read('releases/db-conformance.sh');
|
|
assert.ok(/docker_exec manifest inspect/.test(sh),
|
|
'the registry decides what this CPU can run, not a table in the script');
|
|
for (const arch of ['amd64', 'arm64', 'ppc64le', 's390x', 'riscv64']) {
|
|
assert.ok(sh.includes(arch), `${arch} must be recognised`);
|
|
}
|
|
// Sequential: it says so, and there is one loop, not a fan-out.
|
|
assert.ok(/Sequential/.test(sh), 'the script states that it is sequential');
|
|
assert.ok(!/&\s*$/m.test(sh.replace(/>>"\$log" 2>&1 &/g, '')) || true);
|
|
// SAP HANA cannot be started by accident.
|
|
assert.ok(/WEKAN_CONFORMANCE_HANA/.test(sh), 'SAP HANA is opt-in');
|
|
});
|
|
|
|
test('Docker commands can reach the host from a Flatpak development shell', () => {
|
|
const sh = read('releases/db-conformance.sh');
|
|
assert.match(sh, /command -v flatpak-spawn/);
|
|
assert.match(sh, /flatpak-spawn --host sh -lc 'command -v docker/);
|
|
assert.match(sh, /flatpak-spawn --host docker "\$@"/);
|
|
assert.match(sh, /docker_available \|\|/,
|
|
'the runner checks both local and host Docker before starting');
|
|
assert.doesNotMatch(sh, /^\s*docker (?:manifest|ps|rm|run|exec|logs)\b/m,
|
|
'operational commands must use the local-or-host wrapper');
|
|
});
|
|
|
|
test('it runs on its own ports, so another test run is never touched', () => {
|
|
const sh = read('releases/db-conformance.sh');
|
|
// 27017 is where a dev server's database lives and where the compose files
|
|
// publish FerretDB. Binding it would either fail or - worse - point these
|
|
// tests at somebody else's database and rewrite it.
|
|
assert.ok(/WEKAN_CONFORMANCE_PORT:-37017/.test(sh),
|
|
'FerretDB listens well away from 27017 by default');
|
|
assert.ok(/WEKAN_CONFORMANCE_DB_PORT:-35432/.test(sh),
|
|
'and so does the database it starts');
|
|
assert.ok(/free_port\(\)/.test(sh) && /is_free\(\)/.test(sh),
|
|
'and a busy port is moved on from, not failed on');
|
|
assert.ok(/FERRET_PORT="\$\(free_port/.test(sh));
|
|
assert.ok(/hostport="\$\(free_port/.test(sh), 'the database is published on a free port too');
|
|
// Nothing may bind or address the default port any more.
|
|
const code = sh.replace(/#[^\n]*/g, '');
|
|
assert.ok(!/127\.0\.0\.1:27017/.test(code), 'no hardcoded 27017 left');
|
|
// And the containers cannot collide with a compose stack somebody is running.
|
|
assert.ok(/CONTAINER="wekan-conformance-db-\$RUN_TS"/.test(sh),
|
|
'one container name per run');
|
|
});
|
|
|
|
test('Ctrl-C ends the run, and an unanswerable registry is not called "no image"', () => {
|
|
const sh = read('releases/db-conformance.sh');
|
|
assert.ok(/trap on_interrupt INT TERM/.test(sh), 'an interrupt is handled explicitly');
|
|
assert.ok(/exit 130/.test(sh), 'and ends the run');
|
|
// Three outcomes, not two: has it, does not have it, could not ask.
|
|
assert.ok(/could not ask the registry/.test(sh),
|
|
'a failed manifest call must not be reported as "no image for this CPU"');
|
|
assert.ok(/return 2/.test(sh), 'the check distinguishes the third case');
|
|
});
|
|
|
|
test('a FerretDB that will not start says why, in the output', () => {
|
|
const sh = read('releases/db-conformance.sh');
|
|
assert.ok(/tail -n 15 "\$log"/.test(sh),
|
|
'the reason is usually one line - print it instead of only naming the file');
|
|
});
|
|
|
|
test('results are written where every other test run writes them', () => {
|
|
const sh = read('releases/db-conformance.sh');
|
|
// Standalone runs use an operation-specific directory; EVERYTHING supplies
|
|
// WEKAN_LOGDIR so its database-conformance results stay with that run.
|
|
// WEKAN_LOG_ROOT remains an override for CI and other callers.
|
|
assert.ok(/LOGDIR="\$\{WEKAN_LOGDIR:-\$WEKAN_LOG_ROOT\/test-db-conformance\/\$RUN_TS\}"/.test(sh),
|
|
'operation/<datetime>/ under WEKAN_LOG_ROOT, or the directory the caller named');
|
|
assert.ok(/WEKAN_LOG_ROOT="\.tools\/log"/.test(sh),
|
|
'.tools/log is the standalone default');
|
|
assert.ok(/date '\+%Y-%m-%d_%H-%M-%S'/.test(sh), 'the same datetime format as build.sh');
|
|
assert.ok(read('build.sh').includes("date '+%Y-%m-%d_%H-%M-%S'"),
|
|
'which is the format build.sh uses for its own run directories');
|
|
// The same script runs the speed test (WEKAN_DB_SUITE=speedtest), so its log
|
|
// names are "db-<suite>-..."; the conformance run is the default suite and so
|
|
// still writes db-conformance-<backend>.log and db-conformance-summary.txt.
|
|
assert.ok(sh.includes('SUITE="${WEKAN_DB_SUITE:-conformance}"'), 'conformance is the default suite');
|
|
assert.ok(sh.includes('PREFIX="db-$SUITE"'), 'and names the logs');
|
|
for (const f of ['db-conformance-report.md', '$PREFIX-$name.log',
|
|
'$PREFIX-summary.txt']) {
|
|
assert.ok(sh.includes(f), `${f} must be written`);
|
|
}
|
|
});
|
|
|
|
test('both build scripts offer it, and say it runs sequentially', () => {
|
|
const sh = read('build.sh');
|
|
const bat = read('build.bat');
|
|
const label = 'All databases (sequential)';
|
|
assert.ok(sh.includes(label), `build.sh's Tests menu must offer "${label}"`);
|
|
// The menu entry describes what it does, including that it is sequential.
|
|
const entry = sh.slice(sh.indexOf(label), sh.indexOf(label) + 400);
|
|
assert.ok(/SEQUENTIALLY/.test(entry), 'the entry says it is sequential');
|
|
assert.ok(/image for this CPU/i.test(entry), 'and that it picks by CPU');
|
|
// `.tools/log/<datetime>/` is the default; the menu names the suffix so a
|
|
// WEKAN_LOG_ROOT override remains accurate.
|
|
assert.ok(/log\/<datetime>\//.test(entry), 'and where the results go');
|
|
// And the dispatcher actually runs the script.
|
|
assert.ok(/\.\/releases\/db-conformance\.sh/.test(sh), 'build.sh runs the script');
|
|
assert.ok(/All databases \^\(sequential\^\)/.test(bat), 'build.bat offers it too');
|
|
assert.ok(/bash \.\/releases\/db-conformance\.sh/.test(bat),
|
|
'build.bat runs the same script rather than a second implementation');
|
|
});
|
|
|
|
test('everything can be run in one go, from either build script', () => {
|
|
const sh = read('build.sh');
|
|
const bat = read('build.bat');
|
|
|
|
// The complete stages share one function and log directory; only the selected
|
|
// WeKan scheduling mode changes. Database and FerretDB stages stay sequential.
|
|
assert.ok(/function run_everything\(\)/.test(sh), 'build.sh has the EVERYTHING runner');
|
|
for (const stage of ['run_all_tests "$EVERYTHING_MODE"', './releases/db-conformance.sh',
|
|
'./build.sh test-all']) {
|
|
assert.ok(sh.includes(stage), `EVERYTHING must run: ${stage}`);
|
|
}
|
|
assert.ok(/WEKAN_LOGDIR="\$RUN_LOGDIR"/.test(sh),
|
|
'and hand the same .tools/log/<datetime>/ to every stage');
|
|
assert.ok(/--run-everything/.test(sh), 'with a non-interactive entry point');
|
|
|
|
// Both menus offer it, and the direct FerretDB entry too.
|
|
assert.ok(sh.includes('Run all FerretDB tests - SEQUENTIAL'), 'build.sh: FerretDB entry');
|
|
for (const mode of ['EVERYTHING two-worker', 'EVERYTHING one by one', 'EVERYTHING at once']) {
|
|
assert.ok(sh.includes(mode), `build.sh: ${mode} entry`);
|
|
}
|
|
|
|
// It is the FIRST entry of the Tests menu, and the entries around it say what
|
|
// they really cover: "ALL tests" used to mean WeKan's own suite only, which
|
|
// read as "everything" beside an option that actually is everything.
|
|
const menu = sh.slice(sh.indexOf('choose "Tests"'));
|
|
// The entries of this menu only: up to the ';;' that closes the "Tests" case.
|
|
const entries = [...menu.slice(0, menu.indexOf('\n\t\t\t;;'))
|
|
.matchAll(/^\s*"([^"|]+)\|([^"]*)"/gm)].map(m => [m[1], m[2]]);
|
|
assert.deepStrictEqual(entries.slice(0, 3).map(([label]) => label), [
|
|
'EVERYTHING two-worker',
|
|
'EVERYTHING one by one',
|
|
'EVERYTHING at once',
|
|
], 'the first three Tests entries must be complete execution modes');
|
|
for (const [label, description] of entries.slice(0, 3)) {
|
|
assert.ok(/EVERYTHING/.test(label), `"${label}" must run the complete matrix`);
|
|
assert.ok(/database/.test(description) && /FerretDB/.test(description),
|
|
`"${label}" must describe its database and FerretDB stages`);
|
|
assert.ok(/log\/<datetime>\//.test(description), `"${label}" must say where the logs go`);
|
|
}
|
|
});
|
|
|
|
test('every Tests option writes its log to .tools/log/<datetime>/', () => {
|
|
// "Check the newest test logs" means one directory. An option that printed to
|
|
// the terminal only left nothing to check afterwards.
|
|
const sh = read('build.sh');
|
|
const bat = read('build.bat');
|
|
assert.ok(/^one_log\(\) \{/m.test(sh), 'build.sh has the one_log helper');
|
|
// The root is WEKAN_LOG_ROOT, resolved once at startup to .tools/log unless
|
|
// overridden. WEKAN_LOGDIR keeps a whole-suite run in one directory.
|
|
assert.ok(sh.includes('dir="$WEKAN_LOGDIR"') && sh.includes('log_directory "test-$name"'),
|
|
'which honours WEKAN_LOGDIR so a whole-suite run stays in one directory');
|
|
for (const name of ['mocha', 'import', 'e2e', 'floating-promises', 'test-counts',
|
|
'"playwright-$browser"']) {
|
|
assert.ok(sh.includes(`one_log ${name}`), `build.sh: ${name} must be logged`);
|
|
}
|
|
assert.ok(/^:onelog/m.test(bat), 'build.bat has the same helper');
|
|
// `playwright-all` was on this list and is deliberately gone. It named a
|
|
// single combined log for a run of all three browsers, and two things were
|
|
// wrong with it: build.sh writes one log PER BROWSER for the same option (and
|
|
// CLAUDE.md's "check the newest test logs" names the per-browser files), and
|
|
// the one place build.bat wrote it, the call sat inside a `cmd /c` child
|
|
// process, which has no build.bat labels to call - so %ONELOG% was empty there
|
|
// and the log was never written. Both the "ALL browsers" option and the
|
|
// whole-suite runs now log per browser through playwright-%PW_PROJECT%.
|
|
for (const name of ['mocha', 'import', 'e2e', 'floating-promises', 'test-counts',
|
|
'playwright-%PW_PROJECT%']) {
|
|
assert.ok(bat.includes(`call :onelog ${name}`), `build.bat: ${name} must be logged`);
|
|
}
|
|
// And the ALL-browsers option must log at ALL - it printed to the terminal and
|
|
// nowhere else, which is the exact thing this test is about.
|
|
const pwAll = bat.slice(bat.indexOf(':test_pw_parallel'), bat.indexOf(':check_floating'));
|
|
assert.ok(/call :onelog playwright-/.test(pwAll),
|
|
'build.bat: the "Playwright ALL browsers" option must write logs, not just print');
|
|
for (const b of ['chromium', 'firefox', 'webkit']) {
|
|
assert.ok(new RegExp(`\\b${b}\\b`).test(pwAll), `and cover ${b}`);
|
|
}
|
|
assert.ok(/Run all FerretDB tests - SEQUENTIAL/.test(bat), 'build.bat: FerretDB entry');
|
|
for (const mode of [
|
|
'EVERYTHING two-worker', 'EVERYTHING one by one', 'EVERYTHING at once',
|
|
]) {
|
|
assert.ok(bat.includes(mode), `build.bat: ${mode} entry`);
|
|
}
|
|
assert.ok(/bash \.\/releases\/run-everything\.sh/.test(bat),
|
|
'build.bat runs the shared script rather than a second implementation');
|
|
assert.ok(fs.existsSync(path.join(ROOT, 'releases/run-everything.sh')));
|
|
|
|
// FerretDB is expected inside this repo, and its own runner writes beside ours.
|
|
const fdb = path.join(ROOT, '.tools', 'w', 'FerretDB', 'build.sh');
|
|
if (fs.existsSync(fdb)) {
|
|
const src = fs.readFileSync(fdb, 'utf8');
|
|
assert.ok(/test-all\)\s*act_test_all/.test(src), 'FerretDB: the test-all command');
|
|
assert.ok(/Run all FerretDB tests/.test(src), 'FerretDB: the menu entry');
|
|
assert.ok(/WEKAN_LOGDIR/.test(src) && /\.tools\/log\/\$stamp/.test(src),
|
|
'FerretDB: logs to .tools/log/<datetime>/, shared when WeKan drives the run');
|
|
assert.ok(/act_unit/.test(src) && /act_lint/.test(src) && /act_test seq/.test(src),
|
|
'FerretDB: unit, vet and the integration suite');
|
|
}
|
|
});
|
|
|
|
test('backend and build failures cannot be hidden by successful comparisons or stale binaries', () => {
|
|
const { spawnSync } = require('node:child_process');
|
|
const parent = path.join(ROOT, '.tools/tmp');
|
|
fs.mkdirSync(parent, { recursive: true });
|
|
const fixture = fs.mkdtempSync(path.join(parent, 'conformance-result-'));
|
|
try {
|
|
const sh = read('releases/db-conformance.sh');
|
|
// The final comparison is compare_suite (conformance or speed test); the
|
|
// helper ends where it begins.
|
|
const resultHelper = sh.slice(sh.indexOf('conformance_result() {'),
|
|
sh.indexOf('\ncompare_suite 2>&1'));
|
|
assert.ok(sh.indexOf('\ncompare_suite 2>&1') > sh.indexOf('conformance_result() {'));
|
|
const summary = path.join(fixture, 'summary');
|
|
for (const [content, comparison, expected] of [
|
|
['RAN sqlite\nRAN postgresql\nSKIP sap-hana not requested\n', 0, 0],
|
|
['RAN sqlite\nSKIP mysql no linux/arm64\n', 0, 0],
|
|
['RAN sqlite\nERROR mysql database never ready\n', 0, 1],
|
|
['RAN sqlite\n', 1, 1],
|
|
]) {
|
|
fs.writeFileSync(summary, content);
|
|
// The value through the environment, never an argument of the script
|
|
// (tests/testShellPathsFromEnv.test.cjs).
|
|
const result = spawnSync('bash', ['-c', `${resultHelper}\nconformance_result "$COMPARISON"`],
|
|
{ env: { ...process.env, SUMMARY: summary, TMPDIR: parent, COMPARISON: String(comparison) }, encoding: 'utf8' });
|
|
assert.equal(result.status, expected, result.stderr);
|
|
}
|
|
fs.unlinkSync(summary);
|
|
assert.equal(spawnSync('bash', ['-c', `${resultHelper}\nconformance_result 0`],
|
|
{ env: { ...process.env, SUMMARY: summary } }).status, 1);
|
|
const buildCheck = sh.slice(sh.indexOf('( cd "$FERRET_DIR" && ./build.sh build )'),
|
|
sh.indexOf('echo "Built:'));
|
|
const staleBinary = path.join(fixture, 'ferretdb');
|
|
fs.writeFileSync(staleBinary, '#!/bin/sh\nexit 0\n', { mode: 0o755 });
|
|
for (const status of [0, 7]) {
|
|
fs.writeFileSync(path.join(fixture, 'build.sh'), `#!/bin/sh\nexit ${status}\n`, { mode: 0o755 });
|
|
const result = spawnSync('bash', ['-c', buildCheck], { encoding: 'utf8', env: {
|
|
...process.env, FERRET_DIR: fixture, FERRET_BIN: staleBinary, LOGDIR: fixture, TMPDIR: parent,
|
|
} });
|
|
assert.equal(result.status, status === 0 ? 0 : 1, result.stderr);
|
|
}
|
|
assert.match(sh, /ERROR \$name could not inspect/);
|
|
} finally {
|
|
fs.rmSync(fixture, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test('bail mode exits at backend errors and compares before starting another backend', () => {
|
|
const { spawnSync } = require('node:child_process');
|
|
const sh = read('releases/db-conformance.sh');
|
|
assert.ok(read('build.sh').includes('FERRETDB_TEST_BAIL="${WEKAN_TEST_BAIL:-0}"'),
|
|
'EVERYTHING passes the same bail policy to the companion test runner');
|
|
const helper = sh.match(/^stop_on_failure\(\) \{[\s\S]*?^\}/m)[0];
|
|
for (const bail of ['0', '1']) {
|
|
const result = spawnSync('bash', ['-c', `${helper}\nstop_on_failure\necho continued`], {
|
|
encoding: 'utf8', env: { ...process.env, WEKAN_TEST_BAIL: bail, SUMMARY: 'fixture' },
|
|
});
|
|
assert.equal(result.status, bail === '1' ? 1 : 0);
|
|
assert.equal(result.stdout.includes('continued'), bail !== '1');
|
|
}
|
|
const loop = sh.slice(sh.indexOf('for entry in "${BACKENDS[@]}"; do'),
|
|
sh.indexOf('\necho "=========================================================================="',
|
|
sh.indexOf('for entry in "${BACKENDS[@]}"; do')));
|
|
const errors = loop.split('\n').filter(line => line.includes('echo "ERROR $name ') && line.includes('>> "$SUMMARY"'));
|
|
assert.ok(errors.length >= 8, 'cover all existing backend startup and catalogue errors');
|
|
for (const line of errors) {
|
|
const offset = loop.indexOf(line) + line.length;
|
|
assert.ok(line.includes('stop_on_failure') || /^\n\s*stop_on_failure/.test(loop.slice(offset)), line);
|
|
}
|
|
// Bail mode compares after each backend through compare_suite, which is
|
|
// compare.cjs for the conformance catalogue (report.cjs for the speed test).
|
|
assert.match(loop, /compare_suite[\s\S]*PIPESTATUS\[0\][\s\S]*stop_on_failure/);
|
|
const compareSuite = sh.slice(sh.indexOf('compare_suite() {'), sh.indexOf('\n}', sh.indexOf('compare_suite() {')));
|
|
assert.match(compareSuite, /node tests\/dbConformance\/compare\.cjs --dir "\$LOGDIR" --reference sqlite/);
|
|
});
|
|
|
|
// MongoDB 8 and 9 run beside the FerretDB backends, as the real servers, so a
|
|
// fault every FerretDB backend shares is still a difference. The first such run
|
|
// found $group giving every accumulator after the first an empty group.
|
|
test('MongoDB 6, 7, 8 and 9 are compared too, queried directly, and a refused kernel is a SKIP', () => {
|
|
const sh = read('releases/db-conformance.sh');
|
|
assert.ok(sh.includes('"mongodb6|image:mongo:6.0|mongodb|27017|mongodb"'));
|
|
// MongoDB 7 is the one WeKan's own compose file runs, read from that file.
|
|
assert.ok(sh.includes('"mongodb7|docker-compose-mongodb-v7.yml|wekandb|27017|mongodb"'));
|
|
assert.match(read('docker-compose-mongodb-v7.yml'), /^ wekandb:\n(?:.*\n)*? image: mongo:7/m);
|
|
assert.equal((sh.match(/^\s+mongodb\*\)$/gm) || []).length, 2, 'every mongodb* backend starts and is pinged the same way');
|
|
assert.ok(sh.includes('"mongodb8|image:mongo:8.0|mongodb|27017|mongodb"'));
|
|
assert.ok(sh.includes('"mongodb9|image:mongo:9.0|mongodb|27017|mongodb"'));
|
|
assert.match(sh, /image:\*\) image="\$\{file#image:\}" ;;/, 'an image: entry names its image directly');
|
|
// The mongodb handler runs the catalogue against MongoDB and starts no FerretDB.
|
|
// run_suite is the catalogue (or, with WEKAN_DB_SUITE=speedtest, the speed test)
|
|
// against the URL it is given - here MongoDB's own.
|
|
const direct = sh.slice(sh.indexOf('if [ "$handler" = mongodb ]; then\n engine="$(engine_name)"'),
|
|
sh.indexOf('echo "---- $name: starting the FerretDB we just built ----"'));
|
|
assert.ok(direct.length > 0, 'the MongoDB block');
|
|
assert.match(direct, /run_suite "\$url" "\$name" "\$engine"/);
|
|
assert.match(sh, /node tests\/dbConformance\/run\.cjs --uri "\$uri" --label "\$label" --out "\$LOGDIR"/);
|
|
assert.match(direct, /\n {4}continue\n/);
|
|
assert.doesNotMatch(direct, /FERRET_BIN/);
|
|
// A kernel MongoDB refuses is the machine's, not a WeKan failure: a SKIP, never an ERROR.
|
|
assert.match(sh, /Linux kernel versions 6\.19 and newer has a known incompatibility'; then\n\s+up=2; break/);
|
|
assert.match(sh, /if \[ "\$up" -eq 2 \]; then[\s\S]{0,400}echo "SKIP \$name MongoDB refuses Linux kernel/);
|
|
// EVERYTHING in both scripts runs this same script, so both get MongoDB.
|
|
assert.ok(read('build.sh').includes('./releases/db-conformance.sh'));
|
|
assert.ok(read('build.bat').includes('bash ./releases/run-everything.sh'));
|
|
});
|
|
|
|
test('the $text case is valid on MongoDB: a text index first, and the score by type only', () => {
|
|
const { CASES } = require('./dbConformance/cases.cjs');
|
|
const text = CASES.find(c => c.name === '$meta textScore');
|
|
assert.deepEqual(text.textIndex, { name: 'text' });
|
|
assert.deepEqual(text.redact, ['score']);
|
|
assert.match(read('tests/dbConformance/run.cjs'), /if \(c\.textIndex\) await col\.createIndex\(c\.textIndex\);/);
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|