Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 2 additions & 1 deletion assets/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default defineConfig({
port: 4432,
origin: "http://localhost:4432",
cors: {
origin: ["http://localhost:4000"],
origin:
/^https?:\/\/(?:(?:[^:]+\.)?localhost|127\.0\.0\.1|\[::1\])(?::\d+)?$/,
},
},
});
Expand Down
14 changes: 0 additions & 14 deletions lib/livebook/hubs/broadcasts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,6 @@ defmodule Livebook.Hubs.Broadcasts do
Phoenix.PubSub.subscribe(Livebook.PubSub, "hubs:#{topic}")
end

@doc """
Unsubscribes from `subscribe/0`.
"""
@spec unsubscribe(atom() | list(atom())) :: :ok
def unsubscribe(topics) when is_list(topics) do
for topic <- topics, do: unsubscribe(topic)

:ok
end

def unsubscribe(topic) do
Phoenix.PubSub.unsubscribe(Livebook.PubSub, "hubs:#{topic}")
end

@doc """
Broadcasts under `#{@crud_topic}` topic when hubs changed.
"""
Expand Down
14 changes: 0 additions & 14 deletions lib/livebook/teams/broadcasts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,6 @@ defmodule Livebook.Teams.Broadcasts do
Phoenix.PubSub.subscribe(Livebook.PubSub, "teams:#{topic}")
end

@doc """
Unsubscribes from `subscribe/0`.
"""
@spec unsubscribe(atom() | list(atom())) :: :ok
def unsubscribe(topics) when is_list(topics) do
for topic <- topics, do: unsubscribe(topic)

:ok
end

def unsubscribe(topic) do
Phoenix.PubSub.unsubscribe(Livebook.PubSub, "teams:#{topic}")
end

@doc """
Broadcasts under `#{@clients_topic}` topic when hub received a new client connection.
"""
Expand Down
4 changes: 2 additions & 2 deletions lib/livebook_web/live/apps_live.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LivebookWeb.AppsLive do
use LivebookWeb, :live_view

@events [
@app_folder_events [
:app_folder_created,
:app_folder_updated,
:app_folder_deleted
Expand Down Expand Up @@ -241,7 +241,7 @@ defmodule LivebookWeb.AppsLive do
|> apply_filters()}
end

def handle_info({type, _app_folder}, socket) when type in @events do
def handle_info({type, _app_folder}, socket) when type in @app_folder_events do
{:noreply,
socket
|> load_app_folders()
Expand Down
2 changes: 1 addition & 1 deletion lib/livebook_web/live/hooks/auth_hook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule LivebookWeb.AuthHook do

def on_mount(:default, _params, session, socket) do
uri = get_connect_info(socket, :uri)
socket = attach_hook(socket, :authorization_subscription, :handle_info, &handle_info/2)
socket = attach_hook(socket, :auth_handle_info_subscription, :handle_info, &handle_info/2)

if LivebookWeb.AuthPlug.authorized?(session || %{}, uri.port) do
{:cont, socket}
Expand Down
6 changes: 2 additions & 4 deletions lib/livebook_web/live/hooks/user_hook.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ defmodule LivebookWeb.UserHook do
|> assign_new(:teams_auth, fn ->
LivebookWeb.AuthPlug.teams_auth(session)
end)
|> attach_hook(:current_user_subscription, :handle_info, &handle_info/2)
|> attach_hook(:server_authorization_subscription, :handle_info, &handle_info/2)
|> attach_hook(:user_handle_info_subscription, :handle_info, &handle_info/2)

if connected?(socket) do
Livebook.Users.subscribe(socket.assigns.current_user.id)
Expand All @@ -38,11 +37,10 @@ defmodule LivebookWeb.UserHook do
{:halt, assign(socket, :current_user, user)}
end

defp handle_info({:server_authorization_updated, deployment_group}, socket) do
defp handle_info({:server_authorization_updated, %{hub_id: hub_id}}, socket) do
# Since we checks if the updated deployment group we received belongs
# to the current app server, we don't need to check here.
current_user = socket.assigns.current_user
hub_id = deployment_group.hub_id

if current_user.payload do
metadata = Livebook.ZTA.LivebookTeams.build_metadata(hub_id, current_user.payload)
Expand Down
1 change: 1 addition & 0 deletions test/livebook/intellisense/python_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Livebook.Intellisense.PythonTest do
use ExUnit.Case, async: true
@moduletag :python

import Livebook.TestHelpers

Expand Down
2 changes: 2 additions & 0 deletions test/livebook/runtime/evaluator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,8 @@ defmodule Livebook.Runtime.EvaluatorTest do
end

describe "python evaluation" do
@describetag :python

test "evaluates python code", %{evaluator: evaluator} do
code = """
x = [1, 2, 3]
Expand Down
1 change: 1 addition & 0 deletions test/livebook_web/live/session_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2919,6 +2919,7 @@ defmodule LivebookWeb.SessionLiveTest do
Code.put_compiler_option(:debug_info, false)
end

@tag :python
test "python code evaluation end-to-end", %{conn: conn, session: session} do
# Use the standalone runtime, to install Pythonx and setup the interpreter
Session.set_runtime(session.pid, Runtime.Standalone.new())
Expand Down
59 changes: 29 additions & 30 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
# code evaluation and intellisense. Testing pyproject.toml evaluation
# is tricky because it requires a separate VM, so we only rely on the
# LV integration tests.
ExUnit.CaptureIO.capture_io(fn ->
Pythonx.uv_init("""
[project]
name = "project"
version = "0.0.0"
requires-python = "==3.13.*"
dependencies = []
""")
end)

# TODO: Update `pythonx` to support Nix, downloaded binaries doesn't work
nix? = System.find_executable("nix") != nil

if not nix? do
ExUnit.CaptureIO.capture_io(fn ->
Pythonx.uv_init("""
[project]
name = "project"
version = "0.0.0"
requires-python = "==3.13.*"
dependencies = []
""")
end)
end
Comment on lines +6 to +19
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a branch for pythonx to fix this, it's working but needs to make it simple and add docs


# Start manager on the current node and configure it not to terminate
# automatically, so that we can use it to start runtime servers
Expand Down Expand Up @@ -69,29 +75,22 @@ Livebook.HubHelpers.set_offline_hub()
# Compile anything pending on TeamsServer
Livebook.TeamsServer.setup()

windows? = match?({:win32, _}, :os.type())

erl_docs_exclude =
if match?({:error, _}, Code.fetch_docs(:gen_server)) do
[:erl_docs]
else
[]
end
env = System.get_env()

windows_exclude = if windows?, do: [:unix], else: []

teams_exclude =
if Livebook.TeamsServer.available?() do
[]
else
[:teams_integration]
end

fly_exclude = if System.get_env("TEST_FLY_API_TOKEN"), do: [], else: [:fly]
git_exclude = if System.get_env("TEST_GIT_SSH_KEY"), do: [], else: [:git]
windows? = match?({:win32, _}, :os.type())
without_docs? = match?({:error, _}, Code.fetch_docs(:gen_server))
git_ssh_key? = Map.has_key?(env, "TEST_GIT_SSH_KEY")
fly_api_token? = Map.has_key?(env, "TEST_FLY_API_TOKEN")

ExUnit.start(
assert_receive_timeout: if(windows?, do: 5_000, else: 1_500),
exclude:
erl_docs_exclude ++ windows_exclude ++ teams_exclude ++ fly_exclude ++ [:k8s] ++ git_exclude
exclude: [
python: nix?,
git: not git_ssh_key?,
fly: not fly_api_token?,
teams_integration: not Livebook.TeamsServer.available?(),
unix: windows?,
k8s: true,
erl_docs: without_docs?
]
)