Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ jobs:
- name: Test
run: bun run test

- name: Setup Elixir
uses: erlef/setup-beam@v1
with:
otp-version: "27"
elixir-version: "1.18"

- name: Cache Elixir deps
uses: actions/cache@v5
with:
path: |
apps/harness/_build
apps/harness/deps
key: ${{ runner.os }}-mix-${{ hashFiles('apps/harness/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-

- name: Elixir test
run: |
cd apps/harness
mix deps.get
mix test

- name: Install browser test runtime
run: |
cd apps/web
Expand Down
2 changes: 1 addition & 1 deletion apps/harness/lib/harness/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule Harness.Application do
HarnessWeb.Endpoint
]

opts = [strategy: :one_for_one, name: Harness.Supervisor]
opts = [strategy: :rest_for_one, name: Harness.Supervisor]
Supervisor.start_link(children, opts)
end

Expand Down
1 change: 1 addition & 0 deletions apps/harness/lib/harness/providers/claude_session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ defmodule Harness.Providers.ClaudeSession do
@impl true
def terminate(_reason, state) do
state = %{state | stopped: true}
emit_event(state, :session, "session/closed", %{})

if state.port do
try do
Expand Down
1 change: 1 addition & 0 deletions apps/harness/lib/harness/providers/codex_session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ defmodule Harness.Providers.CodexSession do
@impl true
def terminate(_reason, state) do
state = %{state | stopping: true}
emit_event(state, :session, "session/closed", %{})

if state.port do
try do
Expand Down
1 change: 1 addition & 0 deletions apps/harness/lib/harness/providers/cursor_session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ defmodule Harness.Providers.CursorSession do
# Since terminate runs in the same process as handle_info, the flag is visible
# to any messages processed after Port.close sends the exit notification.
state = %{state | stopped: true}
emit_event(state, :session, "session/closed", %{})
maybe_complete_turn(state, "completed")
cancel_all_pending(state)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Expand Down
1 change: 1 addition & 0 deletions apps/harness/lib/harness/providers/mock_session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ defmodule Harness.Providers.MockSession do
@impl true
def terminate(_reason, state) do
state = %{state | stopping: true}
emit_event(state, :session, "session/closed", %{})

if state.port do
try do
Expand Down
1 change: 1 addition & 0 deletions apps/harness/lib/harness/providers/opencode_session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ defmodule Harness.Providers.OpenCodeSession do
@impl true
def terminate(_reason, state) do
state = %{state | stopped: true}
emit_event(state, :session, "session/closed", %{})

# Cancel pending approvals/elicitations so SQLite rows are cleaned up
cancel_all_pending(state)
Expand Down
4 changes: 2 additions & 2 deletions apps/harness/lib/harness/snapshot_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,11 @@ defmodule Harness.SnapshotServer do
{:reply, {:ok, seq, events}, state}

{:error, _reason} ->
{:reply, {:ok, seq, []}, state}
{:reply, {:gap, seq, after_seq}, state}
end
catch
:exit, _ ->
{:reply, {:ok, seq, []}, state}
{:reply, {:gap, seq, after_seq}, state}
end
end

Expand Down
23 changes: 23 additions & 0 deletions apps/harness/lib/harness_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,31 @@ defmodule HarnessWeb.Endpoint do
pass: ["application/json"],
json_decoder: Phoenix.json_library()

plug :authenticate
plug :route

defp authenticate(%{request_path: "/api/" <> _} = conn, _opts) do
expected = Application.get_env(:harness, :harness_secret, "dev-harness-secret")
conn = Plug.Conn.fetch_query_params(conn)

secret =
case Plug.Conn.get_req_header(conn, "authorization") do
["Bearer " <> token] -> token
_ -> conn.query_params["secret"]
end

if secret == expected do
conn
else
conn
|> Plug.Conn.put_resp_content_type("application/json")
|> Plug.Conn.send_resp(401, Jason.encode!(%{ok: false, error: "Unauthorized"}))
|> Plug.Conn.halt()
end
end
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

defp authenticate(conn, _opts), do: conn

defp route(%{request_path: "/api/snapshot"} = conn, _opts) do
snapshot = Harness.SnapshotServer.get_snapshot()
json_response(conn, 200, snapshot)
Expand Down