diff --git a/docs/NewLanguage.md b/docs/NewLanguage.md index 0763bd9..8336579 100644 --- a/docs/NewLanguage.md +++ b/docs/NewLanguage.md @@ -88,11 +88,11 @@ environment variables, they are not and simple find and replace is performed before the command is executed. - `${SOURCE_FILE}` - Path to a source file which contains the users code from the payload. The file is not in current PWD and is read-only. -- ${SOURCE_ARGS}` - Command line arguments to the users code. +- `${SOURCE_ARGS}` - Command line arguments to the users code. - `${EXECUTOR}` - The executor in the payload. - `${EXECUTOR_ARGS}` - Arguments to the executor (for example to run `python3` with some additional flag). -- `${COMPILER}` and ${COMPILER_ARGS} - Same meaning as executor, but for +- `${COMPILER}` and `${COMPILER_ARGS}` - Same meaning as executor, but for `compiler`. Configs are located in `/evaluator/config/config.yaml`. diff --git a/evaluator/Dockerfile b/evaluator/Dockerfile index 83976d8..81aebf3 100644 --- a/evaluator/Dockerfile +++ b/evaluator/Dockerfile @@ -52,6 +52,7 @@ RUN apt-get install -y \ ghc \ build-essential \ python3 \ + nodejs \ racket COPY --from=builder /rust/app/target/release/evaluator bin/evaluator diff --git a/evaluator/config/config.yaml b/evaluator/config/config.yaml index 016923f..8752ac7 100644 --- a/evaluator/config/config.yaml +++ b/evaluator/config/config.yaml @@ -22,6 +22,13 @@ - rm source.c - ./a.out +- name: js + executors: + - name: nodejs-bookworm + path: /usr/bin/node + commands: + - "${EXECUTOR} ${EXECUTOR_ARGS} ${SOURCE_FILE} ${SOURCE_ARGS}" + - name: lua executors: - name: lua5.4.6 diff --git a/evaluator/infra/languages/lua/setup.sh b/evaluator/infra/languages/lua/setup.sh index f95a8eb..1a42084 100755 --- a/evaluator/infra/languages/lua/setup.sh +++ b/evaluator/infra/languages/lua/setup.sh @@ -18,7 +18,7 @@ setup_lua_version() { pushd lua-${LUA_VERSION} make linux mkdir -p /opt/evaluator/compilers/lua/ - cp src/lua /opt/evaluator/compilers/lua/lua${LUA_VERSION} + cp src/lua "/opt/evaluator/compilers/lua/lua${LUA_VERSION}" popd } diff --git a/integration_tests/evaluator_tests/test_js.py b/integration_tests/evaluator_tests/test_js.py new file mode 100644 index 0000000..774838d --- /dev/null +++ b/integration_tests/evaluator_tests/test_js.py @@ -0,0 +1,16 @@ +import requests + +EVALUATOR_ADDRESS = "http://evaluator:7800/api/v1/evaluate" + +def generate_python(code: str): + return {"language": "js", "code": code, "executor": "nodejs-bookworm"} + +def test_simple_python(): + payload = generate_python(""" +console.log("Hello, World!"); +""") + response = requests.post(EVALUATOR_ADDRESS, json=payload) + assert response.status_code == 200 + values = response.json() + assert values["stdout"] == "Hello, World!\n" + assert values["stderr"] == "" diff --git a/website/package.json b/website/package.json index 563a469..37feeb0 100644 --- a/website/package.json +++ b/website/package.json @@ -2,6 +2,7 @@ "name": "website", "version": "0.0.1", "private": true, + "packageManager": "pnpm@9.15.9", "scripts": { "dev": "vite dev", "build": "vite build", diff --git a/website/src/lib/constants.ts b/website/src/lib/constants.ts index 4ea1930..aa4ac93 100644 --- a/website/src/lib/constants.ts +++ b/website/src/lib/constants.ts @@ -8,6 +8,13 @@ export const languages: { [key in LangKey]: ILanguage } = { text: 'Lua', executors: ['lua5.4.6', 'lua5.3.6', 'lua5.2.4', 'lua5.1.5'] }, + js: { + name: 'js', + server_name: 'js', + editor_name: 'javascript', + text: 'Javascript', + executors: ['nodejs-bookworm'] + }, python3: { name: 'python3', server_name: 'python3', diff --git a/website/src/lib/defaultPrograms.ts b/website/src/lib/defaultPrograms.ts index a42300b..5e87f48 100644 --- a/website/src/lib/defaultPrograms.ts +++ b/website/src/lib/defaultPrograms.ts @@ -14,6 +14,17 @@ export const defaultPrograms: IPrograms = { '', 'print(fact(5))' ].join('\n'), + javascript: [ + 'function fact(n) {', + ' if (n === 0) {', + ' return 1;', + ' } else {', + ' return n * fact(n - 1);', + ' }', + '}', + '', + 'console.log(fact(5));' + ].join('\n'), scheme: [ '#lang racket', '', diff --git a/website/src/lib/types.ts b/website/src/lib/types.ts index c6c57d0..950f3e7 100644 --- a/website/src/lib/types.ts +++ b/website/src/lib/types.ts @@ -37,6 +37,7 @@ export type LinkData = { export type LangKey = | 'lua' + | 'js' | 'python3' | 'racket' | 'bash'