This commit is contained in:
2026-06-25 20:57:09 -05:00
parent 552b86c323
commit e47d09d7d6
35 changed files with 4507 additions and 101 deletions

View File

@@ -2,8 +2,9 @@ import { db, load } from './setup.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
const { seed } = await load('../db.js');
const { getSetting, getBooleanSetting, getStringSetting, updateSettings, effectiveTrustedOrigins } = await load('../models/settingsModel.js');
const { resolvePowerShellExecutable, powerShellSpawnFailureLines } = await load('../services/powershellRunner.js');
const { resolvePowerShellExecutable, powerShellSignalFailureLines, powerShellSpawnFailureLines } = await load('../services/powershellRunner.js');
test('unpinned settings seed as editable defaults', () => {
// No SERVER_FQDN env var is set in the test environment, so server_fqdn is a
@@ -37,6 +38,24 @@ test('powershell_bin config is used by the runner at execution time', () => {
assert.equal(resolvePowerShellExecutable(), 'powershell.exe');
});
test('powershell_bin can be edited even when older databases marked it env-sourced', () => {
db.prepare('UPDATE settings SET value = ?, source = ? WHERE key = ?').run('pwsh', 'env', 'powershell_bin');
const result = updateSettings({ powershell_bin: 'powershell' });
assert.equal(result.powershell_bin.value, 'powershell');
assert.equal(result.powershell_bin.source, 'db');
assert.equal(resolvePowerShellExecutable(), 'powershell');
});
test('seed releases older env-sourced powershell_bin rows to the current default', () => {
db.prepare('UPDATE settings SET value = ?, source = ? WHERE key = ?').run('old-pwsh', 'env', 'powershell_bin');
seed();
const row = db.prepare('SELECT value, source FROM settings WHERE key = ?').get('powershell_bin');
assert.equal(row.value, 'pwsh');
assert.equal(row.source, 'default');
});
test('PowerShell spawn failures include operator guidance', () => {
const lines = powerShellSpawnFailureLines({ code: 'ENOENT', message: 'spawn pwsh ENOENT' }, 'pwsh');
assert.ok(lines.some((line) => line.includes('configured PowerShell executable "pwsh"')));
@@ -44,6 +63,13 @@ test('PowerShell spawn failures include operator guidance', () => {
assert.ok(lines.some((line) => line.includes('powershell.exe')));
});
test('PowerShell signal exits include crash diagnostics', () => {
const lines = powerShellSignalFailureLines('SIGABRT', 'pwsh');
assert.ok(lines.some((line) => line.includes('terminated by signal SIGABRT')));
assert.ok(lines.some((line) => line.includes('PowerShell/.NET process aborted')));
assert.ok(lines.some((line) => line.includes('pwsh -NoProfile')));
});
test('effectiveTrustedOrigins merges admin edits with built-in defaults', () => {
updateSettings({ trusted_origins: 'https://ops.example.com' });
const origins = effectiveTrustedOrigins();