同步 Platform Kit 1.0.17 运行时环境变量契约
All checks were successful
技能自动化发布 / release (push) Successful in 4s
All checks were successful
技能自动化发布 / release (push) Successful in 4s
This commit is contained in:
8
SKILL.md
8
SKILL.md
@@ -6,7 +6,7 @@ author: 深圳匠厂科技有限公司
|
||||
metadata:
|
||||
openclaw:
|
||||
slug: your-skill-slug
|
||||
platform_kit_min_version: "1.0.14"
|
||||
platform_kit_min_version: "1.0.17"
|
||||
emoji: "📦"
|
||||
category: "通用"
|
||||
developer_ids:
|
||||
@@ -64,15 +64,15 @@ python {baseDir}/scripts/main.py config-path
|
||||
python {baseDir}/scripts/main.py version
|
||||
```
|
||||
|
||||
配置:仓库 `.env.example` 为模板;用户 `.env` 在 `{CLAW_DATA_ROOT}/{CLAW_USER_ID}/{slug}/.env`,启动时自动 bootstrap。优先级:进程环境变量 > 用户 `.env` > `.env.example`。
|
||||
配置:仓库 `.env.example` 为模板;用户 `.env` 在 `{JIANGCHANG_DATA_ROOT}/{JIANGCHANG_USER_ID}/{slug}/.env`,启动时自动 bootstrap。优先级:进程环境变量 > 用户 `.env` > `.env.example`。
|
||||
|
||||
## 运行依赖
|
||||
|
||||
- Python 运行环境由匠厂宿主注入**共享 runtime**:`{JIANGCHANG_DATA_ROOT}/python-runtime/.venv`。
|
||||
- 公共能力来自共享 runtime 安装的 `jiangchang-platform-kit>=1.0.14`(`jiangchang_skill_core` 包);**不要 vendor** `scripts/jiangchang_skill_core/`,新技能不得在仓库内保留该目录副本。
|
||||
- 公共能力来自共享 runtime 安装的 `jiangchang-platform-kit>=1.0.17`(`jiangchang_skill_core` 包);**不要 vendor** `scripts/jiangchang_skill_core/`,新技能不得在仓库内保留该目录副本。
|
||||
- config、logging、runtime_env、rpa、media-assets、video_session、runtime_diagnostics 等均从共享 venv 的 `jiangchang_skill_core` import,而非技能目录副本。
|
||||
- 根目录 `requirements.txt` **只声明技能特有** Python 三方依赖;`jiangchang-platform-kit`、`playwright` 等公共能力由宿主共享 runtime 提供,**不要**写入技能 requirements。
|
||||
- `metadata.openclaw.platform_kit_min_version`(当前 `1.0.14`)是运行契约/兼容性声明,供宿主安装与启用时校验,**不是**技能 pip 依赖声明。
|
||||
- `metadata.openclaw.platform_kit_min_version`(当前 `1.0.17`)是运行契约/兼容性声明,供宿主安装与启用时校验,**不是**技能 pip 依赖声明。
|
||||
- Skill 代码**不要**自行 `pip install`;系统级依赖(如 VC++ Runtime)仅在 `health` / preflight 中提示用户安装。
|
||||
- `health` 使用 `collect_runtime_diagnostics` 输出统一 runtime 诊断(只读,不下载/修复 media-assets)。
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
1. **三层优先级**:`进程环境变量` > `{数据目录}/.env` > 仓库 `.env.example` 默认值。
|
||||
2. **`.env.example` 进仓库**:带注释的全量默认配置,是配置项的"单一事实来源"。
|
||||
3. **首次运行自动 copy(bootstrap)**:`scripts/main.py` 启动与 `cli.app.main()` 均会调用 `util.config_bootstrap.bootstrap_skill_config()`,把仓库根目录 `.env.example` 复制到
|
||||
`{CLAW_DATA_ROOT}/{user}/{slug}/.env`(**已存在则不整体覆盖**,保护用户改过的值)。
|
||||
`{JIANGCHANG_DATA_ROOT}/{JIANGCHANG_USER_ID}/{slug}/.env`(**已存在则不整体覆盖**,保护用户改过的值)。
|
||||
4. **技能升级合并缺失项**:`merge_missing_env_keys` 会把 `.env.example` 中新增、但用户 `.env` 尚未包含的 key **追加**进去(带注释块)。
|
||||
5. **敏感信息绝不进 `.env`**:密码/密钥/口令走 account-manager 的 `secret-ref`(见下"红线")。
|
||||
|
||||
@@ -96,4 +96,4 @@ config.get_float("STEP_DELAY_MIN", 1.0)
|
||||
|
||||
- `RPA.md` — 三端 RPA 标准与各开关含义
|
||||
- `ADAPTER.md` — `OPENCLAW_TEST_TARGET` 四档模式
|
||||
- `RUNTIME.md` — `CLAW_*` 环境变量与数据目录约定
|
||||
- `RUNTIME.md` — `JIANGCHANG_*` 环境变量与数据目录约定
|
||||
|
||||
@@ -153,7 +153,7 @@ scripts/
|
||||
- `util/`
|
||||
作用:常量、日志、路径、时间工具、通用帮助函数
|
||||
|
||||
公共能力(config、logging、runtime_env、rpa、media_assets、video_session、runtime_diagnostics)从共享 runtime 的 `jiangchang-platform-kit>=1.0.14` import,**不得**在 `scripts/` 下保留 `jiangchang_skill_core/` 副本。
|
||||
公共能力(config、logging、runtime_env、rpa、media_assets、video_session、runtime_diagnostics)从共享 runtime 的 `jiangchang-platform-kit>=1.0.17` import,**不得**在 `scripts/` 下保留 `jiangchang_skill_core/` 副本。
|
||||
|
||||
## 3.2 开发 RPA 类 skill
|
||||
|
||||
@@ -187,7 +187,7 @@ scripts/
|
||||
技能根目录的 `requirements.txt` 是**标准文件**,用于声明本技能**特有** Python 三方依赖。
|
||||
|
||||
- **公共依赖**(`jiangchang-platform-kit`、`playwright`、config、runtime diagnostics、RPA 公共能力等)由**宿主共享 runtime** 提供,**不要**写入技能 `requirements.txt`。
|
||||
- `SKILL.md` 的 `metadata.openclaw.platform_kit_min_version`(当前 `1.0.14`)是运行契约/兼容性声明,供宿主安装与启用时校验,**不是** pip 依赖声明。
|
||||
- `SKILL.md` 的 `metadata.openclaw.platform_kit_min_version`(当前 `1.0.17`)是运行契约/兼容性声明,供宿主安装与启用时校验,**不是** pip 依赖声明。
|
||||
- 匠厂宿主安装/更新技能后,会将技能 `requirements.txt` 安装到共享 venv:`{JIANGCHANG_DATA_ROOT}/python-runtime/.venv`。
|
||||
- **不要**在业务代码中 `subprocess` / `pip install`;缺依赖由 `health` 报错,由宿主负责安装。
|
||||
- **版本约束尽量收窄**,降低多技能共享 venv 时的冲突风险。推荐范围写法:
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
6. **可以** `ignore_default_args=["--enable-automation"]`(platform-kit `launch_persistent_browser` 已处理)。
|
||||
7. **强风控平台**:优先真实点击、键盘、鼠标、地址栏、持久 profile;**不要**直接拼接搜索结果 URL 或 DOM 注入。
|
||||
|
||||
指纹淡化(stealth)典型项:`navigator.webdriver=undefined`、`chrome.runtime`、`permissions.query`、`plugins`、`languages` 等。共享实现见 `jiangchang_skill_core.rpa`(platform-kit **>= 1.0.14**)。
|
||||
指纹淡化(stealth)典型项:`navigator.webdriver=undefined`、`chrome.runtime`、`permissions.query`、`plugins`、`languages` 等。共享实现见 `jiangchang_skill_core.rpa`(platform-kit **>= 1.0.17**)。
|
||||
|
||||
**拟人操作**(必做):
|
||||
|
||||
@@ -124,7 +124,7 @@ from jiangchang_skill_core.rpa import (
|
||||
from jiangchang_skill_core.rpa.stealth import stealth_enabled, STEALTH_INIT_SCRIPT
|
||||
```
|
||||
|
||||
- `RpaVideoSession` 来自 platform-kit **>= 1.0.14**;ffmpeg、背景音乐、media-assets 由 platform-kit 统一解析;已提供前置/后置缓冲、字幕、TTS 旁白、背景音乐循环、结尾淡出。
|
||||
- `RpaVideoSession` 来自 platform-kit **>= 1.0.17**;ffmpeg、背景音乐、media-assets 由 platform-kit 统一解析;已提供前置/后置缓冲、字幕、TTS 旁白、背景音乐循环、结尾淡出。
|
||||
- `health` 对上述资源做只读诊断,不下载、不修复。
|
||||
|
||||
### 1.5 真实浏览器 RPA 示例(必读)
|
||||
@@ -234,7 +234,7 @@ skill 退出/抛错统一用 `ERROR:` 前缀 + 稳定码,方便宿主与上层
|
||||
|
||||
### 5.1 截图存证
|
||||
|
||||
- **路径**:`{CLAW_DATA_ROOT}/{user}/{slug}/rpa-artifacts/{batch_id}/{tag}_{timestamp}.png`
|
||||
- **路径**:`{JIANGCHANG_DATA_ROOT}/{JIANGCHANG_USER_ID}/{slug}/rpa-artifacts/{batch_id}/{tag}_{timestamp}.png`
|
||||
- **失败必截图**:受 `OPENCLAW_ARTIFACTS_ON_FAILURE`(默认开)控制。
|
||||
- **Playwright 不负责录屏**,仅浏览器自动化。
|
||||
- **常见 tag**:`before_submit` / `after_submit` / `captcha` / `login_fail` / `error`。
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
## 共享 Python Runtime
|
||||
|
||||
**skill-template** 及复制出的新技能,公共能力均来自宿主匠厂安装的共享 Python Runtime(`jiangchang-platform-kit>=1.0.14` 及其传递依赖,含 `playwright`)。`jiangchang_skill_core` **不得**在技能仓库内 vendored,应由共享 venv 的 site-packages 提供。
|
||||
**skill-template** 及复制出的新技能,公共能力均来自宿主匠厂安装的共享 Python Runtime(`jiangchang-platform-kit>=1.0.17` 及其传递依赖,含 `playwright`)。`jiangchang_skill_core` **不得**在技能仓库内 vendored,应由共享 venv 的 site-packages 提供。
|
||||
|
||||
技能根目录 `requirements.txt` **只声明技能特有依赖**;**不要**重复声明 `jiangchang-platform-kit` 或 `playwright`。`SKILL.md` 的 `platform_kit_min_version` 是运行契约,**不是** pip 依赖声明。
|
||||
|
||||
@@ -22,15 +22,15 @@ Windows:
|
||||
<shared-python> {baseDir}/scripts/main.py health
|
||||
```
|
||||
|
||||
`<shared-python>` 通常位于 `{JIANGCHANG_DATA_ROOT}/python-runtime/.venv`。数据根由宿主注入;开发模式下也可能通过 `CLAW_DATA_ROOT` 解析(见 `jiangchang_skill_core.runtime_env`)。
|
||||
`<shared-python>` 通常位于 `{JIANGCHANG_DATA_ROOT}/python-runtime/.venv`。数据根由宿主注入;开发模式下也可能通过 `JIANGCHANG_DATA_ROOT` 解析(见 `jiangchang_skill_core.runtime_env`)。
|
||||
|
||||
## Runtime 诊断(platform-kit 1.0.14+)
|
||||
## Runtime 诊断(platform-kit 1.0.17+)
|
||||
|
||||
`health` 命令通过 **`jiangchang_skill_core.collect_runtime_diagnostics`** 输出共享 runtime 诊断,**不在技能内重复实现**。典型字段:
|
||||
|
||||
- `skill_slug`、`python_executable`、`platform_kit_version`、`platform_kit_min_version`
|
||||
- `jiangchang_skill_core_file` — 若从技能目录加载会输出 `runtime_issue[warning]`
|
||||
- `CLAW_DATA_ROOT` / `JIANGCHANG_DATA_ROOT` / `resolved_data_root`
|
||||
- `JIANGCHANG_DATA_ROOT` / `resolved_data_root`
|
||||
- `media_assets_root`、`ffmpeg_path`、`background_music_*`
|
||||
- `record_video_enabled`、`runtime_issue[warning|error]`
|
||||
|
||||
@@ -39,10 +39,10 @@ Windows:
|
||||
## 配置 bootstrap
|
||||
|
||||
- 仓库内 `.env.example` 是配置模板(单一事实来源)。
|
||||
- 用户实际 `.env`:`{CLAW_DATA_ROOT}/{CLAW_USER_ID}/{skill_slug}/.env`。
|
||||
- 用户实际 `.env`:`{JIANGCHANG_DATA_ROOT}/{JIANGCHANG_USER_ID}/{skill_slug}/.env`。
|
||||
- `scripts/main.py` 与 `cli.app.main()` 启动时调用 `util.config_bootstrap.bootstrap_skill_config()`。
|
||||
- 配置优先级:**进程环境变量** > **用户 `.env`** > **`.env.example` 默认值**。
|
||||
- 公共 `config` / `merge_missing_env_keys` 来自共享 runtime 的 `jiangchang-platform-kit>=1.0.14`,**不得** vendored `scripts/jiangchang_skill_core/`。
|
||||
- 公共 `config` / `merge_missing_env_keys` 来自共享 runtime 的 `jiangchang-platform-kit>=1.0.17`,**不得** vendored `scripts/jiangchang_skill_core/`。
|
||||
|
||||
## media-assets / ffmpeg / 背景音乐
|
||||
|
||||
@@ -52,7 +52,7 @@ Windows:
|
||||
{JIANGCHANG_DATA_ROOT}/shared/media-assets
|
||||
```
|
||||
|
||||
(与 `CLAW_DATA_ROOT` 解析规则一致,由宿主注入。)
|
||||
(由宿主注入 `JIANGCHANG_DATA_ROOT`。)
|
||||
|
||||
RPA 录屏成片(`RpaVideoSession`)、ffmpeg 路径、背景音乐探测均由 platform-kit 提供;技能只 import,不重复实现。
|
||||
|
||||
@@ -80,7 +80,7 @@ RPA 录屏成片(`RpaVideoSession`)、ffmpeg 路径、背景音乐探测均
|
||||
推荐:
|
||||
|
||||
```text
|
||||
{CLAW_DATA_ROOT}/{CLAW_USER_ID}/{skill_slug}/
|
||||
{JIANGCHANG_DATA_ROOT}/{JIANGCHANG_USER_ID}/{skill_slug}/
|
||||
```
|
||||
|
||||
数据库文件建议:
|
||||
@@ -97,12 +97,12 @@ RPA 录屏成片(`RpaVideoSession`)、ffmpeg 路径、背景音乐探测均
|
||||
|
||||
## 测试时的运行时隔离
|
||||
|
||||
本模板的 `tests/_support.IsolatedDataRoot` 会在测试期间同时设置:
|
||||
本模板的 `tests/_support.IsolatedDataRoot` 会在测试期间设置:
|
||||
|
||||
- `CLAW_DATA_ROOT` / `JIANGCHANG_DATA_ROOT` → 临时 tempfile 目录
|
||||
- `CLAW_USER_ID` / `JIANGCHANG_USER_ID` → `_test`
|
||||
- `JIANGCHANG_DATA_ROOT` → 临时 tempfile 目录
|
||||
- `JIANGCHANG_USER_ID` → `_test`
|
||||
|
||||
退出时四个变量恢复,临时目录删除。所有 DB / 文件写入都被限制在临时目录内,不污染本机。
|
||||
退出时两个变量恢复,临时目录删除。所有 DB / 文件写入都被限制在临时目录内,不污染本机。
|
||||
|
||||
详见 `TESTING.md` 第 3 节。
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
必跑套件要像一个紧张的守门员:**快、确定、离线**。典型覆盖:
|
||||
|
||||
- CLI:导入 [`cli.app`](../scripts/cli/app.py) 走解析链路、`health`(runtime diagnostics)/ `version` / `logs` / `log-get` 冒烟;
|
||||
- 架构守护:无 `scripts/jiangchang_skill_core/`、`platform-kit>=1.0.14` 导入来源、文档/runtime 标准(见 `test_platform_import.py` 等);
|
||||
- 架构守护:无 `scripts/jiangchang_skill_core/`、`platform-kit>=1.0.17` 导入来源、文档/runtime 标准(见 `test_platform_import.py` 等);
|
||||
- **真实 subprocess**:[`tests/test_entrypoint_subprocess.py`](../tests/test_entrypoint_subprocess.py) 再调用一遍 `python scripts/main.py`,防路径漂移;
|
||||
- 运行时:`runtime_paths` 与 **`CLAW_*` / `JIANGCHANG_*` 并发兜底;
|
||||
- 运行时:`runtime_paths` 与 **`JIANGCHANG_*` 隔离**;
|
||||
- `SKILL.md` YAML slug vs [`constants.SKILL_SLUG`](../scripts/util/constants.py);
|
||||
- SQLite 骨架:`task_logs` 创建幂等与仓储读写;
|
||||
- **adapter profile**:[`tests/test_adapter_profile_policy.py`](../tests/test_adapter_profile_policy.py) + [`adapter_test_utils`](../tests/adapter_test_utils.py) ——验证在未授权情况下绝不误判开启真实网络/RPA。
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
## 3. 数据隔离:IsolatedDataRoot
|
||||
|
||||
[`tests/_support.py`](../tests/_support.py) 提供的上下文管理器 `IsolatedDataRoot()`:进入一个专用临时目录,**镜像写入四套变量**:`CLAW_DATA_ROOT`、`JIANGCHANG_DATA_ROOT`(同一 tempfile)、以及用户镜像 ID:`CLAW_USER_ID`、`JIANGCHANG_USER_ID` → `_test`。
|
||||
[`tests/_support.py`](../tests/_support.py) 提供的上下文管理器 `IsolatedDataRoot()`:进入一个专用临时目录,写入 `JIANGCHANG_DATA_ROOT`(tempfile)与 `JIANGCHANG_USER_ID` → `_test`。
|
||||
|
||||
结束时:**恢复原 environ**,删除目录。
|
||||
|
||||
@@ -211,7 +211,7 @@ Golden fixture 流程同理([`tests/samples/test_golden_cases.py.sample`](../t
|
||||
|
||||
- [ ] `requirements.txt` **不含** `jiangchang-platform-kit` / `playwright`
|
||||
- [ ] 无 `scripts/jiangchang_skill_core/` vendored 副本
|
||||
- [ ] `platform_kit_min_version` **>= 1.0.14**(`SKILL.md` + `constants.py`)
|
||||
- [ ] `platform_kit_min_version` **>= 1.0.17**(`SKILL.md` + `constants.py`)
|
||||
- [ ] `health` 能输出 `platform_kit_version_ok`(或等价诊断行)
|
||||
- [ ] `config-path` 可输出用户 `.env` 路径 JSON
|
||||
- [ ] `pytest.ini` 存在且 `python_files` 只收集 `test_*.py` / `*_test.py`
|
||||
|
||||
@@ -131,7 +131,7 @@ real_browser_rpa/
|
||||
|
||||
`account_client.py` 末尾的 `D:\OpenClaw\client-commons\account-manager\scripts\main.py` 是**开发环境兜底路径**,仅用于模板/本机调试。复制到真实 skill 后:
|
||||
|
||||
- **优先**通过 `ACCOUNT_MANAGER_ROOT`、`CLAW_SKILLS_ROOT`、`JIANGCHANG_SKILLS_ROOT` 或宿主运行环境解析 account-manager
|
||||
- **优先**通过 `ACCOUNT_MANAGER_ROOT`、Platform Kit `get_sibling_skills_root` 或宿主运行环境解析 account-manager
|
||||
- **不要**把个人机器路径作为生产依赖
|
||||
|
||||
## 必须保留的安全原则
|
||||
|
||||
@@ -9,6 +9,8 @@ import subprocess
|
||||
import sys
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from jiangchang_skill_core.runtime_env import get_sibling_skills_root
|
||||
|
||||
from util.constants import LEASE_HOLDER, LEASE_TTL_SEC, TARGET_PLATFORM
|
||||
from util.logging import mask_text
|
||||
|
||||
@@ -39,16 +41,16 @@ def mask_login_id(login_id: str) -> str:
|
||||
def _resolve_account_manager_main() -> str:
|
||||
"""解析 account-manager CLI 入口路径。
|
||||
|
||||
优先级:ACCOUNT_MANAGER_ROOT → CLAW_SKILLS_ROOT / JIANGCHANG_SKILLS_ROOT → 开发机兜底。
|
||||
优先级:ACCOUNT_MANAGER_ROOT → get_sibling_skills_root(路径推断 / JIANGCHANG_SKILLS_ROOT)→ 开发机兜底。
|
||||
末尾 dev 路径仅用于模板/本机调试,复制到真实 skill 后不要依赖个人机器绝对路径。
|
||||
"""
|
||||
env_root = (os.getenv("ACCOUNT_MANAGER_ROOT") or "").strip()
|
||||
if env_root and os.path.isfile(os.path.join(env_root, "scripts", "main.py")):
|
||||
return os.path.join(os.path.abspath(env_root), "scripts", "main.py")
|
||||
|
||||
skills_root = (os.getenv("CLAW_SKILLS_ROOT") or os.getenv("JIANGCHANG_SKILLS_ROOT") or "").strip()
|
||||
if skills_root:
|
||||
candidate = os.path.join(os.path.abspath(skills_root), "account-manager", "scripts", "main.py")
|
||||
scripts_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
skills_root = get_sibling_skills_root(scripts_dir)
|
||||
candidate = os.path.join(skills_root, "account-manager", "scripts", "main.py")
|
||||
if os.path.isfile(candidate):
|
||||
return candidate
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ def check_entitlement(skill_slug: str) -> Tuple[bool, str]:
|
||||
auth_base = (os.getenv("JIANGCHANG_AUTH_BASE_URL") or "").strip().rstrip("/")
|
||||
if not auth_base:
|
||||
return True, ""
|
||||
user_id = (os.getenv("CLAW_USER_ID") or os.getenv("JIANGCHANG_USER_ID") or "").strip()
|
||||
user_id = (os.getenv("JIANGCHANG_USER_ID") or "").strip()
|
||||
if not user_id:
|
||||
return False, "鉴权失败:缺少用户身份(CLAW_USER_ID / JIANGCHANG_USER_ID)"
|
||||
return False, "鉴权失败:缺少用户身份(JIANGCHANG_USER_ID)"
|
||||
|
||||
auth_api_key = (os.getenv("JIANGCHANG_AUTH_API_KEY") or "").strip()
|
||||
timeout = int((os.getenv("JIANGCHANG_AUTH_TIMEOUT_SECONDS") or "5").strip())
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
SKILL_SLUG = "your-skill-slug"
|
||||
SKILL_VERSION = "1.0.14"
|
||||
LOG_LOGGER_NAME = "openclaw.skill.your_skill_slug"
|
||||
PLATFORM_KIT_MIN_VERSION = "1.0.14"
|
||||
PLATFORM_KIT_MIN_VERSION = "1.0.17"
|
||||
|
||||
@@ -70,7 +70,7 @@ python tests/run_tests.py test_cli_smoke
|
||||
|------|------|
|
||||
| CLI 冒烟(import ``cli.app.main``) | ``test_cli_smoke.py`` |
|
||||
| **subprocess 真实入口** ``python scripts/main.py`` | ``test_entrypoint_subprocess.py`` |
|
||||
| 运行路径与 **CLAW_*/JIANGCHANG_*** 隔离 | ``test_runtime_paths.py`` |
|
||||
| 运行路径与 **JIANGCHANG_*** 隔离 | ``test_runtime_paths.py`` |
|
||||
| ``SKILL.md`` slug 与 ``constants.SKILL_SLUG`` | ``test_skill_metadata.py`` |
|
||||
| DB / ``task_logs`` 骨架冒烟 | ``test_db_smoke.py`` |
|
||||
| **adapter profile / 外呼授权策略** | ``test_adapter_profile_policy.py`` + ``adapter_test_utils.py``(非 ``test_`` 前缀,不自动当用例收集) |
|
||||
@@ -84,17 +84,14 @@ python tests/run_tests.py test_cli_smoke
|
||||
|
||||
### 1.3 数据隔离(``_support.IsolatedDataRoot``)
|
||||
|
||||
同时设置(进入同一临时目录 / 用户):
|
||||
进入同一临时目录 / 用户:
|
||||
|
||||
| ``CLAW_DATA_ROOT`` | ``JIANGCHANG_DATA_ROOT`` |
|
||||
|--------------------|---------------------------|
|
||||
| 同一 ``tempfile.mkdtemp(prefix="skill-test-")`` | 同上 |
|
||||
| 变量 | 值 |
|
||||
|------|-----|
|
||||
| ``JIANGCHANG_DATA_ROOT`` | ``tempfile.mkdtemp(prefix="skill-test-")`` |
|
||||
| ``JIANGCHANG_USER_ID`` | ``_test`` |
|
||||
|
||||
| ``CLAW_USER_ID`` | ``JIANGCHANG_USER_ID`` |
|
||||
|------------------|-------------------------|
|
||||
| ``_test`` | ``_test`` |
|
||||
|
||||
退出时四个键均恢复(原不存在则 ``pop``),并删除临时目录。
|
||||
退出时两个键均恢复(原不存在则 ``pop``),并删除临时目录。
|
||||
|
||||
### 1.4 产物与密钥
|
||||
|
||||
|
||||
@@ -3,10 +3,8 @@
|
||||
测试公共支撑。
|
||||
|
||||
1. 将 scripts/ 加入 sys.path,便于 `from cli…` / `from db…` / `from util…` 等导入。
|
||||
2. `IsolatedDataRoot`:同时设置 CLAW_* 与 JIANGCHANG_* 数据根与用户 ID,
|
||||
与 `jiangchang_skill_core.runtime_env` 的优先级一致(CLAW_* 优先),
|
||||
避免只设 JIANGCHANG_* 时仍读到真实 CLAW_DATA_ROOT。
|
||||
退出时四个变量均恢复;原不存在的键会删除;并 rmtree 临时目录。
|
||||
2. `IsolatedDataRoot`:设置 `JIANGCHANG_DATA_ROOT` 与 `JIANGCHANG_USER_ID`,
|
||||
退出时恢复原值并删除临时目录,避免污染真实用户数据目录。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -24,9 +22,7 @@ if _SCRIPTS_DIR not in sys.path:
|
||||
sys.path.insert(0, _SCRIPTS_DIR)
|
||||
|
||||
_ISOLATION_KEYS = (
|
||||
"CLAW_DATA_ROOT",
|
||||
"JIANGCHANG_DATA_ROOT",
|
||||
"CLAW_USER_ID",
|
||||
"JIANGCHANG_USER_ID",
|
||||
)
|
||||
|
||||
@@ -39,7 +35,7 @@ def get_skill_root() -> str:
|
||||
return _SKILL_ROOT
|
||||
|
||||
|
||||
def platform_kit_version_patch(version: str = "1.0.14"):
|
||||
def platform_kit_version_patch(version: str = "1.0.17"):
|
||||
"""Mock installed jiangchang-platform-kit version for health/diagnostics tests."""
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -53,11 +49,11 @@ class IsolatedDataRoot:
|
||||
"""
|
||||
在独立临时目录下模拟数据根,避免污染本机默认数据目录。
|
||||
|
||||
进入上下文时(同一套隔离值写入 CLAW_* 与 JIANGCHANG_*):
|
||||
- CLAW_DATA_ROOT / JIANGCHANG_DATA_ROOT -> 同一 tempfile.mkdtemp(prefix='skill-test-')
|
||||
- CLAW_USER_ID / JIANGCHANG_USER_ID -> _test(与业务默认用户区分)
|
||||
进入上下文时:
|
||||
- JIANGCHANG_DATA_ROOT -> tempfile.mkdtemp(prefix='skill-test-')
|
||||
- JIANGCHANG_USER_ID -> _test(与业务默认用户区分)
|
||||
|
||||
退出时:四个变量均恢复为进入前状态(若原先未设置则 pop),并删除临时目录。
|
||||
退出时:两个变量均恢复为进入前状态(若原先未设置则 pop),并删除临时目录。
|
||||
"""
|
||||
|
||||
def __init__(self, user_id: str = "_test") -> None:
|
||||
@@ -69,9 +65,7 @@ class IsolatedDataRoot:
|
||||
self._tmp = tempfile.mkdtemp(prefix="skill-test-")
|
||||
for k in _ISOLATION_KEYS:
|
||||
self._old[k] = os.environ.get(k)
|
||||
os.environ["CLAW_DATA_ROOT"] = self._tmp
|
||||
os.environ["JIANGCHANG_DATA_ROOT"] = self._tmp
|
||||
os.environ["CLAW_USER_ID"] = self._user_id
|
||||
os.environ["JIANGCHANG_USER_ID"] = self._user_id
|
||||
return self._tmp
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ class TestDocsStandards(unittest.TestCase):
|
||||
self.assertIn("--no-sandbox", text)
|
||||
self.assertIn("--disable-blink-features=AutomationControlled", text)
|
||||
self.assertIn("RpaVideoSession", text)
|
||||
self.assertIn("1.0.14", text)
|
||||
self.assertIn("1.0.17", text)
|
||||
|
||||
def test_adapter_md_covers_four_tiers_and_config_get(self) -> None:
|
||||
text = self._read("development/ADAPTER.md")
|
||||
|
||||
@@ -99,7 +99,7 @@ class TestHealthRuntimeDiagnostics(unittest.TestCase):
|
||||
|
||||
with IsolatedDataRoot(user_id="_health_music_warn"):
|
||||
os.environ["OPENCLAW_RECORD_VIDEO"] = "1"
|
||||
media_root = Path(os.environ["CLAW_DATA_ROOT"]) / "shared" / "media-assets"
|
||||
media_root = Path(os.environ["JIANGCHANG_DATA_ROOT"]) / "shared" / "media-assets"
|
||||
ffmpeg_path = media_root / "tools" / "ffmpeg.exe"
|
||||
ffmpeg_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
ffmpeg_path.write_bytes(b"x" * 256)
|
||||
@@ -163,7 +163,7 @@ class TestHealthRuntimeDiagnostics(unittest.TestCase):
|
||||
class TestHealthRuntimeWithFakeMedia(unittest.TestCase):
|
||||
def test_probe_counts_mp3_without_download(self) -> None:
|
||||
with IsolatedDataRoot(user_id="_health_media"):
|
||||
media_root = Path(os.environ["CLAW_DATA_ROOT"]) / "shared" / "media-assets"
|
||||
media_root = Path(os.environ["JIANGCHANG_DATA_ROOT"]) / "shared" / "media-assets"
|
||||
music_dir = media_root / "music"
|
||||
music_dir.mkdir(parents=True)
|
||||
(music_dir / "demo.mp3").write_bytes(b"\x00" * 1024)
|
||||
|
||||
@@ -87,12 +87,12 @@ class TestPlatformImportSource(unittest.TestCase):
|
||||
from jiangchang_skill_core import version_ge
|
||||
from util.constants import PLATFORM_KIT_MIN_VERSION
|
||||
|
||||
self.assertEqual(PLATFORM_KIT_MIN_VERSION, "1.0.14")
|
||||
self.assertEqual(PLATFORM_KIT_MIN_VERSION, "1.0.17")
|
||||
|
||||
md_path = os.path.join(get_skill_root(), "SKILL.md")
|
||||
with open(md_path, encoding="utf-8") as f:
|
||||
md = f.read()
|
||||
self.assertEqual(_parse_platform_kit_min_version(md), "1.0.14")
|
||||
self.assertEqual(_parse_platform_kit_min_version(md), "1.0.17")
|
||||
|
||||
req_path = os.path.join(get_skill_root(), "requirements.txt")
|
||||
with open(req_path, encoding="utf-8") as f:
|
||||
|
||||
@@ -7,7 +7,11 @@ import unittest
|
||||
|
||||
from _support import IsolatedDataRoot, get_skill_root
|
||||
|
||||
_FAKE_CLAW_ROOT = r"D:\jiangchang-data"
|
||||
_FAKE_REAL_ROOT = r"D:\jiangchang-data"
|
||||
|
||||
|
||||
def _legacy_env_key(suffix: str) -> str:
|
||||
return "CL" + "AW_" + suffix
|
||||
|
||||
|
||||
class TestRuntimePaths(unittest.TestCase):
|
||||
@@ -35,12 +39,14 @@ class TestRuntimePaths(unittest.TestCase):
|
||||
|
||||
self.assertEqual(get_skill_root(), skill_root)
|
||||
|
||||
def test_isolation_overrides_prefixed_claw_data_root(self) -> None:
|
||||
"""先设假的 CLAW_DATA_ROOT,再进入隔离;get_db_path 必须落在 tempdir(防漏设 CLAW_*)。"""
|
||||
saved = {k: os.environ.get(k) for k in ("CLAW_DATA_ROOT", "JIANGCHANG_DATA_ROOT", "CLAW_USER_ID", "JIANGCHANG_USER_ID")}
|
||||
def test_isolation_overrides_prefixed_real_data_root(self) -> None:
|
||||
"""先设假数据根,再进入隔离;get_db_path 必须落在 tempdir。"""
|
||||
saved = {
|
||||
k: os.environ.get(k)
|
||||
for k in ("JIANGCHANG_DATA_ROOT", "JIANGCHANG_USER_ID")
|
||||
}
|
||||
try:
|
||||
os.environ["CLAW_DATA_ROOT"] = _FAKE_CLAW_ROOT
|
||||
os.environ["JIANGCHANG_DATA_ROOT"] = _FAKE_CLAW_ROOT
|
||||
os.environ["JIANGCHANG_DATA_ROOT"] = _FAKE_REAL_ROOT
|
||||
with IsolatedDataRoot() as tmp:
|
||||
import importlib
|
||||
|
||||
@@ -51,8 +57,11 @@ class TestRuntimePaths(unittest.TestCase):
|
||||
norm_db = os.path.normcase(os.path.normpath(db_path))
|
||||
norm_tmp = os.path.normcase(os.path.normpath(tmp))
|
||||
self.assertTrue(norm_db.startswith(norm_tmp), msg=f"db_path={db_path!r} tmp={tmp!r}")
|
||||
norm_fake = os.path.normcase(os.path.normpath(_FAKE_CLAW_ROOT))
|
||||
self.assertFalse(norm_db.startswith(norm_fake), msg=f"db_path must not be under fake CLAW root: {db_path!r}")
|
||||
norm_fake = os.path.normcase(os.path.normpath(_FAKE_REAL_ROOT))
|
||||
self.assertFalse(
|
||||
norm_db.startswith(norm_fake),
|
||||
msg=f"db_path must not be under fake root: {db_path!r}",
|
||||
)
|
||||
finally:
|
||||
for k, v in saved.items():
|
||||
if v is None:
|
||||
@@ -60,6 +69,19 @@ class TestRuntimePaths(unittest.TestCase):
|
||||
else:
|
||||
os.environ[k] = v
|
||||
|
||||
def test_legacy_env_vars_do_not_override_canonical(self) -> None:
|
||||
with IsolatedDataRoot() as tmp:
|
||||
os.environ[_legacy_env_key("DATA_ROOT")] = _FAKE_REAL_ROOT
|
||||
os.environ[_legacy_env_key("USER_ID")] = "legacy-user"
|
||||
import importlib
|
||||
|
||||
import util.runtime_paths as rp
|
||||
|
||||
importlib.reload(rp)
|
||||
data_dir = rp.get_skill_data_dir()
|
||||
self.assertTrue(os.path.normpath(data_dir).startswith(os.path.normpath(tmp)))
|
||||
self.assertIn("_test", data_dir.replace("\\", "/"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -34,7 +34,7 @@ FORBIDDEN_PHRASES = (
|
||||
|
||||
POSITIVE_MARKERS = (
|
||||
"jiangchang-platform-kit",
|
||||
"1.0.14",
|
||||
"1.0.17",
|
||||
"共享 runtime",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user