diff --git a/src/evaluation/WorkspaceManager.jl b/src/evaluation/WorkspaceManager.jl index 90e61a6ebe..2ed90b2ed2 100644 --- a/src/evaluation/WorkspaceManager.jl +++ b/src/evaluation/WorkspaceManager.jl @@ -57,6 +57,7 @@ function make_workspace((session, notebook)::SN; force_offline::Bool=false)::Wor pid end + Distributed.remotecall_eval(Main, [pid], :(PlutoRunner.notebook_id[] = $(notebook.notebook_id))) log_channel = Core.eval(Main, quote $(Distributed).RemoteChannel(() -> eval(:(Main.PlutoRunner.log_channel)), $pid) end) diff --git a/src/runner/PlutoRunner.jl b/src/runner/PlutoRunner.jl index 57fbf79ef9..c4a262e93f 100644 --- a/src/runner/PlutoRunner.jl +++ b/src/runner/PlutoRunner.jl @@ -17,7 +17,7 @@ import Distributed import Base64 import FuzzyCompletions: Completion, ModuleCompletion, PropertyCompletion, FieldCompletion, completions, completion_text, score import Base: show, istextmime -import UUIDs: UUID +import UUIDs: UUID, uuid4 import Logging export @bind @@ -41,6 +41,11 @@ ObjectDimPair = Tuple{ObjectID,Int64} "The current workspace where your variables live. See [`move_vars`](@ref)." current_module = Main +""" +`PlutoRunner.notebook_id[]` gives you the notebook ID used to identify a session. +""" +const notebook_id = Ref{UUID}(uuid4()) + function set_current_module(newname) # Revise.jl support if isdefined(current_module, :Revise) && diff --git a/test/Dynamic.jl b/test/Dynamic.jl index 28b5c7dfeb..b8fdbbbd8f 100644 --- a/test/Dynamic.jl +++ b/test/Dynamic.jl @@ -148,4 +148,21 @@ end @test occursin("square root", Pluto.PlutoRunner.doc_fetcher("Base.sqrt")[1]) @test occursin("No documentation found", Pluto.PlutoRunner.doc_fetcher("Base.findmeta")[1]) end + + @testset "PlutoRunner API" begin + fakeclient = ClientSession(:fake, nothing) + 🍭 = ServerSession() + 🍭.options.evaluation.workspace_use_distributed = true + 🍭.connected_clients[fakeclient.id] = fakeclient + + notebook = Notebook([ + Cell("PlutoRunner.notebook_id[] |> Text"), + ]) + fakeclient.connected_notebook = notebook + + update_save_run!(🍭, notebook, notebook.cells) + @test notebook.cells[1].output.body == notebook.notebook_id |> string + + WorkspaceManager.unmake_workspace((🍭, notebook)) + end end diff --git a/test/WorkspaceManager.jl b/test/WorkspaceManager.jl index 34d3cca5d2..808442ce0e 100644 --- a/test/WorkspaceManager.jl +++ b/test/WorkspaceManager.jl @@ -11,6 +11,7 @@ import Pluto: update_save_run!, WorkspaceManager, ClientSession, ServerSession, fakeclientA = ClientSession(:fakeA, nothing) fakeclientB = ClientSession(:fakeB, nothing) 🍭 = ServerSession() + 🍭.options.evaluation.workspace_use_distributed = true 🍭.connected_clients[fakeclientA.id] = fakeclientA 🍭.connected_clients[fakeclientB.id] = fakeclientB