mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Admin Panel / Settings / Version was ONE table of 38 rows. The WeKan version, the OS load average, the DDP transport and a V8 heap counter were the same kind of thing in it: one flat list, read top to bottom, with no way to jump to the part you came for. Five tables now, each under a small heading, in the order somebody debugging reads them - Platform (what this IS), OS (what it runs on), Meteor (how it talks to the client: reactivity, reactivity order, DDP transport), Database (type, versions, commits, storage engine, OpLog, sessions) and Node (version, heap, memory). Reactivity and DDP moved to Meteor, where they belong: they are how the client is fed, and they were the two rows most often read as database settings. Whether an OpLog EXISTS stays with the database, because that is a property of it. No row was dropped; a test lists all 38 by name and requires each to still be shown. NEW ROW: what WeKan is installed as - bundle.zip, Snap, Docker or Sandstorm. It is the first thing a support answer turns on, and the pane never said it: the same version keeps its data somewhere else, carries a different database and gives the admin different reach in each of the four. models/lib/platformPackaging.js detects it, most-specific-first: an explicit WEKAN_PACKAGING wins (a packaging that knows what it is should say so, and it is how a future .deb or chart names itself), then Sandstorm, then snapd's own SNAP/SNAP_NAME, then a container runtime's marker file, then the bundle. Sandstorm and Snap are asked BEFORE the container markers on purpose: a grain is a container, and a confined snap can look like one, so the other order answers "Docker" for both. It claims nothing it cannot know - there is no "source checkout" answer, because a `meteor run` and an unpacked bundle are identical from inside the process. The detection is a pure function taking the environment, the Sandstorm flag and a file-exists callback, so all nine of its tests run here without a snap, a container or a grain - including that an empty SNAP is not a snap, that an empty WEKAN_PACKAGING falls through rather than blanking the field, and that an unreadable root answers bundle.zip instead of throwing an admin's Version page away. The headings are SMALLER than the pane title above them, and a test compares the two font sizes rather than trusting the CSS to stay that way: five headings at 1.25rem would read as five pane titles and "Version" would be lost among them, and an unstyled h3 - the browser default here - is larger still. Six new English strings; the other languages fall back to English until translated, as usual. tests/clientBundleImports.test.cjs caught the new stylesheet before it could matter: package.json sets meteor.mainModule, so a .css nobody imports is simply not in the bundle. It is imported from client/features/settings.js now. Thanks to xet7 !
123 lines
5.7 KiB
JavaScript
123 lines
5.7 KiB
JavaScript
'use strict';
|
|
|
|
// Admin Panel / Settings / Version says HOW WeKan was installed - bundle.zip,
|
|
// Snap, Docker or Sandstorm - and that answer is the first thing a support reply
|
|
// turns on: the same version keeps its data somewhere else, carries a different
|
|
// database and gives the admin different reach in each of the four.
|
|
//
|
|
// The detection is a pure function precisely so it can be checked here, without
|
|
// a snap, a container or a Sandstorm grain - none of which this sandbox has. The
|
|
// negative tests are the point of the file: a guess that answers "Docker" for a
|
|
// snap, or "bundle.zip" for a grain, is worse than no field at all, because it
|
|
// is read as fact.
|
|
//
|
|
// Run: node tests/platformPackaging.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
const repoRoot = path.resolve(__dirname, '..');
|
|
const { detectPackaging, PACKAGINGS, CONTAINER_MARKERS } =
|
|
require(path.join(repoRoot, 'models/lib/platformPackaging.js'));
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
// A fake filesystem: only the paths listed exist.
|
|
const exists = (...paths) => p => paths.includes(p);
|
|
|
|
console.log('platformPackaging:');
|
|
|
|
test('a plain install is the bundle .zip', () => {
|
|
assert.strictEqual(detectPackaging({ env: {}, fileExists: exists() }), 'bundle.zip');
|
|
// And with nothing passed at all, rather than throwing: the pane must render.
|
|
assert.strictEqual(detectPackaging(), 'bundle.zip');
|
|
assert.strictEqual(detectPackaging({}), 'bundle.zip');
|
|
});
|
|
|
|
test('snapd\'s own variables mean Snap, either one of them', () => {
|
|
assert.strictEqual(detectPackaging({ env: { SNAP: '/snap/wekan/3609' } }), 'Snap');
|
|
assert.strictEqual(detectPackaging({ env: { SNAP_NAME: 'wekan' } }), 'Snap');
|
|
// An empty value is not a snap - an exported-but-empty variable says nothing.
|
|
assert.strictEqual(detectPackaging({ env: { SNAP: '', SNAP_NAME: ' ' } }), 'bundle.zip');
|
|
});
|
|
|
|
test('a container runtime\'s marker file means Docker', () => {
|
|
for (const marker of CONTAINER_MARKERS) {
|
|
assert.strictEqual(detectPackaging({ env: {}, fileExists: exists(marker) }), 'Docker',
|
|
`${marker} is a container marker`);
|
|
}
|
|
// Podman writes /run/.containerenv rather than /.dockerenv, and both answer
|
|
// the question the pane is asking ("is this an image, not an unpacked zip").
|
|
assert.ok(CONTAINER_MARKERS.includes('/.dockerenv'));
|
|
assert.ok(CONTAINER_MARKERS.includes('/run/.containerenv'));
|
|
});
|
|
|
|
test('the Sandstorm flag wins over the container markers', () => {
|
|
// A grain IS a container, so asking the container question first would answer
|
|
// "Docker" for every Sandstorm install - the exact wrong answer, since a grain
|
|
// is the one packaging where the admin has no machine to log in to.
|
|
assert.strictEqual(
|
|
detectPackaging({ env: {}, isSandstorm: true, fileExists: exists('/.dockerenv') }),
|
|
'Sandstorm');
|
|
});
|
|
|
|
test('Snap wins over the container markers too', () => {
|
|
// Some systems make a confined snap look like a container to those markers.
|
|
assert.strictEqual(
|
|
detectPackaging({ env: { SNAP_NAME: 'wekan' }, fileExists: exists('/.dockerenv') }),
|
|
'Snap');
|
|
});
|
|
|
|
test('WEKAN_PACKAGING is the answer when it is set (negative: whitespace is not)', () => {
|
|
assert.strictEqual(detectPackaging({ env: { WEKAN_PACKAGING: 'Kubernetes' } }), 'Kubernetes');
|
|
// Even against every other signal: a packaging that names itself is not guessed at.
|
|
assert.strictEqual(
|
|
detectPackaging({
|
|
env: { WEKAN_PACKAGING: 'Debian package', SNAP_NAME: 'wekan' },
|
|
isSandstorm: true,
|
|
fileExists: exists('/.dockerenv'),
|
|
}),
|
|
'Debian package');
|
|
// Set but empty is NOT an answer - it must fall through, or an empty variable
|
|
// in a start script would blank the field.
|
|
assert.strictEqual(detectPackaging({ env: { WEKAN_PACKAGING: ' ' } }), 'bundle.zip');
|
|
assert.strictEqual(detectPackaging({ env: { WEKAN_PACKAGING: 42 } }), 'bundle.zip');
|
|
});
|
|
|
|
test('an unreadable filesystem root answers bundle.zip instead of throwing', () => {
|
|
// fs.existsSync does not throw, but the pane must not depend on that: a
|
|
// statistics method that throws leaves the admin with an empty Version page.
|
|
const boom = () => { throw new Error('EACCES'); };
|
|
assert.strictEqual(detectPackaging({ env: {}, fileExists: boom }), 'bundle.zip');
|
|
});
|
|
|
|
test('the four the Version pane names are the four this returns', () => {
|
|
assert.deepStrictEqual(PACKAGINGS, ['bundle.zip', 'Snap', 'Docker', 'Sandstorm']);
|
|
const answers = new Set([
|
|
detectPackaging({ env: {} }),
|
|
detectPackaging({ env: { SNAP_NAME: 'wekan' } }),
|
|
detectPackaging({ env: {}, fileExists: exists('/.dockerenv') }),
|
|
detectPackaging({ env: {}, isSandstorm: true }),
|
|
]);
|
|
assert.deepStrictEqual([...answers].sort(), [...PACKAGINGS].sort());
|
|
});
|
|
|
|
test('the server asks it with the real environment, and the pane shows the answer', () => {
|
|
// The wiring, not the guess: a perfect detector nothing calls is not a feature.
|
|
const server = fs.readFileSync(path.join(repoRoot, 'server/statistics.js'), 'utf8');
|
|
assert.ok(/detectPackaging\(\{/.test(server), 'server/statistics.js calls detectPackaging');
|
|
assert.ok(/env: process\.env/.test(server), 'with the real environment');
|
|
assert.ok(/isSandstorm/.test(server), 'and the real Sandstorm flag');
|
|
assert.ok(/fileExists: p => fs\.existsSync\(p\)/.test(server), 'and the real filesystem');
|
|
assert.ok(/statistics\.platform = \{/.test(server), 'and puts it on statistics.platform');
|
|
|
|
const jade = fs.readFileSync(
|
|
path.join(repoRoot, 'client/components/settings/informationBody.jade'), 'utf8');
|
|
assert.ok(/statistics\.platform\.packaging/.test(jade),
|
|
'the Version pane shows statistics.platform.packaging');
|
|
});
|
|
|
|
console.log(`\nplatformPackaging: ${passed} tests passed`);
|