chatenv 0.2.13__tar.gz → 0.2.15__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.13/src/chatenv.egg-info → chatenv-0.2.15}/PKG-INFO +4 -2
- {chatenv-0.2.13 → chatenv-0.2.15}/README.md +3 -1
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/__init__.py +1 -1
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/cli.py +18 -3
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/fields.py +11 -1
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/store.py +25 -2
- {chatenv-0.2.13 → chatenv-0.2.15/src/chatenv.egg-info}/PKG-INFO +4 -2
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv.egg-info/SOURCES.txt +1 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/tests/test_docs_contract.py +1 -1
- chatenv-0.2.15/tests/test_test_profiles.py +212 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/tests/test_version.py +1 -1
- {chatenv-0.2.13 → chatenv-0.2.15}/LICENSE +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/pyproject.toml +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/setup.cfg +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/configs.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/discovery.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/paste.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/paths.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/policy.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/presets/__init__.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/registry.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/source_chain.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/token_refreshers.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/tokens.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv/utils.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv.egg-info/dependency_links.txt +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv.egg-info/entry_points.txt +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv.egg-info/requires.txt +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/src/chatenv.egg-info/top_level.txt +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/tests/test_chatenv_core.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/tests/test_secret_display.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.15}/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.15
|
|
4
4
|
Summary: ChatArch typed environment profile manager
|
|
5
5
|
Author-email: rexwzh <1073853456@qq.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -94,6 +94,8 @@ 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` / `chatenv test -t example --profile work`。命名 profile 只使用自身字段与 schema 默认值,不切换 active,也不借用默认凭据。
|
|
98
|
+
|
|
97
99
|
```text
|
|
98
100
|
chatenv
|
|
99
101
|
├── --help # Show this message and exit.
|
|
@@ -118,7 +120,7 @@ chatenv
|
|
|
118
120
|
├── set [KEY-VALUE] [--interactive] # Set a configuration value in the matching active typed env file.
|
|
119
121
|
├── save [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Save current active values as a named profile.
|
|
120
122
|
├── delete [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Delete a named profile for one config type.
|
|
121
|
-
└── test [--target TARGET] [--interactive] # Test a
|
|
123
|
+
└── test [PROFILE] [--target TARGET] [--profile NAME] [--interactive] # Test active configuration or a named PROFILE for one target.
|
|
122
124
|
```
|
|
123
125
|
|
|
124
126
|
## 常用命令
|
|
@@ -63,6 +63,8 @@ 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` / `chatenv test -t example --profile work`。命名 profile 只使用自身字段与 schema 默认值,不切换 active,也不借用默认凭据。
|
|
67
|
+
|
|
66
68
|
```text
|
|
67
69
|
chatenv
|
|
68
70
|
├── --help # Show this message and exit.
|
|
@@ -87,7 +89,7 @@ chatenv
|
|
|
87
89
|
├── set [KEY-VALUE] [--interactive] # Set a configuration value in the matching active typed env file.
|
|
88
90
|
├── save [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Save current active values as a named profile.
|
|
89
91
|
├── delete [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Delete a named profile for one config type.
|
|
90
|
-
└── test [--target TARGET] [--interactive] # Test a
|
|
92
|
+
└── test [PROFILE] [--target TARGET] [--profile NAME] [--interactive] # Test active configuration or a named PROFILE for one target.
|
|
91
93
|
```
|
|
92
94
|
|
|
93
95
|
## 常用命令
|
|
@@ -862,16 +862,19 @@ def get_env(ctx: click.Context, key: str | None, interactive: bool | None):
|
|
|
862
862
|
|
|
863
863
|
|
|
864
864
|
@cli.command(name="test")
|
|
865
|
+
@click.argument("profile", required=False)
|
|
865
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.")
|
|
868
|
+
@click.pass_context
|
|
866
869
|
@add_interactive_option
|
|
867
|
-
def test_env(target: str | None, interactive: bool | None):
|
|
868
|
-
"""Test a
|
|
870
|
+
def test_env(ctx: click.Context, profile: str | None, target: str | None, profile_option: str | None, interactive: bool | None):
|
|
871
|
+
"""Test active configuration or a named PROFILE for one target."""
|
|
869
872
|
load_config_providers()
|
|
870
873
|
inputs = resolve_command_inputs(
|
|
871
874
|
schema=TEST_TARGET_SCHEMA,
|
|
872
875
|
provided={"target": target},
|
|
873
876
|
interactive=interactive,
|
|
874
|
-
usage="Usage: chatenv test --target TEXT [-i|-I]",
|
|
877
|
+
usage="Usage: chatenv test [PROFILE] --target TEXT [--profile NAME] [-i|-I]",
|
|
875
878
|
)
|
|
876
879
|
target = inputs["target"]
|
|
877
880
|
config_cls = BaseEnvConfig.get_config_by_alias(target)
|
|
@@ -882,6 +885,18 @@ def test_env(target: str | None, interactive: bool | None):
|
|
|
882
885
|
aliases = ", ".join(cls._aliases)
|
|
883
886
|
click.echo(f" - {cls._title}: {aliases}")
|
|
884
887
|
raise click.Abort()
|
|
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:
|
|
899
|
+
click.echo(f"Profile: {config_cls.get_storage_name()}/{path.stem}")
|
|
885
900
|
config_cls.test()
|
|
886
901
|
|
|
887
902
|
|
|
@@ -100,19 +100,29 @@ 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,
|
|
106
113
|
env_values: dict[str, Any] | None = None,
|
|
107
114
|
override_values: dict[str, Any] | None = None,
|
|
115
|
+
*,
|
|
116
|
+
include_process_env: bool = True,
|
|
108
117
|
) -> None:
|
|
118
|
+
"""Load values, optionally isolating a named profile from process env."""
|
|
109
119
|
env_values = env_values or {}
|
|
110
120
|
override_values = override_values or {}
|
|
111
121
|
for field in cls.get_fields().values():
|
|
112
122
|
value = override_values.get(field.env_key)
|
|
113
123
|
if value is None:
|
|
114
124
|
value = env_values.get(field.env_key)
|
|
115
|
-
if value is None:
|
|
125
|
+
if value is None and include_process_env:
|
|
116
126
|
value = os.getenv(field.env_key)
|
|
117
127
|
field.value = field.default if value is None else value
|
|
118
128
|
|
|
@@ -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.15
|
|
4
4
|
Summary: ChatArch typed environment profile manager
|
|
5
5
|
Author-email: rexwzh <1073853456@qq.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -94,6 +94,8 @@ 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` / `chatenv test -t example --profile work`。命名 profile 只使用自身字段与 schema 默认值,不切换 active,也不借用默认凭据。
|
|
98
|
+
|
|
97
99
|
```text
|
|
98
100
|
chatenv
|
|
99
101
|
├── --help # Show this message and exit.
|
|
@@ -118,7 +120,7 @@ chatenv
|
|
|
118
120
|
├── set [KEY-VALUE] [--interactive] # Set a configuration value in the matching active typed env file.
|
|
119
121
|
├── save [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Save current active values as a named profile.
|
|
120
122
|
├── delete [NAME] [--type CONFIG-TYPES] [--yes] [--interactive] # Delete a named profile for one config type.
|
|
121
|
-
└── test [--target TARGET] [--interactive] # Test a
|
|
123
|
+
└── test [PROFILE] [--target TARGET] [--profile NAME] [--interactive] # Test active configuration or a named PROFILE for one target.
|
|
122
124
|
```
|
|
123
125
|
|
|
124
126
|
## 常用命令
|
|
@@ -58,7 +58,7 @@ def test_public_docs_keep_live_cli_tree_contract() -> None:
|
|
|
58
58
|
"├── token # Manage generic runtime token profiles.",
|
|
59
59
|
"│ ├── refresh <SERVICE> [PROFILE]",
|
|
60
60
|
"│ ├── import <SERVICE> [PROFILE]",
|
|
61
|
-
"└── test [--target TARGET]",
|
|
61
|
+
"└── test [PROFILE] [--target TARGET]",
|
|
62
62
|
]
|
|
63
63
|
for rel in ("README.md", "README.en.md", "docs/cli.md", "docs/cli.en.md"):
|
|
64
64
|
text = Path(rel).read_text(encoding="utf-8")
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""Configuration test selection must not silently validate other credentials."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from click.testing import CliRunner
|
|
5
|
+
|
|
6
|
+
from chatenv.cli import cli
|
|
7
|
+
from chatenv.configs import OpenAIConfig
|
|
8
|
+
from chatenv.fields import BaseEnvConfig, EnvField
|
|
9
|
+
from chatenv.store import EnvStore
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ProbeConfig(BaseEnvConfig):
|
|
13
|
+
_title = "Test Profile Probe"
|
|
14
|
+
_aliases = ["profile-probe"]
|
|
15
|
+
_storage_dir = "ProfileProbe"
|
|
16
|
+
|
|
17
|
+
PROBE_SECRET = EnvField("PROFILE_PROBE_SECRET", is_sensitive=True)
|
|
18
|
+
PROBE_URL = EnvField("PROFILE_PROBE_URL", default="https://default.invalid")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@pytest.fixture
|
|
22
|
+
def probe(monkeypatch, tmp_path):
|
|
23
|
+
calls = []
|
|
24
|
+
|
|
25
|
+
def test_config(cls):
|
|
26
|
+
calls.append({name: field.value for name, field in cls.get_fields().items()})
|
|
27
|
+
|
|
28
|
+
monkeypatch.setattr(ProbeConfig, "test", classmethod(test_config))
|
|
29
|
+
monkeypatch.delenv("PROFILE_PROBE_SECRET", raising=False)
|
|
30
|
+
monkeypatch.delenv("PROFILE_PROBE_URL", raising=False)
|
|
31
|
+
home = tmp_path / "arch"
|
|
32
|
+
return CliRunner(), home, EnvStore(home / "envs"), calls
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_test_without_profile_loads_active_from_selected_home(probe, monkeypatch, tmp_path):
|
|
36
|
+
runner, home, store, calls = probe
|
|
37
|
+
monkeypatch.setenv("CHATARCH_HOME", str(tmp_path / "other-home"))
|
|
38
|
+
monkeypatch.setenv("PROFILE_PROBE_SECRET", "process-secret")
|
|
39
|
+
store.save_active(ProbeConfig, {"PROFILE_PROBE_SECRET": "active-secret"})
|
|
40
|
+
|
|
41
|
+
result = runner.invoke(cli, ["--home", str(home), "test", "-t", "profile-probe", "-I"])
|
|
42
|
+
|
|
43
|
+
assert result.exit_code == 0, result.output
|
|
44
|
+
assert calls == [{"PROBE_SECRET": "active-secret", "PROBE_URL": "https://default.invalid"}]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_test_without_profile_preserves_process_fallback(probe, monkeypatch):
|
|
48
|
+
runner, home, store, calls = probe
|
|
49
|
+
monkeypatch.setenv("PROFILE_PROBE_SECRET", "process-secret")
|
|
50
|
+
|
|
51
|
+
result = runner.invoke(cli, ["--home", str(home), "test", "-t", "profile-probe"])
|
|
52
|
+
|
|
53
|
+
assert result.exit_code == 0, result.output
|
|
54
|
+
assert calls[0]["PROBE_SECRET"] == "process-secret"
|
|
55
|
+
assert not store.active_path(ProbeConfig).exists()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@pytest.mark.parametrize("name", ["work", "work.env"])
|
|
59
|
+
def test_test_named_profile_is_isolated_and_does_not_activate(probe, monkeypatch, name):
|
|
60
|
+
runner, home, store, calls = probe
|
|
61
|
+
active = store.save_active(ProbeConfig, {"PROFILE_PROBE_SECRET": "active-secret"})
|
|
62
|
+
profile = store.save_profile(ProbeConfig, "work", {"PROFILE_PROBE_SECRET": "work-secret"})
|
|
63
|
+
original_active = active.read_bytes()
|
|
64
|
+
original_profile = profile.read_bytes()
|
|
65
|
+
monkeypatch.setenv("PROFILE_PROBE_SECRET", "process-secret")
|
|
66
|
+
monkeypatch.setenv("PROFILE_PROBE_URL", "https://process.invalid")
|
|
67
|
+
monkeypatch.setattr(OpenAIConfig.OPENAI_API_KEY, "value", "unrelated-state")
|
|
68
|
+
store.save_active(OpenAIConfig, {"OPENAI_API_KEY": "unrelated-file-secret"})
|
|
69
|
+
|
|
70
|
+
result = runner.invoke(cli, ["--home", str(home), "test", "-t", "profile-probe", name])
|
|
71
|
+
|
|
72
|
+
assert result.exit_code == 0, result.output
|
|
73
|
+
assert calls == [{"PROBE_SECRET": "work-secret", "PROBE_URL": "https://default.invalid"}]
|
|
74
|
+
assert active.read_bytes() == original_active
|
|
75
|
+
assert profile.read_bytes() == original_profile
|
|
76
|
+
assert OpenAIConfig.OPENAI_API_KEY.value == "unrelated-state"
|
|
77
|
+
assert "work" in result.output
|
|
78
|
+
for secret in ("work-secret", "active-secret", "process-secret"):
|
|
79
|
+
assert secret not in result.output
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_named_profile_missing_secret_does_not_reuse_other_credentials(probe, monkeypatch):
|
|
83
|
+
runner, home, store, calls = probe
|
|
84
|
+
store.save_active(ProbeConfig, {"PROFILE_PROBE_SECRET": "active-secret"})
|
|
85
|
+
store.save_profile(ProbeConfig, "empty", {})
|
|
86
|
+
monkeypatch.setenv("PROFILE_PROBE_SECRET", "process-secret")
|
|
87
|
+
monkeypatch.setattr(ProbeConfig.PROBE_SECRET, "value", "previous-command-secret")
|
|
88
|
+
|
|
89
|
+
result = runner.invoke(cli, ["--home", str(home), "test", "-t", "profile-probe", "empty"])
|
|
90
|
+
|
|
91
|
+
assert result.exit_code == 0, result.output
|
|
92
|
+
assert calls == [{"PROBE_SECRET": None, "PROBE_URL": "https://default.invalid"}]
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def test_missing_named_profile_fails_without_testing_or_changing_active(probe):
|
|
96
|
+
runner, home, store, calls = probe
|
|
97
|
+
active = store.save_active(ProbeConfig, {"PROFILE_PROBE_SECRET": "active-secret"})
|
|
98
|
+
original = active.read_bytes()
|
|
99
|
+
|
|
100
|
+
result = runner.invoke(cli, ["--home", str(home), "test", "-t", "profile-probe", "missing"])
|
|
101
|
+
|
|
102
|
+
assert result.exit_code != 0
|
|
103
|
+
assert "missing" in result.output
|
|
104
|
+
assert "not found" in result.output.lower()
|
|
105
|
+
assert calls == []
|
|
106
|
+
assert active.read_bytes() == original
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_default_after_named_profile_reloads_active(probe):
|
|
110
|
+
runner, home, store, calls = probe
|
|
111
|
+
store.save_active(ProbeConfig, {"PROFILE_PROBE_SECRET": "active-secret"})
|
|
112
|
+
store.save_profile(ProbeConfig, "work", {"PROFILE_PROBE_SECRET": "work-secret"})
|
|
113
|
+
args = ["--home", str(home), "test", "-t", "profile-probe"]
|
|
114
|
+
|
|
115
|
+
named = runner.invoke(cli, [*args, "work"])
|
|
116
|
+
active = runner.invoke(cli, args)
|
|
117
|
+
|
|
118
|
+
assert named.exit_code == 0, named.output
|
|
119
|
+
assert active.exit_code == 0, active.output
|
|
120
|
+
assert [call["PROBE_SECRET"] for call in calls] == ["work-secret", "active-secret"]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_load_from_sources_can_explicitly_disable_process_fallback(monkeypatch):
|
|
124
|
+
monkeypatch.setenv("PROFILE_PROBE_SECRET", "process-secret")
|
|
125
|
+
monkeypatch.setenv("PROFILE_PROBE_URL", "https://process.invalid")
|
|
126
|
+
|
|
127
|
+
ProbeConfig.load_from_sources(env_values={}, include_process_env=False)
|
|
128
|
+
|
|
129
|
+
assert ProbeConfig.PROBE_SECRET.value is None
|
|
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
|