Skip to content

Conversation

@speeddragon
Copy link

This fix enables the use of custom store routes by modifying <<"routes">> to routes, allowing it to be picked up by the configuration. https://github.com/permaweb/HyperBEAM/blob/edge/src/dev_router.erl#L289

There was already a test to check this functionality, but it was incomplete due to missing parameters in the configuration, causing a not_found to be returned, but not for the reason we wanted (to test the routes). I've changed this to use the mock server to provide the object data and the other information is provided by GraphQL (maybe I can mock this as well to not rely on external endpoints).

[
#{ <<"store-module">> => hb_store_gateway,
<<"routes">> => [],
<<"only">> => local
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed <<only>> => local because this will make us load everything necessary from the global configuration, like preloaded_devices, HTTP timeout configurations, and others. To test only routes, we don't need this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting... Why would only => local do that? Its intention is to avoid looking up Opts from the global defaults table.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is the behavior that is shown here. By not loading the remaining configuration from the global defaults, the following modules, which need access to some of the defaults (like preloaded_devices), cannot function properly.

Because we're testing only a different routes configuration, we don't need to add only => local. If we add it, it will complain of no preloaded_devices being available.

Comment on lines -227 to -233
?assertMatch(
not_found,
hb_cache:read(
<<"BOogk_XAI3bvNWnxNxwxmvOfglZt17o4MOVAdPNZ_ew">>,
Opts
)
).
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of error behaviours that mimic a "true" not_found output. Changed this to a value we expect.

apply_route(Msg, Route, Opts) ->
% LoadedRoute = hb_cache:ensure_all_loaded(Route, Opts),
RouteOpts = hb_maps:get(<<"opts">>, Route, #{}),
RouteOpts2 = hb_opts:mimic_default_types(RouteOpts, existing, Opts),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properly change http_client and protocol when loaded from config.flat with binary type to atom type.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's collapse this rather than the *2

[
#{ <<"store-module">> => hb_store_fs, <<"name">> => <<"cache-mainnet">> },
#{ <<"store-module">> => hb_store_gateway, <<"store">> => false }
#{ <<"store-module">> => hb_store_gateway, <<"store">> => [] }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since now <<"routes">> is converted to routes atom, false is not an acceptable result.

@speeddragon speeddragon marked this pull request as ready for review November 21, 2025 12:58
@samcamwilliams
Copy link
Collaborator

Nice! Thank you.

I've changed this to use the mock server to provide the object data and the other information is provided by GraphQL (maybe I can mock this as well to not rely on external endpoints).

Let's avoid using the mock HTTP server unless absolutely necessary. Particularly if we are dependent on external services (GQL) for the test anyway. Mind removing that please? Then I will merge. Thanks!

@speeddragon
Copy link
Author

Let's avoid using the mock HTTP server unless absolutely necessary.

In this case, I'm not sure what other options I can use. I want to avoid:

  • the same response as the arweave.net/raw because we can't be sure if the right route was used or not.
  • not_found because error scenarios return not_found as well.

I think the only solution is to return a response with the custom data we want.

@speeddragon
Copy link
Author

I've found an alternative to mock server by using the device message@1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants