More fixes, cc @junlarsen

This commit is contained in:
Matt Godbolt
2025-05-19 09:18:58 -05:00
parent d2d504787e
commit a78feabbd9
5 changed files with 32 additions and 44 deletions
+1 -10
View File
@@ -30,13 +30,6 @@ import {CompileHandler} from '../handlers/compile.js';
import {PropertyGetter} from '../properties.interfaces.js';
import {CompilerProps} from '../properties.js';
export interface CompilationEnvResult {
compilationQueue: CompilationQueue;
compilationEnvironment: CompilationEnvironment;
compileHandler: CompileHandler;
formattingService: FormattingService;
}
/**
* Initialize the compilation environment components
* @param appArgs - Application arguments
@@ -50,7 +43,7 @@ export async function initializeCompilationEnvironment(
compilerProps: CompilerProps,
ceProps: PropertyGetter,
awsProps: PropertyGetter,
): Promise<CompilationEnvResult> {
) {
const formattingService = new FormattingService();
await formattingService.initialize(ceProps);
@@ -67,9 +60,7 @@ export async function initializeCompilationEnvironment(
compilationEnvironment.setCompilerFinder(compileHandler.findCompiler.bind(compileHandler));
return {
compilationQueue,
compilationEnvironment,
compileHandler,
formattingService,
};
}
+8 -6
View File
@@ -25,8 +25,6 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import _ from 'underscore';
import type {AppArguments} from '../app.interfaces.js';
import {initializeCompilationEnvironment} from './compilation-env.js';
import {setupCompilerChangeHandling} from './compiler-changes.js';
@@ -68,8 +66,12 @@ export async function initialiseApplication(options: ApplicationOptions): Promis
RemoteExecutionQuery.initRemoteExecutionArchs(ceProps, appArgs.env);
const {compilationQueue, compilationEnvironment, compileHandler, formattingService} =
await initializeCompilationEnvironment(appArgs, compilerProps, ceProps, awsProps);
const {compilationEnvironment, compileHandler} = await initializeCompilationEnvironment(
appArgs,
compilerProps,
ceProps,
awsProps,
);
const clientOptionsHandler = new ClientOptionsHandler(sources, compilerProps, appArgs);
const storageType = getStorageTypeByKey(storageSolution);
@@ -84,8 +86,8 @@ export async function initialiseApplication(options: ApplicationOptions): Promis
const controllers = setupControllersAndHandlers(
compileHandler,
formattingService,
compilationQueue,
compilationEnvironment.formattingService,
compilationEnvironment.compilationQueue,
healthCheckFilePath,
isExecutionWorker,
formDataHandler,
+1 -6
View File
@@ -30,12 +30,7 @@ import urljoin from 'url-join';
import {ElementType} from '../../shared/common-utils.js';
import {logger} from '../logger.js';
import {ServerOptions} from './server.interfaces.js';
/**
* Function signature for handling Pug template requires
*/
export type PugRequireHandler = (path: string) => string;
import {PugRequireHandler, ServerOptions} from './server.interfaces.js';
/**
* Creates a default handler for Pug requires
+2 -2
View File
@@ -48,7 +48,7 @@ type FindCompiler = (langId: LanguageKey, compilerId: string) => BaseCompiler |
export class CompilationEnvironment {
ceProps: PropertyGetter;
awsProps: PropFunc;
compilationQueue: CompilationQueue | undefined;
compilationQueue: CompilationQueue;
compilerProps: PropFunc;
okOptions: RegExp;
badOptions: RegExp;
@@ -67,7 +67,7 @@ export class CompilationEnvironment {
constructor(
compilerProps: CompilerProps,
awsProps: PropFunc,
compilationQueue: CompilationQueue | undefined,
compilationQueue: CompilationQueue,
public formattingService: FormattingService,
doCache?: boolean,
) {
@@ -26,6 +26,7 @@ import './utils.js';
import {beforeAll, describe, expect, it} from 'vitest';
import {CompilationEnvironment} from '../lib/compilation-env.js';
import {CompilationQueue} from '../lib/compilation-queue.js';
import {FormattingService} from '../lib/formatting-service.js';
import {CompilerProps, fakeProps} from '../lib/properties.js';
@@ -36,48 +37,47 @@ const props = {
};
describe('Compilation environment', () => {
let compilerProps;
let compilerProps: CompilerProps;
let compilationQueue: CompilationQueue;
beforeAll(() => {
compilerProps = new CompilerProps({}, fakeProps(props));
compilationQueue = new CompilationQueue(1, 1000, 1000);
});
it('Should cache by default', async () => {
// TODO: Work will need to be done here when CompilationEnvironment's constructor is typed better
const ce = new CompilationEnvironment(
compilerProps,
fakeProps({}),
undefined,
new FormattingService(),
undefined,
);
const ce = new CompilationEnvironment(compilerProps, fakeProps({}), compilationQueue, new FormattingService());
await expect(ce.cacheGet('foo')).resolves.toBeNull();
await ce.cachePut('foo', {res: 'bar'}, undefined);
await expect(ce.cacheGet('foo')).resolves.toEqual({res: 'bar'});
await expect(ce.cacheGet('baz')).resolves.toBeNull();
});
it('Should cache when asked', async () => {
const ce = new CompilationEnvironment(compilerProps, fakeProps({}), undefined, new FormattingService(), true);
const ce = new CompilationEnvironment(
compilerProps,
fakeProps({}),
compilationQueue,
new FormattingService(),
true,
);
await expect(ce.cacheGet('foo')).resolves.toBeNull();
await ce.cachePut('foo', {res: 'bar'}, undefined);
await expect(ce.cacheGet('foo')).resolves.toEqual({res: 'bar'});
});
it("Shouldn't cache when asked", async () => {
// TODO: Work will need to be done here when CompilationEnvironment's constructor is typed better
const ce = new CompilationEnvironment(compilerProps, fakeProps({}), undefined, new FormattingService(), false);
const ce = new CompilationEnvironment(
compilerProps,
fakeProps({}),
compilationQueue,
new FormattingService(),
false,
);
await expect(ce.cacheGet('foo')).resolves.toBeNull();
await ce.cachePut('foo', {res: 'bar'}, undefined);
await expect(ce.cacheGet('foo')).resolves.toBeNull();
});
it('Should filter bad options', () => {
// TODO: Work will need to be done here when CompilationEnvironment's constructor is typed better
const ce = new CompilationEnvironment(
compilerProps,
fakeProps({}),
undefined,
new FormattingService(),
undefined,
);
const ce = new CompilationEnvironment(compilerProps, fakeProps({}), compilationQueue, new FormattingService());
expect(ce.findBadOptions(['-O3', '-flto'])).toEqual([]);
expect(ce.findBadOptions(['-O3', '-plugin'])).toEqual(['-plugin']);
});