hyf

Context-aware query service for Radroots
git clone https://radroots.dev/git/hyf.git
Log | Files | Refs | README | LICENSE

test_repo_local_process_contract.mojo (3651B)


      1 from std.testing import TestSuite, assert_equal, assert_true
      2 from std.tempfile import TemporaryDirectory
      3 
      4 from json import Value
      5 from fixture_assertions import load_scenario_request_json
      6 from stdio_process_helper import (
      7     HYF_PATHS_PROFILE_ENV,
      8     HYF_PATHS_REPO_LOCAL_ROOT_ENV,
      9     ScopedEnvVar,
     10     run_stdio_entrypoint,
     11 )
     12 
     13 
     14 def _assert_under_repo_local_root(repo_local_root: String, path: String) raises:
     15     assert_true(path.startswith(repo_local_root + "/"))
     16 
     17 
     18 def _assert_runtime_status_path_under_repo_local_root(
     19     runtime_status: Value, key: String, repo_local_root: String
     20 ) raises:
     21     _assert_under_repo_local_root(
     22         repo_local_root,
     23         runtime_status["paths"][key].string_value(),
     24     )
     25 
     26 
     27 def test_src_main_consumes_repo_local_env_without_outer_wrapper() raises:
     28     with TemporaryDirectory() as repo_local_root:
     29         with ScopedEnvVar(HYF_PATHS_PROFILE_ENV, "repo_local"):
     30             with ScopedEnvVar(HYF_PATHS_REPO_LOCAL_ROOT_ENV, repo_local_root):
     31                 var response = run_stdio_entrypoint(
     32                     "src/main.mojo",
     33                     load_scenario_request_json("scenarios/status_ok.json"),
     34                 )
     35 
     36                 var runtime_status = response["output"]["runtime"].clone()
     37                 assert_equal(
     38                     runtime_status["paths_profile"].string_value(), "repo_local"
     39                 )
     40                 assert_equal(
     41                     runtime_status["repo_local_base_root"].string_value(),
     42                     repo_local_root,
     43                 )
     44 
     45                 _assert_runtime_status_path_under_repo_local_root(
     46                     runtime_status, "config_dir", repo_local_root
     47                 )
     48                 _assert_runtime_status_path_under_repo_local_root(
     49                     runtime_status, "config_path", repo_local_root
     50                 )
     51                 _assert_runtime_status_path_under_repo_local_root(
     52                     runtime_status, "data_dir", repo_local_root
     53                 )
     54                 _assert_runtime_status_path_under_repo_local_root(
     55                     runtime_status, "cache_dir", repo_local_root
     56                 )
     57                 _assert_runtime_status_path_under_repo_local_root(
     58                     runtime_status, "logs_dir", repo_local_root
     59                 )
     60                 _assert_runtime_status_path_under_repo_local_root(
     61                     runtime_status, "diagnostics_dir", repo_local_root
     62                 )
     63                 _assert_runtime_status_path_under_repo_local_root(
     64                     runtime_status, "run_dir", repo_local_root
     65                 )
     66                 _assert_runtime_status_path_under_repo_local_root(
     67                     runtime_status, "secrets_dir", repo_local_root
     68                 )
     69                 _assert_runtime_status_path_under_repo_local_root(
     70                     runtime_status, "identity_path", repo_local_root
     71                 )
     72                 _assert_under_repo_local_root(
     73                     repo_local_root,
     74                     runtime_status["config"]["artifact_path"].string_value(),
     75                 )
     76                 assert_equal(
     77                     runtime_status["config"]["artifact_path_source"].string_value(),
     78                     "canonical_runtime_path",
     79                 )
     80                 assert_equal(
     81                     runtime_status["config"]["artifact_present"].bool_value(),
     82                     False,
     83                 )
     84                 assert_equal(
     85                     runtime_status["config"]["load_state"].string_value(),
     86                     "not_found",
     87                 )
     88 
     89 
     90 def main() raises:
     91     TestSuite.discover_tests[__functions_in_module()]().run()