chatenv 0.2.12__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.
Files changed (32) hide show
  1. {chatenv-0.2.12/src/chatenv.egg-info → chatenv-0.2.14}/PKG-INFO +5 -3
  2. {chatenv-0.2.12 → chatenv-0.2.14}/README.md +4 -2
  3. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/__init__.py +1 -1
  4. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/cli.py +20 -3
  5. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/fields.py +4 -1
  6. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/utils.py +3 -2
  7. {chatenv-0.2.12 → chatenv-0.2.14/src/chatenv.egg-info}/PKG-INFO +5 -3
  8. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv.egg-info/SOURCES.txt +2 -0
  9. {chatenv-0.2.12 → chatenv-0.2.14}/tests/test_chatenv_core.py +6 -3
  10. {chatenv-0.2.12 → chatenv-0.2.14}/tests/test_docs_contract.py +1 -1
  11. chatenv-0.2.14/tests/test_secret_display.py +66 -0
  12. chatenv-0.2.14/tests/test_test_profiles.py +130 -0
  13. {chatenv-0.2.12 → chatenv-0.2.14}/tests/test_version.py +12 -1
  14. {chatenv-0.2.12 → chatenv-0.2.14}/LICENSE +0 -0
  15. {chatenv-0.2.12 → chatenv-0.2.14}/pyproject.toml +0 -0
  16. {chatenv-0.2.12 → chatenv-0.2.14}/setup.cfg +0 -0
  17. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/configs.py +0 -0
  18. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/discovery.py +0 -0
  19. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/paste.py +0 -0
  20. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/paths.py +0 -0
  21. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/policy.py +0 -0
  22. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/presets/__init__.py +0 -0
  23. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/registry.py +0 -0
  24. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/source_chain.py +0 -0
  25. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/store.py +0 -0
  26. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/token_refreshers.py +0 -0
  27. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv/tokens.py +0 -0
  28. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv.egg-info/dependency_links.txt +0 -0
  29. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv.egg-info/entry_points.txt +0 -0
  30. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv.egg-info/requires.txt +0 -0
  31. {chatenv-0.2.12 → chatenv-0.2.14}/src/chatenv.egg-info/top_level.txt +0 -0
  32. {chatenv-0.2.12 → 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.12
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 registered configuration schema.
123
+ └── test [PROFILE] [--target TARGET] [--interactive] # Test active configuration or a named PROFILE for one target.
122
124
  ```
123
125
 
124
126
  ## 常用命令
@@ -134,7 +136,7 @@ chatenv token refresh PyPI RexWzh
134
136
  chatenv token status PyPI RexWzh
135
137
  ```
136
138
 
137
- 敏感值默认 mask;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
139
+ 敏感值默认完整遮罩:`init` 的已有值提示、默认 `cat` 和 `status --detail` 不展示密码/密钥的首尾片段;明确使用 `cat --no-mask` 才主动取原值。遮罩仅影响显示,不把星号写回 profile;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
138
140
 
139
141
  ## Python API
140
142
 
@@ -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 registered configuration schema.
92
+ └── test [PROFILE] [--target TARGET] [--interactive] # Test active configuration or a named PROFILE for one target.
91
93
  ```
92
94
 
93
95
  ## 常用命令
@@ -103,7 +105,7 @@ chatenv token refresh PyPI RexWzh
103
105
  chatenv token status PyPI RexWzh
104
106
  ```
105
107
 
106
- 敏感值默认 mask;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
108
+ 敏感值默认完整遮罩:`init` 的已有值提示、默认 `cat` 和 `status --detail` 不展示密码/密钥的首尾片段;明确使用 `cat --no-mask` 才主动取原值。遮罩仅影响显示,不把星号写回 profile;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
107
109
 
108
110
  ## Python API
109
111
 
@@ -39,4 +39,4 @@ __all__ = [
39
39
  "__version__",
40
40
  ]
41
41
 
42
- __version__ = "0.2.12"
42
+ __version__ = "0.2.14"
@@ -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 registered configuration schema."""
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,10 +1,11 @@
1
1
  from __future__ import annotations
2
2
 
3
3
 
4
- def mask_secret(value: object, *, visible: int = 8) -> str:
4
+ def mask_secret(value: object, *, visible: int = 0) -> str:
5
+ """Fully hide values by default; fingerprints require explicit opt-in."""
5
6
  text = "" if value is None else str(value)
6
7
  if not text:
7
8
  return ""
8
- if len(text) <= visible * 2:
9
+ if visible <= 0 or len(text) <= visible * 2:
9
10
  return "*" * len(text)
10
11
  return f"{text[:visible]}{'*' * (len(text) - visible * 2)}{text[-visible:]}"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: chatenv
3
- Version: 0.2.12
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 registered configuration schema.
123
+ └── test [PROFILE] [--target TARGET] [--interactive] # Test active configuration or a named PROFILE for one target.
122
124
  ```
123
125
 
124
126
  ## 常用命令
@@ -134,7 +136,7 @@ chatenv token refresh PyPI RexWzh
134
136
  chatenv token status PyPI RexWzh
135
137
  ```
136
138
 
137
- 敏感值默认 mask;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
139
+ 敏感值默认完整遮罩:`init` 的已有值提示、默认 `cat` 和 `status --detail` 不展示密码/密钥的首尾片段;明确使用 `cat --no-mask` 才主动取原值。遮罩仅影响显示,不把星号写回 profile;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
138
140
 
139
141
  ## Python API
140
142
 
@@ -24,5 +24,7 @@ src/chatenv.egg-info/top_level.txt
24
24
  src/chatenv/presets/__init__.py
25
25
  tests/test_chatenv_core.py
26
26
  tests/test_docs_contract.py
27
+ tests/test_secret_display.py
28
+ tests/test_test_profiles.py
27
29
  tests/test_version.py
28
30
  tests/test_workflow_contract.py
@@ -573,9 +573,12 @@ def test_cli_paste_active_and_cat(tmp_path):
573
573
  cat = runner.invoke(cli, ["--home", str(home), "cat", "-t", "unit"])
574
574
  assert cat.exit_code == 0, cat.output
575
575
  assert "UNIT_VALUE='from-cli'" in cat.output
576
- assert "sk-abcde" in cat.output
577
- assert "123456" in cat.output
578
- assert "abcdefghijklmnopqrstuvwxyz" not in cat.output
576
+ saved = EnvStore(home / "envs").load_active(UnitConfig)["UNIT_KEY"]
577
+ assert saved not in cat.output
578
+ assert "UNIT_KEY='" + "*" * len(saved) + "'" in cat.output
579
+ raw = runner.invoke(cli, ["--home", str(home), "cat", "-t", "unit", "--no-mask"])
580
+ assert raw.exit_code == 0
581
+ assert "UNIT_KEY='" + saved + "'" in raw.output
579
582
 
580
583
 
581
584
  def test_cli_cat_output_with_blank_lines_can_be_pasted_to_profile(tmp_path):
@@ -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,66 @@
1
+ from types import SimpleNamespace
2
+ import stat
3
+
4
+ import click
5
+ import pytest
6
+ from click.testing import CliRunner
7
+
8
+ import chatenv.cli as cli_module
9
+ from chatenv.cli import cli
10
+ from chatenv.fields import BaseEnvConfig, EnvField
11
+ from chatenv.store import EnvStore
12
+ from chatenv.utils import mask_secret
13
+
14
+ CANARY = 'DUMMY_CANARY_SECRET_VALUE_LONG_123456789'
15
+
16
+ class SecretDisplayConfig(BaseEnvConfig):
17
+ _title = 'Secret Display Regression'
18
+ _aliases = ['secret-display-regression']
19
+ _storage_dir = 'SecretDisplayRegression'
20
+ DISPLAY_PASSWORD = EnvField('DISPLAY_PASSWORD', is_sensitive=True)
21
+
22
+ @pytest.mark.parametrize('value', ['dummy', CANARY, '假密码仅测试01234567890123456789'])
23
+ def test_default_mask_is_complete(value):
24
+ assert mask_secret(value) == '*' * len(value)
25
+
26
+ def test_zero_visibility_never_appends_original():
27
+ assert mask_secret(CANARY, visible=0) == '*' * len(CANARY)
28
+
29
+ def test_explicit_fingerprint_remains_opt_in():
30
+ assert mask_secret(CANARY, visible=3) == CANARY[:3] + '*' * (len(CANARY)-6) + CANARY[-3:]
31
+
32
+ def test_init_masks_existing_fragments_and_retains_on_enter(monkeypatch, tmp_path):
33
+ home = tmp_path/'arch'
34
+ store = EnvStore(home/'envs')
35
+ store.save_active(SecretDisplayConfig, {'DISPLAY_PASSWORD': CANARY})
36
+ prompts = []
37
+ def ask(prompt, **kwargs):
38
+ prompts.append(kwargs)
39
+ click.echo(prompt)
40
+ return ''
41
+ monkeypatch.setattr(cli_module,'load_config_providers',lambda:None)
42
+ monkeypatch.setattr(cli_module,'resolve_interactive_mode',lambda *a,**k:SimpleNamespace(force_interactive=False,can_prompt=True,need_prompt=True))
43
+ monkeypatch.setattr(cli_module,'ask_text',ask)
44
+ result = CliRunner().invoke(cli,['--home',str(home),'init','-t','secret-display-regression','-i'])
45
+ assert result.exit_code == 0, result.output
46
+ assert CANARY[:8] not in result.output and CANARY[-8:] not in result.output
47
+ assert prompts[0]['password'] is True and prompts[0]['default'] == ''
48
+ assert store.load_active(SecretDisplayConfig)['DISPLAY_PASSWORD'] == CANARY
49
+ assert stat.S_IMODE(store.active_path(SecretDisplayConfig).stat().st_mode) == 0o600
50
+
51
+ def test_cat_masks_fragments_by_default(monkeypatch,tmp_path):
52
+ home=tmp_path/'arch'
53
+ EnvStore(home/'envs').save_active(SecretDisplayConfig,{'DISPLAY_PASSWORD':CANARY})
54
+ monkeypatch.setattr(cli_module,'load_config_providers',lambda:None)
55
+ result=CliRunner().invoke(cli,['--home',str(home),'cat','-t','secret-display-regression'])
56
+ assert result.exit_code==0,result.output
57
+ assert CANARY[:8] not in result.output and CANARY[-8:] not in result.output
58
+ assert "DISPLAY_PASSWORD='"+'*'*len(CANARY)+"'" in result.output
59
+
60
+ def test_status_masks_sensitive_default(monkeypatch,tmp_path):
61
+ monkeypatch.setattr(SecretDisplayConfig.DISPLAY_PASSWORD,'default',CANARY)
62
+ monkeypatch.setattr(cli_module,'load_config_providers',lambda:None)
63
+ result=CliRunner().invoke(cli,['--home',str(tmp_path/'arch'),'status','-t','secret-display-regression','--detail'])
64
+ assert result.exit_code==0,result.output
65
+ assert CANARY[:8] not in result.output and CANARY[-8:] not in result.output
66
+ assert 'sensitive=yes' in result.output
@@ -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"
@@ -3,8 +3,19 @@ from chatenv.cli import cli
3
3
  from click.testing import CliRunner
4
4
 
5
5
 
6
+ def test_release_workflow_cannot_publish_from_a_branch_dispatch():
7
+ from pathlib import Path
8
+
9
+ workflow = Path('.github/workflows/publish.yml').read_text(encoding='utf-8')
10
+ assert 'test "${GITHUB_REF_TYPE}" = "tag"' in workflow
11
+ assert "if: github.event_name == 'push'" not in workflow
12
+ assert workflow.index('Require release tag reference') < workflow.index('Publish to PyPI (OIDC)')
13
+ assert workflow.index('Check tag matches package version') < workflow.index('Publish to PyPI (OIDC)')
14
+ assert workflow.index('Check release commit is on default branch') < workflow.index('Publish to PyPI (OIDC)')
15
+
16
+
6
17
  def test_version_present():
7
- assert __version__ == "0.2.12"
18
+ assert __version__ == "0.2.14"
8
19
 
9
20
 
10
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