-
Notifications
You must be signed in to change notification settings - Fork 2
Branch remote runner plugin fixed #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
proto-aiken-13
wants to merge
36
commits into
source-academy:main
Choose a base branch
from
proto-aiken-13:branch-remoteRunnerPlugin-fixed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
fddcd14
Setup of the remoteRunner plugin
proto-aiken-13 bfcea05
Update directory
proto-aiken-13 d0883bd
Modify the remoteRunnerPlugin structure and add ev3Engine usage
proto-aiken-13 04bb38f
fix: migrate remoteExecution to vitest, remove abstract, fix rollup c…
Akshay-2007-1 e9a67bd
chore: add py-slang and transitive deps to yarn.lock
Akshay-2007-1 806e6c2
chore: fix yarn.lock — merge @babel/runtime range, add @sourceacademy…
Akshay-2007-1 b713b50
chore: fix yarn.lock ordering and missing entries
Akshay-2007-1 75af89b
chore: fix extra blank lines in yarn.lock
Akshay-2007-1 3c206eb
chore: remove trailing blank line from yarn.lock
Akshay-2007-1 ec51966
fix: disable verbatimModuleSyntax for remoteExecution package
Akshay-2007-1 549c5b3
fix: set es2020 target and noImplicitAny:false for py-slang compatibi…
Akshay-2007-1 90026d3
fix: use noCheck:true to skip type-checking py-slang source
Akshay-2007-1 19fd917
fix: remove unnecessary re-export of remoteRunnerPlugin from runner-test
Akshay-2007-1 3d467f1
fix: resolve ESLint errors in remoteExecution plugin
Akshay-2007-1 de8bd92
fix: add .ts extensions to nodeResolve in remoteExecution rollup config
Akshay-2007-1 08b2202
fix: include py-slang source in TypeScript program for rollup bundling
Akshay-2007-1 00bce74
fix: add inline plugin to transpile node_modules TypeScript via trans…
Akshay-2007-1 a04d4be
fix: add @rollup/plugin-commonjs to handle moo/nearley CJS modules
Akshay-2007-1 2b1b555
fix: add @rollup/plugin-commonjs dep and update yarn.lock workspace e…
Akshay-2007-1 5a62899
fix: make py-slang external in bundle, inline it via vitest
Akshay-2007-1 575669d
style: fix Prettier formatting in remoteExecution rollup.config.mjs
Akshay-2007-1 f979647
style: drop arrow function parens per Prettier arrowParens:avoid setting
Akshay-2007-1 c318438
test: mock py-slang in runner test to avoid TypeScript source loading
Akshay-2007-1 572ea84
fix: use Promise.resolve instead of async to satisfy require-await li…
Akshay-2007-1 5a257b0
feat(ev3): add conductor-based EV3 evaluator bundle
proto-aiken-13 764ee5b
Merge branch 'main' into branch-remoteRunnerPlugin-fixed
proto-aiken-13 a9f681f
refactor(remoteExecution): make plugin transport-only, remove py-slan…
proto-aiken-13 960563e
Merge branch 'main' into branch-remoteRunnerPlugin-fixed
proto-aiken-13 cbfc00e
Update rollup.config.mjs
proto-aiken-13 9121847
Simplify ev3 plugin design to remove py-slang dependencies
proto-aiken-13 912589b
Merge branch 'branch-remoteRunnerPlugin-fixed' of https://github.com/…
proto-aiken-13 f3b30c0
Update yarn.lock
proto-aiken-13 f32084b
Prettified remoteExecution plugin files
proto-aiken-13 a122ac3
fix(remote-execution): unblock PR CI - add missing common-remote-exec…
Akshay-2007-1 3143293
Merge remote-tracking branch 'origin/main' into remote-runner-plugin-…
Akshay-2007-1 e18a829
Fix yarn.lock drift from merge - commit the actually-resolved lockfile
Akshay-2007-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "type": "installable" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "name": "@sourceacademy/common-remote-execution", | ||
| "version": "0.0.1", | ||
| "packageManager": "yarn@4.6.0", | ||
| "description": "Shared types/constants for the transport-only remote-execution runner plugin and its web-side counterpart", | ||
| "scripts": { | ||
| "build": "rollup -c", | ||
| "prepack": "yarn build" | ||
| }, | ||
| "license": "ISC", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "main": "dist/index.cjs", | ||
| "module": "dist/index.mjs", | ||
| "types": "dist/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/index.mjs", | ||
| "require": "./dist/index.cjs", | ||
| "types": "./dist/index.d.ts" | ||
| } | ||
| }, | ||
| "devDependencies": { | ||
| "@rollup/plugin-node-resolve": "^16.0.3", | ||
| "@rollup/plugin-terser": "^1.0.0", | ||
| "@rollup/plugin-typescript": "^12.3.0", | ||
| "rollup": "^4.60.2", | ||
| "tslib": "^2.8.1", | ||
| "typescript": "^6.0.3", | ||
| "vitest": "^4.1.9" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import nodeResolve from "@rollup/plugin-node-resolve"; | ||
| import terser from "@rollup/plugin-terser"; | ||
| import typescript from "@rollup/plugin-typescript"; | ||
|
|
||
| /** | ||
| * @type {import('rollup').RollupOptions} | ||
| */ | ||
| export default { | ||
| input: "src/index.ts", | ||
| output: [ | ||
| { | ||
| file: "dist/index.cjs", | ||
| format: "cjs", | ||
| }, | ||
| { | ||
| file: "dist/index.mjs", | ||
| format: "esm", | ||
| }, | ||
| ], | ||
| plugins: [nodeResolve(), typescript(), terser()], | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| export const WEB_ID = "__web_remote_execution"; | ||
| export const RUNNER_ID = "__runner_remote_execution"; | ||
|
|
||
| export const CHANNEL_ID = "remote-execution"; | ||
|
|
||
| export const MESSAGE_TYPE_CONNECTION_STATUS = "connectionStatus"; | ||
|
|
||
| /** | ||
| * Mirrors the existing `DeviceConnection['status']` union from the frontend's | ||
| * (non-conductor) remoteExecution feature, so a web-side consumer can reuse | ||
| * the same state machine it already has for the legacy connection flow. | ||
| */ | ||
| export type ConnectionStatus = "CONNECTING" | "CONNECTED" | "FAILED"; | ||
|
|
||
| export type ConnectionStatusMessage = { | ||
| type: typeof MESSAGE_TYPE_CONNECTION_STATUS; | ||
| status: ConnectionStatus; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "exclude": ["./dist"], | ||
| "include": ["./src"], | ||
| "compilerOptions": { | ||
| "declaration": true, | ||
| "outDir": "./dist", | ||
| "rootDir": "./src" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,2 @@ | ||
| import { CHANNEL_ID, RUNNER_ID, type PySlangMessage } from "@sourceacademy/common-test"; | ||
| import type { IPlugin, IChannel, IConduit } from "@sourceacademy/conductor/conduit"; | ||
| import { EV3Engine } from "py-slang/src/engines/ev3/EV3Engine"; | ||
|
|
||
| export class remoteRunnerPlugin implements IPlugin { | ||
| readonly id: string = RUNNER_ID; | ||
| static readonly channelAttach = [CHANNEL_ID]; | ||
| private readonly __channel: IChannel<PySlangMessage>; | ||
| private readonly engine: EV3Engine; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| constructor(_conduit: IConduit, [channel]: IChannel<any>[]) { | ||
| this.__channel = channel; | ||
| this.engine = new EV3Engine(); | ||
|
|
||
| this.__channel.subscribe(async message => { | ||
| if (message.type === "run") { | ||
| const result = await this.engine.execute(message.code); | ||
| console.log("Engine response:", result); | ||
| this.__channel.send({ type: "result", output: JSON.stringify(result) }); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| export { RemoteExecutionPlugin } from "./src"; | ||
| export type { ConnectionStatus, ConnectionStatusMessage } from "./src"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,25 @@ | ||
| export { remoteRunnerPlugin } from "../index"; | ||
| import { | ||
| CHANNEL_ID, | ||
| RUNNER_ID, | ||
| MESSAGE_TYPE_CONNECTION_STATUS, | ||
| type ConnectionStatusMessage, | ||
| type ConnectionStatus, | ||
| } from "@sourceacademy/common-remote-execution"; | ||
| import type { IPlugin, IChannel, IConduit } from "@sourceacademy/conductor/conduit"; | ||
|
|
||
| export class RemoteExecutionPlugin implements IPlugin { | ||
| readonly id: string = RUNNER_ID; | ||
| static readonly channelAttach = [CHANNEL_ID]; | ||
| private readonly __channel: IChannel<ConnectionStatusMessage>; | ||
|
|
||
| constructor(_conduit: IConduit, [channel]: IChannel<ConnectionStatusMessage>[]) { | ||
| if (!channel) { | ||
| throw new Error("Remote execution channel is required but was not provided."); | ||
| } | ||
| this.__channel = channel; | ||
| } | ||
|
|
||
| sendConnectionStatus(status: ConnectionStatus): void { | ||
| this.__channel.send({ type: MESSAGE_TYPE_CONNECTION_STATUS, status }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,32 @@ | ||
| import { vi, test, expect } from "vitest"; | ||
| import { RemoteExecutionPlugin } from "@sourceacademy/runner-remote-execution"; | ||
| import type { ConnectionStatusMessage } from "@sourceacademy/common-remote-execution"; | ||
|
|
||
| vi.mock("py-slang/src/engines/ev3/EV3Engine", () => ({ | ||
| EV3Engine: class MockEV3Engine { | ||
| execute(code: string) { | ||
| return Promise.resolve({ output: `mock: ${code}` }); | ||
| } | ||
| }, | ||
| })); | ||
|
|
||
| import { remoteRunnerPlugin } from "@sourceacademy/runner-remote-execution"; | ||
| import type { PySlangMessage } from "@sourceacademy/common-test"; | ||
|
|
||
| test("plugin subscribes to channel and sends result on run message", async () => { | ||
| const sentMessages: PySlangMessage[] = []; | ||
| let messageHandler: (msg: PySlangMessage) => void = () => {}; | ||
| test("plugin forwards connection status over its channel without touching execution", () => { | ||
| const sentMessages: ConnectionStatusMessage[] = []; | ||
|
|
||
| const mockChannel = { | ||
| name: "py_slang_channel", | ||
| send: (msg: PySlangMessage) => { | ||
| name: "remote-execution", | ||
| send: (msg: ConnectionStatusMessage) => { | ||
| sentMessages.push(msg); | ||
| }, | ||
| subscribe: (handler: (msg: PySlangMessage) => void) => { | ||
| messageHandler = handler; | ||
| }, | ||
| unsubscribe: () => {}, | ||
| close: () => {}, | ||
| subscribe: vi.fn(), | ||
| unsubscribe: vi.fn(), | ||
| close: vi.fn(), | ||
| }; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const mockConduit = {} as any; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| new remoteRunnerPlugin(mockConduit, [mockChannel as any]); | ||
| const plugin = new RemoteExecutionPlugin(mockConduit, [mockChannel]); | ||
|
|
||
| plugin.sendConnectionStatus("CONNECTED"); | ||
|
|
||
| await messageHandler({ type: "run", code: "1 + 1" }); | ||
| expect(sentMessages).toStrictEqual([{ type: "connectionStatus", status: "CONNECTED" }]); | ||
| }); | ||
|
|
||
| test("plugin construction throws if no channel is attached", () => { | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const mockConduit = {} as any; | ||
|
|
||
| expect(sentMessages.length).toBeGreaterThan(0); | ||
| expect(sentMessages[0]).toMatchObject({ type: "result" }); | ||
| expect(() => new RemoteExecutionPlugin(mockConduit, [])).toThrow(); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.