chatenv 0.2.14__tar.gz → 0.2.16__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {chatenv-0.2.14/src/chatenv.egg-info → chatenv-0.2.16}/PKG-INFO +9 -3
- {chatenv-0.2.14 → chatenv-0.2.16}/README.md +8 -2
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/__init__.py +1 -1
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/cli.py +14 -16
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/fields.py +7 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/registry.py +15 -9
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/store.py +25 -2
- {chatenv-0.2.14 → chatenv-0.2.16/src/chatenv.egg-info}/PKG-INFO +9 -3
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv.egg-info/SOURCES.txt +1 -0
- chatenv-0.2.16/tests/test_registry_selection.py +93 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/tests/test_test_profiles.py +82 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/tests/test_version.py +1 -1
- {chatenv-0.2.14 → chatenv-0.2.16}/LICENSE +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/pyproject.toml +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/setup.cfg +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/configs.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/discovery.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/paste.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/paths.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/policy.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/presets/__init__.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/source_chain.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/token_refreshers.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/tokens.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv/utils.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv.egg-info/dependency_links.txt +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv.egg-info/entry_points.txt +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv.egg-info/requires.txt +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/src/chatenv.egg-info/top_level.txt +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/tests/test_chatenv_core.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/tests/test_docs_contract.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/tests/test_secret_display.py +0 -0
- {chatenv-0.2.14 → chatenv-0.2.16}/tests/test_workflow_contract.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chatenv
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.16
|
|
4
4
|
Summary: ChatArch typed environment profile manager
|
|
5
5
|
Author-email: rexwzh <1073853456@qq.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -94,7 +94,7 @@ active-profile 集成目前只由 ChatEnv CLI 实现;其他 ChatArch CLI 仍
|
|
|
94
94
|
|
|
95
95
|
`chatenv --tree` 从当前安装包的 Click 注册表实时输出带参数签名的完整命令面;`chatenv --tree-brief` 读取同一注册表,但省略参数签名。
|
|
96
96
|
|
|
97
|
-
测试当前或命名配置:`chatenv test -t example` / `chatenv test -t example work`。命名 profile 只使用自身字段与 schema 默认值,不切换 active,也不借用默认凭据。
|
|
97
|
+
测试当前或命名配置:`chatenv test -t example` / `chatenv test -t example work` / `chatenv test -t example --profile work`。命名 profile 只使用自身字段与 schema 默认值,不切换 active,也不借用默认凭据。
|
|
98
98
|
|
|
99
99
|
```text
|
|
100
100
|
chatenv
|
|
@@ -120,7 +120,7 @@ chatenv
|
|
|
120
120
|
├── set [KEY-VALUE] [--interactive] # Set a configuration value in the matching active typed env file.
|
|
121
121
|
├── save [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Save current active values as a named profile.
|
|
122
122
|
├── delete [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Delete a named profile for one config type.
|
|
123
|
-
└── test [PROFILE] [--target TARGET] [--interactive] # Test active configuration or a named PROFILE for one target.
|
|
123
|
+
└── test [PROFILE] [--target TARGET] [--profile NAME] [--interactive] # Test active configuration or a named PROFILE for one target.
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
## 常用命令
|
|
@@ -138,6 +138,12 @@ chatenv token status PyPI RexWzh
|
|
|
138
138
|
|
|
139
139
|
敏感值默认完整遮罩:`init` 的已有值提示、默认 `cat` 和 `status --detail` 不展示密码/密钥的首尾片段;明确使用 `cat --no-mask` 才主动取原值。遮罩仅影响显示,不把星号写回 profile;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
|
|
140
140
|
|
|
141
|
+
## 配置类型精确选择
|
|
142
|
+
|
|
143
|
+
`-t/--type` 对每个选择词先匹配完整类型名、存储名或别名;没有精确匹配时才回退前缀匹配。匹配不区分大小写。多个选择词合并并去重,真正重名或前缀匹配多个类型时,要求单类型的命令仍会拒绝歧义。
|
|
144
|
+
|
|
145
|
+
例如安装 ChatCRS 后,`chatenv status -t crs` 和 `chatenv status -t chatcrs` 只选 CRS;`-t codex` 和 `-t chatcrs-codex` 只选 Codex。旧别名和 profile/token 存储目录不变,不会隐式切换配置。
|
|
146
|
+
|
|
141
147
|
## Python API
|
|
142
148
|
|
|
143
149
|
```python
|
|
@@ -63,7 +63,7 @@ active-profile 集成目前只由 ChatEnv CLI 实现;其他 ChatArch CLI 仍
|
|
|
63
63
|
|
|
64
64
|
`chatenv --tree` 从当前安装包的 Click 注册表实时输出带参数签名的完整命令面;`chatenv --tree-brief` 读取同一注册表,但省略参数签名。
|
|
65
65
|
|
|
66
|
-
测试当前或命名配置:`chatenv test -t example` / `chatenv test -t example work`。命名 profile 只使用自身字段与 schema 默认值,不切换 active,也不借用默认凭据。
|
|
66
|
+
测试当前或命名配置:`chatenv test -t example` / `chatenv test -t example work` / `chatenv test -t example --profile work`。命名 profile 只使用自身字段与 schema 默认值,不切换 active,也不借用默认凭据。
|
|
67
67
|
|
|
68
68
|
```text
|
|
69
69
|
chatenv
|
|
@@ -89,7 +89,7 @@ chatenv
|
|
|
89
89
|
├── set [KEY-VALUE] [--interactive] # Set a configuration value in the matching active typed env file.
|
|
90
90
|
├── save [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Save current active values as a named profile.
|
|
91
91
|
├── delete [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Delete a named profile for one config type.
|
|
92
|
-
└── test [PROFILE] [--target TARGET] [--interactive] # Test active configuration or a named PROFILE for one target.
|
|
92
|
+
└── test [PROFILE] [--target TARGET] [--profile NAME] [--interactive] # Test active configuration or a named PROFILE for one target.
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
## 常用命令
|
|
@@ -107,6 +107,12 @@ chatenv token status PyPI RexWzh
|
|
|
107
107
|
|
|
108
108
|
敏感值默认完整遮罩:`init` 的已有值提示、默认 `cat` 和 `status --detail` 不展示密码/密钥的首尾片段;明确使用 `cat --no-mask` 才主动取原值。遮罩仅影响显示,不把星号写回 profile;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
|
|
109
109
|
|
|
110
|
+
## 配置类型精确选择
|
|
111
|
+
|
|
112
|
+
`-t/--type` 对每个选择词先匹配完整类型名、存储名或别名;没有精确匹配时才回退前缀匹配。匹配不区分大小写。多个选择词合并并去重,真正重名或前缀匹配多个类型时,要求单类型的命令仍会拒绝歧义。
|
|
113
|
+
|
|
114
|
+
例如安装 ChatCRS 后,`chatenv status -t crs` 和 `chatenv status -t chatcrs` 只选 CRS;`-t codex` 和 `-t chatcrs-codex` 只选 Codex。旧别名和 profile/token 存储目录不变,不会隐式切换配置。
|
|
115
|
+
|
|
110
116
|
## Python API
|
|
111
117
|
|
|
112
118
|
```python
|
|
@@ -864,16 +864,17 @@ def get_env(ctx: click.Context, key: str | None, interactive: bool | None):
|
|
|
864
864
|
@cli.command(name="test")
|
|
865
865
|
@click.argument("profile", required=False)
|
|
866
866
|
@click.option("--target", "-t", required=False, help="Target service to test.")
|
|
867
|
+
@click.option("--profile", "profile_option", metavar="NAME", help="Test a named profile without activating it.")
|
|
867
868
|
@click.pass_context
|
|
868
869
|
@add_interactive_option
|
|
869
|
-
def test_env(ctx: click.Context, profile: str | None, target: str | None, interactive: bool | None):
|
|
870
|
+
def test_env(ctx: click.Context, profile: str | None, target: str | None, profile_option: str | None, interactive: bool | None):
|
|
870
871
|
"""Test active configuration or a named PROFILE for one target."""
|
|
871
872
|
load_config_providers()
|
|
872
873
|
inputs = resolve_command_inputs(
|
|
873
874
|
schema=TEST_TARGET_SCHEMA,
|
|
874
875
|
provided={"target": target},
|
|
875
876
|
interactive=interactive,
|
|
876
|
-
usage="Usage: chatenv test [PROFILE] --target TEXT [-i|-I]",
|
|
877
|
+
usage="Usage: chatenv test [PROFILE] --target TEXT [--profile NAME] [-i|-I]",
|
|
877
878
|
)
|
|
878
879
|
target = inputs["target"]
|
|
879
880
|
config_cls = BaseEnvConfig.get_config_by_alias(target)
|
|
@@ -884,20 +885,17 @@ def test_env(ctx: click.Context, profile: str | None, target: str | None, intera
|
|
|
884
885
|
aliases = ", ".join(cls._aliases)
|
|
885
886
|
click.echo(f" - {cls._title}: {aliases}")
|
|
886
887
|
raise click.Abort()
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
env_values=store.load_profile(config_cls, profile),
|
|
899
|
-
include_process_env=False,
|
|
900
|
-
)
|
|
888
|
+
try:
|
|
889
|
+
if profile is not None and profile_option is not None:
|
|
890
|
+
if normalize_profile_name(profile) != normalize_profile_name(profile_option):
|
|
891
|
+
raise click.ClickException("Conflicting PROFILE and --profile values.")
|
|
892
|
+
selected_profile = profile_option if profile_option is not None else profile
|
|
893
|
+
path = _store(ctx).load_config(config_cls, profile=selected_profile)
|
|
894
|
+
except ValueError as exc:
|
|
895
|
+
raise click.ClickException(str(exc)) from exc
|
|
896
|
+
except FileNotFoundError as exc:
|
|
897
|
+
raise click.ClickException(f"Environment profile '{exc.args[0]}' not found.") from exc
|
|
898
|
+
if selected_profile is not None:
|
|
901
899
|
click.echo(f"Profile: {config_cls.get_storage_name()}/{path.stem}")
|
|
902
900
|
config_cls.test()
|
|
903
901
|
|
|
@@ -100,6 +100,13 @@ class BaseEnvConfig:
|
|
|
100
100
|
def load_from_dict(cls, env_values: dict[str, Any]) -> None:
|
|
101
101
|
cls.load_from_sources(env_values=env_values)
|
|
102
102
|
|
|
103
|
+
@classmethod
|
|
104
|
+
def load_from_profile(cls, env_values: dict[str, Any]) -> None:
|
|
105
|
+
"""Load an isolated profile without invoking legacy source-loader overrides."""
|
|
106
|
+
for field in cls.get_fields().values():
|
|
107
|
+
value = env_values.get(field.env_key)
|
|
108
|
+
field.value = field.default if value is None else value
|
|
109
|
+
|
|
103
110
|
@classmethod
|
|
104
111
|
def load_from_sources(
|
|
105
112
|
cls,
|
|
@@ -7,19 +7,25 @@ def resolve_config_types(config_types: tuple[str, ...] | list[str] | None) -> li
|
|
|
7
7
|
if not config_types:
|
|
8
8
|
return None
|
|
9
9
|
normalized = [item.lower() for item in config_types]
|
|
10
|
-
|
|
10
|
+
candidates = []
|
|
11
11
|
for config_cls in BaseEnvConfig._registry:
|
|
12
12
|
title = getattr(config_cls, "_title", config_cls.__name__).lower()
|
|
13
13
|
aliases = [alias.lower() for alias in getattr(config_cls, "_aliases", [])]
|
|
14
14
|
storage_name = config_cls.get_storage_name().lower()
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
candidates.append((config_cls, [title, storage_name, *aliases]))
|
|
16
|
+
|
|
17
|
+
selected: set[type[BaseEnvConfig]] = set()
|
|
18
|
+
for item in normalized:
|
|
19
|
+
exact = [config_cls for config_cls, names in candidates if item in names]
|
|
20
|
+
if exact:
|
|
21
|
+
selected.update(exact)
|
|
22
|
+
else:
|
|
23
|
+
selected.update(
|
|
24
|
+
config_cls
|
|
25
|
+
for config_cls, names in candidates
|
|
26
|
+
if any(name.startswith(item) for name in names)
|
|
27
|
+
)
|
|
28
|
+
return [config_cls for config_cls in BaseEnvConfig._registry if config_cls in selected]
|
|
23
29
|
|
|
24
30
|
|
|
25
31
|
def require_single_config(config_types: tuple[str, ...] | list[str] | None, action: str) -> type[BaseEnvConfig]:
|
|
@@ -40,11 +40,34 @@ class EnvStore:
|
|
|
40
40
|
def load_profile(self, config_cls: type[BaseEnvConfig], name: str) -> dict[str, str]:
|
|
41
41
|
return self.load_path(self.profile_path(config_cls, name))
|
|
42
42
|
|
|
43
|
-
def load_path(self, path: str | Path) -> dict[str, str]:
|
|
43
|
+
def load_path(self, path: str | Path, *, interpolate: bool = True) -> dict[str, str]:
|
|
44
44
|
file_path = Path(path)
|
|
45
45
|
if not file_path.exists():
|
|
46
46
|
return {}
|
|
47
|
-
return {
|
|
47
|
+
return {
|
|
48
|
+
key: value
|
|
49
|
+
for key, value in dotenv_values(file_path, interpolate=interpolate).items()
|
|
50
|
+
if value is not None
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
def load_config(self, config_cls: type[BaseEnvConfig], profile: str | None = None) -> Path:
|
|
54
|
+
"""Load one active or isolated named config without activating a profile.
|
|
55
|
+
|
|
56
|
+
Active loading preserves legacy provider source-loader overrides. Named
|
|
57
|
+
profiles use literal file values and schema defaults, avoiding process
|
|
58
|
+
interpolation and overrides that may assume active-profile semantics.
|
|
59
|
+
"""
|
|
60
|
+
if profile is None:
|
|
61
|
+
config_cls.load_from_sources(env_values=self.load_active(config_cls))
|
|
62
|
+
return self.active_path(config_cls)
|
|
63
|
+
profile_name = normalize_profile_name(profile)
|
|
64
|
+
if not profile_name or profile_name in {".", ".."} or "/" in profile_name or "\\" in profile_name:
|
|
65
|
+
raise ValueError("Profile name must be a file name without path separators.")
|
|
66
|
+
path = self.profile_path(config_cls, profile_name)
|
|
67
|
+
if not path.is_file():
|
|
68
|
+
raise FileNotFoundError(path)
|
|
69
|
+
config_cls.load_from_profile(self.load_path(path, interpolate=False))
|
|
70
|
+
return path
|
|
48
71
|
|
|
49
72
|
def save_active(self, config_cls: type[BaseEnvConfig], values: dict[str, Any] | None = None) -> Path:
|
|
50
73
|
return self._save(config_cls, self.active_path(config_cls), values)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chatenv
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.16
|
|
4
4
|
Summary: ChatArch typed environment profile manager
|
|
5
5
|
Author-email: rexwzh <1073853456@qq.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -94,7 +94,7 @@ active-profile 集成目前只由 ChatEnv CLI 实现;其他 ChatArch CLI 仍
|
|
|
94
94
|
|
|
95
95
|
`chatenv --tree` 从当前安装包的 Click 注册表实时输出带参数签名的完整命令面;`chatenv --tree-brief` 读取同一注册表,但省略参数签名。
|
|
96
96
|
|
|
97
|
-
测试当前或命名配置:`chatenv test -t example` / `chatenv test -t example work`。命名 profile 只使用自身字段与 schema 默认值,不切换 active,也不借用默认凭据。
|
|
97
|
+
测试当前或命名配置:`chatenv test -t example` / `chatenv test -t example work` / `chatenv test -t example --profile work`。命名 profile 只使用自身字段与 schema 默认值,不切换 active,也不借用默认凭据。
|
|
98
98
|
|
|
99
99
|
```text
|
|
100
100
|
chatenv
|
|
@@ -120,7 +120,7 @@ chatenv
|
|
|
120
120
|
├── set [KEY-VALUE] [--interactive] # Set a configuration value in the matching active typed env file.
|
|
121
121
|
├── save [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Save current active values as a named profile.
|
|
122
122
|
├── delete [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Delete a named profile for one config type.
|
|
123
|
-
└── test [PROFILE] [--target TARGET] [--interactive] # Test active configuration or a named PROFILE for one target.
|
|
123
|
+
└── test [PROFILE] [--target TARGET] [--profile NAME] [--interactive] # Test active configuration or a named PROFILE for one target.
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
## 常用命令
|
|
@@ -138,6 +138,12 @@ chatenv token status PyPI RexWzh
|
|
|
138
138
|
|
|
139
139
|
敏感值默认完整遮罩:`init` 的已有值提示、默认 `cat` 和 `status --detail` 不展示密码/密钥的首尾片段;明确使用 `cat --no-mask` 才主动取原值。遮罩仅影响显示,不把星号写回 profile;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
|
|
140
140
|
|
|
141
|
+
## 配置类型精确选择
|
|
142
|
+
|
|
143
|
+
`-t/--type` 对每个选择词先匹配完整类型名、存储名或别名;没有精确匹配时才回退前缀匹配。匹配不区分大小写。多个选择词合并并去重,真正重名或前缀匹配多个类型时,要求单类型的命令仍会拒绝歧义。
|
|
144
|
+
|
|
145
|
+
例如安装 ChatCRS 后,`chatenv status -t crs` 和 `chatenv status -t chatcrs` 只选 CRS;`-t codex` 和 `-t chatcrs-codex` 只选 Codex。旧别名和 profile/token 存储目录不变,不会隐式切换配置。
|
|
146
|
+
|
|
141
147
|
## Python API
|
|
142
148
|
|
|
143
149
|
```python
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Exact selectors must not expand into another provider's prefixed alias."""
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
from click.testing import CliRunner
|
|
6
|
+
|
|
7
|
+
import chatenv.cli as cli_module
|
|
8
|
+
from chatenv.cli import cli
|
|
9
|
+
from chatenv.fields import BaseEnvConfig, EnvField
|
|
10
|
+
from chatenv.registry import require_single_config, resolve_config_types
|
|
11
|
+
from chatenv.store import EnvStore
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.fixture
|
|
15
|
+
def schemas(monkeypatch):
|
|
16
|
+
monkeypatch.setattr(BaseEnvConfig, "_registry", [])
|
|
17
|
+
monkeypatch.setattr(BaseEnvConfig, "_registry_keys", {})
|
|
18
|
+
monkeypatch.setattr(cli_module, "load_config_providers", lambda: None)
|
|
19
|
+
|
|
20
|
+
class RelayConfig(BaseEnvConfig):
|
|
21
|
+
_title = "CRS Configuration"
|
|
22
|
+
_storage_dir = "CRS"
|
|
23
|
+
_aliases = ["crs", "chatcrs"]
|
|
24
|
+
CRS_API_KEY = EnvField("CRS_API_KEY", is_sensitive=True)
|
|
25
|
+
|
|
26
|
+
class OAuthConfig(BaseEnvConfig):
|
|
27
|
+
_title = "Codex OAuth Configuration"
|
|
28
|
+
_storage_dir = "Codex"
|
|
29
|
+
_aliases = ["codex", "chatcrs-codex"]
|
|
30
|
+
OPENAI_REFRESH_TOKEN = EnvField("OPENAI_REFRESH_TOKEN", is_sensitive=True)
|
|
31
|
+
|
|
32
|
+
return RelayConfig, OAuthConfig
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@pytest.mark.parametrize("query,index", [("crs", 0), ("chatcrs", 0), ("CRS", 0), ("CHATCRS", 0), ("codex", 1), ("chatcrs-codex", 1), ("Codex OAuth Configuration", 1)])
|
|
36
|
+
def test_exact_storage_title_or_alias_wins_over_prefix(schemas, query, index):
|
|
37
|
+
assert resolve_config_types([query]) == [schemas[index]]
|
|
38
|
+
assert require_single_config([query], "save") is schemas[index]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_prefix_fallback_and_explicit_multi_select_keep_registry_order(schemas):
|
|
42
|
+
relay, oauth = schemas
|
|
43
|
+
assert resolve_config_types(["chatcr"]) == [relay, oauth]
|
|
44
|
+
with pytest.raises(ValueError, match="exactly one"):
|
|
45
|
+
require_single_config(["chatcr"], "save")
|
|
46
|
+
assert resolve_config_types(["codex", "chatcrs", "codex"]) == [relay, oauth]
|
|
47
|
+
assert resolve_config_types(["chatcrs", "not-a-type"]) == [relay]
|
|
48
|
+
assert resolve_config_types(["missing"]) == []
|
|
49
|
+
assert resolve_config_types(None) is None
|
|
50
|
+
assert resolve_config_types([]) is None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_exact_alias_collision_remains_ambiguous(schemas):
|
|
54
|
+
relay, oauth = schemas
|
|
55
|
+
relay._aliases = [*relay._aliases, "shared"]
|
|
56
|
+
oauth._aliases = [*oauth._aliases, "shared"]
|
|
57
|
+
assert resolve_config_types(["shared"]) == [relay, oauth]
|
|
58
|
+
with pytest.raises(ValueError, match="exactly one"):
|
|
59
|
+
require_single_config(["shared"], "save")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@pytest.mark.parametrize("selector,index", [("crs", 0), ("chatcrs", 0), ("codex", 1), ("chatcrs-codex", 1)])
|
|
63
|
+
def test_dispatcher_profile_write_never_crosses_namespace(schemas, tmp_path, selector, index):
|
|
64
|
+
home = tmp_path / "arch"
|
|
65
|
+
store = EnvStore(home / "envs")
|
|
66
|
+
relay, oauth = schemas
|
|
67
|
+
store.save_active(relay, {"CRS_API_KEY": "DUMMY_RELAY_CANARY"})
|
|
68
|
+
store.save_active(oauth, {"OPENAI_REFRESH_TOKEN": "DUMMY_OAUTH_CANARY"})
|
|
69
|
+
before = {c: store.active_path(c).read_bytes() for c in schemas}
|
|
70
|
+
token = home / "tokens" / "Codex" / "receipt.json"
|
|
71
|
+
token.parent.mkdir(parents=True)
|
|
72
|
+
token.write_text('{"synthetic": true}', encoding="utf-8")
|
|
73
|
+
token_before = token.read_bytes()
|
|
74
|
+
runner = CliRunner()
|
|
75
|
+
status = runner.invoke(cli, ["--home", str(home), "status", "-t", selector])
|
|
76
|
+
assert status.exit_code == 0, status.output
|
|
77
|
+
assert "Registered config platforms: 1" in status.output
|
|
78
|
+
saved = runner.invoke(cli, ["--home", str(home), "save", "isolated", "-t", selector, "-I", "--yes"])
|
|
79
|
+
assert saved.exit_code == 0, saved.output
|
|
80
|
+
selected, other = schemas[index], schemas[1 - index]
|
|
81
|
+
assert store.profile_path(selected, "isolated").exists()
|
|
82
|
+
assert not store.profile_path(other, "isolated").exists()
|
|
83
|
+
for cls in schemas:
|
|
84
|
+
assert store.active_path(cls).read_bytes() == before[cls]
|
|
85
|
+
assert token.read_bytes() == token_before
|
|
86
|
+
cat = runner.invoke(cli, ["--home", str(home), "cat", "-t", selector])
|
|
87
|
+
assert cat.exit_code == 0, cat.output
|
|
88
|
+
expected = "CRS_API_KEY" if index == 0 else "OPENAI_REFRESH_TOKEN"
|
|
89
|
+
excluded = "OPENAI_REFRESH_TOKEN" if index == 0 else "CRS_API_KEY"
|
|
90
|
+
assert expected in cat.output
|
|
91
|
+
assert excluded not in cat.output
|
|
92
|
+
assert "DUMMY_RELAY_CANARY" not in cat.output
|
|
93
|
+
assert "DUMMY_OAUTH_CANARY" not in cat.output
|
|
@@ -128,3 +128,85 @@ def test_load_from_sources_can_explicitly_disable_process_fallback(monkeypatch):
|
|
|
128
128
|
|
|
129
129
|
assert ProbeConfig.PROBE_SECRET.value is None
|
|
130
130
|
assert ProbeConfig.PROBE_URL.value == "https://default.invalid"
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@pytest.mark.parametrize("args", [
|
|
134
|
+
["--profile", "work"],
|
|
135
|
+
["work", "--profile", "work"],
|
|
136
|
+
["work.env", "--profile", "work"],
|
|
137
|
+
])
|
|
138
|
+
def test_test_profile_option_accepts_legacy_and_equivalent_positionals(probe, args):
|
|
139
|
+
runner, home, store, calls = probe
|
|
140
|
+
store.save_profile(ProbeConfig, "work", {"PROFILE_PROBE_SECRET": "work-secret"})
|
|
141
|
+
|
|
142
|
+
result = runner.invoke(cli, ["--home", str(home), "test", "-t", "profile-probe", *args])
|
|
143
|
+
|
|
144
|
+
assert result.exit_code == 0, result.output
|
|
145
|
+
assert calls[0]["PROBE_SECRET"] == "work-secret"
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_conflicting_profile_option_and_positional_fail_before_test(probe):
|
|
149
|
+
runner, home, store, calls = probe
|
|
150
|
+
store.save_profile(ProbeConfig, "work", {"PROFILE_PROBE_SECRET": "work-secret"})
|
|
151
|
+
store.save_profile(ProbeConfig, "other", {"PROFILE_PROBE_SECRET": "other-secret"})
|
|
152
|
+
|
|
153
|
+
result = runner.invoke(cli, ["--home", str(home), "test", "-t", "profile-probe", "work", "--profile", "other"])
|
|
154
|
+
|
|
155
|
+
assert result.exit_code != 0
|
|
156
|
+
assert "conflict" in result.output.lower()
|
|
157
|
+
assert calls == []
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
@pytest.mark.parametrize("profile_args, expected", [([], "active-secret"), (["--profile", "work"], "work-secret")])
|
|
161
|
+
def test_legacy_provider_loader_and_parameterless_test_still_work(probe, monkeypatch, profile_args, expected):
|
|
162
|
+
runner, home, store, calls = probe
|
|
163
|
+
store.save_active(ProbeConfig, {"PROFILE_PROBE_SECRET": "active-secret"})
|
|
164
|
+
store.save_profile(ProbeConfig, "work", {"PROFILE_PROBE_SECRET": "work-secret"})
|
|
165
|
+
monkeypatch.setenv("PROFILE_PROBE_SECRET", "process-secret")
|
|
166
|
+
loader_calls = []
|
|
167
|
+
|
|
168
|
+
def legacy_loader(cls, env_values=None, override_values=None):
|
|
169
|
+
loader_calls.append(True)
|
|
170
|
+
BaseEnvConfig.load_from_sources.__func__(cls, env_values, override_values)
|
|
171
|
+
|
|
172
|
+
monkeypatch.setattr(ProbeConfig, "load_from_sources", classmethod(legacy_loader))
|
|
173
|
+
|
|
174
|
+
result = runner.invoke(cli, ["--home", str(home), "test", "-t", "profile-probe", *profile_args])
|
|
175
|
+
|
|
176
|
+
assert result.exit_code == 0, result.output
|
|
177
|
+
assert calls[0]["PROBE_SECRET"] == expected
|
|
178
|
+
assert loader_calls == ([] if profile_args else [True])
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def test_store_load_config_is_reusable_without_cli(probe, monkeypatch):
|
|
182
|
+
runner, home, store, calls = probe
|
|
183
|
+
active = store.save_active(ProbeConfig, {"PROFILE_PROBE_SECRET": "active-secret"})
|
|
184
|
+
named = store.save_profile(ProbeConfig, "work", {})
|
|
185
|
+
monkeypatch.setenv("PROFILE_PROBE_SECRET", "process-secret")
|
|
186
|
+
|
|
187
|
+
assert store.load_config(ProbeConfig) == active
|
|
188
|
+
assert ProbeConfig.PROBE_SECRET.value == "active-secret"
|
|
189
|
+
assert store.load_config(ProbeConfig, profile="work") == named
|
|
190
|
+
assert ProbeConfig.PROBE_SECRET.value is None
|
|
191
|
+
with pytest.raises(FileNotFoundError):
|
|
192
|
+
store.load_config(ProbeConfig, profile="missing")
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def test_named_profile_does_not_interpolate_process_credentials(probe, monkeypatch):
|
|
196
|
+
runner, home, store, calls = probe
|
|
197
|
+
monkeypatch.setenv("PROFILE_PROBE_SECRET", "process-secret")
|
|
198
|
+
store.save_profile(ProbeConfig, "reference", {"PROFILE_PROBE_SECRET": "${PROFILE_PROBE_SECRET}"})
|
|
199
|
+
|
|
200
|
+
result = runner.invoke(cli, ["--home", str(home), "test", "-t", "profile-probe", "--profile", "reference"])
|
|
201
|
+
|
|
202
|
+
assert result.exit_code == 0, result.output
|
|
203
|
+
assert calls[0]["PROBE_SECRET"] == "${PROFILE_PROBE_SECRET}"
|
|
204
|
+
assert "process-secret" not in result.output
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
@pytest.mark.parametrize("profile", [".env", "..", "../Other/work", "Other\\work"])
|
|
208
|
+
def test_store_load_config_rejects_names_outside_target_profile(probe, profile):
|
|
209
|
+
runner, home, store, calls = probe
|
|
210
|
+
|
|
211
|
+
with pytest.raises(ValueError, match="Profile name"):
|
|
212
|
+
store.load_config(ProbeConfig, profile=profile)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|