mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
One executable per platform: that platform's published bundle repackaged as a Node.js single executable application whose ZIP Node 26.11 mounts as a virtual file system (useVfs + vfsArchive). Only FerretDB is copied out, once and verified, to wekan-files/bin; native addons load from the VFS. Everything WeKan writes is in wekan-files beside the executable, which WRITABLE_PATH points at: attachments, avatars, db, bin, backup, logs, versions. WeKan now treats a WRITABLE_PATH named wekan-files as the files root (models/lib/filesRoot.js, shared by every place that derived it). Started in a terminal it shows a menu: start, stop, status, version info as Admin Panel / Version shows it, update to the newest release or change to any other (checksum verified, backed up first, the old executable kept), backup to wekan-files/backup/YYYY-MM-DD_HH-MM-SS, run at boot (systemd, launchd, Task Scheduler, cron, Termux:Boot), log, settings. Every entry is also a command. start runs the start-wekan.sh loop: recovery, requested restore, FerretDB, recovery page, WeKan, restart. Meteor's main.js chdir()s into the bundle, which a VFS cannot be, so the server role keeps a virtual working directory. Node 26.11.1 breaks fs.writev/readv while any VFS is mounted; they are rebuilt on fs.write and fs.read. single-file.yml builds every target in releases/single-file/targets.json from its verified bundle (Macs on a Mac, to re-sign), starts it where a runner exists with browser tests on amd64, and attaches what started. Release All and Release All Missing call it. Thanks to xet7 !
133 lines
6.2 KiB
JavaScript
133 lines
6.2 KiB
JavaScript
'use strict';
|
|
|
|
// Plain-Node regression guard (no Meteor) for issue #6473: the Admin Panel >
|
|
// Attachments > Filesystem Storage page always showed "/data" as the storage
|
|
// path, because the Blaze helpers computed it from process.env.WRITABLE_PATH
|
|
// ON THE CLIENT — and a browser's process.env never has WRITABLE_PATH. On a
|
|
// Snap install the real path is $SNAP_COMMON/files/attachments, so admins were
|
|
// sent looking for a /data directory that does not exist.
|
|
// Run: node tests/attachmentStoragePath.test.cjs
|
|
|
|
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 { computeStoragePaths } = require('../models/lib/attachmentStoragePath');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
// --- computeStoragePaths: the real, Snap-aware path computation ---------------
|
|
|
|
test('Snap: WRITABLE_PATH already ends in /files — /files is not appended twice', () => {
|
|
const p = computeStoragePaths('/var/snap/wekan/common/files');
|
|
assert.strictEqual(p.writablePath, '/var/snap/wekan/common/files');
|
|
assert.strictEqual(p.attachments, '/var/snap/wekan/common/files/attachments');
|
|
assert.strictEqual(p.avatars, '/var/snap/wekan/common/files/avatars');
|
|
});
|
|
|
|
test('Docker: WRITABLE_PATH=/data — files live under /data/files, NOT /data/attachments', () => {
|
|
const p = computeStoragePaths('/data');
|
|
assert.strictEqual(p.attachments, '/data/files/attachments');
|
|
assert.strictEqual(p.avatars, '/data/files/avatars');
|
|
// Negative: the old (wrong) Admin Panel default pointed here
|
|
assert.notStrictEqual(p.attachments, '/data/attachments');
|
|
});
|
|
|
|
test('parallel snap instances resolve to their own common dir', () => {
|
|
const p = computeStoragePaths('/var/snap/wekan_customer1/common/files');
|
|
assert.strictEqual(p.attachments, '/var/snap/wekan_customer1/common/files/attachments');
|
|
});
|
|
|
|
test('dev: no WRITABLE_PATH falls back to the current working directory', () => {
|
|
const p = computeStoragePaths(undefined);
|
|
assert.strictEqual(p.writablePath, process.cwd());
|
|
assert.strictEqual(p.attachments, path.join(process.cwd(), 'files', 'attachments'));
|
|
});
|
|
|
|
test('negative: empty string behaves like unset, never returns bare "/files"', () => {
|
|
const p = computeStoragePaths('');
|
|
assert.strictEqual(p.writablePath, process.cwd());
|
|
assert.ok(p.attachments.startsWith(process.cwd()));
|
|
});
|
|
|
|
test('windows-style base ending in \\files is treated as the files root', () => {
|
|
const p = computeStoragePaths('C:\\wekan\\files');
|
|
assert.ok(p.attachments.endsWith(path.join('C:\\wekan\\files', 'attachments').slice(-11)) ||
|
|
p.attachments.includes('attachments'));
|
|
assert.ok(!p.attachments.includes(`files${path.sep}files`), 'no /files/files duplication');
|
|
});
|
|
|
|
// --- the computation matches the paths WeKan actually stores files at ---------
|
|
// models/attachments.js + server/initializeDirs.js implement the same rule; if
|
|
// either drifts, the Admin Panel would show a path files are not actually in.
|
|
|
|
// The rule lives in ONE place now, models/lib/filesRoot.js, which every one of
|
|
// these asks (it also knows the single-file layout, a WRITABLE_PATH named
|
|
// wekan-files). So "the same rule" is checked as "the same function", and
|
|
// tests/singleFile.test.cjs fails if a copy of the old inline check comes back.
|
|
test('models/attachments.js uses the same files-root rule', () => {
|
|
const src = read('models/attachments.js');
|
|
assert.ok(src.includes("require('/models/lib/filesRoot')"));
|
|
assert.ok(src.includes('isFilesRoot(basePath)'));
|
|
assert.ok(src.includes("'/files/attachments'"));
|
|
});
|
|
|
|
test('server/initializeDirs.js uses the same files-root rule', () => {
|
|
const src = read('server/initializeDirs.js');
|
|
assert.ok(src.includes("require('/models/lib/filesRoot')"));
|
|
assert.ok(src.includes('isFilesRoot(basePath)'));
|
|
});
|
|
|
|
test('computeStoragePaths uses it too, so a single file\'s wekan-files is the files root', () => {
|
|
assert.ok(read('models/lib/attachmentStoragePath.js').includes('isFilesRoot(base)'));
|
|
const p = computeStoragePaths('/opt/wekan/wekan-files');
|
|
assert.equal(p.attachments, path.join('/opt/wekan/wekan-files', 'attachments'));
|
|
// Negative: a name that only ends in "-files" is not one.
|
|
assert.equal(computeStoragePaths('/srv/my-files').attachments, path.join('/srv/my-files', 'files', 'attachments'));
|
|
});
|
|
|
|
// --- the client no longer fabricates the path in the browser ------------------
|
|
|
|
test('client attachments.js path helpers no longer read process.env (undefined in a browser)', () => {
|
|
const src = read('client/components/settings/attachments.js');
|
|
assert.ok(!/process\.env\.WRITABLE_PATH/.test(src),
|
|
'client-side process.env.WRITABLE_PATH is always undefined and rendered "/data"');
|
|
assert.ok(src.includes("Meteor.call('getAttachmentStoragePaths'"),
|
|
'the client must ask the server for the real paths');
|
|
});
|
|
|
|
test('client settingBody.js path helpers no longer read process.env', () => {
|
|
const src = read('client/components/settings/settingBody.js');
|
|
assert.ok(!/WRITABLE_PATH\s*\|\|\s*'\/data'/.test(src),
|
|
'the "/data" fallback in the browser was the bug');
|
|
assert.ok(src.includes("Meteor.call('getAttachmentStoragePaths'"));
|
|
});
|
|
|
|
// --- the server method exists, is admin-only, and uses the shared helper ------
|
|
|
|
test('server exposes an admin-only getAttachmentStoragePaths method', () => {
|
|
const src = read('server/models/attachmentStorageSettings.js');
|
|
const method = src.match(/async getAttachmentStoragePaths\(\) \{[\s\S]*?\n \},/);
|
|
assert.ok(method, 'method getAttachmentStoragePaths found');
|
|
assert.ok(method[0].includes('isAdmin'), 'must require admin');
|
|
assert.ok(method[0].includes('computeStoragePaths(process.env.WRITABLE_PATH)'),
|
|
'must return the real, Snap-aware paths');
|
|
});
|
|
|
|
test('the default settings document no longer defaults to /data/attachments', () => {
|
|
const src = read('server/models/attachmentStorageSettings.js');
|
|
assert.ok(!src.includes("'/data/attachments'"),
|
|
'the old default pointed at a directory that never exists');
|
|
assert.ok(src.includes('computeStoragePaths(process.env.WRITABLE_PATH).attachments'));
|
|
});
|
|
|
|
console.log(`attachmentStoragePath.test.cjs: ${passed} tests passed`);
|