fix(权限): 409 的第二种含义是「本档不该问」——四桥都补上;状态写入点不再兜默认档
线上事故(jianf 经 pi 转达):补投路径漏传 permission_mode,插件拿 undefined 兜了 workspace 档,把 full 档会话写成 workspace-write + ask —— 不是"拦一次",是一整轮 工具能力降级,且状态留在会话里;随后该会话每次受守卫调用都撞 409。 四件事: 1. **状态写入点不接受默认值**(新增共享 `modeForStateWrite`):缺字段/脏值 → `null` = 不写状态。"默认值可以出现在**决策**里,不可以出现在**状态写入**里。" 同时保留共享契约的 fail-closed:真读到 workspace 才写 workspace。 2. **409 的两种含义分开处理**。`allowed-once` 只绕过**审批**,改不了**沙箱** —— 所以 dsh 桥在放行前先把服务端给的权威档位**写回会话**(这也就成了自愈路径: 已经降级的会话,下一次带档位的 409 会把它修回来);只认服务端明说的 full, plan 与"链上没有人类"照旧 fail closed。 3. **同一处缺陷在 zcode / opencode 也在**(`hooks/permission.mjs` 与 `index.js` 都把 409 当永久失败拒绝)。我先前在回信里写过"这两个桥不转发权限询问,不需要改" —— 那句话是错的,我当时的搜索面只有 `<plugin>/src/*.mjs`。按 pi 的要求把这条 **否定性事实变成常驻判据**后,它第一次运行就红给我看。四桥现在都有 「409 + full → 放行」,且**排在永久失败分支之前**(含顺序变异自检)。 4. **共用测试重新同源**:`test/catchup.test.mjs` 从 `153985e` 起就是分叉的 (我那版把平台专属路径写进了共用文件),而 `deploy/install.sh` 第 24 行会跑 `check-shared-libs.sh` —— 也就是说**部署一直是红的**,我没跑过那个脚本。 共用文件只放契约(值/行为),跨平台配对judge 移到平台专属文件,四份逐字节相同。 另外把"判代码 vs 判理由"从记忆变成代码:`test/lib/read.mjs` 提供 `code()/prose()/bytes()`, 判据目录里不得再裸用 `readFileSync`(新判据 `criteria-hygiene` 管,含读取器自检)。 判据证据(每条都做过"能不能红"的变异): - 写回去掉 → 红;纠正块挪到普通 409 之后 → 红;状态写入点退回兜默认 → 红; - zcode/opencode 的放行分支拿掉 → 各自红;共用测试分叉 → check-shared-libs 红。 各套件:dsh 388、pi 443、zcode 387、opencode 333(均经 npm test,含 tsc); electron `npm test` 15/15 判据绿 + vitest 266 + typecheck;`check-shared-libs.sh` 退出 0; Go `go test ./...` 全 ok。
This commit is contained in:
@ -23,9 +23,10 @@
|
||||
* 装上去的人看到的是旧界面,而 Web 上是新的 —— 两边不一致但谁都不报错。
|
||||
*/
|
||||
|
||||
import { code, prose } from './lib/read.mjs';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync, existsSync } from 'node:fs';
|
||||
import { existsSync } from 'node:fs';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
@ -37,7 +38,7 @@ const ROOT = join(HERE, '..');
|
||||
const DIST_HTML = join(ROOT, 'dist', 'index.html');
|
||||
|
||||
test('★ vite 的 base 必须是相对路径(否则 Electron 白屏)', () => {
|
||||
const cfg = readFileSync(join(ROOT, 'vite.config.ts'), 'utf8');
|
||||
const cfg = code(join(ROOT, 'vite.config.ts'));
|
||||
// 不能只看 `base:` 出现在注释里 —— 断言的是真的有一条 base 配置语句
|
||||
assert.match(
|
||||
cfg,
|
||||
@ -53,7 +54,7 @@ test('★ 构建产物里不能有绝对资源路径(这条能在没浏览器
|
||||
console.log('(dist/index.html 不存在 —— 先 cd client/electron && npm run build 才验得到)');
|
||||
return;
|
||||
}
|
||||
const html = readFileSync(DIST_HTML, 'utf8');
|
||||
const html = prose(DIST_HTML);
|
||||
const abs = [...html.matchAll(/(?:src|href)="(\/[^"]*)"/g)].map(m => m[1]);
|
||||
assert.deepEqual(
|
||||
abs,
|
||||
@ -78,7 +79,7 @@ test('★ 安装包里的 dist 必须与当前构建一致(否则装上去的
|
||||
return;
|
||||
}
|
||||
const list = execFileSync('npx', ['asar', 'list', asar], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
|
||||
const wanted = [...readFileSync(DIST_HTML, 'utf8').matchAll(/\.\/(assets\/[^"]+)/g)].map(m => m[1]);
|
||||
const wanted = [...prose(DIST_HTML).matchAll(/\.\/(assets\/[^"]+)/g)].map(m => m[1]);
|
||||
|
||||
const missing = wanted.filter(p => !list.includes(`/dist/${p}`));
|
||||
assert.deepEqual(
|
||||
@ -129,9 +130,9 @@ test('★ 发布脚本:构建失败时不打包(注入失败的构建,看
|
||||
});
|
||||
|
||||
test('★ 发布脚本:构建只有一条路(走 npm run build,不能是裸 vite build)', () => {
|
||||
const pkg = JSON.parse(readFileSync(join(HERE, '..', 'package.json'), 'utf8'));
|
||||
const pkg = JSON.parse(prose(join(HERE, '..', 'package.json')));
|
||||
const scriptPath = join(HERE, '..', 'scripts', 'release-linux.sh');
|
||||
const script = readFileSync(scriptPath, 'utf8');
|
||||
const script = prose(scriptPath);
|
||||
/*
|
||||
* 两个真实的坑,各自被这条挡住:
|
||||
* ① `build:linux` 原来直接跑裸 `vite build` —— 那会**跳过 `gen:bg`**
|
||||
|
||||
Reference in New Issue
Block a user