@@ -72,6 +72,61 @@ def fake_create_app(services, controller_run_funcs=None, _http_client=None):
7272 assert captured ["controller_run_funcs" ] == {"agents-deployment" : plugin_controller }
7373
7474
75+ def test_embedded_auth_preflight_invokes_policy_wasm_helper (monkeypatch ):
76+ calls : list [bool ] = []
77+ auth_cfg = AuthConfig (
78+ enabled = True ,
79+ policy_decision_point_provider = "embedded" ,
80+ embedded_pdp_auto_build_wasm = False ,
81+ )
82+
83+ from nmp .core .auth .app .embedded_pdp import policy_wasm
84+
85+ monkeypatch .setattr (policy_wasm , "ensure_embedded_policy_wasm" , lambda * , auto_build : calls .append (auto_build ))
86+
87+ server .preflight_embedded_auth_policy_wasm (auth_cfg )
88+
89+ assert calls == [False ]
90+
91+
92+ @pytest .mark .parametrize (
93+ "auth_cfg" ,
94+ [
95+ AuthConfig (enabled = False , policy_decision_point_provider = "embedded" ),
96+ AuthConfig (enabled = True , policy_decision_point_provider = "opa" ),
97+ ],
98+ )
99+ def test_embedded_auth_preflight_skips_when_not_needed (auth_cfg , monkeypatch ):
100+ calls : list [bool ] = []
101+
102+ from nmp .core .auth .app .embedded_pdp import policy_wasm
103+
104+ monkeypatch .setattr (policy_wasm , "ensure_embedded_policy_wasm" , lambda * , auto_build : calls .append (auto_build ))
105+
106+ server .preflight_embedded_auth_policy_wasm (auth_cfg )
107+
108+ assert calls == []
109+
110+
111+ def test_run_server_runs_embedded_auth_preflight ():
112+ auth_cfg = _make_auth_config (enabled = True )
113+ calls : list [AuthConfig ] = []
114+ with (
115+ patch ("nmp.platform_runner.server.get_auth_config" , return_value = auth_cfg ),
116+ patch (
117+ "nmp.platform_runner.server.preflight_embedded_auth_policy_wasm" , side_effect = lambda cfg : calls .append (cfg )
118+ ),
119+ patch ("nmp.platform_runner.server.create_app" , return_value = FastAPI ()) as create_app ,
120+ patch ("nmp.platform_runner.server.setup_fastapi_instrumentations" ),
121+ patch ("nmp.platform_runner.server.uvicorn.run" ) as uvicorn_run ,
122+ ):
123+ server .run_server (services = [], host = "127.0.0.1" , port = 9999 )
124+
125+ assert calls == [auth_cfg ]
126+ create_app .assert_called_once_with ([])
127+ uvicorn_run .assert_called_once ()
128+
129+
75130def test_create_default_app_raises_for_unknown_service_from_env (monkeypatch ):
76131 monkeypatch .setattr (server , "_obs_initialized" , True )
77132 monkeypatch .setenv ("NMP_SERVICES" , "missing-service" )
0 commit comments