Skip to content

Commit e299f96

Browse files
committed
fix(config): derive global-config lock path from GLOBAL_CONFIG_DIR
_with_global_config_lock() mkdir'd GLOBAL_CONFIG_DIR but opened the lock via the import-time GLOBAL_CONFIG_LOCK_PATH constant, so the two diverged whenever GLOBAL_CONFIG_DIR was redirected. Tests monkeypatch GLOBAL_CONFIG_DIR to a tmp dir but not the lock constant, so the lock opened the real ~/.config/openkb/ global.lock — present on a dev machine, absent on a fresh CI runner — making the /api/v1/init tests crash with FileNotFoundError (500) only in CI. Derive the lock path from GLOBAL_CONFIG_DIR at call time so it co-locates with the dir just created.
1 parent 2c98df9 commit e299f96

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

openkb/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@
4646
@contextlib.contextmanager
4747
def _with_global_config_lock() -> Iterator[None]:
4848
GLOBAL_CONFIG_DIR.mkdir(parents=True, exist_ok=True)
49-
with GLOBAL_CONFIG_LOCK_PATH.open("a+", encoding="utf-8") as fh:
49+
# Derive the lock path from GLOBAL_CONFIG_DIR (rather than the import-time
50+
# GLOBAL_CONFIG_LOCK_PATH constant) so it always co-locates with the dir we
51+
# just created — including when tests monkeypatch GLOBAL_CONFIG_DIR to a
52+
# throwaway path. Otherwise the lock would open the real ~/.config/openkb,
53+
# which fails on a fresh machine where that dir doesn't exist.
54+
lock_path = GLOBAL_CONFIG_DIR / "global.lock"
55+
with lock_path.open("a+", encoding="utf-8") as fh:
5056
flock(fh, exclusive=True)
5157
try:
5258
yield

0 commit comments

Comments
 (0)