Skip to content

fix(config): reject a bare ~ as a configured path and test the auth config rules in ox-core - #737

Merged
hakula139 merged 5 commits into
mainfrom
test/auth-shape-tests-in-core
Oct 29, 2026
Merged

hakula139 merged 5 commits into
mainfrom
test/auth-shape-tests-in-core

Conversation

@hakula139

@hakula139 hakula139 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

The client.auth shape rules in ox-core/src/config/schema.rs ("client.auth requires exactly one of value or file", "client.auth type login takes no other keys", "invalid client.auth.file: expected an absolute or ~/ path") and the user-layer redaction of private config values in config/load.rs had no ox-core test. Their only pins were the 19-case INVALID_AUTH_CONFIGS table and a relative-path test in crates/ox/tests/cli.rs, which spawned ox config check once per case, so a broken rule failed far from the code that owns it. Those rules now have unit tests next to their code, and the 1,674-line tests/cli.rs becomes one test binary with a file per area.

  • Schema rules: config::schema tests LoginAuth and AuthValue parsing through toml::from_str::<FileConfig> and inline_secret directly, asserting exact messages. They cover an inline value, absolute and ~/ files (with the home directory pinned), neither or both sources, an empty value, keys beside type = 'login', and a header-unsafe value. The file check is the shared expand_absolute, whose own tests now hold its path cases.
  • Bare ~ (user-visible): expand_absolute, which client.auth.file, client.extra_ca_certs, and permission.extra_roots share, accepted ~ and ~/ because they expand to the absolute home directory. client.auth.file = "~" then passed ox config check and Home Manager's checkConfig and failed only when ox read the token, on Windows with a misleading "Access is denied". No caller can use the home directory itself: the credential file and the CA bundle name files, and an extra root already rejects $HOME as too broad. The helper now rejects both spellings with "expected an absolute or ~/ path", so the rule the authentication, configuration, and permissions guides state holds. Its tests pin ~, ~/, ~alice/..., a relative path, and ~/ca.pem under a relative home directory. The extra-root test pins the too-broad message with the home directory's absolute spelling.
  • No raw path in expansion errors: expand_user's missing-home error no longer quotes the raw path and uses the spelling rule.rs already has ("failed to expand ~: no home directory"). Every caller that shows the path already names it in its own context, so "errors never quote raw" now holds by construction, and expand_absolute needs no remap. The missing-home message stays untested, as on main, since no environment variable can force home_dir() to return nothing.
  • Redaction: config::load::read_layer gains a 16-case table of malformed private values in a user file, covering type errors, an unknown type, unknown fields, header errors, each custom message prefix that safe_message passes through, and a TOML syntax error. Each error must start with invalid config at <path>: , name the expected shape, and contain none of the private sentinels. Before this, only a project-layer case pinned redaction in ox-core.
  • End-to-end privacy: config_check::rejects_a_malformed_credential_without_echoing_it keeps two cases, a type error and a syntax error, to show that ox config check prints the headline after Error: and that neither stderr nor any file the run writes contains the value.
  • CLI test layout: crates/ox/tests/cli/main.rs holds the shared helpers (ox, config_check, write_user_config, tree, assert_private_auth_run, request_header) and declares startup, config_check, native_auth, headless, repl, sessions, and signals modules, the last gated once on cfg(unix). Each module starts with use super::*;, and its test names drop the area's prefix, as in config_check::rejects_an_unknown_key_with_its_file. Test bodies are unchanged apart from the moved auth cases.
  • Docs: the testing conventions describe the area layout in Placement and Grouping and Naming, stating that every end-to-end test except the live tests in tests/live.rs builds as the one tests/cli/ binary, and the Home Manager module's comment points at tests/cli/config_check.rs.

Design decisions:

  • Redaction tests in load.rs, rule tests in schema.rs. The design review proposed moving the table into schema.rs, but most of its expected messages (in \client.auth`: expected a string, the custom-prefix pass-through, the TOML syntax error) are composed by read_layer's redaction, so the table tests read_layer. The rules themselves (LoginAuth, AuthValue, inline_secret`) are tested where they are defined, so each case lives in the module whose behavior it asserts.
  • One test binary with area modules over several test binaries. Each file under tests/ is its own crate and link step, while a tests/cli/main.rs with modules links once and keeps the shared helpers in one place, as Codex's exec/tests/all.rs does.

Test plan

  • The verification block passed at the first commit (cargo fmt --check, cargo build, both cargo clippy runs, cargo doc --no-deps, cargo llvm-cov, pnpm format, pnpm lint, pnpm spellcheck). After a test-helper fix in the final commit, cargo fmt, cargo clippy --all-targets, and cargo llvm-cov passed again: 1,924 ox-core, 1,461 ox-tui, 129 ox unit, and 40 CLI tests.
  • cargo test --test cli lists every test under its area module (40 before the rebase, 42 after feat(session)!: store sessions in SQLite #729 added two).
  • Patch coverage from the local lcov over the changed lines is 155/155.
  • CI run 40742080894 passed every job on the previous head b1d7d22, with codecov/patch at 100% of the diff. After the second review's fixes, the verification block passed again at 3791724, and CI passed on that head. After the rebase onto main, which ports feat(session)!: store sessions in SQLite #729's tests/cli.rs changes (the saved_sessions / exported helpers, the export-based resume tests, and the store-backed assertions) into main.rs, sessions.rs, headless.rs, and native_auth.rs, the verification block passed at 7b5e455 with 42 CLI tests.
  • The two moved shape rows without a private value ({ type = 'bearer' } and value = '') are now parse-level schema.rs cases, and the login + file row is covered by login_auth::try_from::rejects_any_other_key.

@hakula139 hakula139 added area: config Touches config loading, layering, or credential discovery test Test coverage changes labels Oct 28, 2026
@hakula139 hakula139 self-assigned this Oct 28, 2026
@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@hakula139
hakula139 force-pushed the test/auth-shape-tests-in-core branch from d001fb5 to b1d7d22 Compare October 28, 2026 18:06
@hakula139 hakula139 changed the title test: pin auth config rules in ox-core and split the CLI tests by area fix(config): reject a bare ~ as a configured path and test the auth config rules in ox-core Oct 28, 2026
@hakula139 hakula139 added the bug Unexpected behavior label Oct 28, 2026
The client.auth shape rules and the user-layer redaction of private
config values had no ox-core test. Their only pins were a 19-case table
and a relative-path test in crates/ox/tests/cli.rs, which spawned
`ox config check` once per case, so a broken rule showed up as a
subprocess failure far from the code that owns it.

schema.rs now tests LoginAuth and AuthValue parsing and inline_secret
directly, with exact messages, and load.rs tests that read_layer names
the shape of each malformed private value without echoing it. One
end-to-end test keeps two cases, a type error and a TOML syntax error,
to show that a rejected credential stays out of stderr and the run's
files.

The 1,674-line cli.rs becomes the tests/cli/ binary: main.rs holds the
shared helpers and declares one module per area (startup, config check,
native auth, headless, REPL, sessions, signals), whose test names drop
the area's prefix. The suite still links as one test binary, and the
testing conventions describe the layout.
The empty `client.auth.value` case lost its parse-level test when the
CLI table moved. A parsed empty value, a bare `~`, and `~/token` under a
relative home directory now pin each `client.auth.file` rule through
the shared `expand_absolute` check, and `require_absolute` splits that
check from `expand_user` so a test can reach the message for a home
directory that cannot be found.

The testing conventions scope the one-binary rule to the mock-backed
tests and name `tests/live.rs`.
`expand_absolute` accepted `~`, which expands to the home directory, so
`client.auth.file = "~"` passed `ox config check` and failed only when
`ox` read the token, with "Access is denied" on Windows. Every caller
needs a path other than the home directory: the credential file and the
CA bundle name files, and an extra root already rejects `$HOME`. The
helper now rejects `~` and `~/`, which keeps the documented "absolute or
`~/`" rule true.

`expand_user` no longer quotes the raw path in its error, so no caller
can leak a pasted secret through it, and `require_absolute` goes away.
The bare-`~` and relative-home cases move into `expand_absolute`'s own
tests, and the testing conventions name what `tests/cli/` holds.
@hakula139
hakula139 force-pushed the test/auth-shape-tests-in-core branch from 3791724 to 7b5e455 Compare October 28, 2026 20:34
@hakula139
hakula139 merged commit 10d4747 into main Oct 29, 2026
9 checks passed
@hakula139
hakula139 deleted the test/auth-shape-tests-in-core branch October 29, 2026 00:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: config Touches config loading, layering, or credential discovery bug Unexpected behavior test Test coverage changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant