## 现场
跑 `pi --help` 时有一行不起眼的警告:
[pi-lens] ignoring invalid project config …/.pi-lens.json:
Expected double-quoted property name in JSON at position 60
`.pi-lens.json` 是 `d50c55d` 专门加的项目级防护(关掉 pi-lens 的格式化与
autofix),但它的说明写成了 `//` 注释 —— 读 pi-lens 的源码确认:
PROJECT_CONFIG_BASENAMES = ['.pi-lens.json', 'pi-lens.json']; // 没有 .jsonc
raw = JSON.parse(text); // 不去注释
// 解析失败 → 打一行警告,然后**整份忽略**
所以「已经关掉了」这个结论是**错的**,防护从落地那天起就没生效过。
而它要防的是两次已发生的真实损失:一次是 `19a3161` 把约 7000 行 biome 重排
扫进功能提交(无法审查、还掩盖了一处删行),一次是 prettier 改坏
`client/electron/index.html` 并打破 `test/theme.test.mjs` 的两条断言。
失败方式是静默的:进程照常跑,只有启动时一行警告 —— 而我正是在
`pi --help` 的输出里才看见它。
## 修
- `.pi-lens.json` 改为**严格 JSON**(只有 `$schema` / `format` / `autofix`;
`$comment` 也不行 —— pi-lens 校验未知键,会为它刷一条
「unknown key … ignored」的警告,而噪声会训练人忽略告警)。
- 理由移到 `docs/DEV-TOOLING.md`(含 pi-lens 的源码依据、两次事故、
以及「为什么不是把格式化器配成本仓库风格」——试过,仍改 17 个文件)。
- `biome.jsonc`(允许注释)里加指针:它只是两道闸中的一道,真正的总开关是
`.pi-lens.json`,而那份**必须是严格 JSON**。
- 验证:`pi --help` 现在 **0 行** pi-lens 输出;反向对照(故意塞回一行注释)
会重新出现 `ignoring invalid project config`。
## 顺带:仓库里有一个活的凭据
`scripts/verify-l2.sh` 把**管理员 user key 硬编码**在文件里(`1759666` 起就在
git 历史里)。实测它**仍然有效**(`/auth/me` → 200),属于用户 `jianf`。
- 已改为从 `VERIFY_L2_TOKEN` 或 `/root/gotmp/verify-l2-token.txt`(600)读取,
两者都没有时**报错退出**(反向对照验过:EXIT=2,不静默跑);
- 跑通一次确认可用(6 通过 0 失败)。
**但删掉当前这行不能把它从历史里拿掉** —— 要真正作废必须轮换那把 key。
这需要你定(它是你账号的密钥,可能还有别的工具在用),见提交后的说明。
60 lines
2.9 KiB
Bash
60 lines
2.9 KiB
Bash
#!/usr/bin/env bash
|
||
# L2 端到端验证脚本
|
||
set -euo pipefail
|
||
# 管理员 user key。**不要把它写进这个文件** —— 仓库是会被看到的地方,
|
||
# 而写进 git 历史的密钥只能靠轮换作废(删掉当前行不能把它从历史里拿掉)。
|
||
#
|
||
# 取法(任一):
|
||
# VERIFY_L2_TOKEN=<key> bash scripts/verify-l2.sh
|
||
# echo <key> > /root/gotmp/verify-l2-token.txt && chmod 600 该文件
|
||
TOKEN="${VERIFY_L2_TOKEN:-}"
|
||
if [ -z "$TOKEN" ] && [ -r /root/gotmp/verify-l2-token.txt ]; then
|
||
TOKEN=$(tr -d '\n' < /root/gotmp/verify-l2-token.txt)
|
||
fi
|
||
if [ -z "$TOKEN" ]; then
|
||
echo "需要管理员 user key:设 VERIFY_L2_TOKEN,或写到 /root/gotmp/verify-l2-token.txt(600)" >&2
|
||
exit 2
|
||
fi
|
||
BASE="http://127.0.0.1:8180/api/v1"
|
||
H=(-H "Authorization: Bearer $TOKEN")
|
||
PASS=0 FAIL=0
|
||
|
||
ok() { echo " ✅ $1"; PASS=$((PASS+1)); }
|
||
bad() { echo " ❌ $1"; FAIL=$((FAIL+1)); }
|
||
|
||
echo "=== L2 端到端验证 ==="
|
||
|
||
# ── 1. PUT /sessions/:id/permission
|
||
SID=$(sqlite3 /opt/agentmail/data/agentmail.db "SELECT session_id FROM sessions ORDER BY updated_at DESC LIMIT 1;")
|
||
echo "1. PUT /sessions/:id/permission ($SID)"
|
||
|
||
# 改 plan
|
||
R=$(curl -s -X PUT "$BASE/sessions/$SID/permission" -H 'Content-Type: application/json' "${H[@]}" -d '{"permission_mode":"plan"}')
|
||
if echo "$R" | grep -q '"permission_mode":"plan"'; then ok "plan 写入成功"; else bad "plan 写入失败: $R"; fi
|
||
|
||
# 改 full
|
||
R=$(curl -s -X PUT "$BASE/sessions/$SID/permission" -H 'Content-Type: application/json' "${H[@]}" -d '{"permission_mode":"full"}')
|
||
if echo "$R" | grep -q '"permission_mode":"full"'; then ok "full 写入成功"; else bad "full 写入失败: $R"; fi
|
||
|
||
# 脏值 → 回落到 workspace
|
||
R=$(curl -s -X PUT "$BASE/sessions/$SID/permission" -H 'Content-Type: application/json' "${H[@]}" -d '{"permission_mode":"bogus"}')
|
||
if echo "$R" | grep -q '"permission_mode":"workspace"'; then ok "脏值回落到 workspace"; else bad "脏值未回落: $R"; fi
|
||
|
||
# 复原
|
||
curl -s -X PUT "$BASE/sessions/$SID/permission" -H 'Content-Type: application/json' "${H[@]}" -d '{"permission_mode":"workspace"}' > /dev/null
|
||
|
||
# ── 2. calendar_events.permission_mode 列
|
||
echo "2. calendar_events.permission_mode 列"
|
||
COL=$(sqlite3 /opt/agentmail/data/agentmail.db "PRAGMA table_info(calendar_events);" | grep permission_mode || true)
|
||
if [ -n "$COL" ]; then ok "列存在: $COL"; else bad "列不存在"; fi
|
||
|
||
# ── 3. 建会话检查 schema 两列
|
||
echo "3. sessions permission_mode/enforcement 列"
|
||
PM=$(sqlite3 /opt/agentmail/data/agentmail.db "PRAGMA table_info(sessions);" | grep permission_mode || true)
|
||
PE=$(sqlite3 /opt/agentmail/data/agentmail.db "PRAGMA table_info(sessions);" | grep permission_enforcement || true)
|
||
if [ -n "$PM" ]; then ok "permission_mode 列存在"; else bad "permission_mode 列缺失"; fi
|
||
if [ -n "$PE" ]; then ok "permission_enforcement 列存在"; else bad "permission_enforcement 列缺失"; fi
|
||
|
||
echo ""
|
||
echo "=== 结果: $PASS 通过, $FAIL 失败 ==="
|