Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@
"vite>sass>@parcel/watcher": false,
"vitest>@vitest/browser>webdriverio>@wdio/utils>edgedriver": false,
"vitest>@vitest/browser>webdriverio>@wdio/utils>geckodriver": false,
"vitest>@vitest/mocker>msw": false
"vitest>@vitest/mocker>msw": false,
"@ocap/cli>@ocap/logger>@ocap/streams": true,
"eslint-plugin-import-x>unrs-resolver": false
}
},
"resolutions": {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@endo/promise-kit": "^1.1.10",
"@metamask/snaps-utils": "^9.1.0",
"@metamask/utils": "^11.4.0",
"@ocap/logger": "workspace:^",
"@ocap/shims": "workspace:^",
"@ocap/utils": "workspace:^",
"@types/node": "^22.13.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@endo/init';

import { Logger } from '@ocap/utils';
import { Logger } from '@ocap/logger';
import path from 'node:path';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
Expand Down
19 changes: 11 additions & 8 deletions packages/cli/src/commands/bundle.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from '@ocap/utils';
import type { Logger } from '@ocap/logger';
import { readFile, rm } from 'fs/promises';
import { basename } from 'path';
import { describe, it, expect, vi, beforeEach, afterAll } from 'vitest';
Expand All @@ -13,11 +13,14 @@ import { fileExists } from '../file.ts';
const mocks = vi.hoisted(() => {
return {
endoBundleSource: vi.fn(),
Logger: vi.fn(() => ({
info: vi.fn(),
error: vi.fn(),
subLogger: vi.fn(),
})),
Logger: vi.fn(
() =>
({
info: vi.fn(),
error: vi.fn(),
subLogger: vi.fn(),
}) as unknown as Logger,
),
isDirectory: vi.fn(),
};
});
Expand All @@ -28,7 +31,7 @@ vi.mock('@endo/bundle-source', () => ({

vi.mock('@endo/init', () => ({}));

vi.mock('@ocap/utils', () => ({
vi.mock('@ocap/logger', () => ({
Logger: mocks.Logger,
}));

Expand All @@ -54,7 +57,7 @@ describe('bundle', async () => {
beforeEach(async () => {
await deleteTestBundles();
vi.resetModules();
logger = new Logger();
logger = mocks.Logger();
vi.resetAllMocks();
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@endo/init';
import endoBundleSource from '@endo/bundle-source';
import { Logger } from '@ocap/utils';
import { Logger } from '@ocap/logger';
import { glob } from 'glob';
import { writeFile } from 'node:fs/promises';
import { resolve, join } from 'node:path';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/watch.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '@ocap/shims/endoify';

import { Logger } from '@ocap/utils';
import { Logger } from '@ocap/logger';
import { watch } from 'chokidar';
import type { FSWatcher } from 'chokidar';
import type { Stats } from 'fs';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/watch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makePromiseKit } from '@endo/promise-kit';
import { Logger } from '@ocap/utils';
import { Logger } from '@ocap/logger';
import { watch } from 'chokidar';
import type { FSWatcher, MatchFunction } from 'chokidar';
import { unlink } from 'fs/promises';
Expand Down
1 change: 1 addition & 0 deletions packages/cli/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"types": ["ses", "node"]
},
"references": [
{ "path": "../logger/tsconfig.build.json" },
{ "path": "../utils/tsconfig.build.json" },
{ "path": "../shims/tsconfig.build.json" }
],
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"types": ["ses", "vitest", "node"],
"noEmit": true
},
"references": [{ "path": "../test-utils" }, { "path": "../utils" }],
"references": [
{ "path": "../logger" },
{ "path": "../test-utils" },
{ "path": "../utils" }
],
"include": [
"../../vitest.config.ts",
"./src/**/*.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@metamask/utils": "^11.4.0",
"@ocap/errors": "workspace:^",
"@ocap/kernel": "workspace:^",
"@ocap/logger": "workspace:^",
"@ocap/rpc-methods": "workspace:^",
"@ocap/shims": "workspace:^",
"@ocap/store": "workspace:^",
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/background.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { isJsonRpcResponse } from '@metamask/utils';
import type { Json } from '@metamask/utils';
import { kernelMethodSpecs } from '@ocap/kernel/rpc';
import { Logger } from '@ocap/logger';
import { RpcClient } from '@ocap/rpc-methods';
import { ChromeRuntimeDuplexStream } from '@ocap/streams/browser';
import { delay, Logger } from '@ocap/utils';
import { delay } from '@ocap/utils';

const OFFSCREEN_DOCUMENT_PATH = '/offscreen.html';

Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/iframe.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { VatSupervisor } from '@ocap/kernel';
import { Logger } from '@ocap/logger';
import {
MessagePortDuplexStream,
receiveMessagePort,
} from '@ocap/streams/browser';
import type { JsonRpcMessage } from '@ocap/utils';
import { isJsonRpcMessage, Logger } from '@ocap/utils';
import { isJsonRpcMessage } from '@ocap/utils';

const logger = new Logger('iframe');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { rpcErrors } from '@metamask/rpc-errors';
import type { JsonRpcResponse } from '@metamask/utils';
import type { VatId, VatConfig } from '@ocap/kernel';
import { Logger } from '@ocap/logger';
import type { PostMessageTarget } from '@ocap/streams/browser';
import { TestDuplexStream } from '@ocap/test-utils/streams';
import type { Logger } from '@ocap/utils';
import { delay, makeLogger, stringify } from '@ocap/utils';
import { delay, stringify } from '@ocap/utils';
import { describe, it, expect, beforeEach, vi } from 'vitest';

import type { VatWorkerClientStream } from './VatWorkerClient.ts';
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('ExtensionVatWorkerClient', () => {

beforeEach(async () => {
stream = await TestDuplexStream.make(() => undefined);
clientLogger = makeLogger('[test client]');
clientLogger = new Logger('test-client');
client = new ExtensionVatWorkerClient(
stream as unknown as VatWorkerClientStream,
clientLogger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isJsonRpcResponse } from '@metamask/utils';
import type { JsonRpcId, JsonRpcResponse } from '@metamask/utils';
import type { VatWorkerManager, VatId, VatConfig } from '@ocap/kernel';
import { vatWorkerServiceMethodSpecs } from '@ocap/kernel/rpc';
import { Logger } from '@ocap/logger';
import { RpcClient } from '@ocap/rpc-methods';
import type { DuplexStream } from '@ocap/streams';
import {
Expand All @@ -12,8 +13,8 @@ import type {
PostMessageEnvelope,
PostMessageTarget,
} from '@ocap/streams/browser';
import type { JsonRpcCall, JsonRpcMessage, Logger } from '@ocap/utils';
import { isJsonRpcMessage, makeLogger, stringify } from '@ocap/utils';
import type { JsonRpcCall, JsonRpcMessage } from '@ocap/utils';
import { isJsonRpcMessage, stringify } from '@ocap/utils';

// Appears in the docs.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -53,7 +54,7 @@ export class ExtensionVatWorkerClient implements VatWorkerManager {
constructor(stream: VatWorkerClientStream, logger?: Logger) {
this.#stream = stream;
this.#portMap = new Map();
this.#logger = logger ?? makeLogger('[vat worker client]');
this.#logger = logger ?? new Logger('vat-worker-client');
this.#rpcClient = new RpcClient(
vatWorkerServiceMethodSpecs,
async (request) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { rpcErrors } from '@metamask/rpc-errors';
import type { JsonRpcRequest } from '@metamask/utils';
import { VatAlreadyExistsError, VatNotFoundError } from '@ocap/errors';
import type { VatConfig, VatId } from '@ocap/kernel';
import { Logger } from '@ocap/logger';
import type { PostMessageTarget } from '@ocap/streams/browser';
import { TestDuplexStream } from '@ocap/test-utils/streams';
import type { Logger } from '@ocap/utils';
import { delay, makeLogger } from '@ocap/utils';
import { delay } from '@ocap/utils';
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
import type { Mock } from 'vitest';

Expand Down Expand Up @@ -124,7 +124,7 @@ describe('ExtensionVatWorkerService', () => {

beforeEach(async () => {
workers = [];
logger = makeLogger('[test server]');
logger = new Logger('test-server');
stream = await TestDuplexStream.make(() => undefined);
server = new ExtensionVatWorkerService(
stream as unknown as VatWorkerServiceStream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import { VatAlreadyExistsError, VatNotFoundError } from '@ocap/errors';
import type { VatId, VatConfig } from '@ocap/kernel';
import type { VatWorkerServiceMethod } from '@ocap/kernel/rpc';
import { vatWorkerServiceMethodSpecs } from '@ocap/kernel/rpc';
import { Logger } from '@ocap/logger';
import type { ExtractParams } from '@ocap/rpc-methods';
import { PostMessageDuplexStream } from '@ocap/streams/browser';
import type {
PostMessageEnvelope,
PostMessageTarget,
} from '@ocap/streams/browser';
import type { Logger } from '@ocap/utils';
import { makeLogger } from '@ocap/utils';

// Appears in the docs.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -67,7 +66,7 @@ export class ExtensionVatWorkerService {
) {
this.#stream = stream;
this.#makeWorker = makeWorker;
this.#logger = logger ?? makeLogger('[vat worker server]');
this.#logger = logger ?? new Logger('vat-worker-server');
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createWindow } from '@metamask/snaps-utils';
import type { VatId, VatConfig } from '@ocap/kernel';
import { Logger } from '@ocap/logger';
import type { initializeMessageChannel } from '@ocap/streams/browser';
import { Logger } from '@ocap/utils';

import type { VatWorker } from './VatWorkerServer.ts';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { JsonRpcEngine } from '@metamask/json-rpc-engine';
import type { JsonRpcRequest, JsonRpcResponse } from '@metamask/utils';
import type { ClusterConfig } from '@ocap/kernel';
import { ClusterConfigStruct, Kernel } from '@ocap/kernel';
import { Logger } from '@ocap/logger';
import { makeSQLKernelDatabase } from '@ocap/store/sqlite/wasm';
import type { PostMessageTarget } from '@ocap/streams/browser';
import {
MessagePortDuplexStream,
receiveMessagePort,
} from '@ocap/streams/browser';
import { fetchValidatedJson, isJsonRpcCall, Logger } from '@ocap/utils';
import { fetchValidatedJson, isJsonRpcCall } from '@ocap/utils';
import type { JsonRpcCall } from '@ocap/utils';

import { makeLoggingMiddleware } from './middleware/logging.ts';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
JsonRpcEngine,
} from '@metamask/json-rpc-engine';
import type { JsonRpcRequest, JsonRpcSuccess } from '@metamask/utils';
import { Logger } from '@ocap/utils';
import { Logger } from '@ocap/logger';
import { describe, it, expect, vi, beforeEach } from 'vitest';

import { makeLoggingMiddleware } from './logging.ts';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createAsyncMiddleware } from '@metamask/json-rpc-engine';
import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
import type { Json, JsonRpcParams } from '@metamask/utils';
import { Logger } from '@ocap/utils';
import { Logger } from '@ocap/logger';

export const makeLoggingMiddleware = (
logger: Logger,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { JsonRpcResponse } from '@metamask/utils';
import { Logger } from '@ocap/logger';
import type { PostMessageTarget } from '@ocap/streams/browser';
import { delay } from '@ocap/test-utils';
import { TestDuplexStream } from '@ocap/test-utils/streams';
import type { JsonRpcCall, Logger } from '@ocap/utils';
import type { JsonRpcCall } from '@ocap/utils';
import { describe, it, expect, vi, beforeEach } from 'vitest';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isJsonRpcRequest, isJsonRpcResponse } from '@metamask/utils';
import type { JsonRpcResponse } from '@metamask/utils';
import type { Logger } from '@ocap/logger';
import { PostMessageDuplexStream } from '@ocap/streams/browser';
import { stringify } from '@ocap/utils';
import type { JsonRpcCall, Logger } from '@ocap/utils';
import type { JsonRpcCall } from '@ocap/utils';
import { nanoid } from 'nanoid';

import { isUiControlCommand } from './ui-control-command.ts';
Expand Down
3 changes: 2 additions & 1 deletion packages/extension/src/offscreen.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { isJsonRpcResponse } from '@metamask/utils';
import type { JsonRpcResponse } from '@metamask/utils';
import { Logger } from '@ocap/logger';
import type { DuplexStream } from '@ocap/streams';
import {
initializeMessageChannel,
ChromeRuntimeDuplexStream,
MessagePortDuplexStream,
} from '@ocap/streams/browser';
import type { PostMessageTarget } from '@ocap/streams/browser';
import { delay, isJsonRpcCall, Logger } from '@ocap/utils';
import { delay, isJsonRpcCall } from '@ocap/utils';
import type { JsonRpcCall } from '@ocap/utils';

import { makeIframeVatWorker } from './kernel-integration/iframe-vat-worker.ts';
Expand Down
4 changes: 2 additions & 2 deletions packages/extension/src/ui/services/logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { makeLogger } from '@ocap/utils';
import { Logger } from '@ocap/logger';

export const logger = makeLogger('[Kernel Panel]');
export const logger = new Logger('kernel-panel');
1 change: 1 addition & 0 deletions packages/extension/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"references": [
{ "path": "../kernel/tsconfig.build.json" },
{ "path": "../logger/tsconfig.build.json" },
{ "path": "../rpc-methods/tsconfig.build.json" },
{ "path": "../shims/tsconfig.build.json" },
{ "path": "../store/tsconfig.build.json" },
Expand Down
1 change: 1 addition & 0 deletions packages/extension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"references": [
{ "path": "../kernel" },
{ "path": "../logger" },
{ "path": "../rpc-methods" },
{ "path": "../shims" },
{ "path": "../store" },
Expand Down
1 change: 1 addition & 0 deletions packages/kernel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@metamask/superstruct": "^3.2.1",
"@metamask/utils": "^11.4.0",
"@ocap/errors": "workspace:^",
"@ocap/logger": "workspace:^",
"@ocap/rpc-methods": "workspace:^",
"@ocap/store": "workspace:^",
"@ocap/streams": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/kernel/src/Kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
VatAlreadyExistsError,
VatNotFoundError,
} from '@ocap/errors';
import { Logger } from '@ocap/logger';
import { RpcService } from '@ocap/rpc-methods';
import type { ExtractParams, ExtractResult } from '@ocap/rpc-methods';
import type { KernelDatabase } from '@ocap/store';
import type { DuplexStream } from '@ocap/streams';
import { Logger } from '@ocap/utils';
import type { JsonRpcCall } from '@ocap/utils';

import { KernelQueue } from './KernelQueue.ts';
Expand Down
13 changes: 8 additions & 5 deletions packages/kernel/src/VatHandle.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Json } from '@metamask/utils';
import type { Logger } from '@ocap/logger';
import { delay } from '@ocap/test-utils';
import { TestDuplexStream } from '@ocap/test-utils/streams';
import type { JsonRpcMessage, Logger } from '@ocap/utils';
import { isJsonRpcMessage, makeLogger } from '@ocap/utils';
import type { JsonRpcMessage } from '@ocap/utils';
import { isJsonRpcMessage } from '@ocap/utils';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import type { MockInstance } from 'vitest';

Expand Down Expand Up @@ -78,12 +79,14 @@ describe('VatHandle', () => {
});

it('throws if the stream throws', async () => {
const logger = makeLogger(`[vat v0]`);
const logger = {
error: vi.fn(),
subLogger: vi.fn(() => logger),
} as unknown as Logger;
const { stream } = await makeVat({ logger });
const logErrorSpy = vi.spyOn(logger, 'error');
await stream.receiveInput(NaN);
await delay(10);
expect(logErrorSpy).toHaveBeenCalledWith(
expect(logger.error).toHaveBeenCalledWith(
'Unexpected read error',
expect.any(Error),
);
Expand Down
Loading
Loading