Plugins belong to the project, and they load before it: the project file gained the field plugins: ["demo-plugin.js"] (default empty, no formatVersion bump), the Plugins tab's switch writes into it as an ordinary undo step (SetPluginActiveCommand) instead of into a server-wide plugins.json, and the start order is turned around - startPlugins only fetches the list of files, then editor.boot() runs and ProjectStore.load(id, prepare) hands the raw JSON through before it is deserialized, where pluginsOf(raw) reads the list and PluginManager.syncTo() activates exactly those; that is the point of the issue, because what a plugin registers has to stand there before normalizeGraph would throw it away as unknown (#126, #127), a project switch first stops what the new project does not name and then starts what it does, a file the server does not have is passed over silently, and after signing out the manager is dead so a late event cannot start anything in a torn-down session; on the server plugins.json, PluginStore::setActive, isActive, the route PUT ?r=plugins/{file} and the 403 for inactive modules are gone and GET ?r=plugins only answers {file,bytes,updatedAt}, which makes every plugin file fetchable - the consequence accepted in #117, written down in the wiki for #115 and #116; publishPlugins(root) only copies files now, the seeder switches the demo plugin on in the fixture project, and the Plugins tab carries a puzzle piece as its icon while only a plugin's own tab still goes without one (the knob and the socket are cubic curves, not arcs, which Pixi's parser draws as a spike after an L); 3 new e2e checks in module 38 and 5 new unit tests cover the project as the owner of the switch, its undo, the order, pluginsOf against crude input and an unknown file name (#119)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c830c7a3aa
commit
5ba796a2b6
28 files changed
+425
-269
No files matched your search
@@ -85,12 +85,12 @@ export async function overflow(t) {
|
||||
.filter((b) => ['scene', 'game', 'plugins'].includes(b.tab))
|
||||
.map((b) => [b.tab, b.icon]);
|
||||
check(
|
||||
'Scene and Game show an icon before their name, Plugins none',
|
||||
'Scene, Game and Plugins show an icon before their name',
|
||||
JSON.stringify(fixedIcons) ===
|
||||
JSON.stringify([
|
||||
['scene', true],
|
||||
['game', true],
|
||||
['plugins', false],
|
||||
['plugins', true],
|
||||
]) && sceneInk >= 20,
|
||||
JSON.stringify({ fixedIcons, sceneInk }),
|
||||
);
|
||||
@@ -141,8 +141,8 @@ export async function overflow(t) {
|
||||
await clickText('»');
|
||||
const offered = (await json('__gm.menuRows()')).filter(Boolean);
|
||||
const offeredIcons = (await json('__gm.menuIcons()')).filter((icon) => icon !== null);
|
||||
// Every hidden tab brings its icon along; only Plugins and a plugin's own tab have none (#176).
|
||||
const withIcon = (tab) => tab !== 'plugins' && !tab.startsWith('plugin:');
|
||||
// Every hidden tab brings its icon along; only a plugin's own tab has none (#176, #119).
|
||||
const withIcon = (tab) => !tab.startsWith('plugin:');
|
||||
check(
|
||||
'the overflow button offers every tab that had to go, each with the icon its tab shows',
|
||||
offered.length === narrow.hidden.length &&
|
||||
|
||||
+49
-20
@@ -1,12 +1,12 @@
|
||||
import { openTab, pickAssetType } from './lib/scaffold.mjs';
|
||||
|
||||
/**
|
||||
* Plugins (#113, #114). The demo plugin in `plugins/` is copied to `data/plugins/` by the build and
|
||||
* the seeder, switched on; the editor loads it at start-up through the API. What only a running
|
||||
* editor can show: that the module really loads and activates, that its tab joins the row, that its
|
||||
* node board draws one node per asset and follows the asset list – created through the + menu,
|
||||
* renamed, and taken away again by undo – and that the switch in the Plugins tab stops and starts
|
||||
* it while the editor runs.
|
||||
* Plugins (#113, #114, #119). The demo plugin in `plugins/` is copied to `data/plugins/` by the
|
||||
* build and the seeder; the fixture project switches it on, and the editor loads it before the
|
||||
* project itself. What only a running editor can show: that the module really loads and activates,
|
||||
* that its tab joins the row, that its node board draws one node per asset and follows the asset
|
||||
* list – created through the + menu, renamed, and taken away again by undo – and that the switch in
|
||||
* the Plugins tab stops and starts it while the editor runs, as an undo step of the project.
|
||||
*/
|
||||
export async function plugins(t) {
|
||||
const { check, sleep, json, evaluate, mutate, clickText, drag, wheel, press, shot, showTab, settle, undo } =
|
||||
@@ -27,6 +27,11 @@ export async function plugins(t) {
|
||||
demo?.status === 'active' && demo.meta?.id === 'demo' && demo.meta.api === 1,
|
||||
JSON.stringify(records),
|
||||
);
|
||||
check(
|
||||
'and it runs because the project switches it on, not the server',
|
||||
JSON.stringify(await json('__gm.state.project.plugins')) === JSON.stringify(['demo-plugin.js']),
|
||||
JSON.stringify(await json('__gm.state.project.plugins')),
|
||||
);
|
||||
check(
|
||||
'no plugin failed',
|
||||
records.every((r) => r.status === 'active'),
|
||||
@@ -158,7 +163,8 @@ export async function plugins(t) {
|
||||
await showTab('scene');
|
||||
check('switching to another tab hides the board', (await board()).visible === false);
|
||||
|
||||
// 38i. The Plugins tab (#114): the switch is the server's, and it works while the editor runs.
|
||||
// 38i. The Plugins tab (#114, #119): the switch belongs to the project, and it works while the
|
||||
// editor runs.
|
||||
await openTab(t, 'plugins');
|
||||
await settle();
|
||||
const pane = () => json('__gm.plugins.pane()');
|
||||
@@ -173,17 +179,20 @@ export async function plugins(t) {
|
||||
JSON.stringify(rows),
|
||||
);
|
||||
|
||||
const settled = async (was) => {
|
||||
// Loading a module is a fetch, so the switch is applied a moment after the click.
|
||||
for (let i = 0; i < 50; i++) {
|
||||
const now = await pane();
|
||||
if (rowOf(now)?.status !== rowOf(was)?.status) return now;
|
||||
await sleep(100);
|
||||
}
|
||||
return pane();
|
||||
};
|
||||
const toggle = async () => {
|
||||
const at = await json('__gm.plugins.switchAt("demo-plugin.js")');
|
||||
await t.click(at.x, at.y);
|
||||
await settle();
|
||||
// Switching goes to the server and back before it is applied.
|
||||
for (let i = 0; i < 50; i++) {
|
||||
const now = await pane();
|
||||
if (rowOf(now)?.status !== rowOf(rows)?.status) return now;
|
||||
await sleep(100);
|
||||
}
|
||||
return pane();
|
||||
return settled(rows);
|
||||
};
|
||||
|
||||
rows = await toggle();
|
||||
@@ -199,16 +208,36 @@ export async function plugins(t) {
|
||||
(await board()) === null,
|
||||
JSON.stringify(rowAfterOff),
|
||||
);
|
||||
// The switch is the server's, not this browser's: the list says so for everyone. (That a
|
||||
// switched-off module is not handed out either is the API's own check, not one for here – the
|
||||
// refusal never reaches the page, the site's firewall answers it with a page of its own.)
|
||||
// The switch is the project's (#119): it stands in the project file and travels with it. The
|
||||
// server's own list knows nothing about it any more – it only says which files there are.
|
||||
const listed = await evaluate(
|
||||
`fetch('/game-maker/api/index.php?r=plugins').then(async (r) => JSON.stringify(await r.json()))`,
|
||||
);
|
||||
const entry = JSON.parse(listed).find((e) => e.file === 'demo-plugin.js');
|
||||
check(
|
||||
'the server stores the switch: its list says the plugin is off',
|
||||
JSON.parse(listed).find((e) => e.file === 'demo-plugin.js')?.active === false,
|
||||
listed,
|
||||
'the project says it is off, while the server still lists the file itself',
|
||||
JSON.stringify(await json('__gm.state.project.plugins')) === '[]' &&
|
||||
entry !== undefined &&
|
||||
entry.active === undefined,
|
||||
JSON.stringify({ plugins: await json('__gm.state.project.plugins'), entry }),
|
||||
);
|
||||
|
||||
// And because it is a change to the project, undo takes it back – plugin, tab and all.
|
||||
await undo();
|
||||
rows = await settled(rows);
|
||||
const afterUndo = await json('__gm.tabRow()');
|
||||
check(
|
||||
'undo switches it on again, as a step of the project',
|
||||
JSON.stringify(await json('__gm.state.project.plugins')) === JSON.stringify(['demo-plugin.js']) &&
|
||||
rowOf(rows)?.status === 'active' &&
|
||||
[...afterUndo.shown.map((p) => p.tab), ...afterUndo.hidden].includes('plugin:assets'),
|
||||
JSON.stringify({ plugins: await json('__gm.state.project.plugins'), row: rowOf(rows) }),
|
||||
);
|
||||
rows = await toggle();
|
||||
check(
|
||||
'and clicking the switch off again stops it once more',
|
||||
rowOf(rows)?.status === 'inactive' && JSON.stringify(await json('__gm.state.project.plugins')) === '[]',
|
||||
JSON.stringify({ row: rowOf(rows), plugins: await json('__gm.state.project.plugins') }),
|
||||
);
|
||||
|
||||
rows = await toggle();
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
export function publishPlugins(root: string, options?: { force?: boolean }): void;
|
||||
export const DEMO_PLUGIN: string;
|
||||
export function publishPlugins(root: string): void;
|
||||
+11
-46
@@ -1,64 +1,29 @@
|
||||
import {
|
||||
chownSync,
|
||||
copyFileSync,
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
readdirSync,
|
||||
readFileSync,
|
||||
statSync,
|
||||
writeFileSync,
|
||||
} from 'node:fs';
|
||||
import { chownSync, copyFileSync, existsSync, mkdirSync, readdirSync, statSync } from 'node:fs';
|
||||
import { resolve } from 'node:path';
|
||||
|
||||
/** The demo plugin the seed projects switch on (#119); `DEMO_PLUGIN` is its file name. */
|
||||
export const DEMO_PLUGIN = 'demo-plugin.js';
|
||||
|
||||
/**
|
||||
* Puts the plugins that ship with the repository (`plugins/*.js`) where the editor loads them from,
|
||||
* `data/plugins/`, and switches them on in `plugins.json` (#114) – a plugin put there by hand stays
|
||||
* off until someone switches it on in the Plugins tab. Used by the build and by the e2e seeder.
|
||||
* `data/plugins/`. Used by the build and by the e2e seeder.
|
||||
*
|
||||
* `force` is the seeder's: the checks need the demo plugin on, whatever a person did with the
|
||||
* switch. The build only switches on what the state does not name yet, so a plugin switched off
|
||||
* on the server stays off across deployments.
|
||||
* Which of them run is not decided here any more (#119): a plugin is switched on by the project
|
||||
* that wants it, so the seeders name it in the projects they write. What lies in `data/plugins/`
|
||||
* is only what is available.
|
||||
*
|
||||
* The API writes `plugins.json` as the web server's user. When this runs as root (the build on the
|
||||
* The API reads the folder as the web server's user. When this runs as root (the build on the
|
||||
* host), the folder and what it wrote are handed to the owner of `data/`, which is that user.
|
||||
*/
|
||||
export function publishPlugins(root, { force = false } = {}) {
|
||||
export function publishPlugins(root) {
|
||||
const target = resolve(root, 'data/plugins');
|
||||
mkdirSync(target, { recursive: true });
|
||||
const written = [target];
|
||||
const shipped = readdirSync(resolve(root, 'plugins')).filter((f) => f.endsWith('.js'));
|
||||
for (const file of shipped) {
|
||||
for (const file of readdirSync(resolve(root, 'plugins')).filter((f) => f.endsWith('.js'))) {
|
||||
copyFileSync(resolve(root, 'plugins', file), resolve(target, file));
|
||||
written.push(resolve(target, file));
|
||||
}
|
||||
|
||||
const statePath = resolve(target, 'plugins.json');
|
||||
let state = {};
|
||||
if (existsSync(statePath)) {
|
||||
try {
|
||||
state = JSON.parse(readFileSync(statePath, 'utf8'));
|
||||
} catch {
|
||||
console.warn(`${statePath} is not readable JSON – left as it is, no plugin switched on`);
|
||||
state = null;
|
||||
}
|
||||
}
|
||||
if (state && typeof state === 'object') {
|
||||
let changed = false;
|
||||
for (const file of shipped) {
|
||||
if (!force && Object.hasOwn(state, file)) continue;
|
||||
if (state[file]?.active === true) continue;
|
||||
state[file] = { active: true };
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
const sorted = Object.fromEntries(
|
||||
Object.entries(state).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),
|
||||
);
|
||||
writeFileSync(statePath, `${JSON.stringify(sorted, null, 4)}\n`);
|
||||
}
|
||||
written.push(statePath);
|
||||
}
|
||||
|
||||
if (process.getuid?.() === 0) {
|
||||
const { uid, gid } = statSync(resolve(root, 'data'));
|
||||
for (const path of written) if (existsSync(path)) chownSync(path, uid, gid);
|
||||
|
||||
+9
-6
@@ -9,19 +9,19 @@
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { sineWav } from './lib/audio.mjs';
|
||||
import { edge, node, port, sceneObject, variable } from './lib/builders.mjs';
|
||||
import { publishPlugins } from './lib/plugins.mjs';
|
||||
import { DEMO_PLUGIN, publishPlugins } from './lib/plugins.mjs';
|
||||
import { PROJECTS, cliArgs, uploadFont, uploadSound, writeProject } from './lib/projects.mjs';
|
||||
import { adjustColorsShader } from './lib/shaders.mjs';
|
||||
|
||||
const { projectId, baseUrl } = cliArgs('seed-e2e.mjs', PROJECTS.fixture);
|
||||
|
||||
/**
|
||||
* The plugins that ship with the repository, where the editor loads them from and switched on –
|
||||
* the build does the same, this makes a run after a plain checkout independent of it, and puts the
|
||||
* demo plugin back on after a step (or a person) switched it off. The server is this checkout
|
||||
* (locally and in CI), so a file copy is enough.
|
||||
* The plugins that ship with the repository, where the editor loads them from – the build does the
|
||||
* same, this makes a run after a plain checkout independent of it. That the demo plugin is also
|
||||
* switched on is part of the fixture project below (#119). The server is this checkout (locally
|
||||
* and in CI), so a file copy is enough.
|
||||
*/
|
||||
publishPlugins(fileURLToPath(new URL('..', import.meta.url)), { force: true });
|
||||
publishPlugins(fileURLToPath(new URL('..', import.meta.url)));
|
||||
|
||||
/**
|
||||
* Two typefaces for the font step to pick and to drop. They are put on the server but not made
|
||||
@@ -84,6 +84,9 @@ const project = {
|
||||
id: projectId,
|
||||
name: 'E2E fixture',
|
||||
activeSceneId: 'scene1',
|
||||
// The demo plugin is switched on by the project since #119, not by a state file on the server –
|
||||
// this is what step 38 finds running.
|
||||
plugins: [DEMO_PLUGIN],
|
||||
assets: [
|
||||
{
|
||||
id: 'scene1',
|
||||
|
||||
Reference in new issue
Block a user