Skip to content

OSW_CRED_FILEPATH does not expand a leading ~, unlike OSW_STATE_DIR #194

Description

@LukasGold

OSW_CRED_FILEPATH=~/accounts.pwd.yaml fails with "does not exist", although the file does exist.

Path("~/accounts.pwd.yaml").is_file() is False, because pathlib never expands ~ by itself. The check at
https://github.com/OpenSemanticLab/osw-python/blob/feat/mcp-server/src/osw/service/config.py#L634 therefore reports the file as missing:

RuntimeError: Configured credential file '~/accounts.pwd.yaml' does not exist. Set OSW_CRED_FILEPATH (...)

The second reader, open(cred_filepath, encoding="utf-8") at
https://github.com/OpenSemanticLab/osw-python/blob/feat/mcp-server/src/osw/service/config.py#L213, has the same gap, but the check above runs first.

Why this is worth fixing

The failure is loud, not silent, so no credential ever goes to the wrong place. The problem is the message: it says the file does not exist while the file is there, so it points the operator at the wrong cause.

OSW_STATE_DIR now expands a leading ~ (#133). The two path settings therefore disagree, and an operator who learns the rule from one gets the opposite result from the other.

Suggested fix

Expand ~ in Settings._validate_cred_filepath (https://github.com/OpenSemanticLab/osw-python/blob/feat/mcp-server/src/osw/service/config.py#L169), the same way _validate_state_dir does, including the RuntimeError catch for an undeterminable home directory.

Unlike state_dir, a relative cred_filepath should stay accepted. The CLI already resolves accounts.pwd.yaml against the working directory on purpose.

Reproduction

printf 'wiki.example.org:\n  username: u\n  password: p\n' > ~/accounts.pwd.yaml
OSW_DOMAIN=wiki.example.org OSW_CRED_FILEPATH='~/accounts.pwd.yaml' osw status

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions