Files
pi-auto-reinject/test/diag.test.ts
T
grayhook ef9b7a8c30 Phase 14: B-002 pre-fix RPC repro — filter snapshots and readSettings fix
RPC E2E with debug shows registered present at session_compact but planned=[]
because kept still contains the skill block; registered=[] still drops skills
absent from kept. Sync file readSettings avoids RPC hook deadlock on
SettingsManager/isProjectTrusted.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-17 15:21:53 +07:00

87 lines
2.0 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { buildReinjectDiagSnapshot, notifyReinjectDiag } from "../src/diag.js";
import { createDefaultSettings } from "../src/settings.js";
import { createInitialState } from "../src/state.js";
describe("buildReinjectDiagSnapshot", () => {
it("collects tracked, kept, registered, planned, and pending", () => {
const state = createInitialState();
state.skills.push({
name: "alpha",
filePath: "/skills/alpha/SKILL.md",
baseDir: "/skills/alpha",
firstSeenAt: 1,
lastSeenAt: 1,
sources: ["slash"],
});
state.pendingReinject = ["alpha"];
expect(
buildReinjectDiagSnapshot(
state,
[{ name: "beta" }],
new Set(["gamma"]),
["alpha"],
),
).toEqual({
tracked: ["alpha"],
kept: ["gamma"],
registered: ["beta"],
planned: ["alpha"],
pending: ["alpha"],
});
});
});
describe("notifyReinjectDiag", () => {
it("no-ops when debug is off", () => {
const notify = vi.fn();
notifyReinjectDiag(
{
hasUI: true,
ui: { notify },
} as never,
createDefaultSettings(),
"session_compact",
{
tracked: [],
kept: [],
registered: [],
planned: [],
pending: [],
},
);
expect(notify).not.toHaveBeenCalled();
});
it("notifies with JSON snapshot when debug is on", () => {
const notify = vi.fn();
const stderrSpy = vi.spyOn(console, "error").mockImplementation(() => {});
const settings = { ...createDefaultSettings(), debug: true };
const snapshot = {
tracked: ["a"],
kept: [],
registered: [],
planned: ["a"],
pending: ["a"],
};
notifyReinjectDiag(
{
hasUI: true,
ui: { notify },
} as never,
settings,
"before_agent_start",
snapshot,
);
expect(stderrSpy).toHaveBeenCalledWith(
`skill-reinject [before_agent_start]: ${JSON.stringify(snapshot)}`,
);
expect(notify).toHaveBeenCalledWith(
`skill-reinject [before_agent_start]: ${JSON.stringify(snapshot)}`,
"info",
);
stderrSpy.mockRestore();
});
});