TestCopilot Closed Loop
Use TestCopilot MCP tools to drive this workflow:
requirement -> project selection -> case generation -> case validation
-> case save/module creation -> test plan creation/binding
-> AI execution -> log polling -> result/defect summary
-> code repair -> regression rerun
Do not print or store user tokens. Use the MCP server already configured in Codex, or the server URL and headers the user explicitly provides.
Init Command
Use this mode when the user says "初始化", "配置", "设置 token", "设置安装路径", "prepare TestCopilot MCP", or when required configuration is missing.
Initialization should collect and validate:
- MCP server URL, defaulting to
https://tgeek.cn/prod-api/sse unless the user provides another URL.
- Personal access token, accepted as
Authorization: Bearer <token> or X-AUTH-TOKEN: <token>.
- TestCopilot local bundled Python runtime readiness when local execution is required.
Never write the token into Skill files, docs, git-tracked files, or final responses. If Codex has an MCP config mechanism available, update that config with the token only when the user explicitly asks Codex to configure it. Otherwise tell the user exactly which MCP config fields to set.
Initialization Workflow
Check whether a TestCopilot MCP server is already configured and reachable.
- Connect to the SSE URL.
- Run
tools/list.
- Confirm the core tools are present.
If authentication fails or no token is configured:
- Ask the user to provide a personal access token generated from TestCopilot.
- Use only token auth. Do not use accessKey, secretKey, or signature.
- After receiving the token, validate it by calling
testcopilot_list_projects with a small page size.
Resolve local bundled Python runtime paths.
- Remote MCP servers cannot see the user's local filesystem. Do not ask a remote MCP server to validate local install paths.
- macOS default install dir:
/Applications/TestCopilot.app
- macOS default Python project dir:
/Applications/TestCopilot.app/Contents/Resources/PythonEnv/deepseek_chat_package_v2
- macOS bundled uv candidates:
/Applications/TestCopilot.app/Contents/Resources/PythonEnv/uv-runtime/darwin-arm64/uv
/Applications/TestCopilot.app/Contents/Resources/PythonEnv/uv-runtime/darwin-x64/uv
- Linux packaged/server candidates:
/opt/TestCopilot/resources/PythonEnv/deepseek_chat_package_v2
/opt/testcopilot/resources/PythonEnv/deepseek_chat_package_v2
/metersphere/static/python-env/deepseek_chat_package_v2
/metersphere/static/python-env/uv-runtime/linux-x64/uv
- Windows has no reliable universal default. Ask the user for the TestCopilot installation directory, then derive:
<install_dir>\\resources\\PythonEnv\\deepseek_chat_package_v2
<install_dir>\\PythonEnv\\deepseek_chat_package_v2
<install_dir>\\resources\\PythonEnv\\uv-runtime\\win-x64\\uv.exe
<install_dir>\\PythonEnv\\uv-runtime\\win-x64\\uv.exe
Validate local runner readiness.
- For a remote MCP server, execution should be run by Codex on the user's machine using the local TestCopilot bundled Python runtime.
- For a local MCP server running on the same machine as the installed app, runtime validation may use
configure_execution_runtime.
- Treat
waiting_local_runner as the normal remote-MCP execution state after task creation.
Report the initialized state.
- Say whether MCP auth works.
- Say which server URL is configured.
- Say whether Codex can locate the local bundled Python runtime or still needs the user to provide the install directory.
- Show install/runtime paths only when they refer to the user's local machine and the user provided or confirmed them. Never show the token.
Example initialization prompts the user may use:
用 $testcopilot 初始化 TestCopilot MCP,服务器是 https://tgeek.cn/prod-api/sse,我会提供 token。
用 $testcopilot 配置执行环境。我的 Windows 安装目录是 C:\Users\me\AppData\Local\Programs\TestCopilot
Preflight Before Every Run
Before every closed-loop run, perform a lightweight preflight. Do this even when the user did not explicitly ask for initialization.
- Check MCP connectivity.
- Try the configured TestCopilot MCP server first.
- If no configured server is discoverable but the user provided a URL, use that URL.
- If neither exists, stop and show this configuration shape:
{
"mcpServers": {
"testcopilot": {
"url": "https://tgeek.cn/prod-api/sse",
"headers": {
"Authorization": "Bearer <your_testcopilot_token>"
}
}
}
}
Validate token authentication.
- Connect to
/sse.
- Run
tools/list.
- Call
testcopilot_list_projects with pageSize = 1.
- If auth fails, ask only for a TestCopilot personal access token. Do not ask for accessKey, secretKey, or signature.
Confirm core tools are available.
- Required before generation/save:
testcopilot_list_projects, generate_function_cases, push_cases_to_testcopilot.
- Required before execution:
trigger_ai_execution.
- Required for logs/results:
get_execution_logs, get_execution_result.
- If tools are missing, stop and report exactly which tools are unavailable.
Check local runner expectations.
- For remote MCP (
https://.../sse), do not check remote server paths for the user's local Python runtime.
- Expect
trigger_ai_execution to create execution records and return waiting_local_runner.
- After task creation, Codex should directly invoke the local bundled Python executor; do not ask the user to start a separate Agent.
- On macOS, try
/Applications/TestCopilot.app and the repository electron-frontend/PythonEnv before asking.
- On Windows, ask the user for the TestCopilot install directory unless already provided.
Continue according to what is missing.
- If MCP/token/tools are missing, stop before generating cases.
- If only local bundled Python runtime is missing, generate/save cases and create execution tasks, then ask for the install directory before starting local execution.
- Ask for the smallest missing piece of configuration, not a full setup form.
Required Inputs
- Requirement source: a
.docx path, text, Markdown, or other readable file.
- Project name or project id.
- Execution scope: first case only, selected cases, or all cases. If unspecified, ask only when executing all cases could be expensive; otherwise default to first case for demos.
Optional inputs:
repo_path
environment
template_id
install_dir for local bundled Python runtime setup
python_project_dir for local MCP only
uv_bin for local MCP only
MCP Tools
Core tools:
testcopilot_list_projects
testcopilot_get_project
testcopilot_search_functional_cases
generate_function_cases
push_cases_to_testcopilot
trigger_ai_execution
get_execution_logs
get_execution_result
Optional/runtime tool:
configure_execution_runtime
Workflow
Run the preflight above.
- Do not skip this step.
- If preflight stops, do not attempt later workflow steps.
Read the requirement.
- For
.docx, extract visible paragraph text.
- Preserve URLs, credentials, feature names, acceptance criteria, and expected behavior.
- Summarize the requirement before running MCP.
Query the project.
- Call
testcopilot_list_projects with the provided project name.
- Prefer exact name match over keyword match.
- If multiple plausible projects remain, ask the user to choose.
- Record
project_id, project name, and platform.
Resolve the functional case template.
- If the user supplied
template_id, use it.
- Otherwise call
testcopilot_search_functional_cases for the selected project and infer a reusable template_id from existing functional cases.
- If no template can be inferred, stop and report that a project functional case template is needed.
Generate cases.
- Call
generate_function_cases(requirement, project_id, template_id).
- Check whether the generated cases match the actual requirement topic and inputs.
- For login requirements, verify that generated steps mention the right login method, target URL, account fields, credentials, and success/failure behavior.
- If generated cases are clearly wrong, report the mismatch as a TestCopilot MCP generation issue.
Select cases for execution.
- If the user says "只执行第一个测试用例", save and execute exactly one case.
- Prefer a generated case that actually matches the requirement.
- If no generated case matches but the user asked to continue the validation, construct a minimal first-case JSON from the requirement and clearly state that it is a fallback for validating the save/execute chain.
Save cases.
- Call
push_cases_to_testcopilot.
- Use the requirement title as-is; do not add any MCP-related marker, prefix, or suffix.
- Let the MCP tool create the module and test plan when supported.
- Record
case_set_id, module_id, case_ids, test_plan_id, test_plan_case_ids, and case_version.
Trigger execution.
- Call
trigger_ai_execution(case_set_id, repo_path, test_plan_id, environment, install_dir?, python_project_dir?, uv_bin?).
- If the user did not provide
repo_path, use the current workspace path when relevant.
- If the requirement includes a test endpoint, pass it as
environment.
- For remote MCP, expect the tool to create execution records and return
waiting_local_runner, not to launch Python on the server.
Run the local bundled Python executor.
- If
trigger_ai_execution returns status = waiting_local_runner, Codex should locate the local Python project and run main.py directly.
- Prefer using
scripts/run-local-python.js from this skill. Create a temporary runner input JSON outside git with repoPath, optional installDir / pythonProjectDir / uvBin, and params.
- Build a base64-encoded JSON payload for each execution context.
- Include at minimum:
serverUrl, token, executionId, testPlanId, testPlanCaseId, caseId, caseName, projectId, projectPlatform, task, isBatchMode, clientVersion, osInfo.
task should be a MeterSphere-style JSON string: { "data": { "name", "moduleName", "functionalPriority", "prerequisite", "steps" } }.
- Use the case JSON already selected/saved in the workflow to construct
task.
- Prefer bundled uv when present:
- macOS arm64:
PythonEnv/uv-runtime/darwin-arm64/uv
- macOS x64:
PythonEnv/uv-runtime/darwin-x64/uv
- Windows x64:
PythonEnv/uv-runtime/win-x64/uv.exe
- Otherwise use the bundled venv python under
PythonEnv/deepseek_chat_package_v2/.venv*.
- Run with cwd set to
PythonEnv/deepseek_chat_package_v2.
- Stream stdout/stderr into the Codex response updates when useful.
- Continue polling logs/results when
task_id exists; the local Python script should upload logs and results as it executes.
- If
trigger_ai_execution returns status = configuration_required, treat it as a legacy/local-MCP runtime setup response. Report the missing field and ask only for that field.
- Do not interpret remote Linux paths as the user's local install path.
Poll logs and results.
- If
task_id exists, call get_execution_logs(task_id, cursor) every few seconds.
- Keep and advance
next_cursor.
- Call
get_execution_result(task_id) after each log poll.
- Stop polling when status is no longer
running, or after a reasonable timeout with a clear "still running" summary.
Defects and repair.
- If defects are returned, summarize
defect_id, title, expected, actual, likely_cause, and suggested_fix_area.
- For repo code defects, inspect the suggested areas and make the smallest necessary fix.
- Run local validation where possible.
- Rerun
trigger_ai_execution as regression and continue until passed or blocked.
Reporting
Final response should include:
- Requirement source and concise requirement summary.
- Selected project name/id.
- Whether generated cases matched the requirement.
- Saved asset ids:
case_set_id, module_id, case_ids, test_plan_id, test_plan_case_ids.
- Execution ids/status if created.
- Log/result/defect summary, or the exact runtime configuration blocker.
Never include a personal access token in the response.
Codex Local Runner Pattern
For remote MCP servers, the expected trigger_ai_execution result is:
status: waiting_local_runner
local_runner_required: true
next_action: run_local_testcopilot_python
Codex should then run the local TestCopilot bundled Python executor directly:
node ./skills/testcopilot/scripts/run-local-python.js /tmp/testcopilot-runner-input.json
Then poll:
get_execution_logs(task_id, cursor)
get_execution_result(task_id)
1---2name: testcopilot3description: Use this skill when the user asks Codex to work with TestCopilot or run a TestCopilot MCP closed-loop workflow from a requirement document or requirement text: configure MCP token/server/runtime paths, query/select a TestCopilot project, generate functional cases, validate generated cases against the requirement, save cases, create or use the MCP-created module/test plan, trigger AI execution, poll logs, collect structured defects, and optionally repair code and rerun regression. Triggers include "$testcopilot", "TestCopilot 闭环", "初始化 TestCopilot MCP", "配置 TestCopilot token", "配置执行环境", "用 MCP 跑需求", "完整跑一遍流程", "只执行第一个测试用例", "生成用例并触发 AI 执行", or similar Chinese/English requests.4---56# TestCopilot Closed Loop78Use TestCopilot MCP tools to drive this workflow:910```text11requirement -> project selection -> case generation -> case validation12-> case save/module creation -> test plan creation/binding13-> AI execution -> log polling -> result/defect summary14-> code repair -> regression rerun15```1617Do not print or store user tokens. Use the MCP server already configured in Codex, or the server URL and headers the user explicitly provides.1819## Init Command2021Use this mode when the user says "初始化", "配置", "设置 token", "设置安装路径", "prepare TestCopilot MCP", or when required configuration is missing.2223Initialization should collect and validate:2425- MCP server URL, defaulting to `https://tgeek.cn/prod-api/sse` unless the user provides another URL.26- Personal access token, accepted as `Authorization: Bearer <token>` or `X-AUTH-TOKEN: <token>`.27- TestCopilot local bundled Python runtime readiness when local execution is required.2829Never write the token into Skill files, docs, git-tracked files, or final responses. If Codex has an MCP config mechanism available, update that config with the token only when the user explicitly asks Codex to configure it. Otherwise tell the user exactly which MCP config fields to set.3031### Initialization Workflow32331. Check whether a TestCopilot MCP server is already configured and reachable.34 - Connect to the SSE URL.35 - Run `tools/list`.36 - Confirm the core tools are present.37382. If authentication fails or no token is configured:39 - Ask the user to provide a personal access token generated from TestCopilot.40 - Use only token auth. Do not use accessKey, secretKey, or signature.41 - After receiving the token, validate it by calling `testcopilot_list_projects` with a small page size.42433. Resolve local bundled Python runtime paths.44 - Remote MCP servers cannot see the user's local filesystem. Do not ask a remote MCP server to validate local install paths.45 - macOS default install dir: `/Applications/TestCopilot.app`46 - macOS default Python project dir: `/Applications/TestCopilot.app/Contents/Resources/PythonEnv/deepseek_chat_package_v2`47 - macOS bundled uv candidates:48 - `/Applications/TestCopilot.app/Contents/Resources/PythonEnv/uv-runtime/darwin-arm64/uv`49 - `/Applications/TestCopilot.app/Contents/Resources/PythonEnv/uv-runtime/darwin-x64/uv`50 - Linux packaged/server candidates:51 - `/opt/TestCopilot/resources/PythonEnv/deepseek_chat_package_v2`52 - `/opt/testcopilot/resources/PythonEnv/deepseek_chat_package_v2`53 - `/metersphere/static/python-env/deepseek_chat_package_v2`54 - `/metersphere/static/python-env/uv-runtime/linux-x64/uv`55 - Windows has no reliable universal default. Ask the user for the TestCopilot installation directory, then derive:56 - `<install_dir>\\resources\\PythonEnv\\deepseek_chat_package_v2`57 - `<install_dir>\\PythonEnv\\deepseek_chat_package_v2`58 - `<install_dir>\\resources\\PythonEnv\\uv-runtime\\win-x64\\uv.exe`59 - `<install_dir>\\PythonEnv\\uv-runtime\\win-x64\\uv.exe`60614. Validate local runner readiness.62 - For a remote MCP server, execution should be run by Codex on the user's machine using the local TestCopilot bundled Python runtime.63 - For a local MCP server running on the same machine as the installed app, runtime validation may use `configure_execution_runtime`.64 - Treat `waiting_local_runner` as the normal remote-MCP execution state after task creation.65665. Report the initialized state.67 - Say whether MCP auth works.68 - Say which server URL is configured.69 - Say whether Codex can locate the local bundled Python runtime or still needs the user to provide the install directory.70 - Show install/runtime paths only when they refer to the user's local machine and the user provided or confirmed them. Never show the token.7172Example initialization prompts the user may use:7374```text75用 $testcopilot 初始化 TestCopilot MCP,服务器是 https://tgeek.cn/prod-api/sse,我会提供 token。76```7778```text79用 $testcopilot 配置执行环境。我的 Windows 安装目录是 C:\Users\me\AppData\Local\Programs\TestCopilot80```8182## Preflight Before Every Run8384Before every closed-loop run, perform a lightweight preflight. Do this even when the user did not explicitly ask for initialization.85861. Check MCP connectivity.87 - Try the configured TestCopilot MCP server first.88 - If no configured server is discoverable but the user provided a URL, use that URL.89 - If neither exists, stop and show this configuration shape:9091```json92{93 "mcpServers": {94 "testcopilot": {95 "url": "https://tgeek.cn/prod-api/sse",96 "headers": {97 "Authorization": "Bearer <your_testcopilot_token>"98 }99 }100 }101}102```1031042. Validate token authentication.105 - Connect to `/sse`.106 - Run `tools/list`.107 - Call `testcopilot_list_projects` with `pageSize = 1`.108 - If auth fails, ask only for a TestCopilot personal access token. Do not ask for accessKey, secretKey, or signature.1091103. Confirm core tools are available.111 - Required before generation/save: `testcopilot_list_projects`, `generate_function_cases`, `push_cases_to_testcopilot`.112 - Required before execution: `trigger_ai_execution`.113 - Required for logs/results: `get_execution_logs`, `get_execution_result`.114 - If tools are missing, stop and report exactly which tools are unavailable.1151164. Check local runner expectations.117 - For remote MCP (`https://.../sse`), do not check remote server paths for the user's local Python runtime.118 - Expect `trigger_ai_execution` to create execution records and return `waiting_local_runner`.119 - After task creation, Codex should directly invoke the local bundled Python executor; do not ask the user to start a separate Agent.120 - On macOS, try `/Applications/TestCopilot.app` and the repository `electron-frontend/PythonEnv` before asking.121 - On Windows, ask the user for the TestCopilot install directory unless already provided.1221235. Continue according to what is missing.124 - If MCP/token/tools are missing, stop before generating cases.125 - If only local bundled Python runtime is missing, generate/save cases and create execution tasks, then ask for the install directory before starting local execution.126 - Ask for the smallest missing piece of configuration, not a full setup form.127128## Required Inputs129130- Requirement source: a `.docx` path, text, Markdown, or other readable file.131- Project name or project id.132- Execution scope: first case only, selected cases, or all cases. If unspecified, ask only when executing all cases could be expensive; otherwise default to first case for demos.133134Optional inputs:135136- `repo_path`137- `environment`138- `template_id`139- `install_dir` for local bundled Python runtime setup140- `python_project_dir` for local MCP only141- `uv_bin` for local MCP only142143## MCP Tools144145Core tools:146147- `testcopilot_list_projects`148- `testcopilot_get_project`149- `testcopilot_search_functional_cases`150- `generate_function_cases`151- `push_cases_to_testcopilot`152- `trigger_ai_execution`153- `get_execution_logs`154- `get_execution_result`155156Optional/runtime tool:157158- `configure_execution_runtime`159160## Workflow1611620. Run the preflight above.163 - Do not skip this step.164 - If preflight stops, do not attempt later workflow steps.1651661. Read the requirement.167 - For `.docx`, extract visible paragraph text.168 - Preserve URLs, credentials, feature names, acceptance criteria, and expected behavior.169 - Summarize the requirement before running MCP.1701712. Query the project.172 - Call `testcopilot_list_projects` with the provided project name.173 - Prefer exact name match over keyword match.174 - If multiple plausible projects remain, ask the user to choose.175 - Record `project_id`, project name, and platform.1761773. Resolve the functional case template.178 - If the user supplied `template_id`, use it.179 - Otherwise call `testcopilot_search_functional_cases` for the selected project and infer a reusable `template_id` from existing functional cases.180 - If no template can be inferred, stop and report that a project functional case template is needed.1811824. Generate cases.183 - Call `generate_function_cases(requirement, project_id, template_id)`.184 - Check whether the generated cases match the actual requirement topic and inputs.185 - For login requirements, verify that generated steps mention the right login method, target URL, account fields, credentials, and success/failure behavior.186 - If generated cases are clearly wrong, report the mismatch as a TestCopilot MCP generation issue.1871885. Select cases for execution.189 - If the user says "只执行第一个测试用例", save and execute exactly one case.190 - Prefer a generated case that actually matches the requirement.191 - If no generated case matches but the user asked to continue the validation, construct a minimal first-case JSON from the requirement and clearly state that it is a fallback for validating the save/execute chain.1921936. Save cases.194 - Call `push_cases_to_testcopilot`.195 - Use the requirement title as-is; do not add any MCP-related marker, prefix, or suffix.196 - Let the MCP tool create the module and test plan when supported.197 - Record `case_set_id`, `module_id`, `case_ids`, `test_plan_id`, `test_plan_case_ids`, and `case_version`.1981997. Trigger execution.200 - Call `trigger_ai_execution(case_set_id, repo_path, test_plan_id, environment, install_dir?, python_project_dir?, uv_bin?)`.201 - If the user did not provide `repo_path`, use the current workspace path when relevant.202 - If the requirement includes a test endpoint, pass it as `environment`.203 - For remote MCP, expect the tool to create execution records and return `waiting_local_runner`, not to launch Python on the server.2042058. Run the local bundled Python executor.206 - If `trigger_ai_execution` returns `status = waiting_local_runner`, Codex should locate the local Python project and run `main.py` directly.207 - Prefer using `scripts/run-local-python.js` from this skill. Create a temporary runner input JSON outside git with `repoPath`, optional `installDir` / `pythonProjectDir` / `uvBin`, and `params`.208 - Build a base64-encoded JSON payload for each execution context.209 - Include at minimum: `serverUrl`, `token`, `executionId`, `testPlanId`, `testPlanCaseId`, `caseId`, `caseName`, `projectId`, `projectPlatform`, `task`, `isBatchMode`, `clientVersion`, `osInfo`.210 - `task` should be a MeterSphere-style JSON string: `{ "data": { "name", "moduleName", "functionalPriority", "prerequisite", "steps" } }`.211 - Use the case JSON already selected/saved in the workflow to construct `task`.212 - Prefer bundled uv when present:213 - macOS arm64: `PythonEnv/uv-runtime/darwin-arm64/uv`214 - macOS x64: `PythonEnv/uv-runtime/darwin-x64/uv`215 - Windows x64: `PythonEnv/uv-runtime/win-x64/uv.exe`216 - Otherwise use the bundled venv python under `PythonEnv/deepseek_chat_package_v2/.venv*`.217 - Run with cwd set to `PythonEnv/deepseek_chat_package_v2`.218 - Stream stdout/stderr into the Codex response updates when useful.219 - Continue polling logs/results when `task_id` exists; the local Python script should upload logs and results as it executes.220 - If `trigger_ai_execution` returns `status = configuration_required`, treat it as a legacy/local-MCP runtime setup response. Report the missing field and ask only for that field.221 - Do not interpret remote Linux paths as the user's local install path.2222239. Poll logs and results.224 - If `task_id` exists, call `get_execution_logs(task_id, cursor)` every few seconds.225 - Keep and advance `next_cursor`.226 - Call `get_execution_result(task_id)` after each log poll.227 - Stop polling when status is no longer `running`, or after a reasonable timeout with a clear "still running" summary.22822910. Defects and repair.230 - If defects are returned, summarize `defect_id`, `title`, `expected`, `actual`, `likely_cause`, and `suggested_fix_area`.231 - For repo code defects, inspect the suggested areas and make the smallest necessary fix.232 - Run local validation where possible.233 - Rerun `trigger_ai_execution` as regression and continue until passed or blocked.234235## Reporting236237Final response should include:238239- Requirement source and concise requirement summary.240- Selected project name/id.241- Whether generated cases matched the requirement.242- Saved asset ids: `case_set_id`, `module_id`, `case_ids`, `test_plan_id`, `test_plan_case_ids`.243- Execution ids/status if created.244- Log/result/defect summary, or the exact runtime configuration blocker.245246Never include a personal access token in the response.247248## Codex Local Runner Pattern249250For remote MCP servers, the expected `trigger_ai_execution` result is:251252```text253status: waiting_local_runner254local_runner_required: true255next_action: run_local_testcopilot_python256```257258Codex should then run the local TestCopilot bundled Python executor directly:259260```bash261node ./skills/testcopilot/scripts/run-local-python.js /tmp/testcopilot-runner-input.json262```263264Then poll:265266```text267get_execution_logs(task_id, cursor)268get_execution_result(task_id)269```