elixir-lang / elixir

Elixir is a dynamic, functional language for building scalable and maintainable applications
https://elixir-lang.org/
Apache License 2.0
24.58k stars 3.38k forks source link

Odd 'module not available' errors on non-pristine builds #13200

Closed mbklein closed 11 months ago

mbklein commented 11 months ago

Elixir and Erlang/OTP versions

Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

Elixir 1.15.7 (compiled with Erlang/OTP 26)

Currently using erlang 26.2.1. But I've gotten the same behavior with elixir 1.15.4 and erlang 26.0.2.

All installed using asdf, if that makes a difference.

Operating system

Linux (x86), Fedora 36 distro

Current behavior

I thought at first this was just a mox problem, but then it spread to other modules and became intermittent enough that I couldn't pin it to any one dependency.

I'm trying to run this project's test suite for the first time in a while. I started getting (UndefinedFunctionError) function Mox.defmock/2 is undefined (module Mox is not available). If I rm -rf _build/test and then run mix test again, it rebuilds and runs the test suite. But then if I immediately run mix test again, I get the missing module error. I even tried running with the same seed just to eliminate another variable.

Sometimes it's not Mox that's missing – sometimes I get 18 test failures telling me that Jason isn't available instead. But whatever error occurs on the second run after the fresh build is the error that keeps happening until I purge the _build directory and rebuild everything.

Example:

$ mix test
Generated ueberauth_nusso app
** (UndefinedFunctionError) function Mox.defmock/2 is undefined (module Mox is not available)
    (mox 1.1.0) Mox.defmock(HTTPMock, [for: HTTPoison.Base])
    test/test_helper.exs:2: (file)

$ rm -rf _build/test

$ mix test
==> file_system
Compiling 7 files (.ex)
Generated file_system app
==> mime
Compiling 1 file (.ex)
Generated mime app
===> Analyzing applications...
===> Compiling unicode_util_compat
===> Analyzing applications...
===> Compiling idna
==> bunt
Compiling 2 files (.ex)
Generated bunt app
===> Analyzing applications...
===> Compiling telemetry
==> jason
Compiling 10 files (.ex)
Generated jason app
==> excoveralls
Compiling 29 files (.ex)
warning: CAStore.file_path/0 is undefined (module CAStore is not available or is yet to be defined)
  lib/excoveralls/poster.ex:111: ExCoveralls.Poster.cacert_option/0

Generated excoveralls app
==> mox
Compiling 3 files (.ex)
Generated mox app
==> plug_crypto
Compiling 5 files (.ex)
Generated plug_crypto app
===> Analyzing applications...
===> Compiling mimerl
==> ssl_verify_fun
Compiling 7 files (.erl)
Generated ssl_verify_fun app
===> Analyzing applications...
===> Compiling certifi
==> credo
Compiling 251 files (.ex)
Generated credo app
==> plug
Compiling 1 file (.erl)
Compiling 40 files (.ex)
Generated plug app
==> ueberauth
Compiling 9 files (.ex)
Generated ueberauth app
===> Analyzing applications...
===> Compiling parse_trans
===> Analyzing applications...
===> Compiling metrics
===> Analyzing applications...
===> Compiling hackney
==> httpoison
Compiling 3 files (.ex)
Generated httpoison app
==> ueberauth_nusso
Compiling 5 files (.ex)
Generated ueberauth_nusso app
...................
Finished in 0.2 seconds (0.00s async, 0.2s sync)
19 tests, 0 failures

Randomized with seed 920256

$ mix test --seed 920256
** (UndefinedFunctionError) function Mox.defmock/2 is undefined (module Mox is not available)
    (mox 1.1.0) Mox.defmock(HTTPMock, [for: HTTPoison.Base])
    test/test_helper.exs:2: (file)

More weird stuff to look at:

$ MIX_ENV=test iex -S mix
Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Code.loaded?(Mox)
false
iex(2)> Code.ensure_loaded(Mox)
{:error, :nofile}
iex(3)> 
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
       (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
^C%

$ ls -la _build/test/lib/mox/ebin
total 64
drwxr-xr-x. 1 ec2-user ec2-user   278 Dec 21 03:30 .
drwxr-xr-x. 1 ec2-user ec2-user    16 Dec 21 03:30 ..
-rw-r--r--. 1 ec2-user ec2-user  2040 Dec 21 03:30 Elixir.Mox.Application.beam
-rw-r--r--. 1 ec2-user ec2-user 28188 Dec 21 03:30 Elixir.Mox.beam
-rw-r--r--. 1 ec2-user ec2-user 19596 Dec 21 03:30 Elixir.Mox.Server.beam
-rw-r--r--. 1 ec2-user ec2-user  3920 Dec 21 03:30 Elixir.Mox.UnexpectedCallError.beam
-rw-r--r--. 1 ec2-user ec2-user  3912 Dec 21 03:30 Elixir.Mox.VerificationError.beam
-rw-r--r--. 1 ec2-user ec2-user   503 Dec 21 03:30 mox.app

In the above example, hitting tab in IEx will autocomplete module names, but those modules aren't actually loaded and have no functions defined (e.g., Jason.Codegen will autocomplete, but Jason.Codegen.bytecase will not).

And one more, where I experiment with only deleting the beams for the "missing" modules:

$ mix test
==> mox
Compiling 3 files (.ex)
Generated mox app
==> ueberauth_nusso
warning: Mox.stub_with/2 is undefined (module Mox is not available or is yet to be defined)
  test/support/test_helpers.ex:14

Generated ueberauth_nusso app

  1) test API bad token (Ueberauth.Strategy.NuSSO.APITest)
     test/ueberauth/strategy/nusso/api_test.exs:92
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     code: assert {:error, response} = API.redeem_token("bad-sso-token")
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{redirecturl: "https://test-nusso.example.edu/nusso/XUI/?#login&realm=test&authIndexType=service&service=ldap-registry"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       test/ueberauth/strategy/nusso/api_test.exs:93: (test)

  2) test API token validation with attributes (Ueberauth.Strategy.NuSSO.APITest)
     test/ueberauth/strategy/nusso/api_test.exs:49
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     code: assert {:ok, user} = API.redeem_token("test-sso-token")
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{netid: "abc123"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       test/ueberauth/strategy/nusso/api_test.exs:50: (test)

  3) test API token validation with attributes when token is valid but attributes empty (Ueberauth.Strategy.NuSSO.APITest)
     test/ueberauth/strategy/nusso/api_test.exs:70
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     code: assert {:ok, user} = API.redeem_token("empty-directory-sso-token")
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{netid: "abc123"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       test/ueberauth/strategy/nusso/api_test.exs:71: (test)

  4) test API token validation without attributes (Ueberauth.Strategy.NuSSO.APITest)
     test/ueberauth/strategy/nusso/api_test.exs:40
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     code: assert {:ok, user} = API.redeem_token("test-sso-token")
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{netid: "abc123"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       test/ueberauth/strategy/nusso/api_test.exs:41: (test)

  5) test API login_url/0 (Ueberauth.Strategy.NuSSO.APITest)
     test/ueberauth/strategy/nusso/api_test.exs:28
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     code: assert uri = API.login_url("http://example.edu/") |> URI.parse()
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{redirecturl: "https://test-nusso.example.edu/nusso/XUI/?#login&realm=test&authIndexType=service&service=ldap-registry&goto=http://example.edu/"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:11: Ueberauth.Strategy.NuSSO.API.login_url/1
       test/ueberauth/strategy/nusso/api_test.exs:29: (test)

  6) test API token validation with attributes when token is valid but attributes missing (Ueberauth.Strategy.NuSSO.APITest)
     test/ueberauth/strategy/nusso/api_test.exs:59
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     code: assert {:ok, user} = API.redeem_token("bad-directory-sso-token")
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{netid: "abc123"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       test/ueberauth/strategy/nusso/api_test.exs:60: (test)

  7) test API token validation when directory_search_response/1 returns a bad response (Ueberauth.Strategy.NuSSO.APITest)
     test/ueberauth/strategy/nusso/api_test.exs:81
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     code: assert {:ok, user} = API.redeem_token("non-json-sso-token")
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{netid: "abc123"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       test/ueberauth/strategy/nusso/api_test.exs:82: (test)

  8) test valid callback extracts UID (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:102
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{netid: "abc123"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:101: Ueberauth.Strategy.NuSSO.handle_token/2
       test/ueberauth/strategy/nusso_test.exs:93: Ueberauth.Strategy.NuSSOTest.__ex_unit_setup_1_0/1
       Ueberauth.Strategy.NuSSOTest.__ex_unit_describe_1/1

  9) test invalid callback (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:76
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     code: |> NuSSO.handle_callback!()
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{redirecturl: "https://test-nusso.example.edu/nusso/XUI/?#login&realm=test&authIndexType=service&service=ldap-registry"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:101: Ueberauth.Strategy.NuSSO.handle_token/2
       test/ueberauth/strategy/nusso_test.exs:80: (test)

 10) test valid callback generates a raw info struct (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:113
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{netid: "abc123"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:101: Ueberauth.Strategy.NuSSO.handle_token/2
       test/ueberauth/strategy/nusso_test.exs:93: Ueberauth.Strategy.NuSSOTest.__ex_unit_setup_1_0/1
       Ueberauth.Strategy.NuSSOTest.__ex_unit_describe_1/1

 11) test valid callback generates an info struct (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:106
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{netid: "abc123"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:101: Ueberauth.Strategy.NuSSO.handle_token/2
       test/ueberauth/strategy/nusso_test.exs:93: Ueberauth.Strategy.NuSSOTest.__ex_unit_setup_1_0/1
       Ueberauth.Strategy.NuSSOTest.__ex_unit_describe_1/1

 12) test valid callback resets original referer (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:118
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{netid: "abc123"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:101: Ueberauth.Strategy.NuSSO.handle_token/2
       test/ueberauth/strategy/nusso_test.exs:93: Ueberauth.Strategy.NuSSOTest.__ex_unit_setup_1_0/1
       Ueberauth.Strategy.NuSSOTest.__ex_unit_describe_1/1

 13) test request phase http referer is converted to https (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:34
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{redirecturl: "https://test-nusso.example.edu/nusso/XUI/?#login&realm=test&authIndexType=service&service=ldap-registry&goto=https://www.example.com?state=ugSlqXlwIo6FFPdMDlp9DpBa"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:11: Ueberauth.Strategy.NuSSO.API.login_url/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:33: Ueberauth.Strategy.NuSSO.handle_request!/1
       test/ueberauth/strategy/nusso_test.exs:18: Ueberauth.Strategy.NuSSOTest.__ex_unit_setup_0_0/1
       Ueberauth.Strategy.NuSSOTest.__ex_unit_describe_0/1

.

 14) test request phase https referer is passed through (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:29
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{redirecturl: "https://test-nusso.example.edu/nusso/XUI/?#login&realm=test&authIndexType=service&service=ldap-registry&goto=https://www.example.com?state=Nnt-JNKoC8d193C93qMpu-Rg"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:11: Ueberauth.Strategy.NuSSO.API.login_url/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:33: Ueberauth.Strategy.NuSSO.handle_request!/1
       test/ueberauth/strategy/nusso_test.exs:18: Ueberauth.Strategy.NuSSOTest.__ex_unit_setup_0_0/1
       Ueberauth.Strategy.NuSSOTest.__ex_unit_describe_0/1

 15) test request phase redirect callback redirects to login url (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:24
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{redirecturl: "https://test-nusso.example.edu/nusso/XUI/?#login&realm=test&authIndexType=service&service=ldap-registry&goto=https://www.example.com?state=GhTbt4OM7zA8s8CCtXww8vJs"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:11: Ueberauth.Strategy.NuSSO.API.login_url/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:33: Ueberauth.Strategy.NuSSO.handle_request!/1
       test/ueberauth/strategy/nusso_test.exs:18: Ueberauth.Strategy.NuSSOTest.__ex_unit_setup_0_0/1
       Ueberauth.Strategy.NuSSOTest.__ex_unit_describe_0/1

 16) test request phase callback includes XSRF state parameter if present (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:39
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{redirecturl: "https://test-nusso.example.edu/nusso/XUI/?#login&realm=test&authIndexType=service&service=ldap-registry&goto=https://www.example.com?state=7LcfX114Oz1h9zQq83jOXytF"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:11: Ueberauth.Strategy.NuSSO.API.login_url/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:33: Ueberauth.Strategy.NuSSO.handle_request!/1
       test/ueberauth/strategy/nusso_test.exs:18: Ueberauth.Strategy.NuSSOTest.__ex_unit_setup_0_0/1
       Ueberauth.Strategy.NuSSOTest.__ex_unit_describe_0/1

 17) test error callback (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:65
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     code: |> NuSSO.handle_callback!()
     stacktrace:
       (jason 1.3.0) Jason.encode!("Server Error")
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:101: Ueberauth.Strategy.NuSSO.handle_token/2
       test/ueberauth/strategy/nusso_test.exs:69: (test)

 18) test valid callback returns user details (Ueberauth.Strategy.NuSSOTest)
     test/ueberauth/strategy/nusso_test.exs:96
     ** (UndefinedFunctionError) function Jason.encode!/1 is undefined (module Jason is not available)
     stacktrace:
       (jason 1.3.0) Jason.encode!(%{netid: "abc123"})
       (ueberauth_nusso 1.0.0) test/support/mock_endpoint.ex:84: Ueberauth.NuSSO.MockEndpoint.http_response/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:94: Ueberauth.Strategy.NuSSO.API.get/2
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso/api.ex:18: Ueberauth.Strategy.NuSSO.API.redeem_token/1
       (ueberauth_nusso 1.0.0) lib/ueberauth/strategy/nusso.ex:101: Ueberauth.Strategy.NuSSO.handle_token/2
       test/ueberauth/strategy/nusso_test.exs:93: Ueberauth.Strategy.NuSSOTest.__ex_unit_setup_1_0/1
       Ueberauth.Strategy.NuSSOTest.__ex_unit_describe_1/1

Finished in 0.2 seconds (0.00s async, 0.2s sync)
19 tests, 18 failures

Randomized with seed 382801

$ rm -rf _build/test/lib/mox _build/test/lib/jason

$ mix test
==> jason
Compiling 10 files (.ex)
Generated jason app
==> mox
Compiling 3 files (.ex)
Generated mox app
==> ueberauth_nusso
warning: Mox.stub_with/2 is undefined (module Mox is not available or is yet to be defined)
  test/support/test_helpers.ex:14

Generated ueberauth_nusso app
...................
Finished in 0.2 seconds (0.00s async, 0.2s sync)
19 tests, 0 failures

Randomized with seed 829791

$ mix test
warning: Mox.stub_with/2 is undefined (module Mox is not available or is yet to be defined)
  test/support/test_helpers.ex:14

** (UndefinedFunctionError) function Mox.defmock/2 is undefined (module Mox is not available)
    (mox 1.0.1) Mox.defmock(HTTPMock, [for: HTTPoison.Base])
    test/test_helper.exs:2: (file)

Expected behavior

I'm not sure how to describe it. I guess, “Compiled code should load and run on subsequent invocations.”

mbklein commented 11 months ago

I just reproduced the same series of errors and behaviors on MacOS (Apple Silicon) with elixir 1.15.7 and erlang 26.0.2. I also confirmed that it's only Jason and Mox that are misbehaving in this way – if I remove them both from the build, the next run works.

josevalim commented 11 months ago

Remove applications: ... entry from the mix.exs. That line says only uberauth should be loaded, which is why other deps are missing (except if they happen to be in memory). :)