From e9aeb58be143032c4430da5aeda7ec4bc3ec0b32 Mon Sep 17 00:00:00 2001 From: Abhishek Deepak Date: Mon, 30 Nov 2026 10:23:44 +0530 Subject: [PATCH] fix(drift-check): resolve default config from meta repo The default drift-check config was resolved against the process cwd, so running the checker from a tool repo silently used permissive defaults while CI enforced required workflows. Resolve it from meta_repo_path and warn when the default file is missing. Regression tests run the CLI from a different cwd with and without a meta config. Full suite: 354 passed, 2 skipped. Sabotage run of the fix made both tests fail. Closes #153 Signed-off-by: Abhishek Deepak --- scripts/drift_check/cli.py | 8 +++++ tests/test_issue_153_config_cwd.py | 57 ++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/test_issue_153_config_cwd.py diff --git a/scripts/drift_check/cli.py b/scripts/drift_check/cli.py index 6b7606f..c32113e 100644 --- a/scripts/drift_check/cli.py +++ b/scripts/drift_check/cli.py @@ -231,6 +231,14 @@ def _build_snapshots( required_refs_path: Optional[Path], gh_token: Optional[str], ) -> List[RepoSnapshot]: + if config_path is None: + config_path = meta_repo_path / "standards" / "drift-checker.config.json" + if not config_path.is_file(): + print( + f"warning: config not found at {config_path}; using permissive defaults", + file=sys.stderr, + ) + try: cfg = load_config(config_path) except ConfigError as exc: diff --git a/tests/test_issue_153_config_cwd.py b/tests/test_issue_153_config_cwd.py new file mode 100644 index 0000000..2e57d73 --- /dev/null +++ b/tests/test_issue_153_config_cwd.py @@ -0,0 +1,57 @@ +"""Regression tests for #153: drift_check must resolve its default config from +the meta repo, not from the process cwd.""" +import json +from pathlib import Path + +from scripts.drift_check import cli +from tests.conftest import FIXTURES + + +def _meta_repo(root: Path, with_config: bool) -> Path: + meta = root / "meta" + meta.mkdir() + (meta / "STANDARDS_VERSION").write_text("1.6.3", encoding="utf-8") + (meta / "standards").mkdir() + (meta / "standards" / "required-refs.json").write_text( + '{"version":1,"requirements":{"cursor-plugin":{},"mcp-server":{}}}', + encoding="utf-8", + ) + if with_config: + (meta / "standards" / "drift-checker.config.json").write_text( + json.dumps({ + "version": 1, + "globals": {"signal_policy": "same-major-minor", "skip_checks": []}, + "types": { + "cursor-plugin": { + "skip_checks": [], + "required_workflows": ["validate.yml", "release.yml"], + } + }, + "repos": {}, + }), + encoding="utf-8", + ) + return meta + + +def test_default_config_is_resolved_from_meta_repo_not_cwd(tmp_path, monkeypatch, capsys): + meta = _meta_repo(tmp_path, with_config=True) + monkeypatch.chdir(tmp_path) + + rc = cli.main(["--local", str(FIXTURES / "clean_repo"), "--meta-repo", str(meta)]) + + captured = capsys.readouterr() + assert rc == 1, captured.err + assert "required workflow 'validate.yml' is absent" in captured.out + captured.err + + +def test_missing_default_config_warns(tmp_path, monkeypatch, capsys): + meta = _meta_repo(tmp_path, with_config=False) + monkeypatch.chdir(tmp_path) + + rc = cli.main(["--local", str(FIXTURES / "clean_repo"), "--meta-repo", str(meta)]) + + captured = capsys.readouterr() + assert rc == 0, captured.err + assert "config not found" in captured.err + assert str(meta / "standards" / "drift-checker.config.json") in captured.err