Skip to content

RSpec DNS helper to permit Vite connections

Joe Shaw requested to merge joe/dns_helpers_vite into master

What does this MR do and why?

The RSpec DNS helpers permit Vite dev-server connections on localhost, but not any other hostnames.

For example, running vite dev in a container may result in non-localhost addresses. This is one approach for GCK - Support Vite for frontend development (gitlab-compose-kit#84). See also instructions for setting up Vite in GCK.

Without this various RSpec tests that call vite_javascript_tag will fail with:

Failure/Error: vite_javascript_tag bundle
      
        #<Addrinfo (class)> received :getaddrinfo with unexpected arguments
          expected: ("redis", anything, nil, :STREAM, anything, anything, *(any args))
               got: ("gitlab-vite", 3038, nil, :STREAM, nil, nil, {:timeout=>nil})

This MR checks if Vite is enabled and permits the configured Vite host and port explicitly.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Set up Vite for local dev - https://gitlab.com/gitlab-org/gitlab-development-kit/-/blob/main/doc/configuration.md#vite-settings.
  2. Verify browser pages are working with Vite.
  3. Before applying this MR, verify a controller spec test works (e.g. bin/rspec ee/spec/requests/projects/incidents_controller_spec.rb).
  4. Edit the Vite GDK config at config/vite.gdk.json and set "host" to something not captured by the DNS helper (e.g. "vite-server").
  5. Run the same controller test again and see the above error.
  6. Apply the MR - you should now get a network timeout (it can't reach the Vite server but it shows that it would otherwise connect).
Edited by Joe Shaw

Merge request reports