From 2a28377be06d286a13c69d6735734d5cfd503309 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 15:55:33 -0500 Subject: [PATCH 01/32] Fix mix task pleroma.instance dialyzer error lib/mix/tasks/pleroma/instance.ex:356:pattern_match_cov The pattern :variable_ can never match, because previous clauses completely cover the type %{ :anonymize => boolean(), :dedupe => boolean(), :read_description => boolean(), :strip_location => boolean() }. --- lib/mix/tasks/pleroma/instance.ex | 2 -- .../controllers/.util_controller.ex.swp | Bin 0 -> 4096 bytes 2 files changed, 2 deletions(-) create mode 100644 lib/pleroma/web/twitter_api/controllers/.util_controller.ex.swp diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex index fd1809a42..0dc30549c 100644 --- a/lib/mix/tasks/pleroma/instance.ex +++ b/lib/mix/tasks/pleroma/instance.ex @@ -352,6 +352,4 @@ defmodule Mix.Tasks.Pleroma.Instance do enabled_filters end - - defp upload_filters(_), do: [] end diff --git a/lib/pleroma/web/twitter_api/controllers/.util_controller.ex.swp b/lib/pleroma/web/twitter_api/controllers/.util_controller.ex.swp new file mode 100644 index 0000000000000000000000000000000000000000..822db48a7f9a36cc155787194b7814dcb658050d GIT binary patch literal 4096 zcmYc?2=nw+u+%eP00IF9hMUT3QfDuJ%3-pOfgvq5Cj}%-2>2!zWf$xEItA!u>Vfp= z<)&iQQU{XMPtPpTFGwva&d*EC(J#nJEy~YL)X&LGg0st0lk`iba8_4VQdAHY3dK}1Dl!@Z eqaiRF0;3@?8UmvsFd71*Aut*OqaiSCLjV9RPcp~= literal 0 HcmV?d00001 From df1d390a49f3f632fbf99b0ffc4724ba03885e7e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 16:01:30 -0500 Subject: [PATCH 02/32] Pleroma.Activity.Queries: fix dialyzer error lib/pleroma/activity/queries.ex:12:unknown_type Unknown type: Activity.t/0. --- lib/pleroma/activity/queries.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/activity/queries.ex b/lib/pleroma/activity/queries.ex index 81c44ac05..d770b9ff3 100644 --- a/lib/pleroma/activity/queries.ex +++ b/lib/pleroma/activity/queries.ex @@ -9,7 +9,7 @@ defmodule Pleroma.Activity.Queries do import Ecto.Query, only: [from: 2, where: 3] - @type query :: Ecto.Queryable.t() | Activity.t() + @type query :: Ecto.Queryable.t() | Pleroma.Activity.t() alias Pleroma.Activity alias Pleroma.User From b16a01ba9d59ff1b5b64f799874dc646fd87aee9 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 16:08:38 -0500 Subject: [PATCH 03/32] Pleroma.ApplicationRequirements: fix dialyzer errors lib/pleroma/application_requirements.ex:19:unknown_type Unknown type: Pleroma.ApplicationRequirements.VerifyError.t/0. lib/pleroma/application_requirements.ex:199:pattern_match_cov The pattern variable_result can never match, because previous clauses completely cover the type :ok. --- lib/pleroma/application_requirements.ex | 7 ++++--- .../controllers/.util_controller.ex.swp | Bin 4096 -> 0 bytes 2 files changed, 4 insertions(+), 3 deletions(-) delete mode 100644 lib/pleroma/web/twitter_api/controllers/.util_controller.ex.swp diff --git a/lib/pleroma/application_requirements.ex b/lib/pleroma/application_requirements.ex index 1dbfea3e2..819245481 100644 --- a/lib/pleroma/application_requirements.ex +++ b/lib/pleroma/application_requirements.ex @@ -7,7 +7,10 @@ defmodule Pleroma.ApplicationRequirements do The module represents the collection of validations to runs before start server. """ - defmodule VerifyError, do: defexception([:message]) + defmodule VerifyError do + defexception([:message]) + @type t :: %__MODULE__{} + end alias Pleroma.Config alias Pleroma.Helpers.MediaHelper @@ -193,8 +196,6 @@ defmodule Pleroma.ApplicationRequirements do end end - defp check_system_commands!(result), do: result - defp check_repo_pool_size!(:ok) do if Pleroma.Config.get([Pleroma.Repo, :pool_size], 10) != 10 and not Pleroma.Config.get([:dangerzone, :override_repo_pool_size], false) do diff --git a/lib/pleroma/web/twitter_api/controllers/.util_controller.ex.swp b/lib/pleroma/web/twitter_api/controllers/.util_controller.ex.swp deleted file mode 100644 index 822db48a7f9a36cc155787194b7814dcb658050d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4096 zcmYc?2=nw+u+%eP00IF9hMUT3QfDuJ%3-pOfgvq5Cj}%-2>2!zWf$xEItA!u>Vfp= z<)&iQQU{XMPtPpTFGwva&d*EC(J#nJEy~YL)X&LGg0st0lk`iba8_4VQdAHY3dK}1Dl!@Z eqaiRF0;3@?8UmvsFd71*Aut*OqaiSCLjV9RPcp~= From dc8045d7664327a2ada9c2a14ec46a0e84bfd6bc Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 16:36:01 -0500 Subject: [PATCH 04/32] FlakeId.Ecto.CompatType.t() does not exist This type is not exported and usable. FlakeId intends to return the type as :uuid, so we replace it in the typespecs with Ecto.UUID.t() which assuages the dialyzer errors e.g., lib/pleroma/bookmark.ex:25:unknown_type Unknown type: FlakeId.Ecto.CompatType.t/0. --- lib/pleroma/bookmark.ex | 6 +++--- lib/pleroma/chat.ex | 12 ++++++------ lib/pleroma/report_note.ex | 4 ++-- lib/pleroma/web/activity_pub/activity_pub.ex | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/pleroma/bookmark.ex b/lib/pleroma/bookmark.ex index 187749e86..5119701f5 100644 --- a/lib/pleroma/bookmark.ex +++ b/lib/pleroma/bookmark.ex @@ -22,7 +22,7 @@ defmodule Pleroma.Bookmark do timestamps() end - @spec create(FlakeId.Ecto.CompatType.t(), FlakeId.Ecto.CompatType.t()) :: + @spec create(Ecto.UUID.t(), Ecto.UUID.t()) :: {:ok, Bookmark.t()} | {:error, Changeset.t()} def create(user_id, activity_id) do attrs = %{ @@ -37,7 +37,7 @@ defmodule Pleroma.Bookmark do |> Repo.insert() end - @spec for_user_query(FlakeId.Ecto.CompatType.t()) :: Ecto.Query.t() + @spec for_user_query(Ecto.UUID.t()) :: Ecto.Query.t() def for_user_query(user_id) do Bookmark |> where(user_id: ^user_id) @@ -52,7 +52,7 @@ defmodule Pleroma.Bookmark do |> Repo.one() end - @spec destroy(FlakeId.Ecto.CompatType.t(), FlakeId.Ecto.CompatType.t()) :: + @spec destroy(Ecto.UUID.t(), Ecto.UUID.t()) :: {:ok, Bookmark.t()} | {:error, Changeset.t()} def destroy(user_id, activity_id) do from(b in Bookmark, diff --git a/lib/pleroma/chat.ex b/lib/pleroma/chat.ex index fe32ec08c..5c4dbc1ff 100644 --- a/lib/pleroma/chat.ex +++ b/lib/pleroma/chat.ex @@ -42,7 +42,7 @@ defmodule Pleroma.Chat do |> unique_constraint(:user_id, name: :chats_user_id_recipient_index) end - @spec get_by_user_and_id(User.t(), FlakeId.Ecto.CompatType.t()) :: + @spec get_by_user_and_id(User.t(), Ecto.UUID.t()) :: {:ok, t()} | {:error, :not_found} def get_by_user_and_id(%User{id: user_id}, id) do from(c in __MODULE__, @@ -52,17 +52,17 @@ defmodule Pleroma.Chat do |> Repo.find_resource() end - @spec get_by_id(FlakeId.Ecto.CompatType.t()) :: t() | nil + @spec get_by_id(Ecto.UUID.t()) :: t() | nil def get_by_id(id) do Repo.get(__MODULE__, id) end - @spec get(FlakeId.Ecto.CompatType.t(), String.t()) :: t() | nil + @spec get(Ecto.UUID.t(), String.t()) :: t() | nil def get(user_id, recipient) do Repo.get_by(__MODULE__, user_id: user_id, recipient: recipient) end - @spec get_or_create(FlakeId.Ecto.CompatType.t(), String.t()) :: + @spec get_or_create(Ecto.UUID.t(), String.t()) :: {:ok, t()} | {:error, Ecto.Changeset.t()} def get_or_create(user_id, recipient) do %__MODULE__{} @@ -75,7 +75,7 @@ defmodule Pleroma.Chat do ) end - @spec bump_or_create(FlakeId.Ecto.CompatType.t(), String.t()) :: + @spec bump_or_create(Ecto.UUID.t(), String.t()) :: {:ok, t()} | {:error, Ecto.Changeset.t()} def bump_or_create(user_id, recipient) do %__MODULE__{} @@ -87,7 +87,7 @@ defmodule Pleroma.Chat do ) end - @spec for_user_query(FlakeId.Ecto.CompatType.t()) :: Ecto.Query.t() + @spec for_user_query(Ecto.UUID.t()) :: Ecto.Query.t() def for_user_query(user_id) do from(c in Chat, where: c.user_id == ^user_id, diff --git a/lib/pleroma/report_note.ex b/lib/pleroma/report_note.ex index f2ad76fa8..1a45b8e99 100644 --- a/lib/pleroma/report_note.ex +++ b/lib/pleroma/report_note.ex @@ -23,7 +23,7 @@ defmodule Pleroma.ReportNote do timestamps() end - @spec create(FlakeId.Ecto.CompatType.t(), FlakeId.Ecto.CompatType.t(), String.t()) :: + @spec create(Ecto.UUID.t(), Ecto.UUID.t(), String.t()) :: {:ok, ReportNote.t()} | {:error, Changeset.t()} def create(user_id, activity_id, content) do attrs = %{ @@ -38,7 +38,7 @@ defmodule Pleroma.ReportNote do |> Repo.insert() end - @spec destroy(FlakeId.Ecto.CompatType.t()) :: + @spec destroy(Ecto.UUID.t()) :: {:ok, ReportNote.t()} | {:error, Changeset.t()} def destroy(id) do from(r in ReportNote, where: r.id == ^id) diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 3980ef7b8..a12438f56 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -499,7 +499,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do end @spec fetch_latest_direct_activity_id_for_context(String.t(), keyword() | map()) :: - FlakeId.Ecto.CompatType.t() | nil + Ecto.UUID.t() | nil def fetch_latest_direct_activity_id_for_context(context, opts \\ %{}) do context |> fetch_activities_for_context_query(Map.merge(%{skip_preload: true}, opts)) From 0b7d2142111fa6ff6d0d9a462322f4bc88f15175 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 16:47:50 -0500 Subject: [PATCH 05/32] Fix invalid typespec references to Ecto.Changeset.t() --- lib/pleroma/bookmark.ex | 4 ++-- lib/pleroma/config_db.ex | 6 +++--- lib/pleroma/report_note.ex | 4 ++-- lib/pleroma/user.ex | 16 ++++++++-------- lib/pleroma/user_invite_token.ex | 2 +- lib/pleroma/web/o_auth/authorization.ex | 8 ++++---- lib/pleroma/web/o_auth/token.ex | 4 ++-- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/pleroma/bookmark.ex b/lib/pleroma/bookmark.ex index 5119701f5..b83d72446 100644 --- a/lib/pleroma/bookmark.ex +++ b/lib/pleroma/bookmark.ex @@ -23,7 +23,7 @@ defmodule Pleroma.Bookmark do end @spec create(Ecto.UUID.t(), Ecto.UUID.t()) :: - {:ok, Bookmark.t()} | {:error, Changeset.t()} + {:ok, Bookmark.t()} | {:error, Ecto.Changeset.t()} def create(user_id, activity_id) do attrs = %{ user_id: user_id, @@ -53,7 +53,7 @@ defmodule Pleroma.Bookmark do end @spec destroy(Ecto.UUID.t(), Ecto.UUID.t()) :: - {:ok, Bookmark.t()} | {:error, Changeset.t()} + {:ok, Bookmark.t()} | {:error, Ecto.Changeset.t()} def destroy(user_id, activity_id) do from(b in Bookmark, where: b.user_id == ^user_id, diff --git a/lib/pleroma/config_db.ex b/lib/pleroma/config_db.ex index 846cede04..e28fcb124 100644 --- a/lib/pleroma/config_db.ex +++ b/lib/pleroma/config_db.ex @@ -54,7 +54,7 @@ defmodule Pleroma.ConfigDB do @spec get_by_params(map()) :: ConfigDB.t() | nil def get_by_params(%{group: _, key: _} = params), do: Repo.get_by(ConfigDB, params) - @spec changeset(ConfigDB.t(), map()) :: Changeset.t() + @spec changeset(ConfigDB.t(), map()) :: Ecto.Changeset.t() def changeset(config, params \\ %{}) do config |> cast(params, [:key, :group, :value]) @@ -138,7 +138,7 @@ defmodule Pleroma.ConfigDB do end end - @spec update_or_create(map()) :: {:ok, ConfigDB.t()} | {:error, Changeset.t()} + @spec update_or_create(map()) :: {:ok, ConfigDB.t()} | {:error, Ecto.Changeset.t()} def update_or_create(params) do params = Map.put(params, :value, to_elixir_types(params[:value])) search_opts = Map.take(params, [:group, :key]) @@ -175,7 +175,7 @@ defmodule Pleroma.ConfigDB do end) end - @spec delete(ConfigDB.t() | map()) :: {:ok, ConfigDB.t()} | {:error, Changeset.t()} + @spec delete(ConfigDB.t() | map()) :: {:ok, ConfigDB.t()} | {:error, Ecto.Changeset.t()} def delete(%ConfigDB{} = config), do: Repo.delete(config) def delete(params) do diff --git a/lib/pleroma/report_note.ex b/lib/pleroma/report_note.ex index 1a45b8e99..f59e5451b 100644 --- a/lib/pleroma/report_note.ex +++ b/lib/pleroma/report_note.ex @@ -24,7 +24,7 @@ defmodule Pleroma.ReportNote do end @spec create(Ecto.UUID.t(), Ecto.UUID.t(), String.t()) :: - {:ok, ReportNote.t()} | {:error, Changeset.t()} + {:ok, ReportNote.t()} | {:error, Ecto.Changeset.t()} def create(user_id, activity_id, content) do attrs = %{ user_id: user_id, @@ -39,7 +39,7 @@ defmodule Pleroma.ReportNote do end @spec destroy(Ecto.UUID.t()) :: - {:ok, ReportNote.t()} | {:error, Changeset.t()} + {:ok, ReportNote.t()} | {:error, Ecto.Changeset.t()} def destroy(id) do from(r in ReportNote, where: r.id == ^id) |> Repo.one() diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 0fd1b6365..45288bb44 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -672,7 +672,7 @@ defmodule Pleroma.User do |> validate_inclusion(:actor_type, ["Person", "Service"]) end - @spec update_as_admin(User.t(), map()) :: {:ok, User.t()} | {:error, Changeset.t()} + @spec update_as_admin(User.t(), map()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()} def update_as_admin(user, params) do params = Map.put(params, "password_confirmation", params["password"]) changeset = update_as_admin_changeset(user, params) @@ -693,7 +693,7 @@ defmodule Pleroma.User do |> put_change(:password_reset_pending, false) end - @spec reset_password(User.t(), map()) :: {:ok, User.t()} | {:error, Changeset.t()} + @spec reset_password(User.t(), map()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()} def reset_password(%User{} = user, params) do reset_password(user, user, params) end @@ -1783,14 +1783,14 @@ defmodule Pleroma.User do BackgroundWorker.enqueue("user_activation", %{"user_id" => user.id, "status" => status}) end - @spec set_activation([User.t()], boolean()) :: {:ok, User.t()} | {:error, Changeset.t()} + @spec set_activation([User.t()], boolean()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()} def set_activation(users, status) when is_list(users) do Repo.transaction(fn -> for user <- users, do: set_activation(user, status) end) end - @spec set_activation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Changeset.t()} + @spec set_activation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()} def set_activation(%User{} = user, status) do with {:ok, user} <- set_activation_status(user, status) do user @@ -1868,7 +1868,7 @@ defmodule Pleroma.User do |> update_and_set_cache() end - @spec purge_user_changeset(User.t()) :: Changeset.t() + @spec purge_user_changeset(User.t()) :: Ecto.Changeset.t() def purge_user_changeset(user) do # "Right to be forgotten" # https://gdpr.eu/right-to-be-forgotten/ @@ -2359,7 +2359,7 @@ defmodule Pleroma.User do updated_user end - @spec set_confirmation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Changeset.t()} + @spec set_confirmation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Ecto.Changeset.t()} def set_confirmation(%User{} = user, bool) do user |> confirmation_changeset(set_confirmation: bool) @@ -2537,7 +2537,7 @@ defmodule Pleroma.User do |> update_and_set_cache() end - @spec confirmation_changeset(User.t(), keyword()) :: Changeset.t() + @spec confirmation_changeset(User.t(), keyword()) :: Ecto.Changeset.t() def confirmation_changeset(user, set_confirmation: confirmed?) do params = if confirmed? do @@ -2555,7 +2555,7 @@ defmodule Pleroma.User do cast(user, params, [:is_confirmed, :confirmation_token]) end - @spec approval_changeset(User.t(), keyword()) :: Changeset.t() + @spec approval_changeset(User.t(), keyword()) :: Ecto.Changeset.t() def approval_changeset(user, set_approval: approved?) do cast(user, %{is_approved: approved?}, [:is_approved]) end diff --git a/lib/pleroma/user_invite_token.ex b/lib/pleroma/user_invite_token.ex index b242a8848..4bfb3a6a7 100644 --- a/lib/pleroma/user_invite_token.ex +++ b/lib/pleroma/user_invite_token.ex @@ -64,7 +64,7 @@ defmodule Pleroma.UserInviteToken do end @spec update_invite(UserInviteToken.t(), map()) :: - {:ok, UserInviteToken.t()} | {:error, Changeset.t()} + {:ok, UserInviteToken.t()} | {:error, Ecto.Changeset.t()} def update_invite(invite, changes) do change(invite, changes) |> Repo.update() end diff --git a/lib/pleroma/web/o_auth/authorization.ex b/lib/pleroma/web/o_auth/authorization.ex index 593d2d66f..3340b4b12 100644 --- a/lib/pleroma/web/o_auth/authorization.ex +++ b/lib/pleroma/web/o_auth/authorization.ex @@ -28,7 +28,7 @@ defmodule Pleroma.Web.OAuth.Authorization do end @spec create_authorization(App.t(), User.t() | %{}, [String.t()] | nil) :: - {:ok, Authorization.t()} | {:error, Changeset.t()} + {:ok, Authorization.t()} | {:error, Ecto.Changeset.t()} def create_authorization(%App{} = app, %User{} = user, scopes \\ nil) do %{ scopes: scopes || app.scopes, @@ -39,7 +39,7 @@ defmodule Pleroma.Web.OAuth.Authorization do |> Repo.insert() end - @spec create_changeset(map()) :: Changeset.t() + @spec create_changeset(map()) :: Ecto.Changeset.t() def create_changeset(attrs \\ %{}) do %Authorization{} |> cast(attrs, [:user_id, :app_id, :scopes, :valid_until]) @@ -58,7 +58,7 @@ defmodule Pleroma.Web.OAuth.Authorization do put_change(changeset, :valid_until, NaiveDateTime.add(NaiveDateTime.utc_now(), lifespan)) end - @spec use_changeset(Authtorizatiton.t(), map()) :: Changeset.t() + @spec use_changeset(Authtorizatiton.t(), map()) :: Ecto.Changeset.t() def use_changeset(%Authorization{} = auth, params) do auth |> cast(params, [:used]) @@ -66,7 +66,7 @@ defmodule Pleroma.Web.OAuth.Authorization do end @spec use_token(Authorization.t()) :: - {:ok, Authorization.t()} | {:error, Changeset.t()} | {:error, String.t()} + {:ok, Authorization.t()} | {:error, Ecto.Changeset.t()} | {:error, String.t()} def use_token(%Authorization{used: false, valid_until: valid_until} = auth) do if NaiveDateTime.diff(NaiveDateTime.utc_now(), valid_until) < 0 do Repo.update(use_changeset(auth, %{used: true})) diff --git a/lib/pleroma/web/o_auth/token.ex b/lib/pleroma/web/o_auth/token.ex index 26de7bb10..4369b3164 100644 --- a/lib/pleroma/web/o_auth/token.ex +++ b/lib/pleroma/web/o_auth/token.ex @@ -56,7 +56,7 @@ defmodule Pleroma.Web.OAuth.Token do |> Repo.find_resource() end - @spec exchange_token(App.t(), Authorization.t()) :: {:ok, Token.t()} | {:error, Changeset.t()} + @spec exchange_token(App.t(), Authorization.t()) :: {:ok, Token.t()} | {:error, Ecto.Changeset.t()} def exchange_token(app, auth) do with {:ok, auth} <- Authorization.use_token(auth), true <- auth.app_id == app.id do @@ -95,7 +95,7 @@ defmodule Pleroma.Web.OAuth.Token do |> validate_required([:valid_until]) end - @spec create(App.t(), User.t(), map()) :: {:ok, Token} | {:error, Changeset.t()} + @spec create(App.t(), User.t(), map()) :: {:ok, Token} | {:error, Ecto.Changeset.t()} def create(%App{} = app, %User{} = user, attrs \\ %{}) do with {:ok, token} <- do_create(app, user, attrs) do if Pleroma.Config.get([:oauth2, :clean_expired_tokens]) do From 8ed506a370f0b4a7743353cd3c96c9dacd290765 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:05:55 -0500 Subject: [PATCH 06/32] Fix invalid type lib/pleroma/docs/json.ex:21:unknown_type Unknown type: Map.t/0. --- lib/pleroma/docs/json.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/docs/json.ex b/lib/pleroma/docs/json.ex index 05f46f39b..f69854935 100644 --- a/lib/pleroma/docs/json.ex +++ b/lib/pleroma/docs/json.ex @@ -18,7 +18,7 @@ defmodule Pleroma.Docs.JSON do :persistent_term.put(@term, Pleroma.Docs.Generator.convert_to_strings(descriptions)) end - @spec compiled_descriptions :: Map.t() + @spec compiled_descriptions :: map() def compiled_descriptions do :persistent_term.get(@term) end From 559aeb5dd0cb66e57fedce9ea20eff505786d0cb Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:08:18 -0500 Subject: [PATCH 07/32] Add missing type Pleroma.Emoji.t() lib/pleroma/emoji/loader.ex:23:unknown_type Unknown type: Pleroma.Emoji.t/0. --- lib/pleroma/emoji.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pleroma/emoji.ex b/lib/pleroma/emoji.ex index 43a3447c3..48302f396 100644 --- a/lib/pleroma/emoji.ex +++ b/lib/pleroma/emoji.ex @@ -24,6 +24,8 @@ defmodule Pleroma.Emoji do defstruct [:code, :file, :tags, :safe_code, :safe_file] + @type t :: %__MODULE__{} + @doc "Build emoji struct" def build({code, file, tags}) do %__MODULE__{ From 593c7e26d4769196a3405b61147dd88aa42e6012 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:13:27 -0500 Subject: [PATCH 08/32] Fix invalid type lib/pleroma/migrators/hashtags_table_migrator.ex:103:unknown_type Unknown type: Map.t/0. --- lib/pleroma/migrators/hashtags_table_migrator.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/migrators/hashtags_table_migrator.ex b/lib/pleroma/migrators/hashtags_table_migrator.ex index dca4bfa6f..bd4dd2f1d 100644 --- a/lib/pleroma/migrators/hashtags_table_migrator.ex +++ b/lib/pleroma/migrators/hashtags_table_migrator.ex @@ -100,7 +100,7 @@ defmodule Pleroma.Migrators.HashtagsTableMigrator do |> where([_o, hashtags_objects], is_nil(hashtags_objects.object_id)) end - @spec transfer_object_hashtags(Map.t()) :: {:noop | :ok | :error, integer()} + @spec transfer_object_hashtags(map()) :: {:noop | :ok | :error, integer()} defp transfer_object_hashtags(object) do embedded_tags = if Map.has_key?(object, :tag), do: object.tag, else: object.data["tag"] hashtags = Object.object_data_hashtags(%{"tag" => embedded_tags}) From e3f52ee13fbda3b45b5d443ef9070e84cb7c1518 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:14:10 -0500 Subject: [PATCH 09/32] Fix invalid types lib/pleroma/web/streamer.ex:37:unknown_type Unknown type: Map.t/0. ________________________________________________________________________________ lib/pleroma/web/streamer.ex:63:unknown_type Unknown type: Map.t/0. --- lib/pleroma/web/streamer.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/streamer.ex b/lib/pleroma/web/streamer.ex index aaee79d8e..0c9f04f82 100644 --- a/lib/pleroma/web/streamer.ex +++ b/lib/pleroma/web/streamer.ex @@ -34,7 +34,7 @@ defmodule Pleroma.Web.Streamer do stream :: String.t(), User.t() | nil, Token.t() | nil, - Map.t() | nil + map() | nil ) :: {:ok, topic :: String.t()} | {:error, :bad_topic} | {:error, :unauthorized} def get_topic_and_add_socket(stream, user, oauth_token, params \\ %{}) do @@ -60,7 +60,7 @@ defmodule Pleroma.Web.Streamer do end @doc "Expand and authorizes a stream" - @spec get_topic(stream :: String.t() | nil, User.t() | nil, Token.t() | nil, Map.t()) :: + @spec get_topic(stream :: String.t() | nil, User.t() | nil, Token.t() | nil, map()) :: {:ok, topic :: String.t() | nil} | {:error, :bad_topic} def get_topic(stream, user, oauth_token, params \\ %{}) From 467a65af90e4ee7893cd40cefe4931f2738219d4 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:14:56 -0500 Subject: [PATCH 10/32] Fix invalid types lib/pleroma/web/rich_media/parser/ttl.ex:6:unknown_type Unknown type: Integer.t/0. lib/pleroma/web/rich_media/parser/ttl.ex:6:unknown_type Unknown type: Map.t/0. --- lib/pleroma/web/rich_media/parser/ttl.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/rich_media/parser/ttl.ex b/lib/pleroma/web/rich_media/parser/ttl.ex index 59d7f87ab..b51298bd8 100644 --- a/lib/pleroma/web/rich_media/parser/ttl.ex +++ b/lib/pleroma/web/rich_media/parser/ttl.ex @@ -3,5 +3,5 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.RichMedia.Parser.TTL do - @callback ttl(Map.t(), String.t()) :: Integer.t() | nil + @callback ttl(map(), String.t()) :: integer() | nil end From 09ae0ab24a30eebbb4880ff44300ee1774bffe93 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:16:10 -0500 Subject: [PATCH 11/32] Fix invalid type lib/pleroma/web/rich_media/parser.ex:105:unknown_type Unknown type: Integer.t/0. --- lib/pleroma/web/rich_media/parser.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/rich_media/parser.ex b/lib/pleroma/web/rich_media/parser.ex index c37c45963..17a6ad617 100644 --- a/lib/pleroma/web/rich_media/parser.ex +++ b/lib/pleroma/web/rich_media/parser.ex @@ -102,7 +102,7 @@ defmodule Pleroma.Web.RichMedia.Parser do ttl_setters: [MyModule] """ @spec set_ttl_based_on_image(map(), String.t()) :: - {:ok, Integer.t() | :noop} | {:error, :no_key} + {:ok, integer() | :noop} | {:error, :no_key} def set_ttl_based_on_image(data, url) do case get_ttl_from_image(data, url) do {:ok, ttl} when is_number(ttl) -> From 65dfaa6cb9f6aa5bf7f66b5f02d63141a93137ba Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:18:16 -0500 Subject: [PATCH 12/32] Fix invalid type due to late aliasing lib/pleroma/web/o_auth/token/query.ex:12:unknown_type Unknown type: Token.t/0. --- lib/pleroma/web/o_auth/token/query.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/o_auth/token/query.ex b/lib/pleroma/web/o_auth/token/query.ex index 4a4d2d3ef..6853ec8dd 100644 --- a/lib/pleroma/web/o_auth/token/query.ex +++ b/lib/pleroma/web/o_auth/token/query.ex @@ -9,10 +9,10 @@ defmodule Pleroma.Web.OAuth.Token.Query do import Ecto.Query, only: [from: 2] - @type query :: Ecto.Queryable.t() | Token.t() - alias Pleroma.Web.OAuth.Token + @type query :: Ecto.Queryable.t() | Token.t() + @spec get_by_refresh_token(query, String.t()) :: query def get_by_refresh_token(query \\ Token, refresh_token) do from(q in query, where: q.refresh_token == ^refresh_token) From e5120a27031c6423504cb15ea1ccd3ef9d47e6e4 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:21:12 -0500 Subject: [PATCH 13/32] Fix invalid type due to typos lib/pleroma/web/o_auth/authorization.ex:61:unknown_type Unknown type: Authtorizatiton.t/0. --- lib/pleroma/web/o_auth/authorization.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/o_auth/authorization.ex b/lib/pleroma/web/o_auth/authorization.ex index 3340b4b12..22e5bfc53 100644 --- a/lib/pleroma/web/o_auth/authorization.ex +++ b/lib/pleroma/web/o_auth/authorization.ex @@ -58,7 +58,7 @@ defmodule Pleroma.Web.OAuth.Authorization do put_change(changeset, :valid_until, NaiveDateTime.add(NaiveDateTime.utc_now(), lifespan)) end - @spec use_changeset(Authtorizatiton.t(), map()) :: Ecto.Changeset.t() + @spec use_changeset(Authorization.t(), map()) :: Ecto.Changeset.t() def use_changeset(%Authorization{} = auth, params) do auth |> cast(params, [:used]) From f050a75b92546968f9ec351f78a48e6b6ac75a6b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:22:40 -0500 Subject: [PATCH 14/32] Fix invalid types due to typos lib/pleroma/web/feed/feed_view.ex:135:unknown_type Unknown type: NativeDateTime.t/0. lib/pleroma/web/feed/feed_view.ex:148:unknown_type Unknown type: NativeDateTime.t/0. --- lib/pleroma/web/feed/feed_view.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/feed/feed_view.ex b/lib/pleroma/web/feed/feed_view.ex index 034722eb2..e1ee33d62 100644 --- a/lib/pleroma/web/feed/feed_view.ex +++ b/lib/pleroma/web/feed/feed_view.ex @@ -132,7 +132,7 @@ defmodule Pleroma.Web.Feed.FeedView do |> safe_to_string() end - @spec to_rfc3339(String.t() | NativeDateTime.t()) :: String.t() + @spec to_rfc3339(String.t() | NaiveDateTime.t()) :: String.t() def to_rfc3339(date) when is_binary(date) do date |> Timex.parse!("{ISO:Extended}") @@ -145,7 +145,7 @@ defmodule Pleroma.Web.Feed.FeedView do |> Timex.format!("{RFC3339}") end - @spec to_rfc2822(String.t() | DateTime.t() | NativeDateTime.t()) :: String.t() + @spec to_rfc2822(String.t() | DateTime.t() | NaiveDateTime.t()) :: String.t() def to_rfc2822(datestr) when is_binary(datestr) do datestr |> Timex.parse!("{ISO:Extended}") From 551e90cd52a11dcb11840c6c4074db4a3c580703 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:28:54 -0500 Subject: [PATCH 15/32] Fix invalid type lib/pleroma/upload.ex:89:unknown_type Unknown type: Map.t/0. --- lib/pleroma/upload.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index bedd7889a..3c355e64d 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -86,7 +86,7 @@ defmodule Pleroma.Upload do end end - @spec store(source, options :: [option()]) :: {:ok, Map.t()} | {:error, any()} + @spec store(source, options :: [option()]) :: {:ok, map()} | {:error, any()} @doc "Store a file. If using a `Plug.Upload{}` as the source, be sure to use `Majic.Plug` to ensure its content_type and filename is correct." def store(upload, opts \\ []) do opts = get_opts(opts) From 2061a1d917a15bfe12b767c665c05750597e6145 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:29:27 -0500 Subject: [PATCH 16/32] Fix invalid type lib/pleroma/uploaders/uploader.ex:43:unknown_type Unknown type: Map.t/0. --- lib/pleroma/uploaders/uploader.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/uploaders/uploader.ex b/lib/pleroma/uploaders/uploader.ex index 77f6f02dd..23caaff1a 100644 --- a/lib/pleroma/uploaders/uploader.ex +++ b/lib/pleroma/uploaders/uploader.ex @@ -40,7 +40,7 @@ defmodule Pleroma.Uploaders.Uploader do @callback delete_file(file :: String.t()) :: :ok | {:error, String.t()} - @callback http_callback(Plug.Conn.t(), Map.t()) :: + @callback http_callback(Plug.Conn.t(), map()) :: {:ok, Plug.Conn.t()} | {:ok, Plug.Conn.t(), file_spec()} | {:error, Plug.Conn.t(), String.t()} From ec5ae83da6f3b630f174288cf3687bf12cee9787 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:31:07 -0500 Subject: [PATCH 17/32] Fix invalid types lib/pleroma/web/activity_pub/mrf/policy.ex:6:unknown_type Unknown type: Map.t/0. lib/pleroma/web/activity_pub/mrf/policy.ex:7:unknown_type Unknown type: Map.t/0. --- lib/pleroma/web/activity_pub/mrf/policy.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/policy.ex b/lib/pleroma/web/activity_pub/mrf/policy.ex index 0234de4d5..1f34883e7 100644 --- a/lib/pleroma/web/activity_pub/mrf/policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/policy.ex @@ -3,8 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.MRF.Policy do - @callback filter(Map.t()) :: {:ok | :reject, Map.t()} - @callback describe() :: {:ok | :error, Map.t()} + @callback filter(map()) :: {:ok | :reject, map()} + @callback describe() :: {:ok | :error, map()} @callback config_description() :: %{ optional(:children) => [map()], key: atom(), From 4f0711610896cb76322d0f527cbea5ed9d0ef474 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:32:19 -0500 Subject: [PATCH 18/32] Fix invalid type lib/pleroma/web/activity_pub/publisher.ex:31:unknown_type Unknown type: Map.t/0. --- lib/pleroma/web/activity_pub/publisher.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index fb7c6f005..2449a3a3e 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -28,7 +28,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do @doc """ Enqueue publishing a single activity. """ - @spec enqueue_one(Map.t(), Keyword.t()) :: {:ok, %Oban.Job{}} + @spec enqueue_one(map(), Keyword.t()) :: {:ok, %Oban.Job{}} def enqueue_one(%{} = params, worker_args \\ []) do PublisherWorker.enqueue( "publish_one", From 83eece7764243d5902df96d2a8a6b99d7465ddba Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:33:37 -0500 Subject: [PATCH 19/32] Fix invalid type lib/pleroma/web/auth/authenticator.ex:8:unknown_type Unknown type: User.t/0. --- lib/pleroma/web/auth/authenticator.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/auth/authenticator.ex b/lib/pleroma/web/auth/authenticator.ex index a0bd154db..01bf1575c 100644 --- a/lib/pleroma/web/auth/authenticator.ex +++ b/lib/pleroma/web/auth/authenticator.ex @@ -5,7 +5,7 @@ defmodule Pleroma.Web.Auth.Authenticator do @callback get_user(Plug.Conn.t()) :: {:ok, user :: struct()} | {:error, any()} @callback create_from_registration(Plug.Conn.t(), registration :: struct()) :: - {:ok, User.t()} | {:error, any()} + {:ok, Pleroma.User.t()} | {:error, any()} @callback get_registration(Plug.Conn.t()) :: {:ok, registration :: struct()} | {:error, any()} @callback handle_error(Plug.Conn.t(), any()) :: any() @callback auth_template() :: String.t() | nil From 38d01ff511ecd7223787772044ca6e3b20578c05 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:37:27 -0500 Subject: [PATCH 20/32] Fix invalid types --- lib/pleroma/reverse_proxy.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/reverse_proxy.ex b/lib/pleroma/reverse_proxy.ex index 880940d07..ec7732946 100644 --- a/lib/pleroma/reverse_proxy.ex +++ b/lib/pleroma/reverse_proxy.ex @@ -81,9 +81,9 @@ defmodule Pleroma.ReverseProxy do import Plug.Conn @type option() :: - {:max_read_duration, :timer.time() | :infinity} + {:max_read_duration, non_neg_integer() | :infinity} | {:max_body_length, non_neg_integer() | :infinity} - | {:failed_request_ttl, :timer.time() | :infinity} + | {:failed_request_ttl, non_neg_integer() | :infinity} | {:http, []} | {:req_headers, [{String.t(), String.t()}]} | {:resp_headers, [{String.t(), String.t()}]} From ea26add540b1da91ebc266b0c0532e1f8c54f4d7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:43:34 -0500 Subject: [PATCH 21/32] Fix incorrect type definition for maybe_direct_follow/2 --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 45288bb44..416a5b5c9 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1048,7 +1048,7 @@ defmodule Pleroma.User do def needs_update?(_), do: true - @spec maybe_direct_follow(User.t(), User.t()) :: {:ok, User.t()} | {:error, String.t()} + @spec maybe_direct_follow(User.t(), User.t()) :: {:ok, User.t(), User.t()} | {:error, String.t()} # "Locked" (self-locked) users demand explicit authorization of follow requests def maybe_direct_follow(%User{} = follower, %User{local: true, is_locked: true} = followed) do From 2fbb67add70e77ba7da388623064bb5a671ce349 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:48:12 -0500 Subject: [PATCH 22/32] Fix typo in typespec --- lib/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 416a5b5c9..ac049ec17 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1011,7 +1011,7 @@ defmodule Pleroma.User do def maybe_send_confirmation_email(_), do: {:ok, :noop} - @spec send_confirmation_email(Uset.t()) :: User.t() + @spec send_confirmation_email(User.t()) :: User.t() def send_confirmation_email(%User{} = user) do user |> Pleroma.Emails.UserEmail.account_confirmation_email() From 7f649a7a19ae5f236dc21aaa11bb9a33c72dabbf Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:50:21 -0500 Subject: [PATCH 23/32] Dialyzer: remove function that will never match --- lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex b/lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex index 97d75ecf2..df4ba819c 100644 --- a/lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/anti_followbot_policy.ex @@ -56,8 +56,6 @@ defmodule Pleroma.Web.ActivityPub.MRF.AntiFollowbotPolicy do nick_score + name_score + actor_type_score end - defp determine_if_followbot(_), do: 0.0 - defp bot_allowed?(%{"object" => target}, bot_actor) do %User{} = user = normalize_by_ap_id(target) From 88042109a3590db25dd9e39f353b1456cbd4e44b Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:56:32 -0500 Subject: [PATCH 24/32] Dialyzer: fix pattern match coverage --- .../activity_pub/object_validators/bare_uri.ex | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/ecto_type/activity_pub/object_validators/bare_uri.ex b/lib/pleroma/ecto_type/activity_pub/object_validators/bare_uri.ex index 1038296e7..a1af8faa1 100644 --- a/lib/pleroma/ecto_type/activity_pub/object_validators/bare_uri.ex +++ b/lib/pleroma/ecto_type/activity_pub/object_validators/bare_uri.ex @@ -8,10 +8,12 @@ defmodule Pleroma.EctoType.ActivityPub.ObjectValidators.BareUri do def type, do: :string def cast(uri) when is_binary(uri) do - case URI.parse(uri) do - %URI{scheme: nil} -> :error - %URI{} -> {:ok, uri} - _ -> :error + parsed = URI.parse(uri) + + if is_nil(parsed.scheme) do + :error + else + {:ok, uri} end end From 65ac5137768d90ee9d2667e68181037e5d5642d3 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 17:58:47 -0500 Subject: [PATCH 25/32] Dialyzer: fix pattern match coverage --- lib/pleroma/release_tasks.ex | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/pleroma/release_tasks.ex b/lib/pleroma/release_tasks.ex index f9e8d1948..bcfcd1243 100644 --- a/lib/pleroma/release_tasks.ex +++ b/lib/pleroma/release_tasks.ex @@ -55,12 +55,6 @@ defmodule Pleroma.ReleaseTasks do {:error, term} when is_binary(term) -> IO.puts(:stderr, "The database for #{inspect(@repo)} couldn't be created: #{term}") - - {:error, term} -> - IO.puts( - :stderr, - "The database for #{inspect(@repo)} couldn't be created: #{inspect(term)}" - ) end end end From 029aaf3d744184737666b1e553ed92d7708f1fee Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 18:14:27 -0500 Subject: [PATCH 26/32] Use config to control max_restarts --- config/config.exs | 3 +++ config/test.exs | 2 ++ lib/pleroma/application.ex | 7 +------ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/config.exs b/config/config.exs index d8f9eb22e..27fbabc73 100644 --- a/config/config.exs +++ b/config/config.exs @@ -904,6 +904,9 @@ config :pleroma, Pleroma.Search.Meilisearch, private_key: nil, initial_indexing_chunk_size: 100_000 +config :pleroma, Pleroma.Application, + max_restarts: 3 + # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. import_config "#{Mix.env()}.exs" diff --git a/config/test.exs b/config/test.exs index 60cdacb0e..11e115b99 100644 --- a/config/test.exs +++ b/config/test.exs @@ -162,6 +162,8 @@ peer_module = config :pleroma, Pleroma.Cluster, peer_module: peer_module +config :pleroma, Pleroma.Application, max_restarts: 100 + if File.exists?("./config/test.secret.exs") do import_config "test.secret.exs" else diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 8fa6f3fae..a01a13b18 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -116,12 +116,7 @@ defmodule Pleroma.Application do # If we have a lot of caches, default max_restarts can cause test # resets to fail. # Go for the default 3 unless we're in test - max_restarts = - if @mix_env == :test do - 100 - else - 3 - end + max_restarts = Application.get_env(:pleroma, __MODULE__)[:max_restarts] opts = [strategy: :one_for_one, name: Pleroma.Supervisor, max_restarts: max_restarts] result = Supervisor.start_link(children, opts) From c7eda0b24ade372e4e167ae560a2debb555a6e02 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 18:22:49 -0500 Subject: [PATCH 27/32] Use config to control loading of custom modules --- config/config.exs | 2 ++ config/test.exs | 5 ++++- lib/pleroma/application.ex | 34 ++++++++++++++++----------------- lib/pleroma/user.ex | 3 ++- lib/pleroma/web/o_auth/token.ex | 3 ++- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/config/config.exs b/config/config.exs index 27fbabc73..c6a12a7b2 100644 --- a/config/config.exs +++ b/config/config.exs @@ -905,6 +905,8 @@ config :pleroma, Pleroma.Search.Meilisearch, initial_indexing_chunk_size: 100_000 config :pleroma, Pleroma.Application, + internal_fetch: true, + load_custom_modules: true, max_restarts: 3 # Import environment specific config. This must remain at the bottom diff --git a/config/test.exs b/config/test.exs index 11e115b99..0a6688823 100644 --- a/config/test.exs +++ b/config/test.exs @@ -162,7 +162,10 @@ peer_module = config :pleroma, Pleroma.Cluster, peer_module: peer_module -config :pleroma, Pleroma.Application, max_restarts: 100 +config :pleroma, Pleroma.Application, + internal_fetch: false, + load_custom_modules: false, + max_restarts: 100 if File.exists?("./config/test.secret.exs") do import_config "test.secret.exs" diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index a01a13b18..de7d06974 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -106,7 +106,7 @@ defmodule Pleroma.Application do {Oban, Config.get(Oban)}, Pleroma.Web.Endpoint ] ++ - task_children(@mix_env) ++ + task_children() ++ dont_run_in_test(@mix_env) ++ shout_child(shout_enabled?()) ++ [Pleroma.Gopher.Server] @@ -154,7 +154,7 @@ defmodule Pleroma.Application do raise "Invalid custom modules" {:ok, modules, _warnings} -> - if @mix_env != :test do + if Application.get_env(:pleroma, __MODULE__)[:load_custom_modules] do Enum.each(modules, fn mod -> Logger.info("Custom module loaded: #{inspect(mod)}") end) @@ -237,29 +237,27 @@ defmodule Pleroma.Application do defp shout_child(_), do: [] - defp task_children(:test) do - [ + defp task_children() do + children = [ %{ id: :web_push_init, start: {Task, :start_link, [&Pleroma.Web.Push.init/0]}, restart: :temporary } ] - end - defp task_children(_) do - [ - %{ - id: :web_push_init, - start: {Task, :start_link, [&Pleroma.Web.Push.init/0]}, - restart: :temporary - }, - %{ - id: :internal_fetch_init, - start: {Task, :start_link, [&Pleroma.Web.ActivityPub.InternalFetchActor.init/0]}, - restart: :temporary - } - ] + if Application.get_env(:pleroma, __MODULE__)[:internal_fetch] do + children ++ + [ + %{ + id: :internal_fetch_init, + start: {Task, :start_link, [&Pleroma.Web.ActivityPub.InternalFetchActor.init/0]}, + restart: :temporary + } + ] + else + children + end end # start hackney and gun pools in tests diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index ac049ec17..89a95c435 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -1048,7 +1048,8 @@ defmodule Pleroma.User do def needs_update?(_), do: true - @spec maybe_direct_follow(User.t(), User.t()) :: {:ok, User.t(), User.t()} | {:error, String.t()} + @spec maybe_direct_follow(User.t(), User.t()) :: + {:ok, User.t(), User.t()} | {:error, String.t()} # "Locked" (self-locked) users demand explicit authorization of follow requests def maybe_direct_follow(%User{} = follower, %User{local: true, is_locked: true} = followed) do diff --git a/lib/pleroma/web/o_auth/token.ex b/lib/pleroma/web/o_auth/token.ex index 4369b3164..d4a7e8999 100644 --- a/lib/pleroma/web/o_auth/token.ex +++ b/lib/pleroma/web/o_auth/token.ex @@ -56,7 +56,8 @@ defmodule Pleroma.Web.OAuth.Token do |> Repo.find_resource() end - @spec exchange_token(App.t(), Authorization.t()) :: {:ok, Token.t()} | {:error, Ecto.Changeset.t()} + @spec exchange_token(App.t(), Authorization.t()) :: + {:ok, Token.t()} | {:error, Ecto.Changeset.t()} def exchange_token(app, auth) do with {:ok, auth} <- Authorization.use_token(auth), true <- auth.app_id == app.id do From 4bb57d4f25bcdc90a63163ba175b6171c9ddbc33 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 18:47:25 -0500 Subject: [PATCH 28/32] Use config to control background migrators --- config/benchmark.exs | 3 +++ config/config.exs | 1 + config/test.exs | 1 + lib/pleroma/application.ex | 15 ++++++++++----- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/config/benchmark.exs b/config/benchmark.exs index e3e1118ed..848344864 100644 --- a/config/benchmark.exs +++ b/config/benchmark.exs @@ -79,6 +79,9 @@ IO.puts("RUM enabled: #{rum_enabled}") config :pleroma, Pleroma.ReverseProxy.Client, Pleroma.ReverseProxy.ClientMock +config :pleroma, Pleroma.Application, + background_migrators: false + if File.exists?("./config/benchmark.secret.exs") do import_config "benchmark.secret.exs" else diff --git a/config/config.exs b/config/config.exs index c6a12a7b2..be9ddba53 100644 --- a/config/config.exs +++ b/config/config.exs @@ -905,6 +905,7 @@ config :pleroma, Pleroma.Search.Meilisearch, initial_indexing_chunk_size: 100_000 config :pleroma, Pleroma.Application, + background_migrators: true, internal_fetch: true, load_custom_modules: true, max_restarts: 3 diff --git a/config/test.exs b/config/test.exs index 0a6688823..898b0828e 100644 --- a/config/test.exs +++ b/config/test.exs @@ -163,6 +163,7 @@ peer_module = config :pleroma, Pleroma.Cluster, peer_module: peer_module config :pleroma, Pleroma.Application, + background_migrators: false, internal_fetch: false, load_custom_modules: false, max_restarts: 100 diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index de7d06974..2eda212b3 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -108,6 +108,7 @@ defmodule Pleroma.Application do ] ++ task_children() ++ dont_run_in_test(@mix_env) ++ + background_migrators() ++ shout_child(shout_enabled?()) ++ [Pleroma.Gopher.Server] @@ -218,14 +219,18 @@ defmodule Pleroma.Application do keys: :duplicate, partitions: System.schedulers_online() ]} - ] ++ background_migrators() + ] end defp background_migrators do - [ - Pleroma.Migrators.HashtagsTableMigrator, - Pleroma.Migrators.ContextObjectsDeletionMigrator - ] + if Application.get_env(:pleroma, __MODULE__)[:background_migrators] do + [ + Pleroma.Migrators.HashtagsTableMigrator, + Pleroma.Migrators.ContextObjectsDeletionMigrator + ] + else + [] + end end defp shout_child(true) do From 17877f612e6c655290c5dc8bdb82f4b34e8b5b9f Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 18:51:20 -0500 Subject: [PATCH 29/32] Use config to control streamer registry --- config/benchmark.exs | 3 ++- config/config.exs | 3 ++- config/test.exs | 3 ++- lib/pleroma/application.ex | 26 ++++++++++++++------------ 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/config/benchmark.exs b/config/benchmark.exs index 848344864..d30c95946 100644 --- a/config/benchmark.exs +++ b/config/benchmark.exs @@ -80,7 +80,8 @@ IO.puts("RUM enabled: #{rum_enabled}") config :pleroma, Pleroma.ReverseProxy.Client, Pleroma.ReverseProxy.ClientMock config :pleroma, Pleroma.Application, - background_migrators: false + background_migrators: false, + streamer_registry: false if File.exists?("./config/benchmark.secret.exs") do import_config "benchmark.secret.exs" diff --git a/config/config.exs b/config/config.exs index be9ddba53..7ff3aaa22 100644 --- a/config/config.exs +++ b/config/config.exs @@ -908,7 +908,8 @@ config :pleroma, Pleroma.Application, background_migrators: true, internal_fetch: true, load_custom_modules: true, - max_restarts: 3 + max_restarts: 3, + streamer_registry: true # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/config/test.exs b/config/test.exs index 898b0828e..afdb71d1d 100644 --- a/config/test.exs +++ b/config/test.exs @@ -166,7 +166,8 @@ config :pleroma, Pleroma.Application, background_migrators: false, internal_fetch: false, load_custom_modules: false, - max_restarts: 100 + max_restarts: 100, + streamer_registry: false if File.exists?("./config/test.secret.exs") do import_config "test.secret.exs" diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 2eda212b3..272529972 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -107,7 +107,7 @@ defmodule Pleroma.Application do Pleroma.Web.Endpoint ] ++ task_children() ++ - dont_run_in_test(@mix_env) ++ + streamer_registry() ++ background_migrators() ++ shout_child(shout_enabled?()) ++ [Pleroma.Gopher.Server] @@ -209,17 +209,19 @@ defmodule Pleroma.Application do defp shout_enabled?, do: Config.get([:shout, :enabled]) - defp dont_run_in_test(env) when env in [:test, :benchmark], do: [] - - defp dont_run_in_test(_) do - [ - {Registry, - [ - name: Pleroma.Web.Streamer.registry(), - keys: :duplicate, - partitions: System.schedulers_online() - ]} - ] + defp streamer_registry() do + if Application.get_env(:pleroma, __MODULE__)[:streamer_registry] do + [ + {Registry, + [ + name: Pleroma.Web.Streamer.registry(), + keys: :duplicate, + partitions: System.schedulers_online() + ]} + ] + else + [] + end end defp background_migrators do From 23301003717a5e154f54c14a5b8cb10ea2033e1a Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 19:10:57 -0500 Subject: [PATCH 30/32] Use config to control starting all HTTP pools in test env --- config/test.exs | 3 ++- lib/pleroma/application.ex | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/config/test.exs b/config/test.exs index afdb71d1d..28d0364c6 100644 --- a/config/test.exs +++ b/config/test.exs @@ -167,7 +167,8 @@ config :pleroma, Pleroma.Application, internal_fetch: false, load_custom_modules: false, max_restarts: 100, - streamer_registry: false + streamer_registry: false, + test_http_pools: true if File.exists?("./config/test.secret.exs") do import_config "test.secret.exs" diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index 272529972..c0bfb898d 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -14,7 +14,6 @@ defmodule Pleroma.Application do @name Mix.Project.config()[:name] @version Mix.Project.config()[:version] @repository Mix.Project.config()[:source_url] - @mix_env Mix.env() def name, do: @name def version, do: @version @@ -98,7 +97,7 @@ defmodule Pleroma.Application do {Task.Supervisor, name: Pleroma.TaskSupervisor} ] ++ cachex_children() ++ - http_children(adapter, @mix_env) ++ + http_children(adapter) ++ [ Pleroma.Stats, Pleroma.JobQueueMonitor, @@ -268,11 +267,19 @@ defmodule Pleroma.Application do end # start hackney and gun pools in tests - defp http_children(_, :test) do - http_children(Tesla.Adapter.Hackney, nil) ++ http_children(Tesla.Adapter.Gun, nil) + defp http_children(adapter) do + if Application.get_env(:pleroma, __MODULE__)[:test_http_pools] do + http_children_hackney() ++ http_children_gun() + else + cond do + match?(Tesla.Adapter.Hackney, adapter) -> http_children_hackney() + match?(Tesla.Adapter.Gun, adapter) -> http_children_gun() + true -> [] + end + end end - defp http_children(Tesla.Adapter.Hackney, _) do + defp http_children_hackney() do pools = [:federation, :media] pools = @@ -288,13 +295,11 @@ defmodule Pleroma.Application do end end - defp http_children(Tesla.Adapter.Gun, _) do + defp http_children_gun() do Pleroma.Gun.ConnectionPool.children() ++ [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}] end - defp http_children(_, _), do: [] - @spec limiters_setup() :: :ok def limiters_setup do config = Config.get(ConcurrentLimiter, []) From cca9d6aeaad6dbfd36becd4c073e153a31e58f21 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 19:29:29 -0500 Subject: [PATCH 31/32] Dialyzer fixes --- changelog.d/dialyzer.skip | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 changelog.d/dialyzer.skip diff --git a/changelog.d/dialyzer.skip b/changelog.d/dialyzer.skip new file mode 100644 index 000000000..e69de29bb From dcd010280034fd35254906831402d96fd59f8098 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Sat, 20 Jan 2024 19:39:13 -0500 Subject: [PATCH 32/32] Credo --- lib/pleroma/application.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex index c0bfb898d..de668052f 100644 --- a/lib/pleroma/application.ex +++ b/lib/pleroma/application.ex @@ -208,7 +208,7 @@ defmodule Pleroma.Application do defp shout_enabled?, do: Config.get([:shout, :enabled]) - defp streamer_registry() do + defp streamer_registry do if Application.get_env(:pleroma, __MODULE__)[:streamer_registry] do [ {Registry, @@ -243,7 +243,7 @@ defmodule Pleroma.Application do defp shout_child(_), do: [] - defp task_children() do + defp task_children do children = [ %{ id: :web_push_init, @@ -279,7 +279,7 @@ defmodule Pleroma.Application do end end - defp http_children_hackney() do + defp http_children_hackney do pools = [:federation, :media] pools = @@ -295,7 +295,7 @@ defmodule Pleroma.Application do end end - defp http_children_gun() do + defp http_children_gun do Pleroma.Gun.ConnectionPool.children() ++ [{Task, &Pleroma.HTTP.AdapterHelper.Gun.limiter_setup/0}] end