Repository navigation
fix(schema+config): validate Config paths, raise on invalid privacy level, dedup XDG state - #525
Conversation
…evel, dedup XDG state Closes #481. Four of the six items in #481 were already resolved on master in earlier audit-fix waves (#504 and predecessors): the content-field denylist now includes name/body/message/input/output, the max_length=0 falsy bug is fixed, POLYLOGUE_FORCE_PLAIN already suppresses ConsoleRenderer colors, and privacy_config.py now imports config_root from polylogue.paths. The two items addressed here are the remaining real defects. XDG state path duplication (polylogue/cli/helper_source_state.py) source_state_path reimplemented XDG_STATE_HOME resolution inline. If the fallback in polylogue/paths/_roots.py changes, the duplicate diverges. Replace the inline logic with state_home() from polylogue.paths. Silent fallback on invalid privacy level (polylogue/schemas/privacy_config.py) _privacy_level_value silently returned "standard" for any unrecognized input. A typo in a TOML file or CLI flag would map to "standard" without warning. Raise ValueError on unknown levels; preserve the explicit None -> "standard" default. Config path validation (polylogue/config.py) Config dataclass had no post-init validation. Relative paths silently shift meaning across processes (CLI from $PWD vs MCP server vs systemd unit), producing different archive locations for the same Config(). Add __post_init__ that requires archive_root, render_root, and db_path to be absolute Paths; raise ConfigError otherwise. Tests: - test_privacy_level_value_rejects_unknown_level (and a positive case for known levels including None default). - test_config_rejects_relative_{archive_root,render_root,db_path}. Verification: devtools verify --quick green; full unit suite 5595 passed. Co-Authored-By: Claude <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
Pull request overview
This PR addresses the remaining two outstanding items from issue #481 by tightening runtime configuration validation and ensuring schema privacy configuration does not silently accept invalid values, while also deduplicating XDG state-path resolution.
Changes:
- Add
Config.__post_init__validation to require absolutePathvalues forarchive_root,render_root, anddb_path(raisingConfigErrorotherwise). - Make
_privacy_level_valuereject unknown privacy levels by raisingValueError(while keepingNone -> "standard"). - Replace inline XDG state path fallback logic with
polylogue.paths.state_home()and add/extend unit tests for these behaviors.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
polylogue/config.py |
Adds post-init validation to prevent relative/invalid path configuration at construction time. |
polylogue/schemas/privacy_config.py |
Makes privacy level parsing strict by raising on unknown levels instead of silently defaulting. |
polylogue/cli/helper_source_state.py |
Deduplicates XDG state dir resolution by using state_home() for last-source state storage. |
tests/unit/core/test_config.py |
Adds tests asserting Config rejects relative archive_root, render_root, and db_path. |
tests/unit/core/test_privacy_config.py |
Adds tests asserting unknown privacy levels raise, and known levels (including None) behave as expected. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…evel, dedup XDG state (#525) ## Summary Closes #481. Four of the six items in #481 were already resolved on master in earlier audit-fix waves (likely #504 and predecessors). This PR addresses the two real outstanding defects plus tightens \`Config\` construction. ## Problem | Sub-item | Status | | --- | --- | | \`name\` not in content field denylist | Already fixed (\`schemas/privacy.py:97\` includes \`name\`, \`body\`, \`message\`, \`input\`, \`output\`) | | \`max_length=0\` treated as falsy | Already fixed (\`schemas/privacy.py:220\`: \`max_length if max_length is not None else _SAFE_ENUM_MAX_LEN\`) | | \`POLYLOGUE_FORCE_PLAIN\` color suppression | Already fixed (\`logging.py:151\`: \`colors=sys.stderr.isatty() and not force_plain\`) | | \`privacy_config.py\` XDG path duplication | Already fixed (uses \`config_root()\` from \`polylogue.paths\`) | | \`helper_source_state.py\` XDG path duplication | **Outstanding** — duplicates the \`XDG_STATE_HOME\` fallback inline; if \`_roots.py\` changes, it diverges silently | | \`Config\` accepts invalid paths; \`PrivacyConfig\` swallows invalid level | **Outstanding** — relative paths and typo'd levels both succeed silently | ## Solution ### XDG state path duplication \`polylogue/cli/helper_source_state.py:source_state_path\` reimplemented the \`XDG_STATE_HOME\` fallback inline. Replace with \`state_home()\` from \`polylogue.paths\` so the fallback stays single-source. ### Silent fallback on invalid privacy level \`_privacy_level_value\` returned \`"standard"\` for any unrecognized input — a typo in TOML or a CLI flag silently mapped to "standard". Raise \`ValueError\` on unknown levels; preserve the explicit \`None → "standard"\` default. ### \`Config\` path validation \`Config\` dataclass had no post-init validation. Relative paths silently shift meaning across processes (CLI from \`\$PWD\` vs MCP server vs systemd unit) — different archive locations for the same nominal \`Config(...)\`. Add \`__post_init__\` requiring \`archive_root\`, \`render_root\`, and \`db_path\` to be absolute \`Path\`s; raise \`ConfigError\` otherwise. ## Verification \`\`\` $ nix develop -c devtools verify --quick verify: all checks passed $ nix develop -c pytest -q tests/unit/core/test_config.py tests/unit/core/test_privacy_config.py 58 passed in 8.72s $ nix develop -c pytest -q tests/ --ignore=tests/integration 5595 passed, 10 xfailed \`\`\` New tests: - \`test_privacy_level_value_rejects_unknown_level\` + positive cases for known levels including \`None\`. - \`test_config_rejects_relative_{archive_root,render_root,db_path}\`. Co-authored-by: Claude <[email protected]>
Summary
Closes #481.
Four of the six items in #481 were already resolved on master in earlier audit-fix waves (likely #504 and predecessors). This PR addresses the two real outstanding defects plus tightens `Config` construction.
Problem
Solution
XDG state path duplication
`polylogue/cli/helper_source_state.py:source_state_path` reimplemented the `XDG_STATE_HOME` fallback inline. Replace with `state_home()` from `polylogue.paths` so the fallback stays single-source.
Silent fallback on invalid privacy level
`_privacy_level_value` returned `"standard"` for any unrecognized input — a typo in TOML or a CLI flag silently mapped to "standard". Raise `ValueError` on unknown levels; preserve the explicit `None → "standard"` default.
`Config` path validation
`Config` dataclass had no post-init validation. Relative paths silently shift meaning across processes (CLI from `$PWD` vs MCP server vs systemd unit) — different archive locations for the same nominal `Config(...)`. Add `post_init` requiring `archive_root`, `render_root`, and `db_path` to be absolute `Path`s; raise `ConfigError` otherwise.
Verification
```
$ nix develop -c devtools verify --quick
verify: all checks passed
$ nix develop -c pytest -q tests/unit/core/test_config.py tests/unit/core/test_privacy_config.py
58 passed in 8.72s
$ nix develop -c pytest -q tests/ --ignore=tests/integration
5595 passed, 10 xfailed
```
New tests: