Skip to content

Extract JS runtime eval logic into packages/jsEval workspace with tests#170

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-js-runtime-tests
Draft

Extract JS runtime eval logic into packages/jsEval workspace with tests#170
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-js-runtime-tests

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

The JavaScript REPL logic (replLikeEval, checkSyntax) lived inline in a web worker with no test coverage, despite having non-trivial behavior around const/letvar rewriting, class hoisting, object-vs-block disambiguation, and syntax completeness detection.

Changes

  • packages/jsEval/src/index.ts – Extracts replLikeEval() and checkSyntax() from the worker. Uses indirect eval (0, eval) so var declarations reach the global scope in both Node.js and browser worker contexts, preserving REPL semantics.
  • packages/jsEval/src/index.test.ts – 28 tests via node:test covering:
    • replLikeEval: const/let/var/undeclared assignment, function, class, array, object literal, block-that-looks-like-object, await, error propagation
    • checkSyntax: complete expressions/blocks, incomplete inputs (if(1){, open brackets), invalid syntax
  • app/terminal/worker/jsEval.worker.ts – Removes the two function definitions; imports them from @my-code/js-eval instead.
  • package.json – Adds "workspaces": ["packages/*"].
  • .github/workflows/node.js.yml – Adds test-js-eval CI job running npm test --workspace=packages/jsEval.
// packages/jsEval/src/index.ts
// Indirect eval puts var declarations in global scope — same REPL behaviour in
// Node.js and browser workers.
const indirectEval: (code: string) => unknown = (0, eval);

export async function replLikeEval(code: string): Promise<unknown> {  }
export async function checkSyntax(code: string): Promise<{ status: "complete" | "incomplete" | "invalid" }> {  }
Original prompt

This section details on the original issue you should resolve

<issue_title>runtimeのテストを細かくする</issue_title>
<issue_description>python, rubyの実行環境はvmの関数をそのまま呼び出しているだけだから間違えようがないけど、javascriptの場合仕様がかなり複雑なので、テストをちゃんと書いたほうが良い
const宣言, let宣言, var宣言, 宣言無しの変数, function, class, array, object, objectに見せかけてコードブロック, ...

というより、jsランタイムを別パッケージにして独立したテストにするべきな気もする

checkSyntax() のテストも要る</issue_description>

<agent_instructions>* packages/jsEval ディレクトリをnpmワークスペースとして作成して。

  • app/terminal/worker/jsEval.worker.tsにあるreplLikeEval(),checkSyntax()をpackages/jsEvalに移し、jsEval.worker.tsはjsEvalワークスペースからその2つの関数をimportするようにして
  • packages/jsEval内でnode:testを使ってテストを実行できるようにして。
    const宣言, let宣言, var宣言, 宣言無しの変数, function, class, array, object, objectに見せかけてコードブロック, などのさまざまな入力に対してreplLikeEval()が意図した動作をするかを確認するテストを書いて。
  • checkSyntax()のテストも書いて。こちらは if(1){ などさまざまな入力途中の行が与えられた時に正しく動作するかをテストして。
  • pull requestの際にgithub actionでそのテストが実行されるようにして。</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…tests

Co-authored-by: na-trium-144 <100704180+na-trium-144@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 24, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
my-code 8af7d3b Commit Preview URL

Branch Preview URL
Feb 24 2026, 08:28 PM

Copilot AI changed the title [WIP] Refactor JavaScript runtime tests for better clarity Extract JS runtime eval logic into packages/jsEval workspace with tests Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runtimeのテストを細かくする

2 participants