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
18 changes: 17 additions & 1 deletion .github/workflows/runtime-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,20 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
- run: pnpm install --frozen-lockfile
- run: pnpm run --filter @my-code/runtime test
- name: Install Boost
run: sudo apt-get update && sudo apt-get install -y libboost-dev
- name: Start unsandbox
run: |
pnpm exec unsandbox --port 3055 &
for i in {1..30}; do
if curl -s http://localhost:3055/api/list.json > /dev/null; then
echo "unsandbox is ready"
break
fi
echo "Waiting for unsandbox..."
sleep 1
done
- name: Run runtime tests
env:
WANDBOX_URL: http://localhost:3055
run: pnpm run --filter @my-code/runtime test
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SENTRY_PROJECT=
SENTRY_URL=
SENTRY_AUTH_TOKEN=
SENTRY_DSN=
# WANDBOX_URL=http://localhost:3055 # C++/Rustのローカル実行用(任意)
```

- チャット用にGeminiのAPIキーまたはOpenRouterのAPIキーのいずれかが必要です。未設定の場合チャットが使えません
Expand Down Expand Up @@ -78,6 +79,27 @@ pnpm run lint

でコードをチェックします。出てくるwarningやerrorはできるだけ直しましょう。

### C++ / Rust のコード実行環境 (unsandbox)

C++ および Rust のコード実行は、デフォルトでは [Wandbox](https://wandbox.org/) の公開 API を使用しますが、ローカルに [unsandbox](https://github.com/ut-code/unsandbox) を立ち上げて実行することも可能です(ローカル実行のほうが高速です)。

```bash
# unsandbox を起動(例: ポート 3055)
pnpm exec unsandbox --port 3055
```

`.env` または `.env.local` に以下を設定すると、Next.js 開発サーバーやテスト実行時にローカルの unsandbox が自動で利用されます(dotenvによりテスト実行時も読み込まれます)。

```dotenv
WANDBOX_URL=http://localhost:3055
```

※ コマンドラインから直接指定して一時的に切り替えることも可能です。

```bash
WANDBOX_URL=http://localhost:3055 pnpm --filter @my-code/runtime test
```

### データベースのスキーマ

- データベースのスキーマ(./app/schema/hoge.ts)を編集した場合、 `pnpm run db-generate` (`pnpm exec drizzle-kit generate`) でmigrationファイルを作成し、 `pnpm run db-migrate` (`pnpm exec drizzle-kit migrate`) でデータベースに反映します。
Expand Down
1 change: 1 addition & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let nextConfig: NextConfig = {
},
env: {
SENTRY_DSN: process.env.SENTRY_DSN,
WANDBOX_URL: process.env.WANDBOX_URL,
},
serverExternalPackages: [
"@prisma/client",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"tsx": "^4.20.6",
"typescript": "5.9.3",
"unified": "^11.0.5",
"unsandbox": "^1.0.0",
"webpack-license-plugin": "^4.5.1",
"wrangler": "^4.27.0"
}
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
## tests

- `pnpm run --filter @my-code/runtime test` でvitestを使ってテストを実行できます
- ルートまたはパッケージ内の `.env` / `.env.local` に `WANDBOX_URL` を記述しておくことで、ローカルで立ち上げた [unsandbox](https://github.com/ut-code/unsandbox) サーバーに自動で接続して高速にテストを実行できます(コマンドラインでの `WANDBOX_URL=...` 指定も可能です)。
```bash
pnpm exec unsandbox --port 3055 &
pnpm run --filter @my-code/runtime test
```
- my.code(); の /about/runtime ページでMochaを使ってテストを実行できます
- どちらからでも実行できるようテスト本体は ./tests/repl.ts, ./tests/fileExecution.ts に記述しています。
新しい言語の実行環境を追加した場合、ここにテストケースを追加してください。
Expand All @@ -41,7 +46,7 @@ workerとの通信部分は言語によらず共通なので、それをworker/r

### Wandbox

wandbox.org のAPIを利用してコードを実行します。
wandbox.org のAPIを利用してコードを実行します(環境変数 `WANDBOX_URL` でローカルの unsandbox 等のエンドポイントに切り替え可能です)

APIから利用可能なコンパイラとオプションのリストが得られるので、言語ごとにそこからオプションを選択するロジックを実装しています。

Expand Down
5 changes: 3 additions & 2 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"test": "vitest run"
},
"dependencies": {
"@my-code/js-eval": "workspace:*",
"@ruby/wasm-wasi": "^2.7.2",
"@typescript/vfs": "^1.6.2",
"async-mutex": "^0.5.0",
Expand All @@ -21,8 +22,7 @@
"react-dom": "^19",
"swr": "^2",
"typescript": "^5",
"zod": "^4.0.17",
"@my-code/js-eval": "workspace:*"
"zod": "^4.0.17"
},
"devDependencies": {
"@testing-library/dom": "^10.0.0",
Expand All @@ -33,6 +33,7 @@
"@types/react-dom": "^19",
"@vitejs/plugin-react": "^5.1.4",
"@vitest/browser-webdriverio": "^4.1.10",
"dotenv": "^17.4.2",
"vitest": "^4.1.10"
}
}
3 changes: 2 additions & 1 deletion packages/runtime/src/wandbox/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { type Fetcher } from "swr";
import { type ReplOutput, RuntimeInfo } from "../interface";

const WANDBOX = "https://wandbox.org";
const WANDBOX = process.env.WANDBOX_URL || "https://wandbox.org";

// https://github.com/melpon/wandbox/blob/ajax/kennel2/API.rst <- 古いけど、説明と例がある
// https://github.com/melpon/wandbox/blob/master/feline/src/types.rs
/* RustのVec<u8>はバイト配列ですが、serialize_with = "serialize_utf8"という指定があるため、
Expand Down
11 changes: 11 additions & 0 deletions packages/runtime/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ import { defineConfig } from "vitest/config";
import path from "path";
import react from "@vitejs/plugin-react";
import { webdriverio } from "@vitest/browser-webdriverio";
import dotenv from "dotenv";

// Load .env and .env.local from project root and package directory
const rootDir = path.resolve(__dirname, "../..");
dotenv.config({ path: path.resolve(rootDir, ".env") });
dotenv.config({ path: path.resolve(rootDir, ".env.local"), override: true });
dotenv.config({ path: path.resolve(__dirname, ".env"), override: true });
dotenv.config({ path: path.resolve(__dirname, ".env.local"), override: true });

// webdriverioは自動でchromeをダウンロードして起動するはずだが、もし何らかの理由でchromeが動作しない場合は、 @puppeteer/browsers を使用してchromeをダウンロードし、環境変数でバイナリのパスを指定してみる
const localChrome = process.env.CHROME_BIN;
const localChromeDriver = process.env.CHROMEDRIVER_PATH;

export default defineConfig({
define: {
"process.env.WANDBOX_URL": JSON.stringify(process.env.WANDBOX_URL || ""),
},
resolve: {
alias: {
"@my-code/js-eval": path.resolve(__dirname, "../jsEval/src"),
Expand Down
33 changes: 33 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ minimumReleaseAge: 1440
minimumReleaseAgeStrict: true
minimumReleaseAgeExclude:
- daisyui@5.7.13
- unsandbox@1.0.0

strictDepBuilds: true
strictPeerDependencies: true
Expand Down
Loading