Files
wekan/tests/cardDescriptionDraft.test.cjs
T
Lauri Ojansivu 794346e396 cpu-exec qemu-user fallback everywhere; tests for all newest fixes.
Fix #6458 completely: the reporter's host runs inside a hypervisor that
masks AVX, and the old per-tool AVX wrappers (amd64-only, PATH-based)
were bypassed by absolute-path mongod invocations.

- New general snap-src/bin/cpu-exec: runs any binary directly when the
  CPU has the features it declares (--features x86_64=avx,aarch64=atomics
  or WEKAN_REQUIRED_CPU_FEATURES) and through same-arch qemu-user when
  not; plain zero-overhead exec with no declared features. Lookup order:
  WEKAN_QEMU_USER, qemu-<arch> next to the script (bundle/Docker),
  $SNAP/qemu-<arch>, the snap's migratemongo/avx one, then system
  qemu-user(-static). Clear error + direct run when no qemu exists, so
  the real SIGILL surfaces instead of hiding.
- Snap: mongodb-control and migration-control run every mongod 7 through
  cpu-exec, so MongoDB works without AVX (slower) and migration can READ
  modern MongoDB data on such CPUs; completed-FerretDB switch and
  migration fallbacks unchanged (switch_to_completed_ferretdb extracted).
- release-all.yml: every Linux bundle .zip ships cpu-exec + this-arch's
  static qemu-user (amd64/arm64/ppc64le/s390x/riscv64; stripped from
  win64/mac bundles), flowing into Docker and Snap automatically;
  Sandstorm .spk gets both via build-deps.sh. Bundle launcher and Docker
  entrypoint route node/ferretdb through cpu-exec.
- Docs: mongodb-avx-qemu.md and mongodb-raspi4-qemu.md document the
  built-in mechanism.

Tests, with negative cases, for the newest features and fixes at
changelog: htmljs array-vs-attributes (#6459), description draft
normalize/reset (#6455), comment draft lifecycle (#5547), attachment
delete guard (#5282), rules move actions + import normalization (#6472),
snap mongod-failure/migration recovery (#6458 #6466), FerretDB polling
defaults (#6467 #6468), UI density guards for every #6465 fix, and a
behavioral cpu-exec test against fake cpuinfo + fake qemu. All wired
into test:unit:node. Go table tests for the FerretDB SQLite filter
pushdown are in the wekan/FerretDB repo.

Updated ChangeLog.

Thanks to xet7.
2026-07-16 17:40:24 +03:00

113 lines
4.7 KiB
JavaScript

'use strict';
// Plain-Node regression guard (no Meteor) for issue #6455: the "You have an
// unsaved description" warning could never be cleared by pressing Save.
// Run: node tests/cardDescriptionDraft.test.cjs
//
// Two bugs, both guarded here:
// 1. Closing the description editor only AVOIDED ADDING a draft when the text
// matched the saved description; it never REMOVED a pre-existing
// unsaved-edits record — so once the warning appeared, "View it" -> Save
// could not clear it, only Discard could.
// 2. The comparison matched a per-line-whitespace-stripped draft against the
// RAW stored description (or null when empty), so descriptions with
// Markdown " \n" hard-breaks re-created a phantom draft on every save.
//
// The behavioral part extracts the actual `normalize` arrow function from the
// component source and exercises it, so the test fails if the normalization
// semantics change; the structural part asserts the reset paths exist.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const repoRoot = path.resolve(__dirname, '..');
const read = rel => fs.readFileSync(path.join(repoRoot, rel), 'utf8');
const cardDetails = read('client/components/cards/cardDetails.js');
const cardDescription = read('client/components/cards/cardDescription.js');
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
// --- Behavioral: the shared normalization used on BOTH sides ----------------
const normalizeSrc = cardDetails.match(
/const normalize = (\(s\) => .*);/,
);
assert.ok(normalizeSrc, 'normalize arrow function found in cardDetails.js');
// eslint-disable-next-line no-new-func
const normalize = new Function(`return ${normalizeSrc[1]};`)();
test('normalize strips per-line trailing whitespace (Markdown hard breaks)', () => {
assert.strictEqual(normalize('line one \nline two\t\nend'), 'line one\nline two\nend');
});
test('normalize maps null/undefined (empty description) to empty string', () => {
assert.strictEqual(normalize(null), '');
assert.strictEqual(normalize(undefined), '');
});
test('normalize makes draft and hard-break description compare EQUAL (#6455 bug 2)', () => {
const stored = 'first line \nsecond'; // what setDescription saved (raw)
const draftFromTextarea = 'first line\nsecond'; // what _getValue() produces
assert.strictEqual(normalize(stored), normalize(draftFromTextarea));
});
test('negative: genuinely different drafts still compare UNEQUAL', () => {
assert.notStrictEqual(normalize('alpha'), normalize('beta'));
// internal (non-trailing) whitespace is content, not noise
assert.notStrictEqual(normalize('a b'), normalize('ab'));
});
// --- Structural: the reset paths that were missing -------------------------
test('closing with a matching draft RESETS the record (bug 1 fix present)', () => {
// The else-branch reset inside _close(); before #6455 only the set() existed.
const closeBody = cardDetails.match(/this\._close = \(isReset = false\) => \{[\s\S]*?\n \};/);
assert.ok(closeBody, '_close found');
assert.ok(
closeBody[0].includes('UnsavedEdits.set(this._getUnsavedEditKey()'),
'still saves a differing draft',
);
assert.ok(
closeBody[0].includes('UnsavedEdits.reset(this._getUnsavedEditKey())'),
'_close must reset the draft when it matches the saved description',
);
});
test('both sides of the _close comparison are normalized the same way', () => {
assert.ok(
/draft !== normalize\(card\.getDescription\(\)\)/.test(cardDetails),
'comparison must normalize getDescription(), not compare it raw',
);
});
test('successful description save clears the draft explicitly (cardDetails.js)', () => {
const submit = cardDetails.match(/async 'submit \.js-card-description'[\s\S]*?\n \},/);
assert.ok(submit, 'submit handler found');
assert.ok(submit[0].includes('await card.setDescription(description);'));
assert.ok(
submit[0].includes("UnsavedEdits.reset({ fieldName: 'cardDescription', docId: card._id })"),
'submit must remove the unsaved-edits record after a successful save',
);
});
test('successful description save clears the draft explicitly (cardDescription.js)', () => {
assert.ok(cardDescription.includes("import { UnsavedEdits } from '/client/lib/unsavedEdits';"));
assert.ok(
/await this\.setDescription\(description\);[\s\S]*?UnsavedEdits\.reset\(\{[\s\S]*?fieldName: 'cardComment'/.test(cardDescription) === false,
'sanity: description form must reset the cardDescription draft, not cardComment',
);
assert.ok(
/UnsavedEdits\.reset\(\{ fieldName: 'cardDescription', docId: this\._id \}\)/.test(cardDescription),
'descriptionForm submit must remove the draft record',
);
});
console.log(`\n${passed} tests passed`);