Skip to content

Commit

Permalink
Change deps to AppManager parameter for runtime and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
d-gubert committed Nov 27, 2023
1 parent c10c691 commit 419ae51
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 44 deletions.
2 changes: 1 addition & 1 deletion deno-runtime/acorn-walk.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ export function findNodeAround<TState>(
*/
export const findNodeAfter: typeof findNodeAround

export const base: RecursiveVisitors<any>
export const base: RecursiveVisitors<unknown>
2 changes: 1 addition & 1 deletion deno-runtime/lib/ast/tests/data/ast_blocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @deno-types="../../../../acorn.d.ts"
import { AnyNode, CallExpression, ClassDeclaration, ExpressionStatement, FunctionDeclaration, VariableDeclaration } from 'acorn';
import { AnyNode, ClassDeclaration, ExpressionStatement, FunctionDeclaration, VariableDeclaration } from 'acorn';

/**
* Partial AST blocks to support testing.
Expand Down
22 changes: 5 additions & 17 deletions src/server/runtime/AppsEngineDenoRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ export function getDenoWrapperPath(): string {
}
}

type ControllerDeps = {
accessors: AppAccessorManager;
api: AppApiManager;
};

export class DenoRuntimeSubprocessController extends EventEmitter {
private readonly deno: child_process.ChildProcess;

Expand All @@ -69,7 +64,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter {
private readonly api: AppApiManager;

// We need to keep the appSource around in case the Deno process needs to be restarted
constructor(private readonly appId: string, private readonly appSource: string, deps: ControllerDeps) {
constructor(private readonly appId: string, private readonly appSource: string, manager: AppManager) {
super();

this.state = 'uninitialized';
Expand All @@ -86,8 +81,8 @@ export class DenoRuntimeSubprocessController extends EventEmitter {
this.state = 'invalid';
}

this.accessors = deps.accessors;
this.api = deps.api;
this.accessors = manager.getAccessorManager();
this.api = manager.getApiManager();
}

emit(eventName: string | symbol, ...args: any[]): boolean {
Expand Down Expand Up @@ -307,21 +302,14 @@ type ExecRequestContext = {
export class AppsEngineDenoRuntime {
private readonly subprocesses: Record<string, DenoRuntimeSubprocessController> = {};

private readonly accessorManager: AppAccessorManager;

private readonly apiManager: AppApiManager;

constructor(manager: AppManager) {
this.accessorManager = manager.getAccessorManager();
this.apiManager = manager.getApiManager();
}
constructor(private readonly manager: AppManager) {}

public async startRuntimeForApp({ appId, appSource }: AppRuntimeParams, options = { force: false }): Promise<void> {
if (appId in this.subprocesses && !options.force) {
throw new Error('App already has an associated runtime');
}

this.subprocesses[appId] = new DenoRuntimeSubprocessController(appId, appSource, { accessors: this.accessorManager, api: this.apiManager });
this.subprocesses[appId] = new DenoRuntimeSubprocessController(appId, appSource, this.manager);

await this.subprocesses[appId].setupApp();
}
Expand Down
15 changes: 0 additions & 15 deletions src/server/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AppsEngineDenoRuntime } from './AppsEngineDenoRuntime';
import { AppsEngineNodeRuntime } from './AppsEngineNodeRuntime';
import { AppsEngineVM2Runtime } from './AppsEngineVM2Runtime';

Expand All @@ -16,17 +15,3 @@ export function _getRuntime(requiredEnv = 'vm2'): AvailableRuntime {
export function getRuntime() {
return _getRuntime(process.env?.ROCKETCHAT_APPS_ENGINE_RUNTIME);
}

export function _getDenoRuntime() {
const runtime = new AppsEngineDenoRuntime();

runtime.startRuntimeForApp({
appId: 'appId',
appSource: 'module.exports={ default: new class { constructor() { this.name = "parangarico" } } };console.log("hi from app")',
});
}

// Used for testing during dev cycle
if (process.argv.includes('bruh')) {
_getDenoRuntime();
}
19 changes: 9 additions & 10 deletions tests/server/runtime/DenoRuntimeSubprocessController.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,35 @@ import { TestFixture, Setup, SetupFixture, Expect, AsyncTest } from 'alsatian';
import { AppAccessorManager, AppApiManager } from '../../../src/server/managers';
import { TestData, TestInfastructureSetup } from '../../test-data/utilities';
import { DenoRuntimeSubprocessController } from '../../../src/server/runtime/AppsEngineDenoRuntime';
import type { AppManager } from '../../../src/server/AppManager';

@TestFixture('DenoRuntimeSubprocessController')
export class DenuRuntimeSubprocessControllerTestFixture {
private accessors: AppAccessorManager;

private api: AppApiManager;

private simpleAppSource = 'module.exports={ default: new class { constructor() { this.name = "parangarico" } } };console.log("hi from app")';

private manager: AppManager;

private controller: DenoRuntimeSubprocessController;

@SetupFixture
public fixture() {
const infrastructure = new TestInfastructureSetup();
const manager = infrastructure.getMockManager();
this.manager = infrastructure.getMockManager();

this.accessors = new AppAccessorManager(manager);
const accessors = new AppAccessorManager(this.manager);

manager.getAccessorManager = () => this.accessors;
this.manager.getAccessorManager = () => accessors;

this.api = new AppApiManager(manager);
const api = new AppApiManager(this.manager);

manager.getApiManager = () => this.api;
this.manager.getApiManager = () => api;
}

@Setup
public setup() {
const app = TestData.getMockApp('deno-controller', 'Deno Controller test');

this.controller = new DenoRuntimeSubprocessController(app.getID(), this.simpleAppSource, { accessors: this.accessors, api: this.api });
this.controller = new DenoRuntimeSubprocessController(app.getID(), this.simpleAppSource, this.manager);
}

@AsyncTest('correctly identifies a call to the HTTP accessor')
Expand Down

0 comments on commit 419ae51

Please sign in to comment.