Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI

on:
push:
branches: [main]
pull_request:

env:
MIX_ENV: test

jobs:
check:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
persist-credentials: false

- uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1
with:
otp-version: "28.4"
elixir-version: "1.20.2"

- name: Restore deps cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: |
deps
_build
key: deps-${{ runner.os }}-${{ hashFiles('mix.lock') }}
restore-keys: deps-${{ runner.os }}-

- name: Restore PLT cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: priv/plts
key: plts-${{ runner.os }}-${{ hashFiles('mix.lock') }}
restore-keys: plts-${{ runner.os }}-

- name: Install deps
run: mix deps.get

- name: Hex Audit
run: mix hex.audit

- name: Compile
run: mix compile --warnings-as-errors

- name: Check formatting
run: mix format --check-formatted

- name: Credo
run: mix credo --all --strict

- name: Dialyzer
run: mix dialyzer

- name: Run tests
run: mix test
5 changes: 3 additions & 2 deletions lib/dataplane_ex/car.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ defmodule DataplaneEx.CAR do
@moduledoc false

use Ecto.Type
alias DASL.CAR.DRISL

def type, do: :map

def cast(%DASL.CAR.DRISL{} = car), do: {:ok, car}
def cast(%DRISL{} = car), do: {:ok, car}

def cast(%CBOR.Tag{tag: :bytes, value: bytes}) do
cast(bytes)
end

def cast(bytes) do
case DASL.CAR.DRISL.decode(bytes) do
case DRISL.decode(bytes) do
{:ok, car} -> {:ok, car}
{:error, _section, _reason} -> :error
end
Expand Down
3 changes: 2 additions & 1 deletion lib/dataplane_ex/indexer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ defmodule DataplaneEx.Indexer do
and the tables are recreated empty when it restarts.
"""
use GenServer
alias DataplaneEx.ATProto.Event
alias DataplaneEx.Progress
require Logger

Expand Down Expand Up @@ -350,7 +351,7 @@ defmodule DataplaneEx.Indexer do
def handle_info({:binary, binary}, state) do
events =
binary
|> DataplaneEx.ATProto.Event.decode()
|> Event.decode()
|> List.wrap()

Enum.each(events, &index_event/1)
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ defmodule DataplaneEx.MixProject do
"compile --warnings-as-errors",
"dialyzer",
"deps.unlock --unused",
"format",
"credo --all",
"format --check-formatted",
"credo --all --strict",
"test"
]
]
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ex_slop": {:hex, :ex_slop, "0.4.2", "142aba9a82eddfb258e39c45d59392ab3cdb6b5a3ad401b09b362b7134fc54eb", [:mix], [{:credo, "~> 1.7", [hex: :credo, repo: "hexpm", optional: false]}], "hexpm", "c7f5316f755f83566e7a0a049f6fedfcd5ff916fce83c6ebfdf806be62fd7a69"},
"file_system": {:hex, :file_system, "1.1.1", "31864f4685b0148f25bd3fbef2b1228457c0c89024ad67f7a81a3ffbc0bbad3a", [:mix], [], "hexpm", "7a15ff97dfe526aeefb090a7a9d3d03aa907e100e262a0f8f7746b78f8f87a5d"},
"fine": {:hex, :fine, "0.1.6", "4bf7151493443c454aac9f2fa2f34f5fefd0346a83fb5586a016c4a135c63247", [:mix], [], "hexpm", "5638eb4495488e885ebec167fa57973e5c35e1a50c344eb7666c90ec1c4e3b12"},
"hpax": {:hex, :hpax, "1.0.3", "ed67ef51ad4df91e75cc6a1494f851850c0bd98ebc0be6e81b026e765ee535aa", [:mix], [], "hexpm", "8eab6e1cfa8d5918c2ce4ba43588e894af35dbd8e91e6e55c817bca5847df34a"},
"hpax": {:hex, :hpax, "1.0.4", "777de5d433b0fbdc7c418159c8055910faa8047ffdb3d6b31098d2a46cd7685c", [:mix], [], "hexpm", "afc7cb142ebcc2d01ce7816190b98ce5dd49e799111b24249f3443d730f377ca"},
"jason": {:hex, :jason, "1.4.5", "2e3a008590b0b8d7388c20293e9dcc9cf3e5d642fd2a114e4cbbb52e595d940a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "b0c823996102bcd0239b3c2444eb00409b72f6a140c1950bc8b457d836b30684"},
"lazy_html": {:hex, :lazy_html, "0.1.11", "136c8e9cd616b4f4e9c1562daa683880891120b759606dc4c3b6b18058ba5d79", [:make, :mix], [{:cc_precompiler, "~> 0.1", [hex: :cc_precompiler, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.9.0", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:fine, "~> 0.1.0", [hex: :fine, repo: "hexpm", optional: false]}], "hexpm", "3b1be592929c31eca1a21673d25696e5c14cddfe922d9d1a3e3b48be4163883b"},
"mime": {:hex, :mime, "2.0.7", "b8d739037be7cd402aee1ba0306edfdef982687ee7e9859bee6198c1e7e2f128", [:mix], [], "hexpm", "6171188e399ee16023ffc5b76ce445eb6d9672e2e241d2df6050f3c771e80ccd"},
Expand Down
3 changes: 2 additions & 1 deletion test/dataplane_ex/atproto/commit_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule DataplaneEx.ATProto.CommitTest do
use ExUnit.Case, async: true
alias DASL.CAR.DRISL
alias DataplaneEx.ATProto.Commit
alias DataplaneEx.Op

Expand All @@ -11,7 +12,7 @@ defmodule DataplaneEx.ATProto.CommitTest do
"ignored" => "not included"
}

{:ok, {blocks, cid}} = DASL.CAR.DRISL.add_block(%DASL.CAR.DRISL{}, record)
{:ok, {blocks, cid}} = DRISL.add_block(%DRISL{}, record)

commit = %Commit{
repo: "did:plc:alice",
Expand Down
11 changes: 6 additions & 5 deletions test/dataplane_ex/car_test.exs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
defmodule DataplaneEx.CARTest do
use ExUnit.Case, async: true
alias DASL.CAR.DRISL
alias DataplaneEx.CAR

test "casts CBOR byte payloads into decoded DASL DRISL CARs" do
record = %{"$type" => "app.bsky.feed.post", "text" => "hello"}
{:ok, {car, cid}} = DASL.CAR.DRISL.add_block(%DASL.CAR.DRISL{}, record)
{:ok, car} = DASL.CAR.DRISL.add_root(car, cid)
{:ok, bytes} = DASL.CAR.DRISL.encode(car)
{:ok, {car, cid}} = DRISL.add_block(%DRISL{}, record)
{:ok, car} = DRISL.add_root(car, cid)
{:ok, bytes} = DRISL.encode(car)

assert {:ok, decoded} = CAR.cast(%CBOR.Tag{tag: :bytes, value: bytes})
assert %DASL.CAR.DRISL{} = decoded
assert %DRISL{} = decoded
assert decoded.roots == [cid]
assert decoded.blocks[cid] == record
end

test "accepts already decoded DASL DRISL CARs" do
car = %DASL.CAR.DRISL{}
car = %DRISL{}

assert CAR.cast(car) == {:ok, car}
end
Expand Down
2 changes: 1 addition & 1 deletion test/dataplane_ex/server_test.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule DataplaneEx.ServerTest do
use ExUnit.Case, async: false
import DataplaneEx.CSVFixtures
alias DataplaneEx.Server
alias DataplaneEx.Indexer
alias DataplaneEx.Server

setup do
did1 = "did:plc:firesim1"
Expand Down
15 changes: 0 additions & 15 deletions test/dataplane_ex_web/controllers/error_html_test.exs

This file was deleted.

16 changes: 1 addition & 15 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
defmodule DataplaneExWeb.ConnCase do
@moduledoc """
This module defines the test case to be used by
tests that require setting up a connection.

Such tests rely on `Phoenix.ConnTest` and also
import other functionality to make it easier
to build common data structures and query the data layer.

Finally, if the test case interacts with the database,
we enable the SQL sandbox, so changes done to the database
are reverted at the end of every test. If you are using
PostgreSQL, you can even run database tests asynchronously
by setting `use DataplaneExWeb.ConnCase, async: true`, although
this option is not recommended for other databases.
"""
@moduledoc false

use ExUnit.CaseTemplate

Expand Down
Loading