fix: dev.py 启动前释放端口并重试 prisma generate,修复 EPERM
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
|
||||
# Don't index SpecStory auto-save files, but allow explicit context inclusion via @ references
|
||||
.specstory/**
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"workspace_id": "25b6-2527-0981-ffed",
|
||||
"workspace_id_at": "2026-06-28T14:08:21Z",
|
||||
"project_name": "artveris"
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
# SpecStory CLI Configuration
|
||||
#
|
||||
# This is the project-level config file for SpecStory CLI.
|
||||
# All settings here apply to this project unless overridden by CLI flags.
|
||||
#
|
||||
# Uncomment (remove the #) the line and edit any setting below to change the default behavior.
|
||||
# For more information, see: https://docs.specstory.com/integrations/terminal-coding-agents/usage
|
||||
|
||||
[local_sync]
|
||||
# Write markdown files locally. (default: true)
|
||||
# enabled = false # equivalent to --only-cloud-sync
|
||||
|
||||
# Custom output directory for markdown files.
|
||||
# Default: ./.specstory/history (relative to the project directory)
|
||||
# output_dir = "~/.specstory/history" # equivalent to --output-dir "~/.specstory/history"
|
||||
|
||||
# Use local timezone for file name and content timestamps (default: false, UTC)
|
||||
# local_time_zone = true # equivalent to --local-time-zone
|
||||
|
||||
[cloud_sync]
|
||||
# Sync session data to SpecStory Cloud. (default: true, when logged in to SpecStory Cloud)
|
||||
# enabled = false # equivalent to --no-cloud-sync
|
||||
|
||||
[logging]
|
||||
# Write logs to .specstory/debug/debug.log (default: false)
|
||||
# log = true # equivalent to --log
|
||||
|
||||
# Debug-level output, requires console or log (default: false)
|
||||
# debug = true # equivalent to --debug
|
||||
|
||||
# Custom output directory for debug data.
|
||||
# Default: ./.specstory/debug (relative to the project directory)
|
||||
# debug_dir = "~/.specstory/debug" # equivalent to --debug-dir "~/.specstory/debug"
|
||||
|
||||
# Error/warn/info output to stdout (default: false)
|
||||
# console = true # equivalent to --console
|
||||
|
||||
# Suppress all non-error output (default: false)
|
||||
# silent = true # equivalent to --silent
|
||||
|
||||
[version_check]
|
||||
# Check for new versions of the CLI on startup.
|
||||
# Default: true
|
||||
# enabled = false # equivalent to --no-version-check
|
||||
|
||||
[analytics]
|
||||
# Send anonymous product usage analytics to help improve SpecStory.
|
||||
# Default: true
|
||||
# enabled = false # equivalent to --no-usage-analytics
|
||||
|
||||
[telemetry]
|
||||
# OTLP gRPC collector endpoint (e.g., "localhost:4317" or "http://localhost:4317")
|
||||
# endpoint = "localhost:4317"
|
||||
|
||||
# Override the default service name (default: "specstory-cli")
|
||||
# service_name = "my-service-name"
|
||||
|
||||
# Include user prompt text in telemetry spans (default: true)
|
||||
# prompts = false
|
||||
|
||||
[providers]
|
||||
# Agent execution commands by provider (used by specstory run)
|
||||
# Pass custom flags (e.g. claude_cmd = "claude --allow-dangerously-skip-permissions")
|
||||
# Use of these is equivalent to -c "custom command"
|
||||
|
||||
# Claude Code command
|
||||
# claude_cmd = "claude"
|
||||
|
||||
# Codex CLI command
|
||||
# codex_cmd = "codex"
|
||||
|
||||
# Cursor CLI command
|
||||
# cursor_cmd = "cursor-agent"
|
||||
|
||||
# Droid CLI command
|
||||
# droid_cmd = "droid"
|
||||
|
||||
# Gemini CLI command
|
||||
# gemini_cmd = "gemini"
|
||||
|
||||
# DeepSeek TUI command
|
||||
# deepseek_cmd = "deepseek"
|
||||
@@ -66,4 +66,5 @@
|
||||
- 迭代(用户新需求):1) 语言包合并为单 json/语言(`locales/zh-CN.json`、`en-US.json`,含 common/menu/pages),默认中文;语言切换改为图标按钮(地球图标 + zh-CN 标记,下拉选择)。2) 主题改用 Naive 官方 light/darkTheme + 清凉青绿主色(theme.ts 仅最小覆盖),`useTheme` 组合式(light/dark/auto,auto 跟随系统),`ThemeSwitch` 图标下拉;App 用 n-global-style + :theme 切换;移除前端硬编码深蓝,统一 CSS 变量 `--brand`。3) 侧边栏改 `show-trigger="arrow-circle"`(官方垂直居中圆形收缩按钮),sider 取消 inverted 跟随主题。4) 追溯码新增分组(trace_code_group 表/groupId):分组管理弹窗、列表/生码按分组、短链列渲染为可点击 `<a target=_blank>`;5) 追溯码批量:DataTable 选择列 + 批量分组/启用/停用(后端 `/trace-codes/batch/group`、`/batch/status`,启用按激活/绑定状态恢复)。后端分组与批量已 API 验证通过。
|
||||
- 追溯码批量导出(按 PRD 6.3):导出支持 Excel/CSV 两种格式,可按当前筛选(分组/批次/状态/关键词)或所选 ids 导出;列含批次编号、分组、追溯码、随机短码、短链、二维码数据(DataURL)、生成时间;CSV 加 UTF-8 BOM。后端 `GET /trace-codes/export?format=xlsx|csv&groupId&batchId&status&keyword&ids`;后台改为"导出"下拉(Excel/CSV × 当前筛选/所选)。已 API 验证 xlsx/csv/所选。
|
||||
- C 端视频播放:节点媒体区分图片/视频(按 `type==='video'` 或扩展名判断),C 端用 `<video controls playsinline>` 播放、`<img>` 显示图片;后台节点弹窗拆分"图片/视频"两个上传区(视频走 /upload?type=video,≤100MB),保存时按 type 合并 mediaFiles;后台节点展示也用 video 播放。已 API 验证 type=video 贯通到公开溯源。
|
||||
- 脚本修复:`dev.py` 启动前先 `free_ports([api,admin,h5])` 结束上次本地服务(同时解除运行中 API 对 Prisma 引擎 DLL 的占用,修复 `prisma generate` EPERM rename),`prisma:generate` 改 `run_retry`(失败重试,最终失败仅告警不中断);`_lib` 新增 `free_port/free_ports/run_retry`。docker_dev/docker_build 的 prisma generate 在镜像构建内执行、无主机文件锁不受影响。已实测 `uv run scripts/dev.py` 三端正常启动、无 EPERM。
|
||||
|
||||
|
||||
@@ -96,6 +96,50 @@ def popen(cmd: str, cwd: Path | None = None) -> subprocess.Popen:
|
||||
return subprocess.Popen(cmd, cwd=str(cwd or ROOT), shell=True)
|
||||
|
||||
|
||||
def free_port(port: int) -> None:
|
||||
"""结束本机占用指定端口的进程(用于释放上次的 api/admin/h5 及被锁的 Prisma 引擎)。
|
||||
仅用于本地 node 进程,不要对 Docker 管理的端口使用。"""
|
||||
try:
|
||||
if IS_WINDOWS:
|
||||
out = subprocess.run(
|
||||
"netstat -ano -p tcp", capture_output=True, text=True, shell=True
|
||||
).stdout
|
||||
pids: set[str] = set()
|
||||
for line in out.splitlines():
|
||||
if f":{port} " in line and "LISTENING" in line.upper():
|
||||
pid = line.split()[-1]
|
||||
if pid and pid != "0":
|
||||
pids.add(pid)
|
||||
for pid in pids:
|
||||
subprocess.run(f"taskkill /F /PID {pid}", shell=True, capture_output=True)
|
||||
print(f"[artveris] 释放端口 {port}(结束 PID {pid})")
|
||||
else:
|
||||
out = subprocess.run(
|
||||
f"lsof -ti tcp:{port}", capture_output=True, text=True, shell=True
|
||||
).stdout
|
||||
for pid in out.split():
|
||||
subprocess.run(f"kill -9 {pid}", shell=True, capture_output=True)
|
||||
print(f"[artveris] 释放端口 {port}(结束 PID {pid})")
|
||||
except Exception as e: # noqa: BLE001
|
||||
print(f"[artveris] 释放端口 {port} 失败(忽略):{e}")
|
||||
|
||||
|
||||
def free_ports(ports: list[int]) -> None:
|
||||
for p in ports:
|
||||
free_port(int(p))
|
||||
|
||||
|
||||
def run_retry(cmd: str, cwd: Path | None = None, attempts: int = 4, delay: float = 2.0) -> bool:
|
||||
"""运行命令,失败自动重试(用于规避偶发文件锁,如 Prisma 引擎 DLL 占用)。"""
|
||||
for i in range(attempts):
|
||||
if run(cmd, cwd=cwd, check=False) == 0:
|
||||
return True
|
||||
if i < attempts - 1:
|
||||
print(f"[artveris] 命令失败,{delay} 秒后重试({i + 1}/{attempts - 1})…")
|
||||
time.sleep(delay)
|
||||
return False
|
||||
|
||||
|
||||
def wait_port(host: str, port: int, timeout: int = 60) -> bool:
|
||||
print(f"[artveris] 等待 {host}:{port} 就绪 …")
|
||||
start = time.time()
|
||||
|
||||
+9
-3
@@ -14,15 +14,20 @@ from __future__ import annotations
|
||||
import sys
|
||||
import time
|
||||
|
||||
from _lib import ROOT, build_env, load_config, popen, run, wait_port, write_env
|
||||
from _lib import build_env, free_ports, load_config, popen, run, run_retry, wait_port, write_env
|
||||
|
||||
|
||||
def main() -> None:
|
||||
args = sys.argv[1:]
|
||||
cfg = load_config()
|
||||
app = cfg["app"]
|
||||
env = build_env(cfg)
|
||||
write_env(env)
|
||||
|
||||
# 0. 释放上次残留的本地服务(同时解除对 Prisma 引擎 DLL 的占用,避免 generate EPERM)
|
||||
free_ports([app["api_port"], app["admin_port"], app["h5_port"]])
|
||||
time.sleep(1.5)
|
||||
|
||||
if "--install" in args:
|
||||
run("pnpm install")
|
||||
|
||||
@@ -35,8 +40,9 @@ def main() -> None:
|
||||
# 2. 构建共享包
|
||||
run("pnpm build:shared")
|
||||
|
||||
# 3. 数据库迁移 + 种子
|
||||
run("pnpm --filter @artveris/api prisma:generate")
|
||||
# 3. 数据库迁移 + 种子(generate 偶发被占用,自动重试)
|
||||
if not run_retry("pnpm --filter @artveris/api prisma:generate", attempts=4, delay=2):
|
||||
print("[artveris] 警告:prisma generate 仍失败(客户端可能已存在),继续启动 …")
|
||||
run("pnpm --filter @artveris/api prisma:deploy")
|
||||
if "--no-seed" not in args:
|
||||
run("pnpm --filter @artveris/api seed", check=False)
|
||||
|
||||
Reference in New Issue
Block a user