pi-ate-workflow 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +1 -0
- package/package.json +2 -2
- package/subagent-model.ts +20 -2
- package/tests/subagent-model.test.ts +109 -0
package/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ export {
|
|
|
25
25
|
isSubagentModelRestored,
|
|
26
26
|
setSubagentModelRestored,
|
|
27
27
|
restoreSubagentModel,
|
|
28
|
+
resolveSelectedByLabel,
|
|
28
29
|
} from "./subagent-model";
|
|
29
30
|
export { createSubagentWidget } from "./widget";
|
|
30
31
|
export { saveSubagentOutput, readSubagentOutput } from "./output";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ate-workflow",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"description": "Workflow orchestration extension for pi-coding-agent — subagent spawning, research workflow, output capture",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
]
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@pi-atelier/shared-utils": "^1.
|
|
13
|
+
"@pi-atelier/shared-utils": "^1.4.0"
|
|
14
14
|
},
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"@earendil-works/pi-coding-agent": ">=0.74.0"
|
package/subagent-model.ts
CHANGED
|
@@ -53,11 +53,29 @@ function persistModelToSettings(model: string): void {
|
|
|
53
53
|
{ defaultModel: model },
|
|
54
54
|
SUBAGENT_MODEL_DEFAULTS,
|
|
55
55
|
);
|
|
56
|
-
} catch {
|
|
57
|
-
//
|
|
56
|
+
} catch (e) {
|
|
57
|
+
// 写入失败不阻塞主流程,但必须留痕(静默吞错曾致持久化失败不可观测,fix-subagent-model-select-persist D3)。
|
|
58
|
+
// 直接传 e 保留 stack 与 Error.cause 链(harden-subagent-model-observability D1)
|
|
59
|
+
console.error("[subagent-model] persist 失败:", e);
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
/**
|
|
64
|
+
* 选择器回查:labels 与 displayItems 同序一一构建,按精确索引映射。
|
|
65
|
+
*
|
|
66
|
+
* 禁止 `choice.includes(item.value)` 子串匹配:候选含互为前缀的模型 ID
|
|
67
|
+
* (如 glm-5.3 / glm-5.3-flash)时,"…glm-5.3-flash…".includes("…glm-5.3")
|
|
68
|
+
* 恒为 true 且短 ID 字母序靠前,find 永远先命中它(fix-subagent-model-select-persist D1)。
|
|
69
|
+
*/
|
|
70
|
+
export function resolveSelectedByLabel<T>(
|
|
71
|
+
labels: string[],
|
|
72
|
+
items: T[],
|
|
73
|
+
choice: string,
|
|
74
|
+
): T | undefined {
|
|
75
|
+
const idx = labels.indexOf(choice);
|
|
76
|
+
return idx >= 0 && idx < items.length ? items[idx] : undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
61
79
|
export function getSubagentModel(): string {
|
|
62
80
|
return subagentModel;
|
|
63
81
|
}
|
|
@@ -22,7 +22,10 @@ import {
|
|
|
22
22
|
restoreSubagentModel,
|
|
23
23
|
isSubagentModelRestored,
|
|
24
24
|
setSubagentModelRestored,
|
|
25
|
+
resolveSelectedByLabel,
|
|
25
26
|
} from "../subagent-model";
|
|
27
|
+
// barrel 防回归:子路径 import 测不到导出遗漏(resolveSelectedByLabel 曾漏导出,UI 侧 import 得 undefined → TypeError 被 catch 吞)
|
|
28
|
+
import * as wfBarrel from "../index";
|
|
26
29
|
import { getEffectiveConfig, getSettingsValue } from "@pi-atelier/shared-utils";
|
|
27
30
|
|
|
28
31
|
describe("subagent-model 持久化", () => {
|
|
@@ -88,3 +91,109 @@ describe("subagent-model 持久化", () => {
|
|
|
88
91
|
expect(getSubagentModel()).toBe("x/y");
|
|
89
92
|
});
|
|
90
93
|
});
|
|
94
|
+
|
|
95
|
+
describe("resolveSelectedByLabel 索引精确回查(前缀子串陷阱)", () => {
|
|
96
|
+
// 复现 fix-subagent-model-select-persist D1:选 glm-5.3-flash 被 includes 误配成 glm-5.3
|
|
97
|
+
interface Item {
|
|
98
|
+
value: string;
|
|
99
|
+
label: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const items: Item[] = [
|
|
103
|
+
{ value: "zai-coding-cn/glm-4.6v", label: "GLM-4.6V" },
|
|
104
|
+
{ value: "zai-coding-cn/glm-5.3", label: "GLM-5.3" },
|
|
105
|
+
{ value: "zai-coding-cn/glm-5.3-flash", label: "GLM-5.3-Flash" },
|
|
106
|
+
{ value: "zai-coding-cn/glm-5.3-highspeed", label: "GLM-5.3-Highspeed" },
|
|
107
|
+
{ value: "zai-coding-cn/glm-5.4", label: "GLM-5.4" },
|
|
108
|
+
];
|
|
109
|
+
const labelOf = (m: Item) => ` ${m.value} (${m.label})`;
|
|
110
|
+
|
|
111
|
+
it("选长 ID(glm-5.3-flash)不被短 ID(glm-5.3)前缀劫持", () => {
|
|
112
|
+
const choice = labelOf(items[2]);
|
|
113
|
+
expect(
|
|
114
|
+
resolveSelectedByLabel(items.map(labelOf), items, choice),
|
|
115
|
+
).toBe(items[2]);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("选短 ID(glm-5.3)不受更长兄弟干扰", () => {
|
|
119
|
+
const choice = labelOf(items[1]);
|
|
120
|
+
expect(
|
|
121
|
+
resolveSelectedByLabel(items.map(labelOf), items, choice),
|
|
122
|
+
).toBe(items[1]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("当前项提前重排后索引仍对齐(● 前缀)", () => {
|
|
126
|
+
const reordered = [items[4], items[0], items[1], items[2], items[3]];
|
|
127
|
+
const labels = reordered.map((m, i) =>
|
|
128
|
+
i === 0 ? `● ${m.value} (${m.label})` : ` ${m.value} (${m.label})`,
|
|
129
|
+
);
|
|
130
|
+
expect(resolveSelectedByLabel(labels, reordered, labels[3])).toBe(items[2]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("未匹配(choice 不在 labels)返回 undefined", () => {
|
|
134
|
+
expect(
|
|
135
|
+
resolveSelectedByLabel(items.map(labelOf), items, "nope"),
|
|
136
|
+
).toBeUndefined();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("旧实现反例:includes 子串匹配会误命中(回归警示)", () => {
|
|
140
|
+
// 模拟旧 find+includes 行为,证明本修复的必要性
|
|
141
|
+
const choice = labelOf(items[2]);
|
|
142
|
+
const legacy = items.find((m) => choice.includes(m.value));
|
|
143
|
+
expect(legacy).toBe(items[1]); // 旧逻辑抓错:flash 被 glm-5.3 劫持
|
|
144
|
+
expect(legacy).not.toBe(items[2]);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("barrel 导出防回归", () => {
|
|
149
|
+
// 子路径 import 测不到 index.ts 导出遗漏;resolveSelectedByLabel 曾漏导出致 UI 侧 TypeError 被 catch 吞
|
|
150
|
+
it("resolveSelectedByLabel 经 index.ts barrel 可达", () => {
|
|
151
|
+
expect(typeof wfBarrel.resolveSelectedByLabel).toBe("function");
|
|
152
|
+
expect(typeof wfBarrel.setSubagentModel).toBe("function");
|
|
153
|
+
expect(typeof wfBarrel.getSubagentModel).toBe("function");
|
|
154
|
+
expect(typeof wfBarrel.restoreSubagentModel).toBe("function");
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe("persist 失败留痕护栏(harden-subagent-model-observability D2/D4)", () => {
|
|
159
|
+
beforeEach(() => {
|
|
160
|
+
vi.clearAllMocks();
|
|
161
|
+
setSubagentModelRestored(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("留痕传原始错误对象(stack/cause 不剥离)", () => {
|
|
165
|
+
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
166
|
+
const boom = new Error("lock contention", { cause: new Error("ENOENT") });
|
|
167
|
+
patchMock.mockImplementation(() => {
|
|
168
|
+
throw boom;
|
|
169
|
+
});
|
|
170
|
+
setSubagentModel("zai-coding-cn/glm-5.4");
|
|
171
|
+
expect(errSpy).toHaveBeenCalledTimes(1);
|
|
172
|
+
// 第二参数必须是原 Error 对象(含 stack/cause),不是 e.message 字符串
|
|
173
|
+
expect(errSpy).toHaveBeenCalledWith(
|
|
174
|
+
"[subagent-model] persist 失败:",
|
|
175
|
+
boom,
|
|
176
|
+
);
|
|
177
|
+
errSpy.mockRestore();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("留痕回退被拦截:静默吞时本用例变红(护栏)", () => {
|
|
181
|
+
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
|
182
|
+
patchMock.mockImplementation(() => {
|
|
183
|
+
throw new Error("boom");
|
|
184
|
+
});
|
|
185
|
+
setSubagentModel("zai-coding-cn/glm-5.4");
|
|
186
|
+
// 若 catch 改回静默吞,这里的 toHaveBeenCalledTimes(1) 失败 → 回归可见
|
|
187
|
+
expect(errSpy).toHaveBeenCalledTimes(1);
|
|
188
|
+
errSpy.mockRestore();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("越界防御:labels 短于 items 时按索引取值(D4)", () => {
|
|
192
|
+
expect(
|
|
193
|
+
resolveSelectedByLabel(["a"], [{ v: 1 }, { v: 2 }], "a"),
|
|
194
|
+
).toEqual({ v: 1 });
|
|
195
|
+
expect(
|
|
196
|
+
resolveSelectedByLabel(["a", "b", "c"], [{ v: 1 }], "c"),
|
|
197
|
+
).toBeUndefined();
|
|
198
|
+
});
|
|
199
|
+
});
|