summaryrefslogtreecommitdiffstats
path: root/nixos/tests/open-webui.nix
blob: 30af530c9f24dff44136c778a68e5a1fa535b390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
  config,
  lib,
  pkgs,
  ...
}:
let
  mainPort = "8080";
  webuiName = "NixOS Test";
in
{
  name = "open-webui";
  meta = with lib.maintainers; {
    maintainers = [ shivaraj-bh ];
  };

  nodes = {
    machine =
      { ... }:
      {
        services.open-webui = {
          enable = true;
          host = "";
          # Use package with all optional dependencies to ensure they are buildable
          package = pkgs.open-webui.overridePythonAttrs (old: {
            dependencies = old.dependencies ++ pkgs.open-webui.optional-dependencies.all;
          });
          environment = {
            # Requires network connection
            RAG_EMBEDDING_MODEL = "";
          };

          # Test that environment variables can be
          # overridden through a file.
          environmentFile = config.node.pkgs.writeText "test.env" ''
            WEBUI_NAME="${webuiName}"
          '';
        };
      };
  };

  testScript = ''
    import json
    import xml.etree.ElementTree as xml

    machine.start()

    machine.wait_for_unit("open-webui.service")
    machine.wait_for_open_port(${mainPort})

    machine.succeed("curl http://127.0.0.1:${mainPort}")

    # Load the Web UI config JSON and parse it.
    webui_config_json = machine.succeed("curl http://127.0.0.1:${mainPort}/api/config")
    webui_config = json.loads(webui_config_json)

    # Check that the name was overridden via the environmentFile option.
    assert webui_config["name"] == "${webuiName} (Open WebUI)"

    webui_opensearch_xml = machine.succeed("curl http://127.0.0.1:${mainPort}/opensearch.xml")
    webui_opensearch = xml.fromstring(webui_opensearch_xml)

    webui_opensearch_url = webui_opensearch.find(
        ".//{http://a9.com/-/spec/opensearch/1.1/}Url"
    )
    assert (
        webui_opensearch_url is not None
    ), f"no url tag found in {webui_opensearch_xml}"
    assert (
        webui_opensearch_url.get("template") == "http://localhost:8080/?q={searchTerms}"
    ), "opensearch url doesn't match the configured port"
  '';
}