Skip to content

Commit ce64840

Browse files
erightsmhofman
authored andcommitted
fix: endow with original unstructured assert (#9514)
closes: #9515 refs: #5672 #8332 #9513 endojs/endo#2323 ## Description To address #5672 , we should change all uses of `assert` to obtain `assert` by importing it from the `@endo/errors` package. However, attempts to do so (#8332 #9513) ran into the symptoms reported at #9515 for the reasons reported there -- accidentally using the imported `assert` as the endowment for the global `assert` of new Compartments. This PR prepares the ground for these fixes to #5672 by unambiguously endowing with the original unstructured `globalThis.assert`, which will remain the correct endowment even when other uses of `assert` have migrated to the one imported from `@endo/errors`. By itself, this PR, preceding those fixes to #5672 , is not actually fixing a bug in the sense of a behavioral change. Reviewers, let me know if you think this PR should be labeled a "refactor" because of this. ### Security Considerations none ### Scaling Considerations none ### Documentation Considerations anyone gathering endowments for a new compartment should be aware of this issue, and be sure to use `globalThis.assert` as the `assert` endowment. Fortunately, this will only be of concern to advanced developers. ### Testing Considerations Since this PR doesn't actually cause any behavioral change, it cannot be tested in place. Rather, its test will be whether #9513 still passes CI once rebased on this PR. ***Update***: #9513 is now passing CI well enough to consider this PR (#9514) to be adequately tested. ### Upgrade Considerations This PR by itself does not have any dependence on @endo/errors existing, and so should be compatible even when linked against fairly ancient versions of endo.
1 parent 17bc6de commit ce64840

File tree

14 files changed

+47
-16
lines changed

14 files changed

+47
-16
lines changed

packages/SwingSet/src/controller/controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ export async function makeSwingsetController(
211211
filePrefix: 'kernel/...',
212212
endowments: {
213213
console: makeConsole(`${debugPrefix}SwingSet:kernel`),
214-
assert,
214+
// See https://github.com/Agoric/agoric-sdk/issues/9515
215+
assert: globalThis.assert,
215216
require: kernelRequire,
216217
URL: globalThis.Base64, // Unavailable only on XSnap
217218
Base64: globalThis.Base64, // Available only on XSnap

packages/SwingSet/src/kernel/kernel.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* global globalThis */
2+
13
import { assert, Fail } from '@agoric/assert';
24
import { isNat } from '@endo/nat';
35
import { importBundle } from '@endo/import-bundle';
@@ -1644,7 +1646,12 @@ export default function buildKernel(
16441646
assert(bundle);
16451647
const NS = await importBundle(bundle, {
16461648
filePrefix: `dev-${name}/...`,
1647-
endowments: harden({ ...vatEndowments, console: devConsole, assert }),
1649+
endowments: harden({
1650+
...vatEndowments,
1651+
console: devConsole,
1652+
// See https://github.com/Agoric/agoric-sdk/issues/9515
1653+
assert: globalThis.assert,
1654+
}),
16481655
});
16491656

16501657
if (deviceEndowments[name] || unendowed) {

packages/SwingSet/src/kernel/vat-loader/manager-local.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export function makeLocalVatManagerFactory({
7474
const workerEndowments = harden({
7575
...vatEndowments,
7676
console: makeVatConsole(makeLogMaker('vat')),
77-
assert,
77+
// See https://github.com/Agoric/agoric-sdk/issues/9515
78+
assert: globalThis.assert,
7879
TextEncoder,
7980
TextDecoder,
8081
Base64: globalThis.Base64, // Available only on XSnap

packages/SwingSet/src/supervisors/subprocess-node/supervisor-subprocess-node.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global WeakRef, FinalizationRegistry */
1+
/* global globalThis, WeakRef, FinalizationRegistry */
22

33
// this file is loaded at the start of a new subprocess
44
import '@endo/init';
@@ -139,7 +139,8 @@ function handleSetBundle(margs) {
139139
// Enable or disable the console accordingly.
140140
const workerEndowments = {
141141
console: makeVatConsole(makeLogMaker(`SwingSet:vat:${vatID}`)),
142-
assert,
142+
// See https://github.com/Agoric/agoric-sdk/issues/9515
143+
assert: globalThis.assert,
143144
};
144145

145146
async function buildVatNamespace(lsEndowments, inescapableGlobalProperties) {

packages/SwingSet/test/zcf-ish-upgrade/pseudo-zcf.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// @ts-nocheck
2-
/* global VatData */
2+
/* global globalThis, VatData */
33
/* eslint-disable no-unused-vars */
44

55
import { Far } from '@endo/far';
66
import { importBundle } from '@endo/import-bundle';
77
import { defineDurableKind } from '@agoric/vat-data';
8-
import { assert } from '@agoric/assert';
98
import {
109
provideHandle,
1110
provideBaggageSubset as provideBaggageSubTree,
@@ -24,7 +23,12 @@ export const buildRootObject = async (vatPowers, vatParameters, baggage) => {
2423
const { D } = vatPowers;
2524
const { contractBundleCap } = vatParameters;
2625
const contractBundle = D(contractBundleCap).getBundle();
27-
const endowments = { console, assert, VatData };
26+
const endowments = {
27+
console,
28+
// See https://github.com/Agoric/agoric-sdk/issues/9515
29+
assert: globalThis.assert,
30+
VatData,
31+
};
2832
const contractNS = await importBundle(contractBundle, { endowments });
2933
const { setupInstallation, setup: _ } = contractNS;
3034
if (!setupInstallation) {

packages/cosmic-swingset/scripts/clean-core-eval.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#! /usr/bin/env node
2+
/* global globalThis */
3+
24
import '@endo/init/debug.js';
35
import * as farExports from '@endo/far';
46
import { isEntrypoint } from '../src/helpers/is-entrypoint.js';
@@ -12,7 +14,8 @@ export const compartmentEvaluate = code => {
1214
const globals = harden({
1315
...modules,
1416
...farExports,
15-
assert,
17+
// See https://github.com/Agoric/agoric-sdk/issues/9515
18+
assert: globalThis.assert,
1619
console: {
1720
// Ensure we don't pollute stdout.
1821
debug: console.warn,

packages/spawner/src/vat-spawned.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { Far } from '@endo/marshal';
66
const endowments = {
77
VatData,
88
console,
9-
assert,
9+
// See https://github.com/Agoric/agoric-sdk/issues/9515
10+
assert: globalThis.assert,
1011
Base64: globalThis.Base64, // Present only on XSnap
1112
URL: globalThis.URL, // Absent only on XSnap
1213
};

packages/swingset-xsnap-supervisor/lib/supervisor-subprocess-xsnap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ function makeWorker(port) {
255255

256256
const workerEndowments = {
257257
console: makeVatConsole(makeLogMaker('vat')),
258-
assert,
258+
// See https://github.com/Agoric/agoric-sdk/issues/9515
259+
assert: globalThis.assert,
259260
// bootstrap provides HandledPromise
260261
HandledPromise: globalThis.HandledPromise,
261262
TextEncoder,

packages/vats/src/core/chain-behaviors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export const bridgeCoreEval = async allPowers => {
3939
const endowments = {
4040
VatData: globalThis.VatData,
4141
console,
42-
assert,
42+
// See https://github.com/Agoric/agoric-sdk/issues/9515
43+
assert: globalThis.assert,
4344
Base64: globalThis.Base64, // Present only on XSnap
4445
URL: globalThis.URL, // Absent only on XSnap
4546
};

packages/vats/src/core/core-eval-env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ declare global {
2929

3030
// endowments
3131
var VatData: VatData;
32+
// This is correctly the `Assert` type from `'ses'`, not from @endo/errors
33+
// See https://github.com/Agoric/agoric-sdk/issues/9515
3234
var assert: Assert;
3335

3436
// console is a VirtualConsole but this directive fails to override the extant global `console`

0 commit comments

Comments
 (0)