From 4850d63d1d41e022330a80ea5e354186efb1dae0 Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Mon, 15 Apr 2024 11:49:19 -0700 Subject: [PATCH 1/3] refactor(daemon): Rename Locator to Config Renames the daemon's `Locator`, used to specify its file and storage paths, to `Config` to get rid of the name collision with endo locator strings. --- packages/daemon/index.js | 48 ++--- packages/daemon/src/daemon-node-powers.js | 35 ++-- packages/daemon/src/daemon-node.js | 6 +- packages/daemon/src/pet-store.js | 6 +- packages/daemon/src/types.d.ts | 2 +- packages/daemon/src/worker-node.js | 6 +- packages/daemon/src/worker.js | 6 +- packages/daemon/test/test-endo.js | 240 +++++++++++----------- packages/daemon/types.d.ts | 14 +- 9 files changed, 184 insertions(+), 179 deletions(-) diff --git a/packages/daemon/index.js b/packages/daemon/index.js index 2dbf76a63c..8158e4be55 100644 --- a/packages/daemon/index.js +++ b/packages/daemon/index.js @@ -41,7 +41,7 @@ const info = { temp, }; -const defaultLocator = { +const defaultConfig = { statePath: whereEndoState(process.platform, process.env, info), ephemeralStatePath: whereEndoEphemeralState( process.platform, @@ -56,11 +56,11 @@ const endoDaemonPath = url.fileURLToPath( new URL('src/daemon-node.js', import.meta.url), ); -export const terminate = async (locator = defaultLocator) => { +export const terminate = async (config = defaultConfig) => { const { resolve: cancel, promise: cancelled } = makePromiseKit(); const { getBootstrap, closed } = await makeEndoClient( 'harbinger', - locator.sockPath, + config.sockPath, cancelled, ); const bootstrap = getBootstrap(); @@ -72,11 +72,11 @@ export const terminate = async (locator = defaultLocator) => { await closed.catch(() => {}); }; -export const start = async (locator = defaultLocator) => { - await fs.promises.mkdir(locator.statePath, { +export const start = async (config = defaultConfig) => { + await fs.promises.mkdir(config.statePath, { recursive: true, }); - const logPath = path.join(locator.statePath, 'endo.log'); + const logPath = path.join(config.statePath, 'endo.log'); const output = fs.openSync(logPath, 'a'); const env = { ...process.env }; @@ -84,10 +84,10 @@ export const start = async (locator = defaultLocator) => { const child = popen.fork( endoDaemonPath, [ - locator.sockPath, - locator.statePath, - locator.ephemeralStatePath, - locator.cachePath, + config.sockPath, + config.statePath, + config.ephemeralStatePath, + config.cachePath, ], { detached: true, @@ -143,31 +143,31 @@ const enoentOk = error => { throw error; }; -export const clean = async (locator = defaultLocator) => { +export const clean = async (config = defaultConfig) => { if (process.platform !== 'win32') { - await removePath(locator.sockPath).catch(enoentOk); + await removePath(config.sockPath).catch(enoentOk); } }; -export const stop = async (locator = defaultLocator) => { - await terminate(locator).catch(() => {}); - await clean(locator); +export const stop = async (config = defaultConfig) => { + await terminate(config).catch(() => {}); + await clean(config); }; -export const restart = async (locator = defaultLocator) => { - await stop(locator); - return start(locator); +export const restart = async (config = defaultConfig) => { + await stop(config); + return start(config); }; -export const purge = async (locator = defaultLocator) => { - await terminate(locator).catch(() => {}); +export const purge = async (config = defaultConfig) => { + await terminate(config).catch(() => {}); - const cleanedUp = clean(locator); - const removedState = removePath(locator.statePath).catch(enoentOk); - const removedEphemeralState = removePath(locator.ephemeralStatePath).catch( + const cleanedUp = clean(config); + const removedState = removePath(config.statePath).catch(enoentOk); + const removedEphemeralState = removePath(config.ephemeralStatePath).catch( enoentOk, ); - const removedCache = removePath(locator.cachePath).catch(enoentOk); + const removedCache = removePath(config.cachePath).catch(enoentOk); await Promise.all([ cleanedUp, removedState, diff --git a/packages/daemon/src/daemon-node-powers.js b/packages/daemon/src/daemon-node-powers.js index 9dceb68823..39e684dd83 100644 --- a/packages/daemon/src/daemon-node-powers.js +++ b/packages/daemon/src/daemon-node-powers.js @@ -290,18 +290,16 @@ export const makeCryptoPowers = crypto => { /** * @param {import('./types.js').FilePowers} filePowers * @param {import('./types.js').CryptoPowers} cryptoPowers - * @param {import('./types.js').Locator} locator - * @param {boolean} [includeWebPageBundler] + * @param {import('./types.js').Config} config * @returns {import('./types.js').DaemonicPersistencePowers} */ export const makeDaemonicPersistencePowers = ( filePowers, cryptoPowers, - locator, - includeWebPageBundler = true, + config, ) => { const initializePersistence = async () => { - const { statePath, ephemeralStatePath, cachePath } = locator; + const { statePath, ephemeralStatePath, cachePath } = config; const statePathP = filePowers.makePath(statePath); const ephemeralStatePathP = filePowers.makePath(ephemeralStatePath); const cachePathP = filePowers.makePath(cachePath); @@ -309,7 +307,7 @@ export const makeDaemonicPersistencePowers = ( }; const provideRootNonce = async () => { - const noncePath = filePowers.joinPath(locator.statePath, 'nonce'); + const noncePath = filePowers.joinPath(config.statePath, 'nonce'); let nonce = await filePowers.maybeReadFileText(noncePath); const isNewlyCreated = nonce === undefined; if (nonce === undefined) { @@ -320,7 +318,7 @@ export const makeDaemonicPersistencePowers = ( }; const makeContentSha512Store = () => { - const { statePath } = locator; + const { statePath } = config; const storageDirectoryPath = filePowers.joinPath(statePath, 'store-sha512'); return harden({ @@ -382,7 +380,7 @@ export const makeDaemonicPersistencePowers = ( * @param {string} formulaNumber */ const makeFormulaPath = formulaNumber => { - const { statePath } = locator; + const { statePath } = config; if (formulaNumber.length < 3) { throw new TypeError(`Invalid formula number ${q(formulaNumber)}`); } @@ -433,8 +431,15 @@ export const makeDaemonicPersistencePowers = ( }); }; +/** + * @param {import('./types.js').Config} config + * @param {import('url').fileURLToPath} fileURLToPath + * @param {import('./types.js').FilePowers} filePowers + * @param {typeof import('fs')} fs + * @param {typeof import('child_process')} popen + */ export const makeDaemonicControlPowers = ( - locator, + config, fileURLToPath, filePowers, fs, @@ -450,7 +455,7 @@ export const makeDaemonicControlPowers = ( * @param {Promise} cancelled */ const makeWorker = async (workerId, daemonWorkerFacet, cancelled) => { - const { cachePath, statePath, ephemeralStatePath, sockPath } = locator; + const { cachePath, statePath, ephemeralStatePath, sockPath } = config; const workerCachePath = filePowers.joinPath(cachePath, 'worker', workerId); const workerStatePath = filePowers.joinPath(statePath, 'worker', workerId); @@ -544,7 +549,7 @@ export const makeDaemonicControlPowers = ( /** * @param {object} opts - * @param {import('./types.js').Locator} opts.locator + * @param {import('./types.js').Config} opts.config * @param {typeof import('fs')} opts.fs * @param {typeof import('child_process')} opts.popen * @param {typeof import('url')} opts.url @@ -553,7 +558,7 @@ export const makeDaemonicControlPowers = ( * @returns {import('./types.js').DaemonicPowers} */ export const makeDaemonicPowers = ({ - locator, + config, fs, popen, url, @@ -562,14 +567,14 @@ export const makeDaemonicPowers = ({ }) => { const { fileURLToPath } = url; - const petStorePowers = makePetStoreMaker(filePowers, locator); + const petStorePowers = makePetStoreMaker(filePowers, config); const daemonicPersistencePowers = makeDaemonicPersistencePowers( filePowers, cryptoPowers, - locator, + config, ); const daemonicControlPowers = makeDaemonicControlPowers( - locator, + config, fileURLToPath, filePowers, fs, diff --git a/packages/daemon/src/daemon-node.js b/packages/daemon/src/daemon-node.js index e484696b15..b7536b66b3 100644 --- a/packages/daemon/src/daemon-node.js +++ b/packages/daemon/src/daemon-node.js @@ -34,8 +34,8 @@ if (process.argv.length < 5) { const [sockPath, statePath, ephemeralStatePath, cachePath] = process.argv.slice(2); -/** @type {import('../types.js').Locator} */ -const locator = { +/** @type {import('./types.js').Config} */ +const config = { sockPath, statePath, ephemeralStatePath, @@ -48,7 +48,7 @@ const networkPowers = makeNetworkPowers({ net }); const filePowers = makeFilePowers({ fs, path }); const cryptoPowers = makeCryptoPowers(crypto); const powers = makeDaemonicPowers({ - locator, + config, fs, popen, url, diff --git a/packages/daemon/src/pet-store.js b/packages/daemon/src/pet-store.js index 732692ef4d..47872fd8be 100644 --- a/packages/daemon/src/pet-store.js +++ b/packages/daemon/src/pet-store.js @@ -8,9 +8,9 @@ const { quote: q } = assert; /** * @param {import('./types.js').FilePowers} filePowers - * @param {import('./types.js').Locator} locator + * @param {import('./types.js').Config} config */ -export const makePetStoreMaker = (filePowers, locator) => { +export const makePetStoreMaker = (filePowers, config) => { /** * @param {string} petNameDirectoryPath * @param {(name: string) => void} assertValidName @@ -211,7 +211,7 @@ export const makePetStoreMaker = (filePowers, locator) => { const prefix = formulaNumber.slice(0, 2); const suffix = formulaNumber.slice(2); const petNameDirectoryPath = filePowers.joinPath( - locator.statePath, + config.statePath, formulaType, prefix, suffix, diff --git a/packages/daemon/src/types.d.ts b/packages/daemon/src/types.d.ts index daf764252a..3b152ea90a 100644 --- a/packages/daemon/src/types.d.ts +++ b/packages/daemon/src/types.d.ts @@ -7,7 +7,7 @@ export type SomehowAsyncIterable = | Iterable | { next: () => IteratorResult }; -export type Locator = { +export type Config = { statePath: string; ephemeralStatePath: string; cachePath: string; diff --git a/packages/daemon/src/worker-node.js b/packages/daemon/src/worker-node.js index ab8812303d..2123d07ffc 100644 --- a/packages/daemon/src/worker-node.js +++ b/packages/daemon/src/worker-node.js @@ -25,8 +25,8 @@ if (process.argv.length < 7) { const [workerUuid, sockPath, statePath, ephemeralStatePath, cachePath] = process.argv.slice(2); -/** @type {import('./types.js').Locator} */ -const locator = { +/** @type {import('./types.js').Config} */ +const config = { sockPath, statePath, ephemeralStatePath, @@ -44,7 +44,7 @@ process.once('SIGINT', () => cancel(new Error('SIGINT'))); // @ts-ignore Yes, we can assign to exitCode, typedoc. process.exitCode = 1; -main(powers, locator, workerUuid, process.pid, cancel, cancelled).then( +main(powers, config, workerUuid, process.pid, cancel, cancelled).then( () => { process.exitCode = 0; }, diff --git a/packages/daemon/src/worker.js b/packages/daemon/src/worker.js index 485878044e..0c9763206d 100644 --- a/packages/daemon/src/worker.js +++ b/packages/daemon/src/worker.js @@ -109,13 +109,13 @@ export const makeWorkerFacet = ({ cancel }) => { /** * @param {import('./types.js').MignonicPowers} powers - * @param {import('./types.js').Locator} locator - * @param {string} uuid + * @param {import('./types.js').Config} _config + * @param {string} _uuid * @param {number | undefined} pid * @param {(error: Error) => void} cancel * @param {Promise} cancelled */ -export const main = async (powers, locator, uuid, pid, cancel, cancelled) => { +export const main = async (powers, _config, _uuid, pid, cancel, cancelled) => { console.error(`Endo worker started on pid ${pid}`); cancelled.catch(() => { console.error(`Endo worker exiting on pid ${pid}`); diff --git a/packages/daemon/test/test-endo.js b/packages/daemon/test/test-endo.js index e77cf5fa1e..c4a15bf981 100644 --- a/packages/daemon/test/test-endo.js +++ b/packages/daemon/test/test-endo.js @@ -62,7 +62,7 @@ const prepareFollowChangesIterator = async host => { }; /** @param {Array} root */ -const makeLocator = (...root) => { +const makeConfig = (...root) => { return { statePath: path.join(dirname, ...root, 'state'), ephemeralStatePath: path.join(dirname, ...root, 'run'), @@ -77,13 +77,13 @@ const makeLocator = (...root) => { }; /** - * @param {ReturnType} locator + * @param {ReturnType} config * @param {Promise} cancelled */ -const makeHost = async (locator, cancelled) => { +const makeHost = async (config, cancelled) => { const { getBootstrap } = await makeEndoClient( 'client', - locator.sockPath, + config.sockPath, cancelled, ); const bootstrap = getBootstrap(); @@ -91,11 +91,11 @@ const makeHost = async (locator, cancelled) => { }; /** - * @param {ReturnType} locator + * @param {ReturnType} config * @param {Promise} cancelled */ -const makeHostWithTestNetwork = async (locator, cancelled) => { - const { host } = await makeHost(locator, cancelled); +const makeHostWithTestNetwork = async (config, cancelled) => { + const { host } = await makeHost(config, cancelled); // Install test network const servicePath = path.join(dirname, 'src', 'networks', 'tcp-netstring.js'); @@ -151,14 +151,14 @@ const doMakeBundle = async (host, filePath, callback) => { return result; }; -let locatorPathId = 0; +let configPathId = 0; /** * @param {string} testTitle - The title of the current test. - * @param {number} locatorNumber - The number of the current locator. If this - * is the n:th locator created for the current test, the locator number is n. + * @param {number} configNumber - The number of the current config. If this + * is the n:th config created for the current test, the config number is n. */ -const getLocatorDirectoryName = (testTitle, locatorNumber) => { +const getConfigDirectoryName = (testTitle, configNumber) => { const defaultPath = testTitle.replace(/\s/giu, '-').replace(/[^\w-]/giu, ''); // We truncate the subdirectory name to 30 characters in an attempt to respect @@ -167,27 +167,27 @@ const getLocatorDirectoryName = (testTitle, locatorNumber) => { // not be enough. const basePath = defaultPath.length <= 22 ? defaultPath : defaultPath.slice(0, 22); - const testId = String(locatorPathId).padStart(4, '0'); - const locatorId = String(locatorNumber).padStart(2, '0'); - const locatorSubDirectory = `${basePath}#${testId}-${locatorId}`; + const testId = String(configPathId).padStart(4, '0'); + const configId = String(configNumber).padStart(2, '0'); + const configSubDirectory = `${basePath}#${testId}-${configId}`; - locatorPathId += 1; + configPathId += 1; - return locatorSubDirectory; + return configSubDirectory; }; /** @param {import('ava').ExecutionContext} t */ -const prepareLocator = async t => { +const prepareConfig = async t => { const { reject: cancel, promise: cancelled } = makePromiseKit(); - const locator = makeLocator( + const config = makeConfig( 'tmp', - getLocatorDirectoryName(t.title, t.context.length), + getConfigDirectoryName(t.title, t.context.length), ); - await purge(locator); - await start(locator); + await purge(config); + await start(config); - const contextObj = { cancel, cancelled, locator }; + const contextObj = { cancel, cancelled, config }; t.context.push(contextObj); return { ...contextObj }; }; @@ -198,24 +198,24 @@ test.beforeEach(t => { test.afterEach.always(async t => { await Promise.allSettled( - /** @type {Awaited>[]} */ (t.context).flatMap( - ({ cancel, cancelled, locator }) => { + /** @type {Awaited>[]} */ (t.context).flatMap( + ({ cancel, cancelled, config }) => { cancel(Error('teardown')); - return [cancelled, stop(locator)]; + return [cancelled, stop(config)]; }, ), ); }); test('lifecycle', async t => { - const { cancel, cancelled, locator } = await prepareLocator(t); + const { cancel, cancelled, config } = await prepareConfig(t); - await stop(locator); - await restart(locator); + await stop(config); + await restart(config); const { getBootstrap, closed } = await makeEndoClient( 'client', - locator.sockPath, + config.sockPath, cancelled, ); const bootstrap = getBootstrap(); @@ -229,8 +229,8 @@ test('lifecycle', async t => { }); test('spawn and evaluate', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('w1'); const ten = await E(host).evaluate('w1', '10', [], []); @@ -238,16 +238,16 @@ test('spawn and evaluate', async t => { }); test('anonymous spawn and evaluate', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const ten = await E(host).evaluate('MAIN', '10', [], []); t.is(ten, 10); }); test('anonymous spawn and evaluate with new worker', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const ten = await E(host).evaluate('NEW', '10', [], []); t.is(ten, 10); @@ -255,8 +255,8 @@ test('anonymous spawn and evaluate with new worker', async t => { // Regression test for https://github.com/endojs/endo/issues/2147 test('spawning a worker does not overwrite existing non-worker name', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const foo = await E(host).evaluate('MAIN', '10', [], [], 'foo'); t.is(foo, 10); @@ -270,10 +270,10 @@ test('spawning a worker does not overwrite existing non-worker name', async t => }); test('persist spawn and evaluation', async t => { - const { cancelled, locator } = await prepareLocator(t); + const { cancelled, config } = await prepareConfig(t); { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('w1'); @@ -295,10 +295,10 @@ test('persist spawn and evaluation', async t => { t.is(20, twenty); } - await restart(locator); + await restart(config); { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); const retwenty = await E(host).lookup('twenty'); t.is(20, retwenty); @@ -306,8 +306,8 @@ test('persist spawn and evaluation', async t => { }); test('store without name', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const readerRef = makeReaderRef([new TextEncoder().encode('hello\n')]); const readable = await E(host).store(readerRef); @@ -316,10 +316,10 @@ test('store without name', async t => { }); test('store with name', async t => { - const { cancelled, locator } = await prepareLocator(t); + const { cancelled, config } = await prepareConfig(t); { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); const readerRef = makeReaderRef([new TextEncoder().encode('hello\n')]); const readable = await E(host).store(readerRef, 'hello-text'); const actualText = await E(readable).text(); @@ -327,7 +327,7 @@ test('store with name', async t => { } { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); const readable = await E(host).lookup('hello-text'); const actualText = await E(readable).text(); t.is(actualText, 'hello\n'); @@ -335,10 +335,10 @@ test('store with name', async t => { }); test('closure state lost by restart', async t => { - const { cancelled, locator } = await prepareLocator(t); + const { cancelled, config } = await prepareConfig(t); { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('w1'); await E(host).evaluate( @@ -393,10 +393,10 @@ test('closure state lost by restart', async t => { t.is(three, 3); } - await restart(locator); + await restart(config); { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); await E(host).lookup('w1'); const one = await E(host).evaluate( 'w1', @@ -423,13 +423,13 @@ test('closure state lost by restart', async t => { }); test('persist unconfined services and their requests', async t => { - const { cancelled, locator } = await prepareLocator(t); + const { cancelled, config } = await prepareConfig(t); const responderFinished = (async () => { const { promise: followerCancelled, reject: cancelFollower } = makePromiseKit(); cancelled.catch(cancelFollower); - const { host } = await makeHost(locator, followerCancelled); + const { host } = await makeHost(config, followerCancelled); await E(host).provideWorker('user-worker'); await E(host).evaluate( @@ -452,7 +452,7 @@ test('persist unconfined services and their requests', async t => { })(); const requesterFinished = (async () => { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('w1'); await E(host).provideGuest('h1', { agentName: 'a1', @@ -476,10 +476,10 @@ test('persist unconfined services and their requests', async t => { await Promise.all([responderFinished, requesterFinished]); - await restart(locator); + await restart(config); { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); const answer = await E(host).lookup('answer'); const number = await E(answer).value(); t.is(number, 42); @@ -487,13 +487,13 @@ test('persist unconfined services and their requests', async t => { }); test('persist confined services and their requests', async t => { - const { cancelled, locator } = await prepareLocator(t); + const { cancelled, config } = await prepareConfig(t); const responderFinished = (async () => { const { promise: followerCancelled, reject: cancelFollower } = makePromiseKit(); cancelled.catch(cancelFollower); - const { host } = await makeHost(locator, followerCancelled); + const { host } = await makeHost(config, followerCancelled); await E(host).provideWorker('user-worker'); await E(host).evaluate( @@ -516,7 +516,7 @@ test('persist confined services and their requests', async t => { })(); const requesterFinished = (async () => { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('w1'); await E(host).provideGuest('h1', { agentName: 'a1' }); @@ -539,10 +539,10 @@ test('persist confined services and their requests', async t => { await Promise.all([responderFinished, requesterFinished]); - await restart(locator); + await restart(config); { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); const answer = await E(host).lookup('answer'); const number = await E(answer).value(); t.is(number, 42); @@ -550,8 +550,8 @@ test('persist confined services and their requests', async t => { }); test('guest facet receives a message for host', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const guest = E(host).provideGuest('guest'); await E(host).provideWorker('worker'); @@ -600,8 +600,8 @@ test('guest facet receives a message for host', async t => { }); test('name changes subscription first publishes existing names', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const existingNames = await E(host).list(); const changesIterator = makeRefIterator(await E(host).followChanges()); @@ -611,8 +611,8 @@ test('name changes subscription first publishes existing names', async t => { }); test('name changes subscription publishes new names', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const changesIterator = await prepareFollowChangesIterator(host); @@ -623,8 +623,8 @@ test('name changes subscription publishes new names', async t => { }); test('name changes subscription publishes removed names', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const changesIterator = await prepareFollowChangesIterator(host); @@ -637,8 +637,8 @@ test('name changes subscription publishes removed names', async t => { }); test('name changes subscription publishes renamed names', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const changesIterator = await prepareFollowChangesIterator(host); @@ -654,8 +654,8 @@ test('name changes subscription publishes renamed names', async t => { }); test('name changes subscription does not notify of redundant pet store writes', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const changesIterator = await prepareFollowChangesIterator(host); @@ -673,8 +673,8 @@ test('name changes subscription does not notify of redundant pet store writes', }); test('direct cancellation', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('worker'); @@ -741,8 +741,8 @@ test('direct cancellation', async t => { // Regression test 1 for https://github.com/endojs/endo/issues/2074 test('indirect cancellation via worker', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('worker'); @@ -810,8 +810,8 @@ test('indirect cancellation via worker', async t => { // Regression test 2 for https://github.com/endojs/endo/issues/2074 test.failing('indirect cancellation via caplet', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('w1'); const counterPath = path.join(dirname, 'test', 'counter.js'); @@ -851,8 +851,8 @@ test.failing('indirect cancellation via caplet', async t => { }); test('cancel because of requested capability', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('worker'); await E(host).provideGuest('guest', { agentName: 'guest-agent' }); @@ -927,8 +927,8 @@ test('cancel because of requested capability', async t => { }); test('unconfined service can respond to cancellation', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('worker'); @@ -952,8 +952,8 @@ test('unconfined service can respond to cancellation', async t => { }); test('confined service can respond to cancellation', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('worker'); @@ -973,8 +973,8 @@ test('confined service can respond to cancellation', async t => { }); test('make a host', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const host2 = E(host).provideHost('fellow-host'); await E(host2).provideWorker('w1'); @@ -983,8 +983,8 @@ test('make a host', async t => { }); test('name and reuse inspector', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('worker'); @@ -1011,8 +1011,8 @@ test('name and reuse inspector', async t => { // Regression test for https://github.com/endojs/endo/issues/2021 test('eval-mediated worker name', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).provideWorker('worker'); @@ -1053,8 +1053,8 @@ test('eval-mediated worker name', async t => { }); test('lookup with single petname', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).provideGuest('guest'); const ten = await E(host).evaluate('MAIN', '10', [], [], 'ten'); @@ -1070,8 +1070,8 @@ test('lookup with single petname', async t => { }); test('lookup with petname path (inspector)', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).evaluate('MAIN', '10', [], [], 'ten'); @@ -1085,8 +1085,8 @@ test('lookup with petname path (inspector)', async t => { }); test('lookup with petname path (caplet with lookup method)', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const lookupPath = path.join(dirname, 'test', 'lookup.js'); await E(host).makeUnconfined('MAIN', lookupPath, 'NONE', 'lookup'); @@ -1101,8 +1101,8 @@ test('lookup with petname path (caplet with lookup method)', async t => { }); test('lookup with petname path (value has no lookup method)', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).evaluate('MAIN', '10', [], [], 'ten'); await t.throwsAsync( @@ -1117,8 +1117,8 @@ test('lookup with petname path (value has no lookup method)', async t => { }); test('evaluate name resolved by lookup path', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); await E(host).evaluate('MAIN', '10', [], [], 'ten'); @@ -1132,8 +1132,8 @@ test('evaluate name resolved by lookup path', async t => { }); test('list special names', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const readerRef = makeReaderRef([new TextEncoder().encode('hello\n')]); await E(host).store(readerRef, 'hello-text'); @@ -1152,8 +1152,8 @@ test('list special names', async t => { }); test('guest cannot access host methods', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const guest = E(host).provideGuest('guest'); const guestsHost = E(guest).lookup('HOST'); @@ -1165,8 +1165,8 @@ test('guest cannot access host methods', async t => { }); test('read unknown node id', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); // write a bogus value for a bogus nodeId const node = await cryptoPowers.randomHex512(); @@ -1184,10 +1184,10 @@ test('read unknown node id', async t => { }); test('read remote value', async t => { - const { locator: locatorA, cancelled: cancelledA } = await prepareLocator(t); - const { locator: locatorB, cancelled: cancelledB } = await prepareLocator(t); - const hostA = await makeHostWithTestNetwork(locatorA, cancelledA); - const hostB = await makeHostWithTestNetwork(locatorB, cancelledB); + const { config: configA, cancelled: cancelledA } = await prepareConfig(t); + const { config: configB, cancelled: cancelledB } = await prepareConfig(t); + const hostA = await makeHostWithTestNetwork(configA, cancelledA); + const hostB = await makeHostWithTestNetwork(configB, cancelledB); // introduce nodes to each other await E(hostA).addPeerInfo(await E(hostB).getPeerInfo()); @@ -1205,8 +1205,8 @@ test('read remote value', async t => { }); test('locate local value', async t => { - const { cancelled, locator } = await prepareLocator(t); - const { host } = await makeHost(locator, cancelled); + const { cancelled, config } = await prepareConfig(t); + const { host } = await makeHost(config, cancelled); const ten = await E(host).evaluate('MAIN', '10', [], [], 'ten'); t.is(ten, 10); @@ -1217,18 +1217,18 @@ test('locate local value', async t => { }); test('locate local persisted value', async t => { - const { cancelled, locator } = await prepareLocator(t); + const { cancelled, config } = await prepareConfig(t); { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); const ten = await E(host).evaluate('MAIN', '10', [], [], 'ten'); t.is(ten, 10); } - await restart(locator); + await restart(config); { - const { host } = await makeHost(locator, cancelled); + const { host } = await makeHost(config, cancelled); const tenLocator = await E(host).locate('ten'); const parsedLocator = parseLocator(tenLocator); t.is(parsedLocator.formulaType, 'eval'); @@ -1236,10 +1236,10 @@ test('locate local persisted value', async t => { }); test('locate remote value', async t => { - const { locator: locatorA, cancelled: cancelledA } = await prepareLocator(t); - const { locator: locatorB, cancelled: cancelledB } = await prepareLocator(t); - const hostA = await makeHostWithTestNetwork(locatorA, cancelledA); - const hostB = await makeHostWithTestNetwork(locatorB, cancelledB); + const { config: configA, cancelled: cancelledA } = await prepareConfig(t); + const { config: configB, cancelled: cancelledB } = await prepareConfig(t); + const hostA = await makeHostWithTestNetwork(configA, cancelledA); + const hostB = await makeHostWithTestNetwork(configB, cancelledB); // introduce nodes to each other await E(hostA).addPeerInfo(await E(hostB).getPeerInfo()); diff --git a/packages/daemon/types.d.ts b/packages/daemon/types.d.ts index 5340542a27..372d13b1a0 100644 --- a/packages/daemon/types.d.ts +++ b/packages/daemon/types.d.ts @@ -1,19 +1,19 @@ export { makeRefReader, makeRefIterator } from './src/ref-reader.js'; export { makeReaderRef, makeIteratorRef } from './src/reader-ref.js'; -export type Locator = { +export type Config = { statePath: string; ephemeralStatePath: string; cachePath: string; sockPath: string; }; -export function start(locator?: Locator); -export function stop(locator?: Locator); -export function restart(locator?: Locator); -export function terminate(locator?: Locator); -export function clean(locator?: Locator); -export function purge(locator?: Locator); +export function start(config?: Config); +export function stop(config?: Config); +export function restart(config?: Config); +export function terminate(config?: Config); +export function clean(config?: Config); +export function purge(config?: Config); export function makeEndoClient( name: string, sockPath: string, From 71808b2625d00e012c02fa46d1959728cd7e0b17 Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Mon, 15 Apr 2024 14:36:17 -0700 Subject: [PATCH 2/3] feat(daemon): Improve ./types.d.ts Adds return values for exported functions in `./types.d.ts`, and removes redundant definition of `Config` type. --- packages/daemon/types.d.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/daemon/types.d.ts b/packages/daemon/types.d.ts index 372d13b1a0..20d5ca438c 100644 --- a/packages/daemon/types.d.ts +++ b/packages/daemon/types.d.ts @@ -1,22 +1,21 @@ +import type { Config, EndoBootstrap } from './src/types.js'; + export { makeRefReader, makeRefIterator } from './src/ref-reader.js'; export { makeReaderRef, makeIteratorRef } from './src/reader-ref.js'; -export type Config = { - statePath: string; - ephemeralStatePath: string; - cachePath: string; - sockPath: string; -}; - -export function start(config?: Config); -export function stop(config?: Config); -export function restart(config?: Config); -export function terminate(config?: Config); -export function clean(config?: Config); -export function purge(config?: Config); +export type { Config }; +export function start(config?: Config): Promise; +export function stop(config?: Config): Promise; +export function restart(config?: Config): Promise; +export function terminate(config?: Config): Promise; +export function clean(config?: Config): Promise; +export function purge(config?: Config): Promise; export function makeEndoClient( name: string, sockPath: string, cancelled: Promise, bootstrap?: TBootstrap, -); +): Promise<{ + getBootstrap: () => Promise; + closed: Promise; +}>; From 89d4a2c02824746f68fa99a217ce1ded9915f1b6 Mon Sep 17 00:00:00 2001 From: Erik Marks Date: Mon, 15 Apr 2024 15:02:19 -0700 Subject: [PATCH 3/3] refactor(cli): Rename locator.js to config.js --- packages/cli/src/{locator.js => config.js} | 0 packages/cli/src/endo.js | 10 +++++----- 2 files changed, 5 insertions(+), 5 deletions(-) rename packages/cli/src/{locator.js => config.js} (100%) diff --git a/packages/cli/src/locator.js b/packages/cli/src/config.js similarity index 100% rename from packages/cli/src/locator.js rename to packages/cli/src/config.js diff --git a/packages/cli/src/endo.js b/packages/cli/src/endo.js index ba405142bf..264a5603c8 100644 --- a/packages/cli/src/endo.js +++ b/packages/cli/src/endo.js @@ -464,7 +464,7 @@ export const main = async rawArgs => { .command('state') .description('prints the state directory path') .action(async _cmd => { - const { statePath } = await import('./locator.js'); + const { statePath } = await import('./config.js'); process.stdout.write(`${statePath}\n`); }); @@ -472,7 +472,7 @@ export const main = async rawArgs => { .command('run') .description('prints the daemon PID file path') .action(async _cmd => { - const { ephemeralStatePath } = await import('./locator.js'); + const { ephemeralStatePath } = await import('./config.js'); process.stdout.write(`${ephemeralStatePath}\n`); }); @@ -480,7 +480,7 @@ export const main = async rawArgs => { .command('sock') .description('prints the UNIX domain socket or Windows named pipe path') .action(async _cmd => { - const { sockPath } = await import('./locator.js'); + const { sockPath } = await import('./config.js'); process.stdout.write(`${sockPath}\n`); }); @@ -488,7 +488,7 @@ export const main = async rawArgs => { .command('log') .description('prints the log file path') .action(async _cmd => { - const { logPath } = await import('./locator.js'); + const { logPath } = await import('./config.js'); process.stdout.write(`${logPath}\n`); }); @@ -496,7 +496,7 @@ export const main = async rawArgs => { .command('cache') .description('prints the cache directory path') .action(async _cmd => { - const { cachePath } = await import('./locator.js'); + const { cachePath } = await import('./config.js'); process.stdout.write(`${cachePath}\n`); });