@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.
@@ -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 { loadExtensions } from "../extensions.js";
16
- import { loadFeatureExtensions } from "../features.js";
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(extensionUrls = []) {
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 fx test (${name}). ` +
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({ test, helpers, sb3, config, seed }) {
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 loadCatalog({ configDir, loaded });
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
- * @param {{allowProjectExtensions?: boolean}} [options]
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({ allowProjectExtensions = false } = {}) {
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(allowProjectExtensions);
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(allowProjectExtensions ? "unsandboxed" : "iframe");
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);
@@ -2,5 +2,5 @@
2
2
  "name": "@penguinmod/packager",
3
3
  "version": "1.9.2",
4
4
  "commit": "53f868b85ec21d2edab9ce00fd2d709da93da6d6",
5
- "builtAt": "2026-11-13T05:41:23.450Z"
5
+ "builtAt": "2026-11-23T19:00:47.193Z"
6
6
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "scratch-vm",
3
3
  "version": "0.2.0",
4
- "commit": "50fddfed34f4eed9eef28ef32bc1022397d29f46",
4
+ "commit": "3822f284c8cda2c3a0a5c6dd928221dd9ff2cee1",
5
5
  "inputHash": "9557b90be391ad2f1deaccfd034fddf0a9591c354da50b13e4cf142a8e2654fc",
6
- "builtAt": "2026-11-13T05:43:32.997Z"
6
+ "builtAt": "2026-11-23T19:02:25.316Z"
7
7
  }
@@ -2,5 +2,5 @@ This directory contains the PenguinMod VM.
2
2
 
3
3
  Upstream: https://github.com/PenguinMod/PenguinMod-Vm
4
4
  Version: 0.2.0
5
- Commit: 50fddfed34f4eed9eef28ef32bc1022397d29f46
5
+ Commit: 3822f284c8cda2c3a0a5c6dd928221dd9ff2cee1
6
6
  License: BSD-3-Clause (see LICENSE)