* test(legacy): snapshot the routes and the settings response Pins every registered route and the key paths of GET /prompt_manager/settings while System S13 (#330) moves the legacy pages' tools to native System. Recorded on the unchanged main; cutover (#334) removes it. * test(legacy): prove each removed legacy control has native coverage TESTING.md gains the "Legacy System UI removed by S13" table (no rows yet). legacy-coverage.test.mjs fails when a removal cites a capability that is not covered, copies another native test, lists an id or method twice, or leaves the id or method on its page. legacy-system-links.spec.mjs holds the System link table and guards the kept admin flows. * refactor(admin): open System for Diagnostics and logs The admin page's Diagnostics and View Logs buttons become links that open System › Diagnostics & logs in a new tab. The legacy Diagnostics and System Logs dialogs and their methods go; TESTING.md lists them against their covered capabilities (rows B1–B7). * refactor(admin): open System for settings and keep page options Settings opens System › Overview in a new tab. The settings dialog becomes Page options (opened from the list header) with only the Infinite Scrolling default, and its Save posts {"infinite_scroll": …} alone, so a stale legacy form can no longer overwrite scan folders or other values edited in System (#330 S13-9). Scan folders, monitoring status, auto-hide, display mode, worker threads, LoraManager and the LoRA import leave the page (rows B8–B14). * refactor(admin): open System for maintenance Maintenance opens System › Maintenance in a new tab, where each operation runs as a reviewed Activity job. The one-click legacy Database Maintenance dialog and its methods go (rows B15–B18); formatFileSize stays for the image modal. * refactor(admin): open System for backup and restore Backup DB and Restore DB open System › Backup & export in a new tab, where a restore is staged, reviewed and run as an Activity job. The one-click Restore dialog and its methods go (rows B19–B20); the scan dialog's quick backup stays. The removed browser tests' data checks live on at the route: a new round trip test restores every prompt with its tags and image links. * test(legacy): find a removed modal id passed to showModal and settle the links spec The removal check also finds an id passed as a string to a ...Modal() call and no longer reads data-id= as id=. The no-request test waits for the page's own start-up reads to finish, the sort check compares as the server sorts, and the kept-flow test checks the added prompt shows in the list. * test(admin): open Page options after the saved default is read Drops the leftover LoraManager section comment above the Page options save. * refactor(gallery): open System for settings and maintenance The gallery's Settings opens System › Appearance in a new tab. Its settings dialog becomes Page options (a new header button) with only the page's own settings: thumbnail startup check, lazy loading, items per page, grid columns, infinite scrolling, debug mode and API timeout. Save and Reset keep every other stored key, so the Appearance values System saves survive (S13-13). Generate Thumbnails, Clear cache, Rescan and Find duplicates leave the page; Page options links System › Maintenance and Sources & scans (rows B21–B28). * refactor(autotag): manage tagging models in System In both auto-tag dialogs a model that is not downloaded shows a Manage in System link to System › Auto-tagging (a new tab) instead of a Download button, and the gallery's Unload Model becomes the same link. The legacy download dialog and the download, cancel and unload methods go (rows B29–B31); the batch and review stay. A test hook marks a fake model loaded. * docs(system): name System as the home for settings and maintenance README and TESTING.md send settings, maintenance, backups, diagnostics, the gallery's tools and auto-tag model downloads to their System section and name each legacy page's Page options. * fix(gallery): keep the default view in Page options and save viewer choices alone System › Appearance's Default layout is the workspace's own key, so the legacy gallery's Default View Mode stays a page option instead of losing its only control. The viewer's mute and loop buttons remember just that choice instead of saving the Page options dialog's unfilled inputs over the stored page options. The pending-thumbnails toast names System › Sources & scans. * test(legacy): check each System link sends no request in its own test The no-request check runs inside each link's test, so a slow page no longer times out the whole table, and it ignores lazy thumbnail loads the layout starts on its own. * test(legacy): a lazy thumbnail load is not a System link's request * fix(gallery): let the header buttons wrap on a narrow screen With Page options beside Settings the header no longer fits a phone's width; it wrapped off the page and covered the Page options dialog in the touch runs. * feat(gallery): remove Default View Mode from Page options (#330) System > Appearance's Default layout is the one default-layout control, as the S13 design's G5 says. The legacy gallery's Page options no longer show or save a default view and Reset no longer resets it. A stored legacy defaultViewMode still picks the view the gallery opens in (grid otherwise), and Save and Reset keep that key for the workspace-preferences migration.
111 lines
5.1 KiB
JavaScript
111 lines
5.1 KiB
JavaScript
// The legacy admin and gallery pages show a server refusal's reason (#220, PR #289 review I1 and M8): a job that
|
|
// runs in the workspace refuses their record-changing requests, and a corrupt config.json refuses a settings save.
|
|
// Each page must name the reason, not report a lost connection, a bare HTTP status or a success.
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const vm = require('node:vm');
|
|
|
|
function elements() {
|
|
const nodes = {};
|
|
return {
|
|
nodes,
|
|
getElementById: id => nodes[id] ||= { id, textContent: '', innerHTML: '', disabled: false, style: {},
|
|
value: '', checked: false, addEventListener() {}, querySelectorAll: () => [] },
|
|
};
|
|
}
|
|
|
|
function jsonResponse(status, body) {
|
|
return { ok: status >= 200 && status < 300, status, statusText: status === 409 ? 'Conflict' : 'OK',
|
|
json: async () => body };
|
|
}
|
|
|
|
function sseResponse(frames) {
|
|
const bytes = new TextEncoder().encode(frames.map(frame => `data: ${JSON.stringify(frame)}\n\n`).join(''));
|
|
let sent = false;
|
|
return { ok: true, status: 200, body: { getReader: () => ({
|
|
read: async () => (sent ? { done: true } : (sent = true, { done: false, value: bytes })),
|
|
}) } };
|
|
}
|
|
|
|
function load(file, className, fetchUrl, extra = {}, dom = elements()) {
|
|
const timers = [];
|
|
const notifications = [];
|
|
const storage = new Map([['pm_cached', '1'], ['userData', 'keep'], ['pm_workspace_theme', 'light'],
|
|
['pm_update_notice_dismissed', '3.3.0']]);
|
|
const localStorage = {
|
|
get length() { return storage.size; },
|
|
key: index => [...storage.keys()][index] ?? null,
|
|
getItem: key => storage.get(key) ?? null,
|
|
setItem: (key, value) => storage.set(key, String(value)),
|
|
removeItem: key => storage.delete(key),
|
|
};
|
|
const context = vm.createContext({
|
|
document: { readyState: 'loading', addEventListener() {}, getElementById: dom.getElementById,
|
|
querySelectorAll: () => [] },
|
|
window: {}, console: { error() {}, warn() {}, debug() {} },
|
|
setTimeout: callback => timers.push(callback),
|
|
confirm: () => true,
|
|
localStorage,
|
|
TextDecoder, TextEncoder, JSON,
|
|
ApiClient: { fetchUrl },
|
|
...extra,
|
|
});
|
|
// gallery.html loads cache-ownership.js before gallery.js (#222).
|
|
vm.runInContext(fs.readFileSync(path.join(__dirname, '../../web/js/cache-ownership.js'), 'utf8'), context);
|
|
const source = fs.readFileSync(path.join(__dirname, `../../web/js/${file}`), 'utf8');
|
|
const Page = vm.runInContext(`${source}\n${className};`, context, { filename: path.join(__dirname, `../../web/js/${file}`) });
|
|
const page = Object.create(Page.prototype);
|
|
page.showNotification = (message, type) => notifications.push([type, message]);
|
|
page.showModal = id => notifications.push(['show', id]);
|
|
page.hideModal = id => notifications.push(['hide', id]);
|
|
return { page, dom, timers, notifications, storage };
|
|
}
|
|
|
|
const BUSY = 'Scan for metadata already running';
|
|
|
|
test('admin settings save shows why config.json refused it', async () => {
|
|
const message = 'config.json cannot be read, so nothing was saved. Fix or remove the file, then save again.';
|
|
const { page, notifications } = load('admin.js', 'PromptAdmin',
|
|
async () => jsonResponse(409, { success: false, persisted: false, code: 'config-unreadable', error: message }));
|
|
page.settings = {};
|
|
page.setInfiniteScroll = () => assert.fail('nothing changes after a refusal');
|
|
|
|
await page.saveSettings();
|
|
|
|
assert.deepEqual(notifications, [['error', `Failed to save settings: ${message}`]]);
|
|
});
|
|
|
|
test('admin settings save keeps its plain message when the reply has no reason', async () => {
|
|
const { page, notifications } = load('admin.js', 'PromptAdmin', async () => ({ ok: false, status: 500,
|
|
json: async () => { throw new SyntaxError('not json'); } }));
|
|
page.settings = {};
|
|
|
|
await page.saveSettings();
|
|
|
|
assert.deepEqual(notifications, [['error', 'Failed to save settings']]);
|
|
});
|
|
|
|
// #330 S13-9: the admin page's reduced Page options save sends only the list's scroll default, so a stale legacy form
|
|
// can no longer overwrite scan folders or other settings edited in System.
|
|
test('admin Page options save posts only infinite_scroll', async () => {
|
|
const sent = [];
|
|
const { page, dom, notifications } = load('admin.js', 'PromptAdmin', async (url, init) => {
|
|
sent.push([url, init.method, JSON.parse(init.body)]);
|
|
return jsonResponse(200, { success: true, restart_required: true });
|
|
});
|
|
page.settings = { infiniteScroll: false };
|
|
const scrolled = [];
|
|
page.setInfiniteScroll = (on, options) => scrolled.push([on, { ...options }]);
|
|
dom.getElementById('infiniteScrollDefault').checked = true;
|
|
|
|
await page.saveSettings();
|
|
|
|
assert.deepEqual(sent, [['/prompt_manager/settings', 'POST', { infinite_scroll: true }]]);
|
|
assert.deepEqual(scrolled, [[true, { session: false }]]);
|
|
assert.equal(page.settings.infiniteScroll, true);
|
|
assert.deepEqual(notifications, [['success', 'Page options saved'], ['hide', 'settingsModal']]);
|
|
});
|
|
|