diff --git a/AUDIT.md b/AUDIT.md index cbd5d79..e7d303e 100644 --- a/AUDIT.md +++ b/AUDIT.md @@ -43,6 +43,7 @@ after each item. - [x] `scripting/job_store.ex` - [x] `desktop/server.ex` - [x] `desktop/shell_live/code_entity_editor.ex` +- [x] `scripting/runtime.ex` --- diff --git a/lib/bds/scripting.ex b/lib/bds/scripting.ex index 40cb452..cb42dfb 100644 --- a/lib/bds/scripting.ex +++ b/lib/bds/scripting.ex @@ -6,7 +6,7 @@ defmodule BDS.Scripting do require Logger alias BDS.Scripting.Capabilities - alias BDS.Scripting.Runtime + alias BDS.Scripting.Lua @type job_status :: :queued | :running | :completed | :failed | :cancelled @type job_snapshot :: %{ @@ -31,7 +31,7 @@ defmodule BDS.Scripting do runtime().validate(source) end - @spec execute(String.t(), String.t(), [term()], [Runtime.execution_option()]) :: + @spec execute(String.t(), String.t(), [term()], [Lua.execution_option()]) :: {:ok, term()} | {:error, term()} def execute(source, entrypoint, args \\ [], opts \\ []) when is_binary(source) and is_binary(entrypoint) and is_list(args) and is_list(opts) do @@ -39,7 +39,7 @@ defmodule BDS.Scripting do end @spec execute_project_script(String.t(), String.t(), String.t(), [term()], [ - Runtime.execution_option() + Lua.execution_option() ]) :: {:ok, term()} | {:error, term()} def execute_project_script(project_id, source, entrypoint, args \\ [], opts \\ []) @@ -75,7 +75,7 @@ defmodule BDS.Scripting do end end - @spec start_job(String.t(), String.t(), [term()], [Runtime.execution_option()]) :: + @spec start_job(String.t(), String.t(), [term()], [Lua.execution_option()]) :: {:ok, job_snapshot()} | {:error, term()} def start_job(source, entrypoint, args \\ [], opts \\ []) when is_binary(source) and is_binary(entrypoint) and is_list(args) and is_list(opts) do diff --git a/lib/bds/scripting/lua.ex b/lib/bds/scripting/lua.ex index d77fe60..76c240a 100644 --- a/lib/bds/scripting/lua.ex +++ b/lib/bds/scripting/lua.ex @@ -6,7 +6,23 @@ defmodule BDS.Scripting.Lua do and opt-in. """ - @behaviour BDS.Scripting.Runtime + @type source :: String.t() + @type entrypoint :: String.t() + @type args :: [term()] + @type progress_event :: map() + @type progress_callback :: (progress_event() -> any()) + @type execution_option :: + {:timeout, non_neg_integer() | :infinity} + | {:max_reductions, pos_integer() | :none} + | {:spawn_opts, [term()]} + | {:on_progress, progress_callback()} + | {:capabilities, map()} + + @callback validate(source()) :: :ok | {:error, term()} + @callback execute(source(), entrypoint(), args(), [execution_option()]) :: + {:ok, term()} | {:error, term()} + + @behaviour __MODULE__ @type lua_state :: tuple() @type runtime_result :: {:ok, term(), lua_state} | {:error, term()} diff --git a/lib/bds/scripting/runtime.ex b/lib/bds/scripting/runtime.ex deleted file mode 100644 index d1432b3..0000000 --- a/lib/bds/scripting/runtime.ex +++ /dev/null @@ -1,24 +0,0 @@ -defmodule BDS.Scripting.Runtime do - @moduledoc """ - Behaviour for user-script runtimes hosted by bDS. - - The runtime boundary is intentionally narrow: syntax validation and - bounded entrypoint execution. - """ - - @type source :: String.t() - @type entrypoint :: String.t() - @type args :: [term()] - @type progress_event :: map() - @type progress_callback :: (progress_event() -> any()) - @type execution_option :: - {:timeout, non_neg_integer() | :infinity} - | {:max_reductions, pos_integer() | :none} - | {:spawn_opts, [term()]} - | {:on_progress, progress_callback()} - | {:capabilities, map()} - - @callback validate(source()) :: :ok | {:error, term()} - @callback execute(source(), entrypoint(), args(), [execution_option()]) :: - {:ok, term()} | {:error, term()} -end diff --git a/test/bds/scripting/job_test.exs b/test/bds/scripting/job_test.exs index 41d0f0b..3e21a20 100644 --- a/test/bds/scripting/job_test.exs +++ b/test/bds/scripting/job_test.exs @@ -2,7 +2,7 @@ defmodule BDS.Scripting.JobTest do use ExUnit.Case, async: false defmodule FakeRuntime do - @behaviour BDS.Scripting.Runtime + @behaviour BDS.Scripting.Lua @impl true def validate(_source), do: :ok @@ -19,7 +19,7 @@ defmodule BDS.Scripting.JobTest do end defmodule BlockingRuntime do - @behaviour BDS.Scripting.Runtime + @behaviour BDS.Scripting.Lua @impl true def validate(_source), do: :ok @@ -37,7 +37,7 @@ defmodule BDS.Scripting.JobTest do end defmodule ShutdownAwareRuntime do - @behaviour BDS.Scripting.Runtime + @behaviour BDS.Scripting.Lua @impl true def validate(_source), do: :ok