chatenv 0.2.14__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.
Files changed (32) hide show
  1. {chatenv-0.2.14/src/chatenv.egg-info → chatenv-0.2.15}/PKG-INFO +3 -3
  2. {chatenv-0.2.14 → chatenv-0.2.15}/README.md +2 -2
  3. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/__init__.py +1 -1
  4. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/cli.py +14 -16
  5. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/fields.py +7 -0
  6. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/store.py +25 -2
  7. {chatenv-0.2.14 → chatenv-0.2.15/src/chatenv.egg-info}/PKG-INFO +3 -3
  8. {chatenv-0.2.14 → chatenv-0.2.15}/tests/test_test_profiles.py +82 -0
  9. {chatenv-0.2.14 → chatenv-0.2.15}/tests/test_version.py +1 -1
  10. {chatenv-0.2.14 → chatenv-0.2.15}/LICENSE +0 -0
  11. {chatenv-0.2.14 → chatenv-0.2.15}/pyproject.toml +0 -0
  12. {chatenv-0.2.14 → chatenv-0.2.15}/setup.cfg +0 -0
  13. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/configs.py +0 -0
  14. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/discovery.py +0 -0
  15. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/paste.py +0 -0
  16. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/paths.py +0 -0
  17. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/policy.py +0 -0
  18. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/presets/__init__.py +0 -0
  19. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/registry.py +0 -0
  20. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/source_chain.py +0 -0
  21. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/token_refreshers.py +0 -0
  22. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/tokens.py +0 -0
  23. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv/utils.py +0 -0
  24. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv.egg-info/SOURCES.txt +0 -0
  25. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv.egg-info/dependency_links.txt +0 -0
  26. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv.egg-info/entry_points.txt +0 -0
  27. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv.egg-info/requires.txt +0 -0
  28. {chatenv-0.2.14 → chatenv-0.2.15}/src/chatenv.egg-info/top_level.txt +0 -0
  29. {chatenv-0.2.14 → chatenv-0.2.15}/tests/test_chatenv_core.py +0 -0
  30. {chatenv-0.2.14 → chatenv-0.2.15}/tests/test_docs_contract.py +0 -0
  31. {chatenv-0.2.14 → chatenv-0.2.15}/tests/test_secret_display.py +0 -0
  32. {chatenv-0.2.14 → 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.14
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,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
  ## 常用命令
@@ -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
  ## 常用命令
@@ -39,4 +39,4 @@ __all__ = [
39
39
  "__version__",
40
40
  ]
41
41
 
42
- __version__ = "0.2.14"
42
+ __version__ = "0.2.15"
@@ -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
- 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
- )
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,
@@ -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 {key: value for key, value in dotenv_values(file_path).items() if value is not None}
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.14
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,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
  ## 常用命令
@@ -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)
@@ -15,7 +15,7 @@ def test_release_workflow_cannot_publish_from_a_branch_dispatch():
15
15
 
16
16
 
17
17
  def test_version_present():
18
- assert __version__ == "0.2.14"
18
+ assert __version__ == "0.2.15"
19
19
 
20
20
 
21
21
  def test_cli_version_option():
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes