Files
yun-xue-tang-assistant/start-headless.cmd
T
void ae117222df feat: v2.8.0 无头运行器、考试自动交卷、改为退避重试不跳课
新增无头运行能力,解决 Linux 无图形化服务器上无法常驻的问题;同时改掉
"遇到考试课/无进展课就跳过"的策略,改为在同门课上退避重试。

- runner/:自己起无头 Chromium,用 CDP 把构建产物注入页面主世界(等价
  @grant none),不装插件、不需要桌面环境或 Xvfb;含浏览器探测与启动参数、
  持久化 profile、陈旧 SingletonLock 清理、优雅退出、日志轮转、启动预检
- runner.config.mjs / start-headless.cmd:通用配置 + Windows 一键入口;
  凭据只走 YUN_XUE_TANG_USR / YUN_XUE_TANG_PWD 环境变量
- src/exam.js:含考试章节的课程自动进考试 → 开始/继续 → 空卷提交 → 确定,
  交卷后靠平台记账推进课程;maxExamTries 限制同门课交卷次数,防不记账时死循环
- 去掉跳过与黑名单:没学完就退避重试(30s 起翻倍,最长 5 分钟),
  同门课超过 maxCourseRetries 次才停整轮并提示,替代原 maxConsecutiveFailures
- 每完成一门都重新拉列表接口取平台实时状态再选下一门,避免用陈旧队列
- 学习进度改存 sessionStorage(yun-xue-tang-run-state-v3),整页跳转/刷新可续;
  运行开关不跨会话,浏览器重启后必须显式开跑
- dev/:新增 real-cdp / real-run / real-test / real-e2e 实跑脚本与 check.mjs
  统一静态检查(JS 22 + 批处理 2),替代逐文件 node --check
- docs/evidence/headless-linux-evidence.txt + 实跑截图,README 补无头部署章节
2026-10-25 23:04:40 +08:00

61 lines
1.7 KiB
Batchfile

@echo off
rem ---------------------------------------------------------------
rem This file must stay PURE ASCII.
rem cmd.exe reads batch files byte-by-byte with the current code page;
rem multi-byte characters (e.g. Chinese) corrupt line offsets and make
rem it report nonsense like "'npm' is not recognized".
rem All Chinese messages come from the Node runner output instead.
rem
rem Usage:
rem start-headless.cmd use runner.config.mjs
rem start-headless.cmd --help print all options
rem start-headless.cmd --max 3 command line overrides config file
rem ---------------------------------------------------------------
setlocal
chcp 65001 >nul
cd /d "%~dp0"
title YunXueTang Assistant - headless runner
where node >nul 2>nul
if errorlevel 1 goto no_node
if exist "yun-xue-tang-assistant.user.js" goto have_build
echo [build] build output not found, running npm run build ...
call npm run build
if errorlevel 1 goto build_fail
:have_build
if not exist "runner.config.mjs" goto no_config
echo [config] runner.config.mjs found, editing it is enough (no rebuild needed)
goto run
:no_config
echo [warn] runner.config.mjs not found, built-in defaults will be used
:run
echo [run] headless runner starting, press Ctrl+C to stop
echo.
node "runner/headless.mjs" %*
set RC=%ERRORLEVEL%
if "%RC%"=="0" goto done
echo.
echo [exit] code %RC%
echo 0 finished 1 no progress 2 env/args error 3 login failed
echo full log: run-logs\headless.log
pause
exit /b %RC%
:done
exit /b 0
:no_node
echo [error] node.exe not found. Install Node.js 22+ from https://nodejs.org/
pause
exit /b 1
:build_fail
echo [error] build failed. Run npm install first.
pause
exit /b 1