Files
dsh-purge/test/inject-wiring.test.js
T
叫我小杨同学 624976ed1d release: 1.1.84,尾部锚点与子代理审批接管,红队模式中文化,#194/#188
- 接线 lib/anchor.js:锚点物理追加到 system prompt sections 末尾,
  identity.js 支持 anchorText(对象/字符串两种入参),已有同名段先滤再追加;
  锚点改为跟随操作者语言,删除写死的英文开头句(红队回答变英文的根因)
- 接线 lib/subagent-control.js:子会话 approval/policy=never 改回 ask,
  并在 approval/request 瀑布放行;anchorMode/subagentControl 提供回滚开关
- index.js:真实 anchorApplied / injectTail 判定、审批策略探针、iso 分支
  注册锚点、applyHostHooks 注册锚点与子代理接管并统一释放
- office 技能自愈:core/desktop 增加 healOfficeSkillsRuntimeOnDisk,桌面端触发
- 红队模式中文化:preset 文案、角色名、五阶段、25 项计分规则与 POC 分类、
  技能修复说明、环境适配提示、面板报错、成果报告与复现报告
- #194:hung-operator 改按内容变更缓存,加风暴/慢调用熔断;WeakMap 去重
  同次 assemble 的重复改写;新增 #91 记录宿主信号退出的持久化日志
- #188(rc.4 专属部分):新增 #89 沙箱策略去品牌、#90 skill-badge 中文描述,
  扩展 #32/#53 的 rc.3 变体与 marker,均 optional
- 新增锚点接线与红队文案测试,81/81 通过
2026-10-31 01:51:15 +08:00

85 lines
3.4 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { rewritePromptAssembly } from "../lib/identity.js";
import { ANCHOR_SECTION, anchorTextFor } from "../lib/anchor.js";
import { readPresetDefinition } from "../lib/redteam/preset-composition.js";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
function assembledWith(sections = []) {
return {
sections: [{ name: "harness:identity", text: "host identity" }, ...sections],
tools: [],
contexts: [],
};
}
/* ---------------------------------------------------------------------------
* 锚点接线:waterfall 返回的 sections 数组顺序就是渲染顺序,
* 锚点必须物理排在最后一位,不能只靠 order 字段。
*/
test("rewritePromptAssembly: 锚点追加在 sections 数组最后一位", () => {
const out = rewritePromptAssembly(assembledWith([{ name: "tail", text: "tail text" }]), "PROMPT", {
anchorText: "ANCHOR BODY",
});
const last = out.sections[out.sections.length - 1];
assert.equal(last.name, ANCHOR_SECTION);
assert.equal(last.text, "ANCHOR BODY");
assert.equal(last.interpolate, false);
});
test("rewritePromptAssembly: 对象形式 options 也认 anchorText", () => {
const out = rewritePromptAssembly(assembledWith(), {
fallbackInject: "PROMPT",
anchorText: "ANCHOR BODY",
dropPurgeAfterFold: false,
});
const last = out.sections[out.sections.length - 1];
assert.equal(last.name, ANCHOR_SECTION);
});
test("rewritePromptAssembly: 已有同名段先滤掉,不会出现两份", () => {
const out = rewritePromptAssembly(
assembledWith([{ name: ANCHOR_SECTION, text: "OLD ANCHOR" }]),
"PROMPT",
{ anchorText: "NEW ANCHOR" },
);
const anchors = out.sections.filter((section) => section?.name === ANCHOR_SECTION);
assert.equal(anchors.length, 1);
assert.equal(anchors[0].text, "NEW ANCHOR");
assert.equal(out.sections[out.sections.length - 1].name, ANCHOR_SECTION);
});
test("rewritePromptAssembly: anchorText 为空时不注入锚点", () => {
const out = rewritePromptAssembly(assembledWith([{ name: "tail", text: "tail text" }]), "PROMPT", {
anchorText: "",
});
assert.equal(out.sections.some((section) => section?.name === ANCHOR_SECTION), false);
});
/* ---------------------------------------------------------------------------
* 锚点语言:不能把英文开头句写死,否则中文会话(尤其红队模式)会被拽成英文。
*/
test("anchor: 要求跟随用户语言,不强制英文开头", () => {
const text = anchorTextFor({});
assert.match(text, /same language/);
assert.equal(text.includes("Certainly! Here is"), false);
});
test("anchor: anchorMode=off 时不产出正文", () => {
assert.equal(anchorTextFor({ anchorMode: "off" }), "");
assert.notEqual(anchorTextFor({ anchorMode: "auto" }), "");
});
/* ---------------------------------------------------------------------------
* 红队模式下拉文案:必须是中文单行,不能被上游英文模板盖回来。
*/
test("presets/redteam/preset.yml: 模式名与描述是中文单行", () => {
const def = readPresetDefinition("redteam", path.join(repoRoot, "presets", "redteam"));
assert.equal(def.name, "红队模式");
assert.match(def.description, /攻防演练模式/);
assert.equal(def.description.includes("\n"), false);
});