chatenv 0.2.11__tar.gz → 0.2.13__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.11/src/chatenv.egg-info → chatenv-0.2.13}/PKG-INFO +15 -2
- {chatenv-0.2.11 → chatenv-0.2.13}/README.md +14 -1
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/__init__.py +17 -2
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/cli.py +19 -11
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/configs.py +16 -1
- chatenv-0.2.13/src/chatenv/policy.py +80 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/utils.py +3 -2
- {chatenv-0.2.11 → chatenv-0.2.13/src/chatenv.egg-info}/PKG-INFO +15 -2
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv.egg-info/SOURCES.txt +2 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/tests/test_chatenv_core.py +289 -4
- chatenv-0.2.13/tests/test_secret_display.py +66 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/tests/test_version.py +12 -1
- {chatenv-0.2.11 → chatenv-0.2.13}/LICENSE +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/pyproject.toml +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/setup.cfg +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/discovery.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/fields.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/paste.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/paths.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/presets/__init__.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/registry.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/source_chain.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/store.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/token_refreshers.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv/tokens.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv.egg-info/dependency_links.txt +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv.egg-info/entry_points.txt +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv.egg-info/requires.txt +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/src/chatenv.egg-info/top_level.txt +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/tests/test_docs_contract.py +0 -0
- {chatenv-0.2.11 → chatenv-0.2.13}/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.13
|
|
4
4
|
Summary: ChatArch typed environment profile manager
|
|
5
5
|
Author-email: rexwzh <1073853456@qq.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -77,6 +77,19 @@ $CHATARCH_HOME/tokens/ # generated runtime tokens/sessions, parallel to env p
|
|
|
77
77
|
|
|
78
78
|
ChatEnv 只负责 stable env/profile 与 runtime token-store 的存储规则,不额外创建 config/cache/data/state,也不把 `tokens/` 当作第二个手工维护 secret/env 层。
|
|
79
79
|
|
|
80
|
+
## 自动补问设置
|
|
81
|
+
|
|
82
|
+
`CHATARCH_AUTO_PROMPT` 是 ChatEnv 内置、非敏感的 `ChatArch` typed 字段,默认字符串值为 `true`。它的 active profile 固定存储在 `$CHATARCH_HOME/envs/ChatArch/.env`,类型别名为 `chatarch`:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
chatenv set CHATARCH_AUTO_PROMPT=false
|
|
86
|
+
chatenv cat -t chatarch
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
当 ChatEnv 缺少需要补问的命令输入时,优先级依次为显式 `-i/-I`、进程环境变量 `CHATARCH_AUTO_PROMPT`、所选 home 下的 `ChatArch/.env` active profile、默认值 `true`。`-i` 仍要求可交互 TTY;`-I` 始终禁用补问。`0`、`false`、`no`、`off` 关闭默认补问,其他字符串保持启用语义。
|
|
90
|
+
|
|
91
|
+
active-profile 集成目前只由 ChatEnv CLI 实现;其他 ChatArch CLI 仍需自行接入该 profile。进程环境变量仍是可供已支持它的 CLI 共享的覆盖方式。
|
|
92
|
+
|
|
80
93
|
## CLI 树
|
|
81
94
|
|
|
82
95
|
`chatenv --tree` 从当前安装包的 Click 注册表实时输出带参数签名的完整命令面;`chatenv --tree-brief` 读取同一注册表,但省略参数签名。
|
|
@@ -121,7 +134,7 @@ chatenv token refresh PyPI RexWzh
|
|
|
121
134
|
chatenv token status PyPI RexWzh
|
|
122
135
|
```
|
|
123
136
|
|
|
124
|
-
|
|
137
|
+
敏感值默认完整遮罩:`init` 的已有值提示、默认 `cat` 和 `status --detail` 不展示密码/密钥的首尾片段;明确使用 `cat --no-mask` 才主动取原值。遮罩仅影响显示,不把星号写回 profile;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
|
|
125
138
|
|
|
126
139
|
## Python API
|
|
127
140
|
|
|
@@ -46,6 +46,19 @@ $CHATARCH_HOME/tokens/ # generated runtime tokens/sessions, parallel to env p
|
|
|
46
46
|
|
|
47
47
|
ChatEnv 只负责 stable env/profile 与 runtime token-store 的存储规则,不额外创建 config/cache/data/state,也不把 `tokens/` 当作第二个手工维护 secret/env 层。
|
|
48
48
|
|
|
49
|
+
## 自动补问设置
|
|
50
|
+
|
|
51
|
+
`CHATARCH_AUTO_PROMPT` 是 ChatEnv 内置、非敏感的 `ChatArch` typed 字段,默认字符串值为 `true`。它的 active profile 固定存储在 `$CHATARCH_HOME/envs/ChatArch/.env`,类型别名为 `chatarch`:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
chatenv set CHATARCH_AUTO_PROMPT=false
|
|
55
|
+
chatenv cat -t chatarch
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
当 ChatEnv 缺少需要补问的命令输入时,优先级依次为显式 `-i/-I`、进程环境变量 `CHATARCH_AUTO_PROMPT`、所选 home 下的 `ChatArch/.env` active profile、默认值 `true`。`-i` 仍要求可交互 TTY;`-I` 始终禁用补问。`0`、`false`、`no`、`off` 关闭默认补问,其他字符串保持启用语义。
|
|
59
|
+
|
|
60
|
+
active-profile 集成目前只由 ChatEnv CLI 实现;其他 ChatArch CLI 仍需自行接入该 profile。进程环境变量仍是可供已支持它的 CLI 共享的覆盖方式。
|
|
61
|
+
|
|
49
62
|
## CLI 树
|
|
50
63
|
|
|
51
64
|
`chatenv --tree` 从当前安装包的 Click 注册表实时输出带参数签名的完整命令面;`chatenv --tree-brief` 读取同一注册表,但省略参数签名。
|
|
@@ -90,7 +103,7 @@ chatenv token refresh PyPI RexWzh
|
|
|
90
103
|
chatenv token status PyPI RexWzh
|
|
91
104
|
```
|
|
92
105
|
|
|
93
|
-
|
|
106
|
+
敏感值默认完整遮罩:`init` 的已有值提示、默认 `cat` 和 `status --detail` 不展示密码/密钥的首尾片段;明确使用 `cat --no-mask` 才主动取原值。遮罩仅影响显示,不把星号写回 profile;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
|
|
94
107
|
|
|
95
108
|
## Python API
|
|
96
109
|
|
|
@@ -5,11 +5,20 @@ from .paths import ChatArchPaths, get_paths
|
|
|
5
5
|
from .store import EnvStore
|
|
6
6
|
from .token_refreshers import TokenRefreshResult
|
|
7
7
|
from .tokens import TokenStore
|
|
8
|
-
from .configs import FeishuConfig, OpenAIConfig
|
|
8
|
+
from .configs import ChatArchConfig, FeishuConfig, OpenAIConfig
|
|
9
9
|
from .discovery import get_provider_configs, get_provider_errors, load_config_providers
|
|
10
|
+
from .policy import (
|
|
11
|
+
AUTO_PROMPT_DEFAULT,
|
|
12
|
+
AUTO_PROMPT_ENV_VAR,
|
|
13
|
+
auto_prompt_enabled,
|
|
14
|
+
auto_prompt_value_enabled,
|
|
15
|
+
resolve_auto_prompt_enabled,
|
|
16
|
+
resolve_auto_prompt_value,
|
|
17
|
+
)
|
|
10
18
|
|
|
11
19
|
__all__ = [
|
|
12
20
|
"BaseEnvConfig",
|
|
21
|
+
"ChatArchConfig",
|
|
13
22
|
"ChatArchPaths",
|
|
14
23
|
"EnvField",
|
|
15
24
|
"EnvStore",
|
|
@@ -17,11 +26,17 @@ __all__ = [
|
|
|
17
26
|
"OpenAIConfig",
|
|
18
27
|
"TokenRefreshResult",
|
|
19
28
|
"TokenStore",
|
|
29
|
+
"AUTO_PROMPT_DEFAULT",
|
|
30
|
+
"AUTO_PROMPT_ENV_VAR",
|
|
31
|
+
"auto_prompt_enabled",
|
|
32
|
+
"auto_prompt_value_enabled",
|
|
20
33
|
"get_provider_configs",
|
|
21
34
|
"get_provider_errors",
|
|
22
35
|
"get_paths",
|
|
23
36
|
"load_config_providers",
|
|
37
|
+
"resolve_auto_prompt_enabled",
|
|
38
|
+
"resolve_auto_prompt_value",
|
|
24
39
|
"__version__",
|
|
25
40
|
]
|
|
26
41
|
|
|
27
|
-
__version__ = "0.2.
|
|
42
|
+
__version__ = "0.2.13"
|
|
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
4
|
import sys
|
|
5
|
-
import os
|
|
6
5
|
from pathlib import Path
|
|
7
6
|
import click
|
|
8
7
|
|
|
@@ -26,6 +25,7 @@ from .discovery import get_provider_errors, load_config_providers
|
|
|
26
25
|
from .fields import BaseEnvConfig, EnvField, normalize_profile_name
|
|
27
26
|
from .paste import iter_fields_for_values, parse_pasted_env_text
|
|
28
27
|
from .paths import get_paths
|
|
28
|
+
from .policy import AUTO_PROMPT_ENV_VAR, FALSE_VALUES, resolve_auto_prompt_enabled
|
|
29
29
|
from .registry import resolve_config_types
|
|
30
30
|
from .store import EnvStore
|
|
31
31
|
from .token_refreshers import refresh_token as refresh_runtime_token
|
|
@@ -59,15 +59,21 @@ TEST_TARGET_SCHEMA = CommandSchema(
|
|
|
59
59
|
)
|
|
60
60
|
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
def _selected_home_for_auto_prompt() -> Path | None:
|
|
63
|
+
"""Read the selected root from the active Click context without mutation."""
|
|
64
|
+
context = click.get_current_context(silent=True)
|
|
65
|
+
while context is not None:
|
|
66
|
+
if isinstance(context.obj, dict):
|
|
67
|
+
paths = context.obj.get("paths")
|
|
68
|
+
if paths is not None:
|
|
69
|
+
return paths.home_dir
|
|
70
|
+
context = context.parent
|
|
71
|
+
return None
|
|
64
72
|
|
|
65
73
|
|
|
66
|
-
def auto_prompt_enabled() -> bool:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return True
|
|
70
|
-
return value.strip().lower() not in FALSE_VALUES
|
|
74
|
+
def auto_prompt_enabled(home: str | Path | None = None) -> bool:
|
|
75
|
+
"""Return ChatEnv's process/profile/default auto-prompt policy."""
|
|
76
|
+
return resolve_auto_prompt_enabled(home)
|
|
71
77
|
|
|
72
78
|
|
|
73
79
|
def resolve_interactive_mode(
|
|
@@ -77,8 +83,10 @@ def resolve_interactive_mode(
|
|
|
77
83
|
respect_auto_prompt_env: bool = False,
|
|
78
84
|
):
|
|
79
85
|
effective_auto_prompt_condition = auto_prompt_condition
|
|
80
|
-
if respect_auto_prompt_env:
|
|
81
|
-
effective_auto_prompt_condition =
|
|
86
|
+
if respect_auto_prompt_env and interactive is None and auto_prompt_condition:
|
|
87
|
+
effective_auto_prompt_condition = auto_prompt_enabled(
|
|
88
|
+
_selected_home_for_auto_prompt()
|
|
89
|
+
)
|
|
82
90
|
return _chatstyle_resolve_interactive_mode(
|
|
83
91
|
interactive,
|
|
84
92
|
auto_prompt_condition=effective_auto_prompt_condition,
|
|
@@ -144,13 +152,13 @@ class TokenCommandGroup(OrderedGroup):
|
|
|
144
152
|
@click.pass_context
|
|
145
153
|
def cli(ctx: click.Context, home: Path | None):
|
|
146
154
|
"""Manage typed env profiles under $CHATARCH_HOME/envs."""
|
|
147
|
-
load_config_providers()
|
|
148
155
|
paths = get_paths(home)
|
|
149
156
|
ctx.obj = {
|
|
150
157
|
"paths": paths,
|
|
151
158
|
"store": EnvStore(paths.envs_dir),
|
|
152
159
|
"token_store": TokenStore(tokens_dir=paths.tokens_dir),
|
|
153
160
|
}
|
|
161
|
+
load_config_providers()
|
|
154
162
|
|
|
155
163
|
|
|
156
164
|
def _store(ctx: click.Context) -> EnvStore:
|
|
@@ -10,6 +10,21 @@ from __future__ import annotations
|
|
|
10
10
|
from .fields import BaseEnvConfig, EnvField
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
class ChatArchConfig(BaseEnvConfig):
|
|
14
|
+
"""Shared ChatArch runtime preferences."""
|
|
15
|
+
|
|
16
|
+
_title = "ChatArch Configuration"
|
|
17
|
+
_aliases = ["chatarch"]
|
|
18
|
+
_storage_dir = "ChatArch"
|
|
19
|
+
_order = 0
|
|
20
|
+
|
|
21
|
+
CHATARCH_AUTO_PROMPT = EnvField(
|
|
22
|
+
"CHATARCH_AUTO_PROMPT",
|
|
23
|
+
default="true",
|
|
24
|
+
desc="Enable ChatEnv default prompts when command input is missing.",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
13
28
|
class OpenAIConfig(BaseEnvConfig):
|
|
14
29
|
"""Shared OpenAI-compatible model provider configuration."""
|
|
15
30
|
|
|
@@ -100,4 +115,4 @@ class FeishuConfig(BaseEnvConfig):
|
|
|
100
115
|
)
|
|
101
116
|
|
|
102
117
|
|
|
103
|
-
__all__ = ["OpenAIConfig", "FeishuConfig"]
|
|
118
|
+
__all__ = ["ChatArchConfig", "OpenAIConfig", "FeishuConfig"]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""Runtime policy for ChatEnv's missing-input prompts.
|
|
2
|
+
|
|
3
|
+
This module intentionally reads only the active ChatArch profile. It does not
|
|
4
|
+
load profile values into ``os.environ`` or into ``EnvField.value`` state.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
from collections.abc import Mapping
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from .configs import ChatArchConfig
|
|
14
|
+
from .paths import get_paths
|
|
15
|
+
from .store import EnvStore
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
AUTO_PROMPT_ENV_VAR = "CHATARCH_AUTO_PROMPT"
|
|
19
|
+
AUTO_PROMPT_DEFAULT = "true"
|
|
20
|
+
FALSE_VALUES = frozenset({"0", "false", "no", "off"})
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def auto_prompt_value_enabled(value: str | None) -> bool:
|
|
24
|
+
"""Interpret a prompt setting using the established false-value semantics."""
|
|
25
|
+
if value is None:
|
|
26
|
+
return True
|
|
27
|
+
return value.strip().lower() not in FALSE_VALUES
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def resolve_auto_prompt_value(
|
|
31
|
+
home: str | Path | None = None,
|
|
32
|
+
*,
|
|
33
|
+
environment: Mapping[str, str] | None = None,
|
|
34
|
+
) -> str:
|
|
35
|
+
"""Return the effective raw auto-prompt setting for one selected home.
|
|
36
|
+
|
|
37
|
+
A process setting has priority. Without it, only
|
|
38
|
+
``envs/ChatArch/.env`` under the selected ChatArch home is consulted.
|
|
39
|
+
"""
|
|
40
|
+
source_environment = os.environ if environment is None else environment
|
|
41
|
+
process_value = source_environment.get(AUTO_PROMPT_ENV_VAR)
|
|
42
|
+
if process_value is not None:
|
|
43
|
+
return process_value
|
|
44
|
+
|
|
45
|
+
paths = get_paths(home)
|
|
46
|
+
profile_value = EnvStore(paths.envs_dir).load_active(ChatArchConfig).get(
|
|
47
|
+
AUTO_PROMPT_ENV_VAR
|
|
48
|
+
)
|
|
49
|
+
return AUTO_PROMPT_DEFAULT if profile_value is None else profile_value
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def resolve_auto_prompt_enabled(
|
|
53
|
+
home: str | Path | None = None,
|
|
54
|
+
*,
|
|
55
|
+
environment: Mapping[str, str] | None = None,
|
|
56
|
+
) -> bool:
|
|
57
|
+
"""Resolve process, active-profile, then default prompt policy."""
|
|
58
|
+
return auto_prompt_value_enabled(
|
|
59
|
+
resolve_auto_prompt_value(home, environment=environment)
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def auto_prompt_enabled(
|
|
64
|
+
home: str | Path | None = None,
|
|
65
|
+
*,
|
|
66
|
+
environment: Mapping[str, str] | None = None,
|
|
67
|
+
) -> bool:
|
|
68
|
+
"""Compatibility-friendly name for :func:`resolve_auto_prompt_enabled`."""
|
|
69
|
+
return resolve_auto_prompt_enabled(home, environment=environment)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
__all__ = [
|
|
73
|
+
"AUTO_PROMPT_DEFAULT",
|
|
74
|
+
"AUTO_PROMPT_ENV_VAR",
|
|
75
|
+
"FALSE_VALUES",
|
|
76
|
+
"auto_prompt_enabled",
|
|
77
|
+
"auto_prompt_value_enabled",
|
|
78
|
+
"resolve_auto_prompt_enabled",
|
|
79
|
+
"resolve_auto_prompt_value",
|
|
80
|
+
]
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
def mask_secret(value: object, *, visible: int =
|
|
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.
|
|
3
|
+
Version: 0.2.13
|
|
4
4
|
Summary: ChatArch typed environment profile manager
|
|
5
5
|
Author-email: rexwzh <1073853456@qq.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -77,6 +77,19 @@ $CHATARCH_HOME/tokens/ # generated runtime tokens/sessions, parallel to env p
|
|
|
77
77
|
|
|
78
78
|
ChatEnv 只负责 stable env/profile 与 runtime token-store 的存储规则,不额外创建 config/cache/data/state,也不把 `tokens/` 当作第二个手工维护 secret/env 层。
|
|
79
79
|
|
|
80
|
+
## 自动补问设置
|
|
81
|
+
|
|
82
|
+
`CHATARCH_AUTO_PROMPT` 是 ChatEnv 内置、非敏感的 `ChatArch` typed 字段,默认字符串值为 `true`。它的 active profile 固定存储在 `$CHATARCH_HOME/envs/ChatArch/.env`,类型别名为 `chatarch`:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
chatenv set CHATARCH_AUTO_PROMPT=false
|
|
86
|
+
chatenv cat -t chatarch
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
当 ChatEnv 缺少需要补问的命令输入时,优先级依次为显式 `-i/-I`、进程环境变量 `CHATARCH_AUTO_PROMPT`、所选 home 下的 `ChatArch/.env` active profile、默认值 `true`。`-i` 仍要求可交互 TTY;`-I` 始终禁用补问。`0`、`false`、`no`、`off` 关闭默认补问,其他字符串保持启用语义。
|
|
90
|
+
|
|
91
|
+
active-profile 集成目前只由 ChatEnv CLI 实现;其他 ChatArch CLI 仍需自行接入该 profile。进程环境变量仍是可供已支持它的 CLI 共享的覆盖方式。
|
|
92
|
+
|
|
80
93
|
## CLI 树
|
|
81
94
|
|
|
82
95
|
`chatenv --tree` 从当前安装包的 Click 注册表实时输出带参数签名的完整命令面;`chatenv --tree-brief` 读取同一注册表,但省略参数签名。
|
|
@@ -121,7 +134,7 @@ chatenv token refresh PyPI RexWzh
|
|
|
121
134
|
chatenv token status PyPI RexWzh
|
|
122
135
|
```
|
|
123
136
|
|
|
124
|
-
|
|
137
|
+
敏感值默认完整遮罩:`init` 的已有值提示、默认 `cat` 和 `status --detail` 不展示密码/密钥的首尾片段;明确使用 `cat --no-mask` 才主动取原值。遮罩仅影响显示,不把星号写回 profile;`token status/list/clear` 只输出 safe metadata,不输出 raw token/cookie/CSRF values。
|
|
125
138
|
|
|
126
139
|
## Python API
|
|
127
140
|
|
|
@@ -8,6 +8,7 @@ src/chatenv/discovery.py
|
|
|
8
8
|
src/chatenv/fields.py
|
|
9
9
|
src/chatenv/paste.py
|
|
10
10
|
src/chatenv/paths.py
|
|
11
|
+
src/chatenv/policy.py
|
|
11
12
|
src/chatenv/registry.py
|
|
12
13
|
src/chatenv/source_chain.py
|
|
13
14
|
src/chatenv/store.py
|
|
@@ -23,5 +24,6 @@ src/chatenv.egg-info/top_level.txt
|
|
|
23
24
|
src/chatenv/presets/__init__.py
|
|
24
25
|
tests/test_chatenv_core.py
|
|
25
26
|
tests/test_docs_contract.py
|
|
27
|
+
tests/test_secret_display.py
|
|
26
28
|
tests/test_version.py
|
|
27
29
|
tests/test_workflow_contract.py
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import json
|
|
2
|
+
import os
|
|
2
3
|
from pathlib import Path
|
|
4
|
+
import subprocess
|
|
5
|
+
import sys
|
|
3
6
|
from types import SimpleNamespace
|
|
4
7
|
|
|
5
8
|
import pytest
|
|
6
9
|
from click.testing import CliRunner
|
|
10
|
+
from chatenv import ChatArchConfig as ExportedChatArchConfig
|
|
11
|
+
from chatenv import auto_prompt_enabled as exported_auto_prompt_enabled
|
|
7
12
|
import chatenv.discovery as discovery_module
|
|
8
13
|
import chatenv.cli as cli_module
|
|
9
14
|
from chatenv.cli import cli
|
|
10
|
-
from chatenv.configs import FeishuConfig, OpenAIConfig
|
|
15
|
+
from chatenv.configs import ChatArchConfig, FeishuConfig, OpenAIConfig
|
|
11
16
|
from chatenv.fields import BaseEnvConfig, EnvField
|
|
17
|
+
from chatenv.policy import resolve_auto_prompt_enabled
|
|
12
18
|
from chatenv.paste import parse_pasted_env_text
|
|
13
19
|
from chatenv.paths import get_paths
|
|
14
20
|
from chatenv.store import EnvStore
|
|
@@ -567,9 +573,12 @@ def test_cli_paste_active_and_cat(tmp_path):
|
|
|
567
573
|
cat = runner.invoke(cli, ["--home", str(home), "cat", "-t", "unit"])
|
|
568
574
|
assert cat.exit_code == 0, cat.output
|
|
569
575
|
assert "UNIT_VALUE='from-cli'" in cat.output
|
|
570
|
-
|
|
571
|
-
assert
|
|
572
|
-
assert "
|
|
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
|
|
573
582
|
|
|
574
583
|
|
|
575
584
|
def test_cli_cat_output_with_blank_lines_can_be_pasted_to_profile(tmp_path):
|
|
@@ -698,6 +707,282 @@ def test_chatenv_auto_prompt_env_false_keeps_force_interactive(monkeypatch):
|
|
|
698
707
|
assert resolution.need_prompt is True
|
|
699
708
|
|
|
700
709
|
|
|
710
|
+
def test_builtin_chatarch_auto_prompt_schema_is_registered_and_non_sensitive():
|
|
711
|
+
assert BaseEnvConfig.get_config_by_alias("chatarch") is ChatArchConfig
|
|
712
|
+
assert ExportedChatArchConfig is ChatArchConfig
|
|
713
|
+
assert ChatArchConfig.get_storage_name() == "ChatArch"
|
|
714
|
+
|
|
715
|
+
field = ChatArchConfig.get_fields()["CHATARCH_AUTO_PROMPT"]
|
|
716
|
+
assert field.env_key == "CHATARCH_AUTO_PROMPT"
|
|
717
|
+
assert field.default == "true"
|
|
718
|
+
assert field.is_sensitive is False
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
@pytest.mark.parametrize("false_value", ["0", "false", "no", "off"])
|
|
722
|
+
def test_auto_prompt_policy_keeps_false_and_unknown_string_semantics(false_value, tmp_path):
|
|
723
|
+
home = tmp_path / "arch"
|
|
724
|
+
|
|
725
|
+
assert (
|
|
726
|
+
resolve_auto_prompt_enabled(
|
|
727
|
+
home,
|
|
728
|
+
environment={"CHATARCH_AUTO_PROMPT": false_value},
|
|
729
|
+
)
|
|
730
|
+
is False
|
|
731
|
+
)
|
|
732
|
+
assert (
|
|
733
|
+
resolve_auto_prompt_enabled(
|
|
734
|
+
home,
|
|
735
|
+
environment={"CHATARCH_AUTO_PROMPT": "enabled-by-process"},
|
|
736
|
+
)
|
|
737
|
+
is True
|
|
738
|
+
)
|
|
739
|
+
assert (
|
|
740
|
+
exported_auto_prompt_enabled(
|
|
741
|
+
home,
|
|
742
|
+
environment={"CHATARCH_AUTO_PROMPT": "true"},
|
|
743
|
+
)
|
|
744
|
+
is True
|
|
745
|
+
)
|
|
746
|
+
|
|
747
|
+
|
|
748
|
+
def test_chatarch_auto_prompt_default_is_visible_through_status_cat_and_get(tmp_path, monkeypatch):
|
|
749
|
+
runner = CliRunner()
|
|
750
|
+
home = tmp_path / "arch"
|
|
751
|
+
monkeypatch.delenv("CHATARCH_AUTO_PROMPT", raising=False)
|
|
752
|
+
|
|
753
|
+
status = runner.invoke(cli, ["--home", str(home), "status", "-t", "chatarch", "--detail"])
|
|
754
|
+
cat = runner.invoke(cli, ["--home", str(home), "cat", "-t", "chatarch"])
|
|
755
|
+
get = runner.invoke(cli, ["--home", str(home), "get", "CHATARCH_AUTO_PROMPT"])
|
|
756
|
+
|
|
757
|
+
assert status.exit_code == 0, status.output
|
|
758
|
+
assert "ChatArch | title=ChatArch Configuration" in status.output
|
|
759
|
+
assert "aliases=chatarch" in status.output
|
|
760
|
+
assert "CHATARCH_AUTO_PROMPT" in status.output
|
|
761
|
+
assert "default=true" in status.output
|
|
762
|
+
assert cat.exit_code == 0, cat.output
|
|
763
|
+
assert "CHATARCH_AUTO_PROMPT='true'" in cat.output
|
|
764
|
+
assert get.exit_code == 0, get.output
|
|
765
|
+
assert get.output == "true\n"
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
def test_chatarch_auto_prompt_set_save_new_and_use_round_trip(tmp_path):
|
|
769
|
+
runner = CliRunner()
|
|
770
|
+
home = tmp_path / "arch"
|
|
771
|
+
|
|
772
|
+
set_false = runner.invoke(
|
|
773
|
+
cli,
|
|
774
|
+
["--home", str(home), "set", "CHATARCH_AUTO_PROMPT=false"],
|
|
775
|
+
)
|
|
776
|
+
save_false = runner.invoke(
|
|
777
|
+
cli,
|
|
778
|
+
["--home", str(home), "save", "-t", "chatarch", "disabled"],
|
|
779
|
+
)
|
|
780
|
+
set_true = runner.invoke(
|
|
781
|
+
cli,
|
|
782
|
+
["--home", str(home), "set", "CHATARCH_AUTO_PROMPT=true"],
|
|
783
|
+
)
|
|
784
|
+
new_true = runner.invoke(
|
|
785
|
+
cli,
|
|
786
|
+
["--home", str(home), "new", "-t", "chatarch", "enabled"],
|
|
787
|
+
)
|
|
788
|
+
use_false = runner.invoke(
|
|
789
|
+
cli,
|
|
790
|
+
["--home", str(home), "use", "-t", "chatarch", "disabled"],
|
|
791
|
+
)
|
|
792
|
+
get_false = runner.invoke(
|
|
793
|
+
cli,
|
|
794
|
+
["--home", str(home), "get", "CHATARCH_AUTO_PROMPT"],
|
|
795
|
+
)
|
|
796
|
+
|
|
797
|
+
for result in (set_false, save_false, set_true, new_true, use_false, get_false):
|
|
798
|
+
assert result.exit_code == 0, result.output
|
|
799
|
+
assert (home / "envs" / "ChatArch" / "disabled.env").read_text(encoding="utf-8").count(
|
|
800
|
+
"CHATARCH_AUTO_PROMPT='false'"
|
|
801
|
+
) == 1
|
|
802
|
+
assert (home / "envs" / "ChatArch" / "enabled.env").read_text(encoding="utf-8").count(
|
|
803
|
+
"CHATARCH_AUTO_PROMPT='true'"
|
|
804
|
+
) == 1
|
|
805
|
+
assert get_false.output == "false\n"
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
def _set_chatarch_auto_prompt(home: Path, value: str) -> None:
|
|
809
|
+
EnvStore(home / "envs").save_active(
|
|
810
|
+
ChatArchConfig,
|
|
811
|
+
{"CHATARCH_AUTO_PROMPT": value},
|
|
812
|
+
)
|
|
813
|
+
|
|
814
|
+
|
|
815
|
+
def _mock_tty_interactive_mode(monkeypatch):
|
|
816
|
+
monkeypatch.setattr(
|
|
817
|
+
"chatenv.cli._chatstyle_resolve_interactive_mode",
|
|
818
|
+
_tty_resolution,
|
|
819
|
+
)
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
def test_profile_auto_prompt_false_and_true_control_missing_input_in_mocked_tty(tmp_path, monkeypatch):
|
|
823
|
+
runner = CliRunner()
|
|
824
|
+
disabled_home = tmp_path / "disabled"
|
|
825
|
+
enabled_home = tmp_path / "enabled"
|
|
826
|
+
_set_chatarch_auto_prompt(disabled_home, "false")
|
|
827
|
+
_set_chatarch_auto_prompt(enabled_home, "true")
|
|
828
|
+
monkeypatch.delenv("CHATARCH_AUTO_PROMPT", raising=False)
|
|
829
|
+
_mock_tty_interactive_mode(monkeypatch)
|
|
830
|
+
selected: list[str] = []
|
|
831
|
+
monkeypatch.setattr(
|
|
832
|
+
"chatenv.cli.ask_select",
|
|
833
|
+
lambda message, choices: selected.append(message) or ChatArchConfig,
|
|
834
|
+
)
|
|
835
|
+
|
|
836
|
+
disabled = runner.invoke(cli, ["--home", str(disabled_home), "new", "disabled-profile"])
|
|
837
|
+
enabled = runner.invoke(cli, ["--home", str(enabled_home), "new", "enabled-profile"])
|
|
838
|
+
|
|
839
|
+
assert disabled.exit_code != 0
|
|
840
|
+
assert "new requires --type/-t outside interactive mode" in disabled.output
|
|
841
|
+
assert enabled.exit_code == 0, enabled.output
|
|
842
|
+
assert selected == ["Select one config type for new:"]
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
def test_process_auto_prompt_environment_overrides_active_profile_in_both_directions(tmp_path, monkeypatch):
|
|
846
|
+
runner = CliRunner()
|
|
847
|
+
profile_false_home = tmp_path / "profile-false"
|
|
848
|
+
profile_true_home = tmp_path / "profile-true"
|
|
849
|
+
_set_chatarch_auto_prompt(profile_false_home, "off")
|
|
850
|
+
_set_chatarch_auto_prompt(profile_true_home, "true")
|
|
851
|
+
_mock_tty_interactive_mode(monkeypatch)
|
|
852
|
+
selected: list[str] = []
|
|
853
|
+
monkeypatch.setattr(
|
|
854
|
+
"chatenv.cli.ask_select",
|
|
855
|
+
lambda message, choices: selected.append(message) or ChatArchConfig,
|
|
856
|
+
)
|
|
857
|
+
|
|
858
|
+
monkeypatch.setenv("CHATARCH_AUTO_PROMPT", "enabled-by-process")
|
|
859
|
+
process_true = runner.invoke(cli, ["--home", str(profile_false_home), "new", "process-true"])
|
|
860
|
+
|
|
861
|
+
monkeypatch.setenv("CHATARCH_AUTO_PROMPT", "0")
|
|
862
|
+
process_false = runner.invoke(cli, ["--home", str(profile_true_home), "new", "process-false"])
|
|
863
|
+
|
|
864
|
+
assert process_true.exit_code == 0, process_true.output
|
|
865
|
+
assert process_false.exit_code != 0
|
|
866
|
+
assert "new requires --type/-t outside interactive mode" in process_false.output
|
|
867
|
+
assert selected == ["Select one config type for new:"]
|
|
868
|
+
|
|
869
|
+
|
|
870
|
+
def test_explicit_interactive_flags_override_profile_but_force_mode_needs_a_tty(tmp_path, monkeypatch):
|
|
871
|
+
runner = CliRunner()
|
|
872
|
+
home = tmp_path / "arch"
|
|
873
|
+
_set_chatarch_auto_prompt(home, "false")
|
|
874
|
+
monkeypatch.delenv("CHATARCH_AUTO_PROMPT", raising=False)
|
|
875
|
+
selected: list[str] = []
|
|
876
|
+
with monkeypatch.context() as tty_monkeypatch:
|
|
877
|
+
_mock_tty_interactive_mode(tty_monkeypatch)
|
|
878
|
+
tty_monkeypatch.setattr(
|
|
879
|
+
"chatenv.cli.ask_select",
|
|
880
|
+
lambda message, choices: selected.append(message) or ChatArchConfig,
|
|
881
|
+
)
|
|
882
|
+
|
|
883
|
+
force_interactive = runner.invoke(cli, ["--home", str(home), "new", "-i", "forced"])
|
|
884
|
+
force_noninteractive = runner.invoke(cli, ["--home", str(home), "new", "-I", "disabled"])
|
|
885
|
+
|
|
886
|
+
assert force_interactive.exit_code == 0, force_interactive.output
|
|
887
|
+
assert force_noninteractive.exit_code != 0
|
|
888
|
+
assert "new requires --type/-t outside interactive mode" in force_noninteractive.output
|
|
889
|
+
assert selected == ["Select one config type for new:"]
|
|
890
|
+
|
|
891
|
+
no_tty = runner.invoke(cli, ["--home", str(home), "get", "-i"])
|
|
892
|
+
assert no_tty.exit_code != 0
|
|
893
|
+
assert "tty" in no_tty.output.lower()
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
def test_auto_prompt_policy_uses_explicit_home_before_chatarch_home(tmp_path, monkeypatch):
|
|
897
|
+
runner = CliRunner()
|
|
898
|
+
inherited_home = tmp_path / "inherited"
|
|
899
|
+
selected_home = tmp_path / "selected"
|
|
900
|
+
_set_chatarch_auto_prompt(inherited_home, "true")
|
|
901
|
+
monkeypatch.setenv("CHATARCH_HOME", str(inherited_home))
|
|
902
|
+
monkeypatch.delenv("CHATARCH_AUTO_PROMPT", raising=False)
|
|
903
|
+
_mock_tty_interactive_mode(monkeypatch)
|
|
904
|
+
monkeypatch.setattr("chatenv.cli.ask_select", lambda message, choices: ChatArchConfig)
|
|
905
|
+
|
|
906
|
+
set_result = runner.invoke(
|
|
907
|
+
cli,
|
|
908
|
+
["--home", str(selected_home), "set", "CHATARCH_AUTO_PROMPT=false"],
|
|
909
|
+
)
|
|
910
|
+
|
|
911
|
+
result = runner.invoke(cli, ["--home", str(selected_home), "new", "isolated"])
|
|
912
|
+
|
|
913
|
+
assert set_result.exit_code == 0, set_result.output
|
|
914
|
+
assert EnvStore(selected_home / "envs").load_active(ChatArchConfig) == {
|
|
915
|
+
"CHATARCH_AUTO_PROMPT": "false"
|
|
916
|
+
}
|
|
917
|
+
assert EnvStore(inherited_home / "envs").load_active(ChatArchConfig) == {
|
|
918
|
+
"CHATARCH_AUTO_PROMPT": "true"
|
|
919
|
+
}
|
|
920
|
+
assert result.exit_code != 0
|
|
921
|
+
assert "new requires --type/-t outside interactive mode" in result.output
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
def test_auto_prompt_policy_does_not_leak_class_field_state_between_cli_homes(tmp_path, monkeypatch):
|
|
925
|
+
runner = CliRunner()
|
|
926
|
+
disabled_home = tmp_path / "disabled"
|
|
927
|
+
fresh_home = tmp_path / "fresh"
|
|
928
|
+
_set_chatarch_auto_prompt(disabled_home, "false")
|
|
929
|
+
monkeypatch.delenv("CHATARCH_AUTO_PROMPT", raising=False)
|
|
930
|
+
_mock_tty_interactive_mode(monkeypatch)
|
|
931
|
+
selected: list[str] = []
|
|
932
|
+
monkeypatch.setattr(
|
|
933
|
+
"chatenv.cli.ask_select",
|
|
934
|
+
lambda message, choices: selected.append(message) or ChatArchConfig,
|
|
935
|
+
)
|
|
936
|
+
|
|
937
|
+
cat = runner.invoke(cli, ["--home", str(disabled_home), "cat", "-t", "chatarch"])
|
|
938
|
+
disabled = runner.invoke(cli, ["--home", str(disabled_home), "new", "disabled-profile"])
|
|
939
|
+
fresh = runner.invoke(cli, ["--home", str(fresh_home), "new", "fresh-profile"])
|
|
940
|
+
|
|
941
|
+
assert cat.exit_code == 0, cat.output
|
|
942
|
+
assert disabled.exit_code != 0
|
|
943
|
+
assert fresh.exit_code == 0, fresh.output
|
|
944
|
+
assert selected == ["Select one config type for new:"]
|
|
945
|
+
|
|
946
|
+
|
|
947
|
+
def test_new_python_process_uses_persisted_auto_prompt_false(tmp_path):
|
|
948
|
+
home = tmp_path / "arch"
|
|
949
|
+
_set_chatarch_auto_prompt(home, "false")
|
|
950
|
+
project_root = Path(__file__).resolve().parents[1]
|
|
951
|
+
environment = os.environ.copy()
|
|
952
|
+
environment.pop("CHATARCH_AUTO_PROMPT", None)
|
|
953
|
+
environment["PYTHONPATH"] = str(project_root / "src")
|
|
954
|
+
script = """
|
|
955
|
+
import sys
|
|
956
|
+
from types import SimpleNamespace
|
|
957
|
+
from click.testing import CliRunner
|
|
958
|
+
import chatenv.cli as cli_module
|
|
959
|
+
|
|
960
|
+
def tty_resolution(interactive=None, *, auto_prompt_condition=True):
|
|
961
|
+
return SimpleNamespace(
|
|
962
|
+
interactive=interactive,
|
|
963
|
+
can_prompt=True,
|
|
964
|
+
force_interactive=interactive is True,
|
|
965
|
+
need_prompt=interactive is True or (interactive is None and auto_prompt_condition),
|
|
966
|
+
)
|
|
967
|
+
|
|
968
|
+
cli_module._chatstyle_resolve_interactive_mode = tty_resolution
|
|
969
|
+
result = CliRunner().invoke(cli_module.cli, ["--home", sys.argv[1], "get"])
|
|
970
|
+
if result.exit_code == 0 or "required" not in result.output.lower():
|
|
971
|
+
raise SystemExit(result.output)
|
|
972
|
+
"""
|
|
973
|
+
|
|
974
|
+
completed = subprocess.run(
|
|
975
|
+
[sys.executable, "-c", script, str(home)],
|
|
976
|
+
cwd=project_root,
|
|
977
|
+
env=environment,
|
|
978
|
+
capture_output=True,
|
|
979
|
+
text=True,
|
|
980
|
+
check=False,
|
|
981
|
+
)
|
|
982
|
+
|
|
983
|
+
assert completed.returncode == 0, completed.stdout + completed.stderr
|
|
984
|
+
|
|
985
|
+
|
|
701
986
|
def test_cli_new_missing_type_errors_when_auto_prompt_disabled(
|
|
702
987
|
tmp_path, monkeypatch
|
|
703
988
|
):
|
|
@@ -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
|
|
@@ -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.
|
|
18
|
+
assert __version__ == "0.2.13"
|
|
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
|
|
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
|