|
| 1 | +# SPDX-License-Identifier: PMPL-1.0-or-later |
| 2 | +# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk> |
| 3 | +# |
| 4 | +# Consolidated tests for all new language/database registry adapters. |
| 5 | +# Each adapter follows the same contract (search/2, fetch_package/2, |
| 6 | +# versions/1, exists?/1) so we test them with a shared suite. |
| 7 | + |
| 8 | +defmodule Opsm.Registries.LanguageAdaptersTest do |
| 9 | + use ExUnit.Case, async: true |
| 10 | + |
| 11 | + # All new adapters introduced in the first-class system sprint (2026-04-12) |
| 12 | + @adapters [ |
| 13 | + {Opsm.Registries.Betlang, :betlang, "betlang-rt"}, |
| 14 | + {Opsm.Registries.Ephapax, :ephapax, "ephapax-std"}, |
| 15 | + {Opsm.Registries.Phronesis, :phronesis, "phronesis-core"}, |
| 16 | + {Opsm.Registries.Tangle, :tangle, "tangle-std"}, |
| 17 | + {Opsm.Registries.Wokelang, :wokelang, "wokelang-std"}, |
| 18 | + {Opsm.Registries.Lithoglyph, :lithoglyph, "lithoglyph-core"}, |
| 19 | + {Opsm.Registries.Quandledb, :quandledb, "quandledb-core"}, |
| 20 | + {Opsm.Registries.Nqc, :nqc, "nqc-core"}, |
| 21 | + ] |
| 22 | + |
| 23 | + # --------------------------------------------------------------------------- |
| 24 | + # Module interface — every adapter must export the standard 4 functions |
| 25 | + # --------------------------------------------------------------------------- |
| 26 | + |
| 27 | + for {mod, _forth, _known_pkg} <- @adapters do |
| 28 | + mod_name = mod |> Module.split() |> List.last() |
| 29 | + |
| 30 | + describe "#{mod_name} — module interface" do |
| 31 | + test "exports search/2" do |
| 32 | + assert function_exported?(unquote(mod), :search, 2) |
| 33 | + end |
| 34 | + |
| 35 | + test "exports fetch_package/2" do |
| 36 | + assert function_exported?(unquote(mod), :fetch_package, 2) |
| 37 | + end |
| 38 | + |
| 39 | + test "exports versions/1" do |
| 40 | + assert function_exported?(unquote(mod), :versions, 1) |
| 41 | + end |
| 42 | + |
| 43 | + test "exports exists?/1" do |
| 44 | + assert function_exported?(unquote(mod), :exists?, 1) |
| 45 | + end |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + # --------------------------------------------------------------------------- |
| 50 | + # search/2 — must return a list, never crash |
| 51 | + # --------------------------------------------------------------------------- |
| 52 | + |
| 53 | + for {mod, _forth, _known_pkg} <- @adapters do |
| 54 | + mod_name = mod |> Module.split() |> List.last() |
| 55 | + |
| 56 | + describe "#{mod_name}.search/2" do |
| 57 | + test "returns list for a relevant query" do |
| 58 | + result = unquote(mod).search(unquote(mod_name |> String.downcase()), []) |
| 59 | + assert is_list(result) |
| 60 | + end |
| 61 | + |
| 62 | + test "returns list for empty string" do |
| 63 | + result = unquote(mod).search("", []) |
| 64 | + assert is_list(result) |
| 65 | + end |
| 66 | + |
| 67 | + test "returns list for nonsense query" do |
| 68 | + result = unquote(mod).search("xyzzy-no-match-999", []) |
| 69 | + assert is_list(result) |
| 70 | + end |
| 71 | + end |
| 72 | + end |
| 73 | + |
| 74 | + # --------------------------------------------------------------------------- |
| 75 | + # exists?/1 — must return a boolean, never crash |
| 76 | + # --------------------------------------------------------------------------- |
| 77 | + |
| 78 | + for {mod, _forth, known_pkg} <- @adapters do |
| 79 | + mod_name = mod |> Module.split() |> List.last() |
| 80 | + |
| 81 | + describe "#{mod_name}.exists?/1" do |
| 82 | + test "returns boolean for known package name" do |
| 83 | + result = unquote(mod).exists?(unquote(known_pkg)) |
| 84 | + assert is_boolean(result) |
| 85 | + end |
| 86 | + |
| 87 | + test "returns false for obviously non-existent package" do |
| 88 | + result = unquote(mod).exists?("xyz-definitely-not-real-abc-999") |
| 89 | + assert result == false |
| 90 | + end |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + # --------------------------------------------------------------------------- |
| 95 | + # versions/1 — must return {:ok, list} |
| 96 | + # --------------------------------------------------------------------------- |
| 97 | + |
| 98 | + for {mod, _forth, known_pkg} <- @adapters do |
| 99 | + mod_name = mod |> Module.split() |> List.last() |
| 100 | + |
| 101 | + describe "#{mod_name}.versions/1" do |
| 102 | + test "returns ok tuple with list for known package" do |
| 103 | + assert {:ok, versions} = unquote(mod).versions(unquote(known_pkg)) |
| 104 | + assert is_list(versions) |
| 105 | + end |
| 106 | + |
| 107 | + test "returns ok tuple with list for unknown package" do |
| 108 | + assert {:ok, versions} = unquote(mod).versions("xyz-definitely-not-real-abc-999") |
| 109 | + assert is_list(versions) |
| 110 | + end |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + # --------------------------------------------------------------------------- |
| 115 | + # fetch_package/2 — non-existent packages return {:error, :not_found} |
| 116 | + # --------------------------------------------------------------------------- |
| 117 | + |
| 118 | + for {mod, _forth, _known_pkg} <- @adapters do |
| 119 | + mod_name = mod |> Module.split() |> List.last() |
| 120 | + |
| 121 | + describe "#{mod_name}.fetch_package/2" do |
| 122 | + test "returns error for non-existent package" do |
| 123 | + result = unquote(mod).fetch_package("xyz-definitely-not-real-abc-999", "latest") |
| 124 | + assert match?({:error, _}, result) |
| 125 | + end |
| 126 | + |
| 127 | + @tag :external_api |
| 128 | + test "returns ok or not_found for a known package name" do |
| 129 | + case unquote(mod).fetch_package(unquote(mod_name |> String.downcase() |> Kernel.<>("-core")), "latest") do |
| 130 | + {:ok, pkg} -> |
| 131 | + assert is_map(pkg) |
| 132 | + assert Map.has_key?(pkg, :forth) |
| 133 | + {:error, :not_found} -> :ok |
| 134 | + {:error, _} -> :ok |
| 135 | + end |
| 136 | + end |
| 137 | + end |
| 138 | + end |
| 139 | +end |
0 commit comments