chatenv 0.2.13__tar.gz → 0.2.14__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.14}/PKG-INFO +4 -2
- {chatenv-0.2.13 → chatenv-0.2.14}/README.md +3 -1
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/__init__.py +1 -1
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/cli.py +20 -3
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/fields.py +4 -1
- {chatenv-0.2.13 → chatenv-0.2.14/src/chatenv.egg-info}/PKG-INFO +4 -2
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv.egg-info/SOURCES.txt +1 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/tests/test_docs_contract.py +1 -1
- chatenv-0.2.14/tests/test_test_profiles.py +130 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/tests/test_version.py +1 -1
- {chatenv-0.2.13 → chatenv-0.2.14}/LICENSE +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/pyproject.toml +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/setup.cfg +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/configs.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/discovery.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/paste.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/paths.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/policy.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/presets/__init__.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/registry.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/source_chain.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/store.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/token_refreshers.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/tokens.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv/utils.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv.egg-info/dependency_links.txt +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv.egg-info/entry_points.txt +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv.egg-info/requires.txt +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/src/chatenv.egg-info/top_level.txt +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/tests/test_chatenv_core.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/tests/test_secret_display.py +0 -0
- {chatenv-0.2.13 → chatenv-0.2.14}/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.14
|
|
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`。命名 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] [--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`。命名 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] [--interactive] # Test active configuration or a named PROFILE for one target.
|
|
91
93
|
```
|
|
92
94
|
|
|
93
95
|
## 常用命令
|
|
@@ -862,16 +862,18 @@ 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.pass_context
|
|
866
868
|
@add_interactive_option
|
|
867
|
-
def test_env(target: str | None, interactive: bool | None):
|
|
868
|
-
"""Test a
|
|
869
|
+
def test_env(ctx: click.Context, profile: str | None, target: str | None, interactive: bool | None):
|
|
870
|
+
"""Test active configuration or a named PROFILE for one target."""
|
|
869
871
|
load_config_providers()
|
|
870
872
|
inputs = resolve_command_inputs(
|
|
871
873
|
schema=TEST_TARGET_SCHEMA,
|
|
872
874
|
provided={"target": target},
|
|
873
875
|
interactive=interactive,
|
|
874
|
-
usage="Usage: chatenv test --target TEXT [-i|-I]",
|
|
876
|
+
usage="Usage: chatenv test [PROFILE] --target TEXT [-i|-I]",
|
|
875
877
|
)
|
|
876
878
|
target = inputs["target"]
|
|
877
879
|
config_cls = BaseEnvConfig.get_config_by_alias(target)
|
|
@@ -882,6 +884,21 @@ def test_env(target: str | None, interactive: bool | None):
|
|
|
882
884
|
aliases = ", ".join(cls._aliases)
|
|
883
885
|
click.echo(f" - {cls._title}: {aliases}")
|
|
884
886
|
raise click.Abort()
|
|
887
|
+
store = _store(ctx)
|
|
888
|
+
if profile is None:
|
|
889
|
+
config_cls.load_from_sources(env_values=store.load_active(config_cls))
|
|
890
|
+
else:
|
|
891
|
+
try:
|
|
892
|
+
path = store.profile_path(config_cls, profile)
|
|
893
|
+
except ValueError as exc:
|
|
894
|
+
raise click.ClickException(str(exc)) from exc
|
|
895
|
+
if not path.is_file():
|
|
896
|
+
raise click.ClickException(f"Environment profile '{path}' not found.")
|
|
897
|
+
config_cls.load_from_sources(
|
|
898
|
+
env_values=store.load_profile(config_cls, profile),
|
|
899
|
+
include_process_env=False,
|
|
900
|
+
)
|
|
901
|
+
click.echo(f"Profile: {config_cls.get_storage_name()}/{path.stem}")
|
|
885
902
|
config_cls.test()
|
|
886
903
|
|
|
887
904
|
|
|
@@ -105,14 +105,17 @@ class BaseEnvConfig:
|
|
|
105
105
|
cls,
|
|
106
106
|
env_values: dict[str, Any] | None = None,
|
|
107
107
|
override_values: dict[str, Any] | None = None,
|
|
108
|
+
*,
|
|
109
|
+
include_process_env: bool = True,
|
|
108
110
|
) -> None:
|
|
111
|
+
"""Load values, optionally isolating a named profile from process env."""
|
|
109
112
|
env_values = env_values or {}
|
|
110
113
|
override_values = override_values or {}
|
|
111
114
|
for field in cls.get_fields().values():
|
|
112
115
|
value = override_values.get(field.env_key)
|
|
113
116
|
if value is None:
|
|
114
117
|
value = env_values.get(field.env_key)
|
|
115
|
-
if value is None:
|
|
118
|
+
if value is None and include_process_env:
|
|
116
119
|
value = os.getenv(field.env_key)
|
|
117
120
|
field.value = field.default if value is None else value
|
|
118
121
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: chatenv
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.14
|
|
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`。命名 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] [--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,130 @@
|
|
|
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"
|
|
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
|
|
File without changes
|