pi-ate-workflow 0.2.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-ate-workflow",
3
- "version": "0.2.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",
package/subagent-model.ts CHANGED
@@ -54,11 +54,9 @@ function persistModelToSettings(model: string): void {
54
54
  SUBAGENT_MODEL_DEFAULTS,
55
55
  );
56
56
  } catch (e) {
57
- // 写入失败不阻塞主流程,但必须留痕(静默吞错曾致持久化失败不可观测,fix-subagent-model-select-persist D3)
58
- console.error(
59
- "[subagent-model] persist 失败:",
60
- e instanceof Error ? e.message : e,
61
- );
57
+ // 写入失败不阻塞主流程,但必须留痕(静默吞错曾致持久化失败不可观测,fix-subagent-model-select-persist D3)。
58
+ // 直接传 e 保留 stack 与 Error.cause 链(harden-subagent-model-observability D1)
59
+ console.error("[subagent-model] persist 失败:", e);
62
60
  }
63
61
  }
64
62
 
@@ -154,3 +154,46 @@ describe("barrel 导出防回归", () => {
154
154
  expect(typeof wfBarrel.restoreSubagentModel).toBe("function");
155
155
  });
156
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
+ });