From f3693a8a32c514213c2d6af0063997a2b1d6ef9b Mon Sep 17 00:00:00 2001 From: ByeongUk Choi Date: Sun, 3 Apr 2022 20:15:43 +0900 Subject: [PATCH 1/5] allow embedded runtime by env --- README.md | 3 +++ lib/livebook.ex | 4 ++++ lib/livebook/config.ex | 7 +++++++ .../live/session_live/runtime_component.ex | 16 +++++++++------- test/livebook_web/live/session_live_test.exs | 14 ++++++++++++++ 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3f8a9f29925..4e46030d2a8 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,9 @@ The following environment variables configure Livebook: * LIVEBOOK_FORCE_SSL_HOST - set a host to redirect to if the request is not over HTTP. Note it does not apply when accessing Livebook via localhost. Defaults to nil. + * LIVEBOOK_EMBEDDED_RUNTIME_ENABLED - controls whether runtime type embedded is enabled. + Set it to "true" to enable it. Defaults to "false" + If running Livebook as a Docker image or an Elixir release, [the environment diff --git a/lib/livebook.ex b/lib/livebook.ex index 816b0104eba..3d281e8831e 100644 --- a/lib/livebook.ex +++ b/lib/livebook.ex @@ -130,6 +130,10 @@ defmodule Livebook do config :livebook, :force_ssl_host, force_ssl_host end + config :livebook, + :embedded_runtime_enabled, + Livebook.Config.embedded_runtime_enabled!("LIVEBOOK_EMBEDDED_RUNTIME_ENABLED") + config :livebook, :cookie, Livebook.Config.cookie!("LIVEBOOK_COOKIE") || diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index 36fe5311970..078393835cb 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -204,6 +204,13 @@ defmodule Livebook.Config do System.get_env(env) end + @doc """ + Parses embedded runtime setting from env. + """ + def embedded_runtime_enabled!(env) do + System.get_env(env, "0") in ~w(true 1) + end + @doc """ Parses and validates default runtime from env. """ diff --git a/lib/livebook_web/live/session_live/runtime_component.ex b/lib/livebook_web/live/session_live/runtime_component.ex index 7eb3125c661..8d1b3983020 100644 --- a/lib/livebook_web/live/session_live/runtime_component.ex +++ b/lib/livebook_web/live/session_live/runtime_component.ex @@ -51,13 +51,15 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do phx-target={@myself}> Attached node - <.choice_button - active={@type == "embedded"} - phx-click="set_runtime_type" - phx-value-type="embedded" - phx-target={@myself}> - Embedded - + <%= if Application.get_env(:livebook, :embedded_runtime_enabled) do %> + <.choice_button + active={@type == "embedded"} + phx-click="set_runtime_type" + phx-value-type="embedded" + phx-target={@myself}> + Embedded + + <% end %>
<%= live_render @socket, live_view_for_type(@type), diff --git a/test/livebook_web/live/session_live_test.exs b/test/livebook_web/live/session_live_test.exs index b0126b80bfb..2df7c3116fb 100644 --- a/test/livebook_web/live/session_live_test.exs +++ b/test/livebook_web/live/session_live_test.exs @@ -433,6 +433,20 @@ defmodule LivebookWeb.SessionLiveTest do assert page =~ "Reconnect" assert page =~ "Disconnect" end + + test "hide embedded runtime type button when defaults.", %{conn: conn, session: session} do + {:ok, view, _} = live(conn, "/sessions/#{session.id}/settings/runtime") + + refute view |> element("button", "Embedded") |> has_element?() + end + + test "show embedded runtime type button when :embedded_runtime_enabled is true", + %{conn: conn, session: session} do + Application.put_env(:livebook, :embedded_runtime_enabled, true) + {:ok, view, _} = live(conn, "/sessions/#{session.id}/settings/runtime") + + assert view |> element("button", "Embedded") |> has_element?() + end end describe "persistence settings" do From 81ca7d1c88e90b0684c70e13c317cbca5ff7fe82 Mon Sep 17 00:00:00 2001 From: ByeongUk Choi Date: Sun, 3 Apr 2022 20:53:19 +0900 Subject: [PATCH 2/5] fix session live test --- lib/livebook/config.ex | 11 ++++++++ .../live/session_live/runtime_component.ex | 2 +- test/livebook_web/live/session_live_test.exs | 27 +++++++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index 078393835cb..a7e139488a8 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -26,6 +26,17 @@ defmodule Livebook.Config do Application.fetch_env!(:livebook, :default_runtime) end + @doc """ + Returns the enable embedded runtime module. + """ + @spec embedded_runtime_enabled() :: boolean() + def embedded_runtime_enabled() do + case default_runtime() do + %Livebook.Runtime.Embedded{} -> true + _other -> Application.fetch_env!(:livebook, :embedded_runtime_enabled) + end + end + @doc """ Returns the authentication mode. """ diff --git a/lib/livebook_web/live/session_live/runtime_component.ex b/lib/livebook_web/live/session_live/runtime_component.ex index 8d1b3983020..9455388f9c5 100644 --- a/lib/livebook_web/live/session_live/runtime_component.ex +++ b/lib/livebook_web/live/session_live/runtime_component.ex @@ -51,7 +51,7 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do phx-target={@myself}> Attached node - <%= if Application.get_env(:livebook, :embedded_runtime_enabled) do %> + <%= if Livebook.Config.embedded_runtime_enabled() do %> <.choice_button active={@type == "embedded"} phx-click="set_runtime_type" diff --git a/test/livebook_web/live/session_live_test.exs b/test/livebook_web/live/session_live_test.exs index 2df7c3116fb..cfaa0cd4fcb 100644 --- a/test/livebook_web/live/session_live_test.exs +++ b/test/livebook_web/live/session_live_test.exs @@ -433,14 +433,37 @@ defmodule LivebookWeb.SessionLiveTest do assert page =~ "Reconnect" assert page =~ "Disconnect" end + end + + describe "runtime settings - allow Embedded" do + setup do + default_runtime = Application.get_env(:livebook, :default_runtime) + Application.put_env(:livebook, :default_runtime, Livebook.Runtime.ElixirStandalone.new()) + Application.put_env(:livebook, :embedded_runtime_enabled, false) + + on_exit(fn -> + Application.put_env(:livebook, :default_runtime, default_runtime) + end) - test "hide embedded runtime type button when defaults.", %{conn: conn, session: session} do + :ok + end + + test "hide embedded runtime button when :default_runtime is Elixir Standalone", + %{conn: conn, session: session} do {:ok, view, _} = live(conn, "/sessions/#{session.id}/settings/runtime") refute view |> element("button", "Embedded") |> has_element?() end - test "show embedded runtime type button when :embedded_runtime_enabled is true", + test "show embedded runtime button when :default_runtime is Embedded.", + %{conn: conn, session: session} do + Application.put_env(:livebook, :default_runtime, Livebook.Runtime.Embedded.new()) + {:ok, view, _} = live(conn, "/sessions/#{session.id}/settings/runtime") + + assert view |> element("button", "Embedded") |> has_element?() + end + + test "show embedded runtime button when :embedded_runtime_enabled is true", %{conn: conn, session: session} do Application.put_env(:livebook, :embedded_runtime_enabled, true) {:ok, view, _} = live(conn, "/sessions/#{session.id}/settings/runtime") From 516b509cf3774707a26299ae32dab7516fc45a9f Mon Sep 17 00:00:00 2001 From: ByeongUk Choi Date: Mon, 4 Apr 2022 00:40:25 +0900 Subject: [PATCH 3/5] This reverts commit f36931d6ef9b..81ca7d --- README.md | 3 -- lib/livebook.ex | 4 -- lib/livebook/config.ex | 18 --------- .../live/session_live/runtime_component.ex | 16 ++++---- test/livebook_web/live/session_live_test.exs | 37 ------------------- 5 files changed, 7 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 4e46030d2a8..3f8a9f29925 100644 --- a/README.md +++ b/README.md @@ -187,9 +187,6 @@ The following environment variables configure Livebook: * LIVEBOOK_FORCE_SSL_HOST - set a host to redirect to if the request is not over HTTP. Note it does not apply when accessing Livebook via localhost. Defaults to nil. - * LIVEBOOK_EMBEDDED_RUNTIME_ENABLED - controls whether runtime type embedded is enabled. - Set it to "true" to enable it. Defaults to "false" - If running Livebook as a Docker image or an Elixir release, [the environment diff --git a/lib/livebook.ex b/lib/livebook.ex index 3d281e8831e..816b0104eba 100644 --- a/lib/livebook.ex +++ b/lib/livebook.ex @@ -130,10 +130,6 @@ defmodule Livebook do config :livebook, :force_ssl_host, force_ssl_host end - config :livebook, - :embedded_runtime_enabled, - Livebook.Config.embedded_runtime_enabled!("LIVEBOOK_EMBEDDED_RUNTIME_ENABLED") - config :livebook, :cookie, Livebook.Config.cookie!("LIVEBOOK_COOKIE") || diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index a7e139488a8..36fe5311970 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -26,17 +26,6 @@ defmodule Livebook.Config do Application.fetch_env!(:livebook, :default_runtime) end - @doc """ - Returns the enable embedded runtime module. - """ - @spec embedded_runtime_enabled() :: boolean() - def embedded_runtime_enabled() do - case default_runtime() do - %Livebook.Runtime.Embedded{} -> true - _other -> Application.fetch_env!(:livebook, :embedded_runtime_enabled) - end - end - @doc """ Returns the authentication mode. """ @@ -215,13 +204,6 @@ defmodule Livebook.Config do System.get_env(env) end - @doc """ - Parses embedded runtime setting from env. - """ - def embedded_runtime_enabled!(env) do - System.get_env(env, "0") in ~w(true 1) - end - @doc """ Parses and validates default runtime from env. """ diff --git a/lib/livebook_web/live/session_live/runtime_component.ex b/lib/livebook_web/live/session_live/runtime_component.ex index 9455388f9c5..7eb3125c661 100644 --- a/lib/livebook_web/live/session_live/runtime_component.ex +++ b/lib/livebook_web/live/session_live/runtime_component.ex @@ -51,15 +51,13 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do phx-target={@myself}> Attached node - <%= if Livebook.Config.embedded_runtime_enabled() do %> - <.choice_button - active={@type == "embedded"} - phx-click="set_runtime_type" - phx-value-type="embedded" - phx-target={@myself}> - Embedded - - <% end %> + <.choice_button + active={@type == "embedded"} + phx-click="set_runtime_type" + phx-value-type="embedded" + phx-target={@myself}> + Embedded +
<%= live_render @socket, live_view_for_type(@type), diff --git a/test/livebook_web/live/session_live_test.exs b/test/livebook_web/live/session_live_test.exs index cfaa0cd4fcb..b0126b80bfb 100644 --- a/test/livebook_web/live/session_live_test.exs +++ b/test/livebook_web/live/session_live_test.exs @@ -435,43 +435,6 @@ defmodule LivebookWeb.SessionLiveTest do end end - describe "runtime settings - allow Embedded" do - setup do - default_runtime = Application.get_env(:livebook, :default_runtime) - Application.put_env(:livebook, :default_runtime, Livebook.Runtime.ElixirStandalone.new()) - Application.put_env(:livebook, :embedded_runtime_enabled, false) - - on_exit(fn -> - Application.put_env(:livebook, :default_runtime, default_runtime) - end) - - :ok - end - - test "hide embedded runtime button when :default_runtime is Elixir Standalone", - %{conn: conn, session: session} do - {:ok, view, _} = live(conn, "/sessions/#{session.id}/settings/runtime") - - refute view |> element("button", "Embedded") |> has_element?() - end - - test "show embedded runtime button when :default_runtime is Embedded.", - %{conn: conn, session: session} do - Application.put_env(:livebook, :default_runtime, Livebook.Runtime.Embedded.new()) - {:ok, view, _} = live(conn, "/sessions/#{session.id}/settings/runtime") - - assert view |> element("button", "Embedded") |> has_element?() - end - - test "show embedded runtime button when :embedded_runtime_enabled is true", - %{conn: conn, session: session} do - Application.put_env(:livebook, :embedded_runtime_enabled, true) - {:ok, view, _} = live(conn, "/sessions/#{session.id}/settings/runtime") - - assert view |> element("button", "Embedded") |> has_element?() - end - end - describe "persistence settings" do @tag :tmp_dir test "saving to file shows the newly created file in file selector", From c693c1576cdf44b4744508147e4a1cc3640fef8c Mon Sep 17 00:00:00 2001 From: ByeongUk Choi Date: Mon, 4 Apr 2022 00:49:47 +0900 Subject: [PATCH 4/5] allow runtime modules --- lib/livebook.ex | 8 +++ lib/livebook/config.ex | 8 +++ .../live/session_live/attached_live.ex | 4 ++ .../session_live/elixir_standalone_live.ex | 4 ++ .../live/session_live/embedded_live.ex | 4 ++ .../live/session_live/mix_standalone_live.ex | 4 ++ .../live/session_live/runtime_component.ex | 64 +++++++++++-------- test/livebook_web/live/session_live_test.exs | 13 ++++ 8 files changed, 81 insertions(+), 28 deletions(-) diff --git a/lib/livebook.ex b/lib/livebook.ex index 816b0104eba..19bcf27f716 100644 --- a/lib/livebook.ex +++ b/lib/livebook.ex @@ -118,6 +118,14 @@ defmodule Livebook do Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") || Livebook.Runtime.ElixirStandalone.new() + config :livebook, + :runtime_modules, + [ + Livebook.Runtime.ElixirStandalone, + Livebook.Runtime.MixStandalone, + Livebook.Runtime.Attached + ] + if home = Livebook.Config.writable_dir!("LIVEBOOK_HOME") do config :livebook, :home, home end diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index 36fe5311970..9afcea98fd8 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -26,6 +26,14 @@ defmodule Livebook.Config do Application.fetch_env!(:livebook, :default_runtime) end + @doc """ + Returns the enable runtime module. + """ + @spec enable_runtime(Livebook.Runtime.t()) :: boolean() + def enable_runtime(runtime) do + runtime in Application.fetch_env!(:livebook, :runtime_modules) or runtime == default_runtime() + end + @doc """ Returns the authentication mode. """ diff --git a/lib/livebook_web/live/session_live/attached_live.ex b/lib/livebook_web/live/session_live/attached_live.ex index 6ad736f30e4..077505c747e 100644 --- a/lib/livebook_web/live/session_live/attached_live.ex +++ b/lib/livebook_web/live/session_live/attached_live.ex @@ -5,6 +5,10 @@ defmodule LivebookWeb.SessionLive.AttachedLive do @impl true def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do + unless Livebook.Config.enable_runtime(Livebook.Runtime.Attached) do + raise "Now allow runtime module" + end + if connected?(socket) do Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}") end diff --git a/lib/livebook_web/live/session_live/elixir_standalone_live.ex b/lib/livebook_web/live/session_live/elixir_standalone_live.ex index 0021813b3d9..c2d182816a1 100644 --- a/lib/livebook_web/live/session_live/elixir_standalone_live.ex +++ b/lib/livebook_web/live/session_live/elixir_standalone_live.ex @@ -5,6 +5,10 @@ defmodule LivebookWeb.SessionLive.ElixirStandaloneLive do @impl true def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do + unless Livebook.Config.enable_runtime(Livebook.Runtime.ElixirStandalone) do + raise "Now allow runtime module" + end + if connected?(socket) do Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}") end diff --git a/lib/livebook_web/live/session_live/embedded_live.ex b/lib/livebook_web/live/session_live/embedded_live.ex index 13f465c3a7b..794f0ab019b 100644 --- a/lib/livebook_web/live/session_live/embedded_live.ex +++ b/lib/livebook_web/live/session_live/embedded_live.ex @@ -5,6 +5,10 @@ defmodule LivebookWeb.SessionLive.EmbeddedLive do @impl true def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do + unless Livebook.Config.enable_runtime(Livebook.Runtime.Embedded) do + raise "Now allow runtime module" + end + if connected?(socket) do Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}") end diff --git a/lib/livebook_web/live/session_live/mix_standalone_live.ex b/lib/livebook_web/live/session_live/mix_standalone_live.ex index 9541e0474f5..2b1cfa2c323 100644 --- a/lib/livebook_web/live/session_live/mix_standalone_live.ex +++ b/lib/livebook_web/live/session_live/mix_standalone_live.ex @@ -7,6 +7,10 @@ defmodule LivebookWeb.SessionLive.MixStandaloneLive do @impl true def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do + unless Livebook.Config.enable_runtime(Livebook.Runtime.MixStandalone) do + raise "Now allow runtime module" + end + if connected?(socket) do Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}") end diff --git a/lib/livebook_web/live/session_live/runtime_component.ex b/lib/livebook_web/live/session_live/runtime_component.ex index 7eb3125c661..372fd167e1b 100644 --- a/lib/livebook_web/live/session_live/runtime_component.ex +++ b/lib/livebook_web/live/session_live/runtime_component.ex @@ -30,34 +30,42 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do
- <.choice_button - active={@type == "elixir_standalone"} - phx-click="set_runtime_type" - phx-value-type="elixir_standalone" - phx-target={@myself}> - Elixir standalone - - <.choice_button - active={@type == "mix_standalone"} - phx-click="set_runtime_type" - phx-value-type="mix_standalone" - phx-target={@myself}> - Mix standalone - - <.choice_button - active={@type == "attached"} - phx-click="set_runtime_type" - phx-value-type="attached" - phx-target={@myself}> - Attached node - - <.choice_button - active={@type == "embedded"} - phx-click="set_runtime_type" - phx-value-type="embedded" - phx-target={@myself}> - Embedded - + <%= if Livebook.Config.enable_runtime(Livebook.Runtime.ElixirStandalone) do %> + <.choice_button + active={@type == "elixir_standalone"} + phx-click="set_runtime_type" + phx-value-type="elixir_standalone" + phx-target={@myself}> + Elixir standalone + + <% end %> + <%= if Livebook.Config.enable_runtime(Livebook.Runtime.MixStandalone) do %> + <.choice_button + active={@type == "mix_standalone"} + phx-click="set_runtime_type" + phx-value-type="mix_standalone" + phx-target={@myself}> + Mix standalone + + <% end %> + <%= if Livebook.Config.enable_runtime(Livebook.Runtime.Attached) do %> + <.choice_button + active={@type == "attached"} + phx-click="set_runtime_type" + phx-value-type="attached" + phx-target={@myself}> + Attached node + + <% end %> + <%= if Livebook.Config.enable_runtime(Livebook.Runtime.Embedded) do %> + <.choice_button + active={@type == "embedded"} + phx-click="set_runtime_type" + phx-value-type="embedded" + phx-target={@myself}> + Embedded + + <% end %>
<%= live_render @socket, live_view_for_type(@type), diff --git a/test/livebook_web/live/session_live_test.exs b/test/livebook_web/live/session_live_test.exs index b0126b80bfb..4428d631e90 100644 --- a/test/livebook_web/live/session_live_test.exs +++ b/test/livebook_web/live/session_live_test.exs @@ -412,6 +412,19 @@ defmodule LivebookWeb.SessionLiveTest do describe "runtime settings" do test "connecting to elixir standalone updates connect button to reconnect", %{conn: conn, session: session} do + runtime_modules = Application.get_env(:livebook, :runtime_modules) + + Application.put_env(:livebook, :runtime_modules, [ + Livebook.Runtime.ElixirStandalone, + Livebook.Runtime.MixStandalone, + Livebook.Runtime.Attached, + Livebook.Runtime.Embedded + ]) + + on_exit(fn -> + Application.put_env(:livebook, :runtime_modules, runtime_modules) + end) + {:ok, view, _} = live(conn, "/sessions/#{session.id}/settings/runtime") Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}") From f166ec4b22dacbb396b08c05bb65e1848426e2e6 Mon Sep 17 00:00:00 2001 From: ByeongUk Choi Date: Mon, 4 Apr 2022 19:12:09 +0900 Subject: [PATCH 5/5] Apply suggestions from code review --- lib/livebook/config.ex | 9 +++++---- lib/livebook_web/live/session_live/attached_live.ex | 4 ++-- .../live/session_live/elixir_standalone_live.ex | 4 ++-- lib/livebook_web/live/session_live/embedded_live.ex | 4 ++-- .../live/session_live/mix_standalone_live.ex | 4 ++-- .../live/session_live/runtime_component.ex | 8 ++++---- test/livebook_web/live/session_live_test.exs | 13 ------------- test/test_helper.exs | 7 +++++++ 8 files changed, 24 insertions(+), 29 deletions(-) diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index 9afcea98fd8..e81b154ed55 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -27,11 +27,12 @@ defmodule Livebook.Config do end @doc """ - Returns the enable runtime module. + Returns if the runtime module is enabled. """ - @spec enable_runtime(Livebook.Runtime.t()) :: boolean() - def enable_runtime(runtime) do - runtime in Application.fetch_env!(:livebook, :runtime_modules) or runtime == default_runtime() + @spec runtime_enabled?(module()) :: boolean() + def runtime_enabled?(runtime) do + runtime in Application.fetch_env!(:livebook, :runtime_modules) or + runtime == default_runtime().__struct__ end @doc """ diff --git a/lib/livebook_web/live/session_live/attached_live.ex b/lib/livebook_web/live/session_live/attached_live.ex index 077505c747e..e008fe66cd1 100644 --- a/lib/livebook_web/live/session_live/attached_live.ex +++ b/lib/livebook_web/live/session_live/attached_live.ex @@ -5,8 +5,8 @@ defmodule LivebookWeb.SessionLive.AttachedLive do @impl true def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do - unless Livebook.Config.enable_runtime(Livebook.Runtime.Attached) do - raise "Now allow runtime module" + unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Attached) do + raise "runtime module not allowed" end if connected?(socket) do diff --git a/lib/livebook_web/live/session_live/elixir_standalone_live.ex b/lib/livebook_web/live/session_live/elixir_standalone_live.ex index c2d182816a1..0f0e2dc6e41 100644 --- a/lib/livebook_web/live/session_live/elixir_standalone_live.ex +++ b/lib/livebook_web/live/session_live/elixir_standalone_live.ex @@ -5,8 +5,8 @@ defmodule LivebookWeb.SessionLive.ElixirStandaloneLive do @impl true def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do - unless Livebook.Config.enable_runtime(Livebook.Runtime.ElixirStandalone) do - raise "Now allow runtime module" + unless Livebook.Config.runtime_enabled?(Livebook.Runtime.ElixirStandalone) do + raise "runtime module not allowed" end if connected?(socket) do diff --git a/lib/livebook_web/live/session_live/embedded_live.ex b/lib/livebook_web/live/session_live/embedded_live.ex index 794f0ab019b..75fbbcebdb2 100644 --- a/lib/livebook_web/live/session_live/embedded_live.ex +++ b/lib/livebook_web/live/session_live/embedded_live.ex @@ -5,8 +5,8 @@ defmodule LivebookWeb.SessionLive.EmbeddedLive do @impl true def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do - unless Livebook.Config.enable_runtime(Livebook.Runtime.Embedded) do - raise "Now allow runtime module" + unless Livebook.Config.runtime_enabled?(Livebook.Runtime.Embedded) do + raise "runtime module not allowed" end if connected?(socket) do diff --git a/lib/livebook_web/live/session_live/mix_standalone_live.ex b/lib/livebook_web/live/session_live/mix_standalone_live.ex index 2b1cfa2c323..08f1d64df9a 100644 --- a/lib/livebook_web/live/session_live/mix_standalone_live.ex +++ b/lib/livebook_web/live/session_live/mix_standalone_live.ex @@ -7,8 +7,8 @@ defmodule LivebookWeb.SessionLive.MixStandaloneLive do @impl true def mount(_params, %{"session" => session, "current_runtime" => current_runtime}, socket) do - unless Livebook.Config.enable_runtime(Livebook.Runtime.MixStandalone) do - raise "Now allow runtime module" + unless Livebook.Config.runtime_enabled?(Livebook.Runtime.MixStandalone) do + raise "runtime module not allowed" end if connected?(socket) do diff --git a/lib/livebook_web/live/session_live/runtime_component.ex b/lib/livebook_web/live/session_live/runtime_component.ex index 372fd167e1b..1ed281a6b60 100644 --- a/lib/livebook_web/live/session_live/runtime_component.ex +++ b/lib/livebook_web/live/session_live/runtime_component.ex @@ -30,7 +30,7 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do
- <%= if Livebook.Config.enable_runtime(Livebook.Runtime.ElixirStandalone) do %> + <%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.ElixirStandalone) do %> <.choice_button active={@type == "elixir_standalone"} phx-click="set_runtime_type" @@ -39,7 +39,7 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do Elixir standalone <% end %> - <%= if Livebook.Config.enable_runtime(Livebook.Runtime.MixStandalone) do %> + <%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.MixStandalone) do %> <.choice_button active={@type == "mix_standalone"} phx-click="set_runtime_type" @@ -48,7 +48,7 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do Mix standalone <% end %> - <%= if Livebook.Config.enable_runtime(Livebook.Runtime.Attached) do %> + <%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.Attached) do %> <.choice_button active={@type == "attached"} phx-click="set_runtime_type" @@ -57,7 +57,7 @@ defmodule LivebookWeb.SessionLive.RuntimeComponent do Attached node <% end %> - <%= if Livebook.Config.enable_runtime(Livebook.Runtime.Embedded) do %> + <%= if Livebook.Config. runtime_enabled?(Livebook.Runtime.Embedded) do %> <.choice_button active={@type == "embedded"} phx-click="set_runtime_type" diff --git a/test/livebook_web/live/session_live_test.exs b/test/livebook_web/live/session_live_test.exs index 4428d631e90..b0126b80bfb 100644 --- a/test/livebook_web/live/session_live_test.exs +++ b/test/livebook_web/live/session_live_test.exs @@ -412,19 +412,6 @@ defmodule LivebookWeb.SessionLiveTest do describe "runtime settings" do test "connecting to elixir standalone updates connect button to reconnect", %{conn: conn, session: session} do - runtime_modules = Application.get_env(:livebook, :runtime_modules) - - Application.put_env(:livebook, :runtime_modules, [ - Livebook.Runtime.ElixirStandalone, - Livebook.Runtime.MixStandalone, - Livebook.Runtime.Attached, - Livebook.Runtime.Embedded - ]) - - on_exit(fn -> - Application.put_env(:livebook, :runtime_modules, runtime_modules) - end) - {:ok, view, _} = live(conn, "/sessions/#{session.id}/settings/runtime") Phoenix.PubSub.subscribe(Livebook.PubSub, "sessions:#{session.id}") diff --git a/test/test_helper.exs b/test/test_helper.exs index 24490641a8a..ca5f7050cfa 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -11,6 +11,13 @@ Livebook.Runtime.ErlDist.NodeManager.start( # and setting them explicitly Application.put_env(:livebook, :default_runtime, Livebook.Runtime.Embedded.new()) +Application.put_env(:livebook, :runtime_modules, [ + Livebook.Runtime.ElixirStandalone, + Livebook.Runtime.MixStandalone, + Livebook.Runtime.Attached, + Livebook.Runtime.Embedded +]) + defmodule Livebook.Runtime.Embedded.Dependencies do def entries() do [