Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(settings): keep a repo's excluded paths and wiki style in .repowise/config.yaml (#4676)
Raghav Chamadiyad252bdbfc966
diff --git a/docs/architecture/ARCHITECTURE.md b/docs/architecture/ARCHITECTURE.mdindex 9672b514b..129bd2975 100644--- a/docs/architecture/ARCHITECTURE.md+++ b/docs/architecture/ARCHITECTURE.md@@ -392,7 +392,8 @@ priority order:`src/generated/` without affecting other directories with the same name.4. **`extra_exclude_patterns`** (constructor param): additional gitignore-stylepatterns passed at runtime from `--exclude/-x` CLI flags or- `repo.settings["exclude_patterns"]` (set via Web UI or REST API PATCH). Applied+ `.repowise/config.yaml exclude_patterns` (also written by the Web UI and REST API+ PATCH). Appliedto both directory pruning (entire subtree skipped) and individual file filtering.5. Hardcoded blocklist (`node_modules`, `.git`, `__pycache__`, `vendor`,`*.lock`, `*.min.js`, generated protobuf files, etc.). `build`, `coverage`,@@ -425,8 +426,8 @@ FileTraverser(|--------|------------------------------|| `repowise init -x vendor/ -x 'src/gen/**'` | Merged with `config.yaml exclude_patterns`, passed directly || `repowise update` | Read from `.repowise/config.yaml exclude_patterns` |-| Web UI Excluded Paths section | Saved to `repo.settings["exclude_patterns"]` via REST API |-| Server sync job | Read from `repo.settings.get("exclude_patterns", [])` |+| Web UI Excluded Paths section | Saved to `.repowise/config.yaml exclude_patterns` via REST API PATCH |+| Server sync job | Read from `.repowise/config.yaml exclude_patterns`; an older `repo.settings` copy applies only while the file lacks the key |The traverser also detects monorepo structure by looking for multiple`pyproject.toml`, `package.json`, `go.mod`, or `Cargo.toml` files at depth 1–2.@@ -1434,9 +1435,9 @@ a different problem:3. **`extra_exclude_patterns` (runtime)**: patterns injected without touching anyfile on disk: from `--exclude/-x` CLI flags (dev workflow), from- `config.yaml exclude_patterns` (persisted per repo), or from- `repo.settings["exclude_patterns"]` (Web UI / REST API). This lets teams configure- exclusions through the UI without git access to the target repo.+ `config.yaml exclude_patterns` (persisted per repo, and written by the Web UI /+ REST API too). This lets teams configure exclusions through the UI, and the CLI+ and the UI always show the same list.All three layers use `pathspec` with `gitwildmatch` semantics, the same library usedfor `.gitignore` parsing, so the full gitignore syntax works everywhere.diff --git a/packages/core/src/repowise/core/ingestion/traverser.py b/packages/core/src/repowise/core/ingestion/traverser.pyindex bc9aca6cc..1f84633c7 100644--- a/packages/core/src/repowise/core/ingestion/traverser.py+++ b/packages/core/src/repowise/core/ingestion/traverser.py@@ -397,7 +397,7 @@ class FileTraverser:extra_ignore_filename: Name of an additional gitignore-syntax file.Defaults to ``.repowiseIgnore``.extra_exclude_patterns: Additional gitignore-style patterns to exclude- (from CLI ``--exclude`` flags or ``repo.settings["exclude_patterns"]``).+ (from CLI ``--exclude`` flags or ``.repowise/config.yaml exclude_patterns``).include_submodules: When False (default), directories listed in``.gitmodules`` are skipped during traversal.include_nested_repos: When False (default), any subdirectory that isdiff --git a/packages/core/src/repowise/core/persistence/crud/analysis/health/exclude.py b/packages/core/src/repowise/core/persistence/crud/analysis/health/exclude.pyindex 31a7d29bc..8cbdcefd5 100644--- a/packages/core/src/repowise/core/persistence/crud/analysis/health/exclude.py+++ b/packages/core/src/repowise/core/persistence/crud/analysis/health/exclude.py@@ -3,6 +3,7 @@from __future__ import annotationsimport json+import loggingfrom pathlib import Pathfrom typing import Any@@ -10,6 +11,8 @@ from sqlalchemy.ext.asyncio import AsyncSessionfrom ....models import Repository+logger = logging.getLogger(__name__)+async def health_exclude_spec(session: AsyncSession, repository_id: str, repo_path: Path | str | None = None@@ -26,32 +29,28 @@ async def health_exclude_spec(if repo is None:return None- patterns: list[str] = []- seen: set[str] = set()-- def _add(values: Any) -> None:- if not isinstance(values, list):- return- for value in values:- if isinstance(value, str) and value not in seen:- seen.add(value)- patterns.append(value)+ from repowise.core.repo_config import resolve_file_settingstry:- settings = json.loads(getattr(repo, "settings_json", "") or "{}")- if isinstance(settings, dict):- _add(settings.get("exclude_patterns"))+ stored = json.loads(getattr(repo, "settings_json", "") or "{}")except (TypeError, ValueError):- pass-+ stored = {}+ if not isinstance(stored, dict):+ stored = {}+ # config.yaml first; a legacy settings copy only while the file lacks the key.try:- from repowise.core.repo_config import load_repo_config-- cfg = load_repo_config(Path(repo_path or repo.local_path))- if isinstance(cfg, dict):- _add(cfg.get("exclude_patterns"))+ values = resolve_file_settings(Path(repo_path or repo.local_path), stored)except Exception:- pass+ logger.warning(+ "Could not read config.yaml exclude_patterns for %s; using saved settings",+ repo_path or repo.local_path,+ exc_info=True,+ )+ values = stored+ raw = values.get("exclude_patterns")+ if not isinstance(raw, list):+ raw = []+ patterns = list(dict.fromkeys(v for v in raw if isinstance(v, str)))if not patterns:return Nonediff --git a/packages/core/src/repowise/core/repo_config.py b/packages/core/src/repowise/core/repo_config.pyindex ca866d68b..a05936182 100644--- a/packages/core/src/repowise/core/repo_config.py+++ b/packages/core/src/repowise/core/repo_config.py@@ -161,6 +161,76 @@ def save_repo_config(repo_path: Path | str, config: dict[str, Any]) -> None:resolver.forget_cached(target)+#: Repo settings whose one home is ``.repowise/config.yaml``, so the CLI and the+#: web UI read and write the same value. A server row's ``settings_json`` may+#: still hold them from before: that stored value is a fallback while the file+#: lacks the key, and moves into the file on the next save.+FILE_SETTING_KEYS: tuple[str, ...] = ("exclude_patterns", "wiki_style")+++def _file_setting_default(key: str) -> Any:+ """What an absent ``key`` means, so writing it would change nothing."""+ if key == "wiki_style":+ from repowise.core.generation.styles import DEFAULT_STYLE++ return DEFAULT_STYLE+ return []+++def resolve_file_settings(repo_path: Path | str, stored: dict[str, Any]) -> dict[str, Any]:+ """The effective :data:`FILE_SETTING_KEYS` values: config.yaml's, else *stored*'s.++ *stored* is the legacy server copy (``settings_json``). Keys neither source+ sets are left out; a bare ``key:`` (null) in the file counts as unset.+ Raises :class:`RepoConfigError` for a broken config file.+ """+ config = load_repo_config(repo_path)+ resolved = {}+ for key in FILE_SETTING_KEYS:+ value = config.get(key)+ if value is None:+ value = stored.get(key)+ if value is not None:+ resolved[key] = value+ return resolved+++def save_file_settings(+ repo_path: Path | str, updates: dict[str, Any], stored: dict[str, Any]+) -> dict[str, Any]:+ """Write *updates* for :data:`FILE_SETTING_KEYS` into config.yaml.++ Legacy *stored* values the file lacks move in with this save, so the server+ copy can be dropped afterwards. A value equal to what the file already+ means is not written, and the default removes the key: a save that changes+ nothing leaves the bytes, and so the config fingerprint, alone. Other keys+ are preserved. Returns the saved :data:`FILE_SETTING_KEYS` values.+ """+ config = load_repo_config(repo_path)+ before = dict(config)+ for key in FILE_SETTING_KEYS:+ default = _file_setting_default(key)+ if config.get(key) is None and stored.get(key) not in (None, default):+ config[key] = stored[key]+ if key in updates:+ _set_file_setting(config, key, updates[key], default)+ if config != before:+ save_repo_config(repo_path, config)+ return {key: config[key] for key in FILE_SETTING_KEYS if config.get(key) is not None}+++def _set_file_setting(config: dict[str, Any], key: str, value: Any, default: Any) -> None:+ """Set *key* to *value* in *config*; the default (or ``None``) removes it."""+ value = default if value is None else value+ current = config.get(key)+ if value == (default if current is None else current):+ return+ if value == default:+ config.pop(key, None)+ else:+ config[key] = value++def config_fingerprint(repo_path: Path | str) -> str:"""SHA-256 hex of ``.repowise/config.yaml`` + ``health-rules.json`` content.diff --git a/packages/core/src/repowise/core/workspace/update/repo.py b/packages/core/src/repowise/core/workspace/update/repo.pyindex f93c15def..bbf183d9e 100644--- a/packages/core/src/repowise/core/workspace/update/repo.py+++ b/packages/core/src/repowise/core/workspace/update/repo.py@@ -20,17 +20,15 @@ async def _merged_repo_excludes(repo_path: Path,extra_exclude_patterns: list[str] | None = None,) -> list[str]:- """Merge config.yaml excludes with the persisted repo settings' excludes.+ """config.yaml excludes, else a legacy settings copy, plus *extra_exclude_patterns*.- Local indexes read ``settings_json`` straight from the repo-local- ``wiki.db`` (cheaper than an engine for one row); a configured shared- database is the source of truth instead.+ The legacy copy (``settings_json`` from before the web UI wrote+ config.yaml) applies only while the file lacks the key. Local indexes read+ it straight from the repo-local ``wiki.db`` (cheaper than an engine for one+ row); a configured shared database is the source of truth instead."""- from ...repo_config import load_repo_config-- patterns: list[str] = list(load_repo_config(repo_path).get("exclude_patterns") or [])-from ...persistence.database import get_configured_db_url+ from ...repo_config import resolve_file_settingsconfigured_url = get_configured_db_url()if configured_url is None:@@ -38,13 +36,10 @@ async def _merged_repo_excludes(else:settings_json = await _configured_settings_json(configured_url, repo_path)- if settings_json:- _merge_settings_excludes(patterns, settings_json)-- for pattern in extra_exclude_patterns or []:- if pattern not in patterns:- patterns.append(pattern)- return patterns+ stored = _settings_excludes(settings_json) if settings_json else {}+ saved = resolve_file_settings(repo_path, stored).get("exclude_patterns") or []+ merged = [p for p in saved if isinstance(p, str)] + list(extra_exclude_patterns or [])+ return list(dict.fromkeys(merged))def _local_settings_json(repo_path: Path) -> str | None:@@ -93,18 +88,18 @@ async def _configured_settings_json(configured_url: str, repo_path: Path) -> strreturn settings_json-def _merge_settings_excludes(patterns: list[str], settings_json: str) -> None:- """Append the string ``exclude_patterns`` of *settings_json* not already in *patterns*."""+def _settings_excludes(settings_json: str) -> dict[str, Any]:+ """``{"exclude_patterns": ...}`` from *settings_json* when it has them, else ``{}``."""try:settings = _json.loads(settings_json)- if isinstance(settings, dict):- for value in settings.get("exclude_patterns") or []:- if isinstance(value, str) and value not in patterns:- patterns.append(value)except Exception:_log.warning("Could not parse settings_json; saved exclude patterns not applied", exc_info=True)+ return {}+ if isinstance(settings, dict) and "exclude_patterns" in settings:+ return {"exclude_patterns": settings["exclude_patterns"]}+ return {}@dataclassdiff --git a/packages/server/src/repowise/server/job_executor.py b/packages/server/src/repowise/server/job_executor.pyindex 0d267fe7e..43d19f4cf 100644--- a/packages/server/src/repowise/server/job_executor.py+++ b/packages/server/src/repowise/server/job_executor.py@@ -65,70 +65,42 @@ from repowise.server.services.coupling import warm_coupling_modellogger = structlog.get_logger(__name__)-def _repo_exclude_patterns(repo: Any, repo_path: str) -> list[str]:- """Collect a server job's exclude patterns from both config sources.+def _repo_file_settings(repo: Any, repo_path: str) -> dict[str, Any]:+ """The repo's ``exclude_patterns`` and ``wiki_style`` as a job sees them.- ``Repository.settings_json`` (web UI) and ``.repowise/config.yaml`` (CLI),- merged in order, de-duplicated, settings first. A missing or malformed- source is ignored.+ ``.repowise/config.yaml`` is their home; a legacy ``settings_json`` value+ applies only while the file lacks the key (``resolve_file_settings``). A+ malformed source is ignored."""- patterns: list[str] = []-- def _add(values: Any) -> None:- if not isinstance(values, list):- return- for value in values:- if isinstance(value, str) and value not in patterns:- patterns.append(value)+ from repowise.core.repo_config import FILE_SETTING_KEYS, resolve_file_settings- # Source 1: DB-stored repo settings (web UI).try:- settings = json.loads(getattr(repo, "settings_json", "") or "{}")- if isinstance(settings, dict):- _add(settings.get("exclude_patterns"))+ stored = json.loads(getattr(repo, "settings_json", "") or "{}")except (TypeError, ValueError):logger.debug("repo_settings_json_unparsable", repo_path=repo_path)-- # Source 2: repo-local .repowise/config.yaml (CLI/init), via the shared loader.+ stored = {}+ if not isinstance(stored, dict):+ stored = {}try:- from repowise.core.repo_config import load_repo_config-- cfg = load_repo_config(Path(repo_path))- if isinstance(cfg, dict):- _add(cfg.get("exclude_patterns"))+ return resolve_file_settings(Path(repo_path), stored)except Exception:logger.debug("repo_config_yaml_unreadable", repo_path=repo_path)+ return {key: stored[key] for key in FILE_SETTING_KEYS if key in stored}- return patterns+def _repo_exclude_patterns(repo: Any, repo_path: str) -> list[str]:+ """A server job's exclude patterns, de-duplicated, non-strings dropped."""+ values = _repo_file_settings(repo, repo_path).get("exclude_patterns")+ if not isinstance(values, list):+ return []+ return list(dict.fromkeys(v for v in values if isinstance(v, str)))-def _repo_wiki_style(repo: Any, repo_path: str) -> str:- """Resolve a server job's effective wiki style from both config sources.- ``Repository.settings_json`` wins (the web UI is the more deliberate- signal), then ``.repowise/config.yaml``, then the default. Unknown values- resolve to the default rather than failing the job.- """+def _repo_wiki_style(repo: Any, repo_path: str) -> str:+ """A server job's wiki style; an unknown value resolves to the default."""from repowise.core.generation.styles import resolve_style- style: str | None = None- try:- settings = json.loads(getattr(repo, "settings_json", "") or "{}")- if isinstance(settings, dict):- style = settings.get("wiki_style")- except (TypeError, ValueError):- logger.debug("repo_settings_json_unparsable", repo_path=repo_path)-- if not style:- try:- from repowise.core.repo_config import load_repo_config-- cfg = load_repo_config(Path(repo_path))- if isinstance(cfg, dict):- style = cfg.get("wiki_style")- except Exception:- logger.debug("repo_config_yaml_unreadable", repo_path=repo_path)-+ style = _repo_file_settings(repo, repo_path).get("wiki_style")return resolve_style(style, repo_path=repo_path).namediff --git a/packages/server/src/repowise/server/routers/_repo_settings.py b/packages/server/src/repowise/server/routers/_repo_settings.pynew file mode 100644index 000000000..b8b308b6c--- /dev/null+++ b/packages/server/src/repowise/server/routers/_repo_settings.py@@ -0,0 +1,108 @@+"""Repo settings the PATCH and POST bodies carry that live in ``.repowise/config.yaml``.++``exclude_patterns`` and ``wiki_style`` are read by the CLI and the indexer+from the repo's config.yaml, so the server writes them there and keeps only the+remaining keys in ``Repository.settings_json``.+"""++from __future__ import annotations++import json+from pathlib import Path+from typing import Any++from fastapi import HTTPException++from repowise.server.routers._repo_generate import _reject_unknown_style+from repowise.server.schemas import RepoResponse+++def stored_settings(raw: str | None) -> dict[str, Any]:+ """The row's ``settings_json`` as a dict; ``{}`` when unparseable."""+ try:+ data = json.loads(raw or "{}")+ except (TypeError, ValueError):+ return {}+ return data if isinstance(data, dict) else {}+++def _validate(updates: dict[str, Any]) -> None:+ """400 for a value the CLI could not read back."""+ style = updates.get("wiki_style")+ if style is not None:+ if not isinstance(style, str):+ raise HTTPException(status_code=400, detail="wiki_style must be a string.")+ _reject_unknown_style(style, "wiki_style")+ patterns = updates.get("exclude_patterns")+ if patterns is not None and not (+ isinstance(patterns, list) and all(isinstance(p, str) for p in patterns)+ ):+ raise HTTPException(status_code=400, detail="exclude_patterns must be a list of strings.")+++def save_settings(+ local_path: str, settings: dict[str, Any], stored: dict[str, Any]+) -> dict[str, Any]:+ """Write the config.yaml keys of *settings*; return what ``settings_json`` keeps.++ *stored* is the row's current settings. When *settings* sends none of the+ file keys, nothing is written and any legacy copy stays in the row. When it+ sends one, legacy copies move into the file with it and leave the row. A+ checkout this server cannot reach or write is an error, never a silent+ write to the row instead.+ """+ from repowise.core.repo_config import FILE_SETTING_KEYS, RepoConfigError, save_file_settings++ updates = {k: settings[k] for k in FILE_SETTING_KEYS if k in settings}+ rest = {k: v for k, v in settings.items() if k not in FILE_SETTING_KEYS}+ if not updates:+ return {**rest, **{k: stored[k] for k in FILE_SETTING_KEYS if k in stored}}+ _validate(updates)+ repo_path = Path(local_path)+ if not repo_path.is_dir():+ raise HTTPException(+ status_code=409,+ detail=(+ f"Can't save excluded paths or documentation style: {repo_path} is not "+ "reachable from this server. They are stored in its .repowise/config.yaml."+ ),+ )+ try:+ save_file_settings(repo_path, updates, stored)+ except RepoConfigError as exc:+ raise HTTPException(status_code=400, detail=str(exc)) from exc+ except OSError as exc:+ raise HTTPException(+ status_code=409,+ detail=f"Can't write {repo_path / '.repowise' / 'config.yaml'}: {exc.strerror or exc}",+ ) from exc+ return rest+++def effective_settings(repo: Any) -> dict[str, Any]:+ """The row's settings with the config.yaml keys read from its checkout.++ A legacy stored value shows until the file sets the key. An unreadable+ config leaves the stored settings as they are: a listing must not fail on+ one broken file, and saving those keys reports the parse error.+ """+ from repowise.core.repo_config import (+ FILE_SETTING_KEYS,+ RepoConfigError,+ resolve_file_settings,+ )++ stored = stored_settings(repo.settings_json)+ if not repo.local_path:+ return stored+ try:+ effective = resolve_file_settings(repo.local_path, stored)+ except (RepoConfigError, OSError):+ return stored+ rest = {k: v for k, v in stored.items() if k not in FILE_SETTING_KEYS}+ return {**rest, **effective}+++def repo_response(repo: Any) -> RepoResponse:+ """:class:`RepoResponse` for *repo*, settings as the CLI sees them."""+ return RepoResponse.from_orm(repo, settings=effective_settings(repo))diff --git a/packages/server/src/repowise/server/routers/repos.py b/packages/server/src/repowise/server/routers/repos.pyindex 772d29973..7610820c0 100644--- a/packages/server/src/repowise/server/routers/repos.py+++ b/packages/server/src/repowise/server/routers/repos.py@@ -31,7 +31,6 @@ from repowise.server.routers._repo_generate import (GenerateRequestBody,GenerateSelectionBody, # noqa: F401 - re-exported beside the body that nests it_generate_job_config,- _reject_unknown_style,_validate_generate_selection,_validate_generate_style,)@@ -48,6 +47,7 @@ from repowise.server.routers._repo_pricing import (probe_provider,resolve_provider,)+from repowise.server.routers._repo_settings import repo_response, save_settings, stored_settingsfrom repowise.server.routers._repo_summary import _freshness_for, _summary_rows_forfrom repowise.server.schemas import (JobAcceptedResponse,@@ -123,6 +123,9 @@ async def create_repo(configured — is enqueued immediately; the created job's id is returnedas ``initial_job_id`` so clients can attach to its progress stream."""+ if body.settings is not None:+ # A style picked at registration lands in config.yaml like a PATCH.+ body.settings = save_settings(body.local_path, body.settings, {})if not body.index:# Metadata-only registration: per-repo storage is created on first index.url, branch = _sent_metadata(body)@@ -134,7 +137,7 @@ async def create_repo(default_branch=branch,settings=body.settings,)- return RepoResponse.from_orm(repo)+ return repo_response(repo)from repowise.server.repo_db import ensure_repo_registration, upsert_registry_row@@ -170,7 +173,7 @@ async def create_repo(crud.keep_analysis_ran(repo.settings_json, body.settings))await repo_session.flush()- response = RepoResponse.from_orm(repo)+ response = repo_response(repo)stored_url, stored_branch = repo.url, repo.default_branchelse: # pragma: no cover — the row was created two lines aboveraise HTTPException(status_code=500, detail="Repository registration failed")@@ -239,7 +242,7 @@ async def list_repos(repos, indexed_repo_ids = await load_repositories(session, getattr(app_state, "workspace_sessions", {}))- responses = [RepoResponse.from_orm(r) for r in repos]+ responses = [repo_response(r) for r in repos]heal_indexed_commits(responses)flag_unindexed(responses, indexed_repo_ids)@@ -309,7 +312,7 @@ async def get_repo(session: AsyncSession = Depends(get_db_session),) -> RepoResponse:"""Get a single repository by ID."""- return RepoResponse.from_orm(await _get_repo_or_404(session, repo_id))+ return repo_response(await _get_repo_or_404(session, repo_id))@router.patch("/{repo_id}", response_model=RepoResponse)@@ -318,26 +321,31 @@ async def update_repo(body: RepoUpdate,session: AsyncSession = Depends(get_db_session),) -> RepoResponse:- """Update repository fields."""+ """Update repository fields.++ ``exclude_patterns`` and ``wiki_style`` in ``settings`` go to the repo's+ ``.repowise/config.yaml`` (where the CLI reads them), written first so a+ failed write leaves the row untouched.+ """+ import json+repo = await _get_repo_or_404(session, repo_id)+ row_settings = None+ if body.settings is not None:+ row_settings = save_settings(+ repo.local_path, body.settings, stored_settings(repo.settings_json)+ )if body.name is not None:repo.name = body.nameif body.url is not None:repo.url = body.urlif body.default_branch is not None:repo.default_branch = body.default_branch- if body.settings is not None:- import json-- # Validate a wiki_style setting up front so a typo surfaces as a 400 here- # rather than silently falling back to the default during generation.- style = body.settings.get("wiki_style")- if style is not None:- _reject_unknown_style(style, "wiki_style")- repo.settings_json = json.dumps(crud.keep_analysis_ran(repo.settings_json, body.settings))+ if row_settings is not None:+ repo.settings_json = json.dumps(crud.keep_analysis_ran(repo.settings_json, row_settings))await session.flush()- return RepoResponse.from_orm(repo)+ return repo_response(repo)def _forget_workspace_member(app_state: Any, alias: str) -> bool:diff --git a/packages/server/src/repowise/server/schemas/repository.py b/packages/server/src/repowise/server/schemas/repository.pyindex 8a46aa7b9..517b80422 100644--- a/packages/server/src/repowise/server/schemas/repository.py+++ b/packages/server/src/repowise/server/schemas/repository.py@@ -79,7 +79,8 @@ class RepoResponse(BaseModel):initial_job_id: str | None = None@classmethod- def from_orm(cls, obj: object) -> RepoResponse:+ def from_orm(cls, obj: object, settings: dict | None = None) -> RepoResponse:+ """*settings* replaces the row's stored ``settings_json`` when given."""local_path = obj.local_path # type: ignore[attr-defined]scope = load_index_scope(local_path) if local_path else Nonereturn cls(@@ -89,7 +90,7 @@ class RepoResponse(BaseModel):local_path=local_path,default_branch=obj.default_branch, # type: ignore[attr-defined]head_commit=obj.head_commit, # type: ignore[attr-defined]- settings=json.loads(obj.settings_json), # type: ignore[attr-defined]+ settings=json.loads(obj.settings_json) if settings is None else settings, # type: ignore[attr-defined]created_at=obj.created_at, # type: ignore[attr-defined]updated_at=obj.updated_at, # type: ignore[attr-defined]index_scope=scope,diff --git a/tests/unit/core/test_repo_file_settings.py b/tests/unit/core/test_repo_file_settings.pynew file mode 100644index 000000000..dab2d1b78--- /dev/null+++ b/tests/unit/core/test_repo_file_settings.py@@ -0,0 +1,88 @@+"""config.yaml is the one home of exclude_patterns and wiki_style."""++from __future__ import annotations++from pathlib import Path++import pytest++from repowise.core.repo_config import (+ RepoConfigError,+ load_repo_config,+ resolve_file_settings,+ save_file_settings,+)+++def _write_config(root: Path, text: str) -> Path:+ path = root / ".repowise" / "config.yaml"+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_text(text, encoding="utf-8")+ return path+++def test_resolve_prefers_config_and_falls_back_to_stored(tmp_path: Path) -> None:+ _write_config(tmp_path, "exclude_patterns:\n- vendor/\n")+ stored = {"exclude_patterns": ["old/"], "wiki_style": "caveman", "other": 1}++ assert resolve_file_settings(tmp_path, stored) == {+ "exclude_patterns": ["vendor/"],+ "wiki_style": "caveman",+ }+ assert resolve_file_settings(tmp_path / "missing", {}) == {}+++def test_resolve_raises_on_broken_config(tmp_path: Path) -> None:+ _write_config(tmp_path, "- not a mapping\n")+ with pytest.raises(RepoConfigError):+ resolve_file_settings(tmp_path, {})+++def test_save_preserves_other_keys_and_migrates_legacy(tmp_path: Path) -> None:+ _write_config(tmp_path, "provider: openai\nmodel: gpt\n")++ saved = save_file_settings(+ tmp_path, {"exclude_patterns": ["dist/"]}, {"wiki_style": "reference"}+ )++ assert saved == {"exclude_patterns": ["dist/"], "wiki_style": "reference"}+ assert load_repo_config(tmp_path) == {+ "provider": "openai",+ "model": "gpt",+ "exclude_patterns": ["dist/"],+ "wiki_style": "reference",+ }+++def test_save_of_unchanged_or_default_values_leaves_file_alone(tmp_path: Path) -> None:+ path = _write_config(tmp_path, "provider: openai\n")+ before = path.read_bytes()++ save_file_settings(tmp_path, {"exclude_patterns": [], "wiki_style": "comprehensive"}, {})++ assert path.read_bytes() == before+ assert list((tmp_path / ".repowise").glob("*.tmp")) == []+++def test_null_in_file_counts_as_unset(tmp_path: Path) -> None:+ _write_config(tmp_path, "exclude_patterns:\nwiki_style:\n")+ stored = {"wiki_style": "tutorial"}++ assert resolve_file_settings(tmp_path, stored) == {"wiki_style": "tutorial"}+ assert save_file_settings(tmp_path, {}, stored) == {"wiki_style": "tutorial"}+++def test_save_default_or_empty_removes_key(tmp_path: Path) -> None:+ _write_config(tmp_path, "wiki_style: caveman\nexclude_patterns:\n- a/\n")++ saved = save_file_settings(+ tmp_path, {"wiki_style": "comprehensive", "exclude_patterns": []}, {}+ )++ assert saved == {}+ assert load_repo_config(tmp_path) == {}+++def test_save_creates_config_when_absent(tmp_path: Path) -> None:+ save_file_settings(tmp_path, {"wiki_style": "tutorial"}, {})+ assert load_repo_config(tmp_path) == {"wiki_style": "tutorial"}diff --git a/tests/unit/server/test_health_excludes.py b/tests/unit/server/test_health_excludes.pyindex d33482f81..9fbb0dfa5 100644--- a/tests/unit/server/test_health_excludes.py+++ b/tests/unit/server/test_health_excludes.py@@ -11,6 +11,23 @@ from repowise.core.persistence.crud import (from repowise.core.pipeline.persist import _prune_stale_file_rows+async def test_health_excludes_follow_config_yaml_over_legacy_settings(session, tmp_path) -> None:+ from repowise.core.persistence.crud.analysis.health.exclude import health_exclude_spec++ (tmp_path / ".repowise").mkdir()+ (tmp_path / ".repowise" / "config.yaml").write_text(+ "exclude_patterns:\n- vendor/\n", encoding="utf-8"+ )+ repo = await upsert_repository(+ session, name="repo", local_path=str(tmp_path), settings={"exclude_patterns": ["tools/"]}+ )++ spec = await health_exclude_spec(session, repo.id)++ assert spec.match_file("vendor/a.py")+ assert not spec.match_file("tools/gen.py")++async def test_health_reads_honor_repo_settings_excludes(session, tmp_path) -> None:repo = await upsert_repository(session,@@ -187,3 +204,23 @@ async def test_prune_stale_rows_removes_excluded_health_data(session, tmp_path)assert [m.file_path for m in metrics] == ["src/app.py"]assert [f.file_path for f in findings] == ["src/app.py"]+++async def test_health_excludes_fall_back_to_saved_settings_on_broken_config(+ session, tmp_path, caplog+) -> None:+ import logging++ from repowise.core.persistence.crud.analysis.health.exclude import health_exclude_spec++ (tmp_path / ".repowise").mkdir()+ (tmp_path / ".repowise" / "config.yaml").write_text("- not a mapping\n", encoding="utf-8")+ repo = await upsert_repository(+ session, name="repo", local_path=str(tmp_path), settings={"exclude_patterns": ["tools/"]}+ )++ with caplog.at_level(logging.WARNING):+ spec = await health_exclude_spec(session, repo.id)++ assert spec.match_file("tools/gen.py")+ assert "using saved settings" in caplog.textdiff --git a/tests/unit/server/test_job_executor.py b/tests/unit/server/test_job_executor.pyindex 6da61ed32..97c8f3a46 100644--- a/tests/unit/server/test_job_executor.py+++ b/tests/unit/server/test_job_executor.py@@ -114,23 +114,29 @@ async def test_execute_job_no_excludes_passes_none(session_factory, tmp_path):assert run_pipeline_mock.await_args.kwargs["exclude_patterns"] is None-def test_repo_exclude_patterns_merges_settings_and_config(tmp_path):- """DB settings + .repowise/config.yaml merge, order-preserved & de-duped."""+def test_repo_exclude_patterns_config_yaml_wins_over_stored(tmp_path):+ """config.yaml is the one source; a legacy DB copy cannot re-add a removed pattern."""import jsonconfig_dir = tmp_path / ".repowise"config_dir.mkdir()(config_dir / "config.yaml").write_text(- "exclude_patterns:\n - node_modules/\n - vendor/\n", encoding="utf-8"+ "exclude_patterns:\n - node_modules/\n - vendor/\n - vendor/\n", encoding="utf-8")repo = SimpleNamespace(settings_json=json.dumps({"exclude_patterns": ["tools/", "node_modules/"]}))- patterns = _repo_exclude_patterns(repo, str(tmp_path))+ assert _repo_exclude_patterns(repo, str(tmp_path)) == ["node_modules/", "vendor/"]- assert patterns == ["tools/", "node_modules/", "vendor/"]++def test_repo_exclude_patterns_legacy_stored_value_applies_without_config(tmp_path):+ """A repo whose patterns predate config.yaml keeps them until a save moves them."""+ import json++ repo = SimpleNamespace(settings_json=json.dumps({"exclude_patterns": ["tools/"]}))+ assert _repo_exclude_patterns(repo, str(tmp_path)) == ["tools/"]def test_repo_exclude_patterns_ignores_malformed_sources(tmp_path):@@ -165,8 +171,8 @@ async def test_execute_job_passes_wiki_style_from_settings(session_factory, tmp_assert run_pipeline_mock.await_args.kwargs["wiki_style"] == "caveman"-def test_repo_wiki_style_settings_precedence(tmp_path):- """DB settings (web) win over .repowise/config.yaml (CLI) for wiki_style."""+def test_repo_wiki_style_config_yaml_precedence(tmp_path):+ """.repowise/config.yaml wins over a legacy DB copy for wiki_style."""import jsonfrom repowise.server.job_executor import _repo_wiki_style@@ -176,7 +182,7 @@ def test_repo_wiki_style_settings_precedence(tmp_path):(config_dir / "config.yaml").write_text("wiki_style: reference\n", encoding="utf-8")repo = SimpleNamespace(settings_json=json.dumps({"wiki_style": "caveman"}))- assert _repo_wiki_style(repo, str(tmp_path)) == "caveman"+ assert _repo_wiki_style(repo, str(tmp_path)) == "reference"def test_repo_wiki_style_falls_back_to_config(tmp_path):diff --git a/tests/unit/server/test_repo_settings_config_yaml.py b/tests/unit/server/test_repo_settings_config_yaml.pynew file mode 100644index 000000000..170288920--- /dev/null+++ b/tests/unit/server/test_repo_settings_config_yaml.py@@ -0,0 +1,213 @@+"""/api/repos keeps exclude_patterns and wiki_style in the repo's config.yaml."""++from __future__ import annotations++import json+import shutil+from pathlib import Path++import pytest+from httpx import AsyncClient++from repowise.core.persistence import crud+from repowise.core.repo_config import load_repo_config+from tests.unit.server.conftest import create_test_repo+++def _config_path(repo: dict) -> Path:+ return Path(repo["local_path"]) / ".repowise" / "config.yaml"+++async def _row_settings(session_factory, repo_id: str) -> dict:+ async with session_factory() as s:+ row = await crud.get_repository(s, repo_id)+ return json.loads(row.settings_json)+++async def test_patch_writes_config_yaml_and_keeps_other_keys(+ client: AsyncClient, session_factory+) -> None:+ repo = await create_test_repo(client)+ path = _config_path(repo)+ path.parent.mkdir(parents=True)+ path.write_text("provider: openai\n", encoding="utf-8")++ resp = await client.patch(+ f"/api/repos/{repo['id']}",+ json={"settings": {"exclude_patterns": ["dist/"], "wiki_style": "caveman", "a": 1}},+ )++ assert resp.status_code == 200+ assert resp.json()["settings"] == {+ "a": 1,+ "exclude_patterns": ["dist/"],+ "wiki_style": "caveman",+ }+ assert load_repo_config(repo["local_path"]) == {+ "provider": "openai",+ "exclude_patterns": ["dist/"],+ "wiki_style": "caveman",+ }+ assert await _row_settings(session_factory, repo["id"]) == {"a": 1}+++async def test_get_reads_a_cli_edit_of_config_yaml(client: AsyncClient) -> None:+ repo = await create_test_repo(client)+ await client.patch(f"/api/repos/{repo['id']}", json={"settings": {"wiki_style": "caveman"}})+ _config_path(repo).write_text(+ "wiki_style: reference\nexclude_patterns:\n- vendor/\n", encoding="utf-8"+ )++ settings = (await client.get(f"/api/repos/{repo['id']}")).json()["settings"]++ assert settings == {"wiki_style": "reference", "exclude_patterns": ["vendor/"]}+++async def test_legacy_row_values_show_then_move_into_config_on_save(+ client: AsyncClient, session_factory+) -> None:+ repo = await create_test_repo(client)+ async with session_factory() as s:+ row = await crud.get_repository(s, repo["id"])+ row.settings_json = json.dumps({"wiki_style": "tutorial", "exclude_patterns": ["old/"]})+ await s.commit()++ shown = (await client.get(f"/api/repos/{repo['id']}")).json()["settings"]+ assert shown == {"wiki_style": "tutorial", "exclude_patterns": ["old/"]}++ resp = await client.patch(+ f"/api/repos/{repo['id']}", json={"settings": {"exclude_patterns": ["new/"]}}+ )++ assert resp.status_code == 200+ assert load_repo_config(repo["local_path"]) == {+ "wiki_style": "tutorial",+ "exclude_patterns": ["new/"],+ }+ assert await _row_settings(session_factory, repo["id"]) == {}+++async def test_settings_without_file_keys_keep_legacy_row_values(+ client: AsyncClient, session_factory+) -> None:+ repo = await create_test_repo(client)+ async with session_factory() as s:+ row = await crud.get_repository(s, repo["id"])+ row.settings_json = json.dumps({"wiki_style": "tutorial"})+ await s.commit()++ resp = await client.patch(f"/api/repos/{repo['id']}", json={"settings": {"a": 1}})++ assert resp.status_code == 200+ assert await _row_settings(session_factory, repo["id"]) == {"a": 1, "wiki_style": "tutorial"}+ assert not _config_path(repo).exists()+++async def test_missing_checkout_is_an_error_not_a_row_write(+ client: AsyncClient, session_factory+) -> None:+ repo = await create_test_repo(client)+ shutil.rmtree(repo["local_path"])++ resp = await client.patch(+ f"/api/repos/{repo['id']}",+ json={"name": "renamed", "settings": {"wiki_style": "caveman"}},+ )++ assert resp.status_code == 409+ assert "not reachable" in resp.json()["detail"]+ async with session_factory() as s:+ row = await crud.get_repository(s, repo["id"])+ assert row.name == "test-repo"+ assert "wiki_style" not in json.loads(row.settings_json)+++async def test_unwritable_config_is_an_error(client: AsyncClient, monkeypatch) -> None:+ repo = await create_test_repo(client)++ def _deny(*_a, **_k):+ raise PermissionError(13, "Permission denied")++ monkeypatch.setattr("repowise.core.repo_config.save_repo_config", _deny)+ resp = await client.patch(+ f"/api/repos/{repo['id']}", json={"settings": {"wiki_style": "caveman"}}+ )++ assert resp.status_code == 409+ assert "Permission denied" in resp.json()["detail"]+++async def test_broken_config_yaml_is_a_400_and_left_alone(client: AsyncClient) -> None:+ repo = await create_test_repo(client)+ path = _config_path(repo)+ path.parent.mkdir(parents=True)+ path.write_text("- not a mapping\n", encoding="utf-8")++ resp = await client.patch(+ f"/api/repos/{repo['id']}", json={"settings": {"wiki_style": "caveman"}}+ )++ assert resp.status_code == 400+ assert "config.yaml" in resp.json()["detail"]+ assert path.read_text(encoding="utf-8") == "- not a mapping\n"+ # A listing still renders with the broken file in place.+ assert (await client.get("/api/repos")).status_code == 200+++ "settings",+ [{"exclude_patterns": "dist/"}, {"exclude_patterns": ["ok/", 3]}, {"wiki_style": 5}],+)+async def test_malformed_values_are_rejected(client: AsyncClient, settings: dict) -> None:+ repo = await create_test_repo(client)+ resp = await client.patch(f"/api/repos/{repo['id']}", json={"settings": settings})+ assert resp.status_code == 400+ assert not _config_path(repo).exists()+++async def test_create_writes_registration_style_to_config_yaml(+ client: AsyncClient, tmp_path: Path, session_factory+) -> None:+ repo_dir = tmp_path / "r"+ (repo_dir / ".git").mkdir(parents=True)++ resp = await client.post(+ "/api/repos",+ json={+ "index": False,+ "name": "r",+ "local_path": str(repo_dir),+ "settings": {"wiki_style": "caveman"},+ },+ )++ assert resp.status_code == 201+ assert resp.json()["settings"] == {"wiki_style": "caveman"}+ assert load_repo_config(repo_dir) == {"wiki_style": "caveman"}+ assert await _row_settings(session_factory, resp.json()["id"]) == {}+++async def test_unchanged_save_leaves_config_bytes_alone(client: AsyncClient) -> None:+ repo = await create_test_repo(client)+ path = _config_path(repo)+ path.parent.mkdir(parents=True)+ path.write_text("provider: openai\nexclude_patterns:\n- dist/\n", encoding="utf-8")+ before = path.read_bytes()++ resp = await client.patch(+ f"/api/repos/{repo['id']}",+ json={"settings": {"exclude_patterns": ["dist/"], "wiki_style": "comprehensive"}},+ )++ assert resp.status_code == 200+ assert path.read_bytes() == beforediff --git a/tests/unit/workspace/test_incremental_update.py b/tests/unit/workspace/test_incremental_update.pyindex 5287798f5..e372aabc2 100644--- a/tests/unit/workspace/test_incremental_update.py+++ b/tests/unit/workspace/test_incremental_update.py@@ -346,6 +346,19 @@ def test_full_pipeline_merges_repo_settings_excludes(tmp_path, stub_full_pipelinassert stub_full_pipeline[0]["exclude_patterns"] == ["tools/"]+def test_config_yaml_excludes_win_over_legacy_settings(tmp_path, stub_full_pipeline):+ repo = _make_git_repo(tmp_path)+ _mark_indexed(repo, "deadbeef" * 5)+ _write_repo_settings(repo, {"exclude_patterns": ["tools/"]})+ (repo / ".repowise" / "config.yaml").write_text(+ "exclude_patterns:\n- vendor/\n", encoding="utf-8"+ )++ asyncio.run(update_single_repo_index(repo))++ assert stub_full_pipeline[0]["exclude_patterns"] == ["vendor/"]++def test_full_pipeline_uses_repo_history_settings(tmp_path, stub_full_pipeline):from repowise.core.repo_config import save_repo_configdiff --git a/tests/unit/workspace/test_update.py b/tests/unit/workspace/test_update.pyindex b1e3f0ff5..853222436 100644--- a/tests/unit/workspace/test_update.py+++ b/tests/unit/workspace/test_update.py@@ -1269,12 +1269,10 @@ class TestSavedExcludeSources:def test_unparseable_settings_json_logs_a_warning(self, caplog) -> None:import logging- from repowise.core.workspace.update.repo import _merge_settings_excludes+ from repowise.core.workspace.update.repo import _settings_excludescaplog.set_level(logging.WARNING, logger="repowise.workspace.update")- patterns = ["dist/**"]- _merge_settings_excludes(patterns, "{not json")- assert patterns == ["dist/**"]+ assert _settings_excludes("{not json") == {}assert "saved exclude patterns not applied" in caplog.text