Files
my-pi/pi-notify/tests/config.test.ts
T
云服务部-叶林立andDevin <158243242+devin-ai-integration[bot]@users.noreply.github.com> e996f59469 refactor: notify/footer 持久配置收编到 config/,chrome bridge 地址固定
仓库规则要求 config/ 为唯一配置来源、不以环境变量作持久默认值:
- pi-notify 改读 config/pi-notify.json(逐字段校验回退,复用原 parsers 钳制)
- pi-minimal-footer 改读 config/pi-minimal-footer.json
- pi-chrome 移除 PI_CHROME_BRIDGE_HOST/PORT,固定 127.0.0.1:17318
  (浏览器端 service_worker.js 硬编码同一地址,单侧可配只会断连)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-21 19:16:47 -07:00

97 lines
2.9 KiB
TypeScript

import assert from "node:assert/strict";
import { describe, it } from "node:test";
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
import { getConfig, shouldNotify } from "../src/config.ts";
import type { NotifySettings } from "../src/settings.ts";
const defaultSettings = (): NotifySettings => ({
enabled: true,
title: "π - {project}",
body: "{message}",
messageSource: "assistant",
messageMax: 80,
minDurationMs: 3_000,
visibility: "always",
action: "focus",
});
function context(): ExtensionContext {
return {
cwd: "/tmp/pi-notify",
model: { provider: "openai", id: "gpt-4.1" },
} as ExtensionContext;
}
const runtime = { notificationId: "pi-session", toolErrorCount: 0 };
describe("config", () => {
it("builds safe Kitty defaults from the settled assistant output", () => {
const config = getConfig(
context(),
800,
[
{ role: "user", content: "please fix this" },
{ role: "assistant", content: "fixed it" },
],
runtime,
5_000,
defaultSettings(),
);
assert.deepEqual(config, {
enabled: true,
title: "π - pi-notify",
body: "fixed it",
durationMs: 4_200,
minDurationMs: 3_000,
notificationId: "pi-session",
visibility: "always",
action: "focus",
soundCommand: undefined,
});
assert.equal(shouldNotify(config), true);
});
it("supports privacy, threshold, focus, and status template settings", () => {
const config = getConfig(context(), 1_000, [{ role: "assistant", content: "secret" }], {
notificationId: "pi-session",
toolErrorCount: 2,
}, 2_000, {
...defaultSettings(),
enabled: false,
title: "{status_icon} {status} {tool_error_count}",
body: "{message}",
messageSource: "none",
minDurationMs: 10_500,
visibility: "invisible",
action: "none",
soundCommand: "say done",
});
assert.equal(config.title, "⚠ ready · 2 tool errors 2");
assert.equal(config.body, "Ready for input");
assert.equal(config.enabled, false);
assert.equal(config.minDurationMs, 10_500);
assert.equal(config.visibility, "invisible");
assert.equal(config.action, "none");
assert.equal(config.soundCommand, "say done");
assert.equal(shouldNotify(config), false);
assert.equal(shouldNotify(config, true), false, "the minimum duration still applies to command overrides");
});
it("applies selected-message truncation and a session override", () => {
const config = getConfig(
context(),
1_000,
[{ role: "user", content: "hello world" }],
runtime,
2_000,
{ ...defaultSettings(), messageSource: "user", messageMax: 5, minDurationMs: 0 },
);
assert.equal(config.body, "hell…");
assert.equal(shouldNotify(config, false), false);
assert.equal(shouldNotify(config, true), true);
});
});