fix(proxy): use basename for reload_includes config pattern

Uvicorn's resolve_reload_patterns() calls pathlib.Path.glob(), which
raises NotImplementedError on absolute patterns (uvicorn discussion
2156). Passing config_abs (an absolute path) when the config file lived
outside cwd crashed startup under --reload. The config_dir is already
added to reload_dirs, so using just the basename as the include pattern
is sufficient to match the specific config file.
This commit is contained in:
Cursor Agent 2026-05-06 03:40:17 +00:00
parent c01d7a6f5a
commit d9cc076d97
No known key found for this signature in database
2 changed files with 11 additions and 11 deletions

View file

@ -188,13 +188,13 @@ class ProxyInitializationHelpers:
if config_dir and config_dir != cwd:
reload_dirs.append(config_dir)
options["reload_dirs"] = reload_dirs
# Qualify the config-file pattern with its directory so only the
# specific config file (not any same-named file in cwd) triggers a
# reload when config_dir != cwd.
if config_dir and config_dir != cwd:
config_include = config_abs
else:
config_include = os.path.basename(config_abs)
# Use the basename as the include pattern. Uvicorn's
# resolve_reload_patterns() calls pathlib.Path.glob(), which raises
# NotImplementedError on absolute patterns (uvicorn discussion #2156),
# so an absolute path here would crash startup. The config_dir is
# already added to reload_dirs above, so a basename pattern is enough
# to match the specific config file uvicorn is watching.
config_include = os.path.basename(config_abs)
options["reload_includes"] = ["*.py", config_include]
return options

View file

@ -161,10 +161,10 @@ class TestProxyInitializationHelpers:
assert opts["reload"] is True
assert opts["reload_dirs"] == [str(cwd_dir), str(elsewhere)]
# When config lives outside cwd, the reload_includes entry must be the
# absolute path so that a same-named file in cwd does not trigger an
# unintended reload.
assert opts["reload_includes"] == ["*.py", str(config_file)]
# The reload_includes entry must be a relative pattern (basename)
# because uvicorn's resolve_reload_patterns() calls pathlib.Path.glob(),
# which raises NotImplementedError on absolute patterns.
assert opts["reload_includes"] == ["*.py", "proxy.yaml"]
@patch("asyncio.run")
@patch("builtins.print")