@triflare/fx 2.2.0-alpha.1 → 2.2.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/product.yml +4 -4
- package/src/build.js +13 -2
- package/src/catalog.js +35 -0
- package/src/cli/commands/check.js +4 -1
- package/src/cli/commands/feature.js +3 -1
- package/src/cli/commands/index.js +2 -0
- package/src/cli/commands/lint.js +8 -2
- package/src/cli/commands/run.js +109 -0
- package/src/cli/context.js +11 -10
- package/src/compiler.js +23 -0
- package/src/config.js +76 -0
- package/src/features.js +48 -4
- package/src/index.js +3 -0
- package/src/lint/analyze.js +40 -10
- package/src/lint/config-file.js +18 -8
- package/src/project-catalog.js +42 -0
- package/src/project.js +9 -8
- package/src/run/discover.js +24 -0
- package/src/run/parse.js +99 -0
- package/src/run/pattern.js +9 -0
- package/src/run/runner.js +636 -0
- package/src/test/runner.js +21 -38
- package/src/vm.js +16 -7
- package/vendor/pm-packager-dist/.fx-build.json +1 -1
- package/vendor/pm-vm-dist/.fx-build.json +2 -2
- package/vendor/pm-vm-dist/NOTICE +1 -1
- package/vendor/pm-vm-dist/dist/scratch-vm.js +3 -3
- /package/vendor/pm-vm-dist/dist/js/extension-worker/{extension-worker.7aa98c98b43d49535069.js → extension-worker.0d57461eefdca9f130a6.js} +0 -0
package/src/test/runner.js
CHANGED
|
@@ -12,9 +12,8 @@ import path from "node:path";
|
|
|
12
12
|
import { build } from "../build.js";
|
|
13
13
|
import { loadProject } from "../vm.js";
|
|
14
14
|
import { loadConfigFrom, DEFAULT_TESTS } from "../config.js";
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { loadVendorExtensions } from "../vendor.js";
|
|
15
|
+
import { loadProjectCatalog } from "../project-catalog.js";
|
|
16
|
+
import { coreFeatureExtensionUrls } from "../features.js";
|
|
18
17
|
import { productVersion } from "../brand.js";
|
|
19
18
|
import { discoverTests } from "./discover.js";
|
|
20
19
|
import { parseTests } from "./parse.js";
|
|
@@ -918,7 +917,10 @@ const EXTERNAL_IO_APIS = ["fetch", "WebSocket"];
|
|
|
918
917
|
* access, so this covers the VM's web APIs rather than containing code the
|
|
919
918
|
* user chose to run. Every replaced property is restored after the test.
|
|
920
919
|
*/
|
|
921
|
-
export function installExternalIOGuard(
|
|
920
|
+
export function installExternalIOGuard(
|
|
921
|
+
extensionUrls = [],
|
|
922
|
+
{ label = "fx test", hint = 'Pass "--allow-external-io" to allow it.' } = {},
|
|
923
|
+
) {
|
|
922
924
|
const allowed = new Set(extensionUrls);
|
|
923
925
|
for (const url of extensionUrls) {
|
|
924
926
|
try {
|
|
@@ -931,8 +933,7 @@ export function installExternalIOGuard(extensionUrls = []) {
|
|
|
931
933
|
const originalFetch = globalThis.fetch;
|
|
932
934
|
const block = (name) => {
|
|
933
935
|
throw new TestError(
|
|
934
|
-
`External network access is blocked during
|
|
935
|
-
'Pass "--allow-external-io" to allow it.',
|
|
936
|
+
`External network access is blocked during ${label} (${name}). ${hint}`,
|
|
936
937
|
{ exitCode: TEST_EXIT.ERROR },
|
|
937
938
|
);
|
|
938
939
|
};
|
|
@@ -992,12 +993,20 @@ async function runOneTest(options) {
|
|
|
992
993
|
* Run one test in a fresh VM and return its outcome.
|
|
993
994
|
* @returns {Promise<object>} status, duration, ticks and any failure
|
|
994
995
|
*/
|
|
995
|
-
async function runOneTestInVm({
|
|
996
|
+
async function runOneTestInVm({
|
|
997
|
+
test,
|
|
998
|
+
helpers,
|
|
999
|
+
sb3,
|
|
1000
|
+
config,
|
|
1001
|
+
seed,
|
|
1002
|
+
trustedExtensionUrls = [],
|
|
1003
|
+
}) {
|
|
996
1004
|
const started = performance.now();
|
|
997
1005
|
let vm;
|
|
998
1006
|
try {
|
|
999
1007
|
vm = await loadProject(sb3, {
|
|
1000
1008
|
allowProjectExtensions: config.allowProjectExtensions,
|
|
1009
|
+
trustedExtensionUrls,
|
|
1001
1010
|
});
|
|
1002
1011
|
} catch (error) {
|
|
1003
1012
|
// A VM or extension load failure is an execution error, not a failed
|
|
@@ -1100,36 +1109,6 @@ async function runOneTestInVm({ test, helpers, sb3, config, seed }) {
|
|
|
1100
1109
|
|
|
1101
1110
|
// ---------------------------------------------------------------------- driver
|
|
1102
1111
|
|
|
1103
|
-
/** Load vendored, feature and legacy extensions into one catalog. */
|
|
1104
|
-
async function loadCatalog({ configDir, loaded }) {
|
|
1105
|
-
const catalog = {};
|
|
1106
|
-
const extensionUrls = {};
|
|
1107
|
-
const warnings = [];
|
|
1108
|
-
if (loaded.vendor?.length) {
|
|
1109
|
-
const vendored = await loadVendorExtensions({ configDir, config: loaded });
|
|
1110
|
-
Object.assign(catalog, vendored.catalog);
|
|
1111
|
-
Object.assign(extensionUrls, vendored.extensionUrls);
|
|
1112
|
-
warnings.push(...vendored.warnings);
|
|
1113
|
-
}
|
|
1114
|
-
if (loaded.features?.length) {
|
|
1115
|
-
const features = await loadFeatureExtensions({ configDir, config: loaded });
|
|
1116
|
-
Object.assign(catalog, features.catalog);
|
|
1117
|
-
Object.assign(extensionUrls, features.extensionUrls);
|
|
1118
|
-
warnings.push(...features.warnings);
|
|
1119
|
-
}
|
|
1120
|
-
if (loaded.project?.extensions?.length) {
|
|
1121
|
-
const legacy = await loadExtensions(loaded.project.extensions, {
|
|
1122
|
-
baseDir: configDir,
|
|
1123
|
-
expectUnsandboxed: loaded.project.unsandboxed,
|
|
1124
|
-
reportUnmatchedUnsandboxed: false,
|
|
1125
|
-
});
|
|
1126
|
-
Object.assign(catalog, legacy.catalog);
|
|
1127
|
-
Object.assign(extensionUrls, legacy.extensionUrls);
|
|
1128
|
-
warnings.push(...legacy.warnings);
|
|
1129
|
-
}
|
|
1130
|
-
return { catalog, extensionUrls, warnings };
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
1112
|
/** One-line description of a failure, with its source location. */
|
|
1134
1113
|
function describeFailure(error) {
|
|
1135
1114
|
if (!error) return "";
|
|
@@ -1295,7 +1274,7 @@ export async function runTests({
|
|
|
1295
1274
|
});
|
|
1296
1275
|
|
|
1297
1276
|
let extensions = { catalog, extensionUrls, warnings: [] };
|
|
1298
|
-
if (!catalog) extensions = await
|
|
1277
|
+
if (!catalog) extensions = await loadProjectCatalog({ configDir, loaded });
|
|
1299
1278
|
|
|
1300
1279
|
// A project extension is arbitrary JavaScript that would run with Node
|
|
1301
1280
|
// process access in the VM, including its top-level code and configured
|
|
@@ -1377,6 +1356,10 @@ export async function runTests({
|
|
|
1377
1356
|
config,
|
|
1378
1357
|
seed: config.seed,
|
|
1379
1358
|
extensionUrls: extensions.extensionUrls,
|
|
1359
|
+
trustedExtensionUrls: coreFeatureExtensionUrls(
|
|
1360
|
+
loaded,
|
|
1361
|
+
extensions.extensionUrls,
|
|
1362
|
+
),
|
|
1380
1363
|
});
|
|
1381
1364
|
} catch (error) {
|
|
1382
1365
|
outcome = {
|
package/src/vm.js
CHANGED
|
@@ -305,31 +305,40 @@ export function createRenderer() {
|
|
|
305
305
|
* The dispatch broker is a process-wide singleton; dropping its services keeps
|
|
306
306
|
* one VM's extensions from logging a provider conflict for the next.
|
|
307
307
|
*
|
|
308
|
-
*
|
|
308
|
+
* `trustedExtensionUrls` names extensions that Fx itself ships. They load even
|
|
309
|
+
* when the project's own extensions are denied, because trusting a project
|
|
310
|
+
* must not silently disable a language feature the user enabled.
|
|
311
|
+
*
|
|
312
|
+
* @param {{allowProjectExtensions?: boolean, trustedExtensionUrls?: string[]}} [options]
|
|
309
313
|
*/
|
|
310
|
-
export function createVm({
|
|
314
|
+
export function createVm({
|
|
315
|
+
allowProjectExtensions = false,
|
|
316
|
+
trustedExtensionUrls = [],
|
|
317
|
+
} = {}) {
|
|
311
318
|
const { VirtualMachine, centralDispatch } = loadVmModules();
|
|
312
319
|
centralDispatch.services = {};
|
|
320
|
+
const trusted = new Set(trustedExtensionUrls.map(String));
|
|
321
|
+
const allowed = (url) => allowProjectExtensions || trusted.has(String(url));
|
|
313
322
|
const vm = new VirtualMachine();
|
|
314
323
|
vm.attachStorage(createStorage());
|
|
315
324
|
vm.attachRenderer(createRenderer());
|
|
316
325
|
// Denying the load keeps both the extension source and its top-level code
|
|
317
326
|
// from running, even when the project only configured it and no block uses
|
|
318
327
|
// it. The VM reports "Permission to load extension denied" for the project.
|
|
319
|
-
vm.securityManager.canLoadExtensionFromProject = () =>
|
|
320
|
-
Promise.resolve(
|
|
328
|
+
vm.securityManager.canLoadExtensionFromProject = (url) =>
|
|
329
|
+
Promise.resolve(allowed(url));
|
|
321
330
|
// Node has neither the web worker nor the iframe sandbox the VM would use, so
|
|
322
331
|
// a permitted extension runs in this process, exactly like PenguinMod's
|
|
323
332
|
// unsandboxed mode. Denied extensions never reach the sandbox selector.
|
|
324
|
-
vm.securityManager.getSandboxMode = () =>
|
|
325
|
-
Promise.resolve(
|
|
333
|
+
vm.securityManager.getSandboxMode = (url) =>
|
|
334
|
+
Promise.resolve(allowed(url) ? "unsandboxed" : "iframe");
|
|
326
335
|
return vm;
|
|
327
336
|
}
|
|
328
337
|
|
|
329
338
|
/**
|
|
330
339
|
* Build a fresh VM and load an sb3/pmp buffer into it.
|
|
331
340
|
* @param {Buffer} sb3
|
|
332
|
-
* @param {{allowProjectExtensions?: boolean}} [options]
|
|
341
|
+
* @param {{allowProjectExtensions?: boolean, trustedExtensionUrls?: string[]}} [options]
|
|
333
342
|
*/
|
|
334
343
|
export const loadProject = async (sb3, options = {}) => {
|
|
335
344
|
const vm = createVm(options);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scratch-vm",
|
|
3
3
|
"version": "0.2.0",
|
|
4
|
-
"commit": "
|
|
4
|
+
"commit": "3822f284c8cda2c3a0a5c6dd928221dd9ff2cee1",
|
|
5
5
|
"inputHash": "9557b90be391ad2f1deaccfd034fddf0a9591c354da50b13e4cf142a8e2654fc",
|
|
6
|
-
"builtAt": "2026-11-
|
|
6
|
+
"builtAt": "2026-11-23T19:02:25.316Z"
|
|
7
7
|
}
|
package/vendor/pm-vm-dist/NOTICE
CHANGED