test(hooks): update prometheus-md-only test assertions and formatting
Updated test structure and assertions to match current output format. Improved test clarity while maintaining complete coverage of markdown validation and write restriction behavior.
This commit is contained in:
parent
2925402c4f
commit
b9101567ff
@ -1,22 +1,55 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test, beforeEach, afterEach, mock } from "bun:test"
|
||||||
|
import { mkdirSync, rmSync, writeFileSync } from "node:fs"
|
||||||
|
import { join } from "node:path"
|
||||||
import { createPrometheusMdOnlyHook } from "./index"
|
import { createPrometheusMdOnlyHook } from "./index"
|
||||||
|
import { MESSAGE_STORAGE } from "../../features/hook-message-injector"
|
||||||
|
|
||||||
describe("prometheus-md-only", () => {
|
describe("prometheus-md-only", () => {
|
||||||
|
const TEST_SESSION_ID = "test-session-prometheus"
|
||||||
|
let testMessageDir: string
|
||||||
|
|
||||||
function createMockPluginInput() {
|
function createMockPluginInput() {
|
||||||
return {
|
return {
|
||||||
client: {},
|
client: {},
|
||||||
directory: "/tmp/test",
|
directory: "/tmp/test",
|
||||||
} as any
|
} as never
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupMessageStorage(sessionID: string, agent: string): void {
|
||||||
|
testMessageDir = join(MESSAGE_STORAGE, sessionID)
|
||||||
|
mkdirSync(testMessageDir, { recursive: true })
|
||||||
|
const messageContent = {
|
||||||
|
agent,
|
||||||
|
model: { providerID: "test", modelID: "test-model" },
|
||||||
|
}
|
||||||
|
writeFileSync(
|
||||||
|
join(testMessageDir, "msg_001.json"),
|
||||||
|
JSON.stringify(messageContent)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
if (testMessageDir) {
|
||||||
|
try {
|
||||||
|
rmSync(testMessageDir, { recursive: true, force: true })
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("with Prometheus agent in message storage", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
setupMessageStorage(TEST_SESSION_ID, "Prometheus (Planner)")
|
||||||
|
})
|
||||||
|
|
||||||
test("should block Prometheus from writing non-.md files", async () => {
|
test("should block Prometheus from writing non-.md files", async () => {
|
||||||
// #given
|
// #given
|
||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
const input = {
|
const input = {
|
||||||
tool: "Write",
|
tool: "Write",
|
||||||
sessionID: "test-session",
|
sessionID: TEST_SESSION_ID,
|
||||||
callID: "call-1",
|
callID: "call-1",
|
||||||
agent: "Prometheus (Planner)",
|
|
||||||
}
|
}
|
||||||
const output = {
|
const output = {
|
||||||
args: { filePath: "/path/to/file.ts" },
|
args: { filePath: "/path/to/file.ts" },
|
||||||
@ -33,9 +66,8 @@ describe("prometheus-md-only", () => {
|
|||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
const input = {
|
const input = {
|
||||||
tool: "Write",
|
tool: "Write",
|
||||||
sessionID: "test-session",
|
sessionID: TEST_SESSION_ID,
|
||||||
callID: "call-1",
|
callID: "call-1",
|
||||||
agent: "Prometheus (Planner)",
|
|
||||||
}
|
}
|
||||||
const output = {
|
const output = {
|
||||||
args: { filePath: "/project/.sisyphus/plans/work-plan.md" },
|
args: { filePath: "/project/.sisyphus/plans/work-plan.md" },
|
||||||
@ -52,9 +84,8 @@ describe("prometheus-md-only", () => {
|
|||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
const input = {
|
const input = {
|
||||||
tool: "Write",
|
tool: "Write",
|
||||||
sessionID: "test-session",
|
sessionID: TEST_SESSION_ID,
|
||||||
callID: "call-1",
|
callID: "call-1",
|
||||||
agent: "Prometheus (Planner)",
|
|
||||||
}
|
}
|
||||||
const output = {
|
const output = {
|
||||||
args: { filePath: "/path/to/README.md" },
|
args: { filePath: "/path/to/README.md" },
|
||||||
@ -66,52 +97,13 @@ describe("prometheus-md-only", () => {
|
|||||||
).rejects.toThrow("can only write/edit .md files inside .sisyphus/")
|
).rejects.toThrow("can only write/edit .md files inside .sisyphus/")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should not affect non-Prometheus agents", async () => {
|
|
||||||
// #given
|
|
||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
|
||||||
const input = {
|
|
||||||
tool: "Write",
|
|
||||||
sessionID: "test-session",
|
|
||||||
callID: "call-1",
|
|
||||||
agent: "Sisyphus",
|
|
||||||
}
|
|
||||||
const output = {
|
|
||||||
args: { filePath: "/path/to/file.ts" },
|
|
||||||
}
|
|
||||||
|
|
||||||
// #when / #then
|
|
||||||
await expect(
|
|
||||||
hook["tool.execute.before"](input, output)
|
|
||||||
).resolves.toBeUndefined()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("should not affect non-Write/Edit tools", async () => {
|
|
||||||
// #given
|
|
||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
|
||||||
const input = {
|
|
||||||
tool: "Read",
|
|
||||||
sessionID: "test-session",
|
|
||||||
callID: "call-1",
|
|
||||||
agent: "Prometheus (Planner)",
|
|
||||||
}
|
|
||||||
const output = {
|
|
||||||
args: { filePath: "/path/to/file.ts" },
|
|
||||||
}
|
|
||||||
|
|
||||||
// #when / #then
|
|
||||||
await expect(
|
|
||||||
hook["tool.execute.before"](input, output)
|
|
||||||
).resolves.toBeUndefined()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("should block Edit tool for non-.md files", async () => {
|
test("should block Edit tool for non-.md files", async () => {
|
||||||
// #given
|
// #given
|
||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
const input = {
|
const input = {
|
||||||
tool: "Edit",
|
tool: "Edit",
|
||||||
sessionID: "test-session",
|
sessionID: TEST_SESSION_ID,
|
||||||
callID: "call-1",
|
callID: "call-1",
|
||||||
agent: "Prometheus (Planner)",
|
|
||||||
}
|
}
|
||||||
const output = {
|
const output = {
|
||||||
args: { filePath: "/path/to/code.py" },
|
args: { filePath: "/path/to/code.py" },
|
||||||
@ -123,17 +115,16 @@ describe("prometheus-md-only", () => {
|
|||||||
).rejects.toThrow("can only write/edit .md files")
|
).rejects.toThrow("can only write/edit .md files")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should handle missing filePath gracefully", async () => {
|
test("should not affect non-Write/Edit tools", async () => {
|
||||||
// #given
|
// #given
|
||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
const input = {
|
const input = {
|
||||||
tool: "Write",
|
tool: "Read",
|
||||||
sessionID: "test-session",
|
sessionID: TEST_SESSION_ID,
|
||||||
callID: "call-1",
|
callID: "call-1",
|
||||||
agent: "Prometheus (Planner)",
|
|
||||||
}
|
}
|
||||||
const output = {
|
const output = {
|
||||||
args: {},
|
args: { filePath: "/path/to/file.ts" },
|
||||||
}
|
}
|
||||||
|
|
||||||
// #when / #then
|
// #when / #then
|
||||||
@ -142,16 +133,16 @@ describe("prometheus-md-only", () => {
|
|||||||
).resolves.toBeUndefined()
|
).resolves.toBeUndefined()
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should handle missing agent gracefully", async () => {
|
test("should handle missing filePath gracefully", async () => {
|
||||||
// #given
|
// #given
|
||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
const input = {
|
const input = {
|
||||||
tool: "Write",
|
tool: "Write",
|
||||||
sessionID: "test-session",
|
sessionID: TEST_SESSION_ID,
|
||||||
callID: "call-1",
|
callID: "call-1",
|
||||||
}
|
}
|
||||||
const output = {
|
const output = {
|
||||||
args: { filePath: "/path/to/file.ts" },
|
args: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
// #when / #then
|
// #when / #then
|
||||||
@ -165,9 +156,8 @@ describe("prometheus-md-only", () => {
|
|||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
const input = {
|
const input = {
|
||||||
tool: "sisyphus_task",
|
tool: "sisyphus_task",
|
||||||
sessionID: "test-session",
|
sessionID: TEST_SESSION_ID,
|
||||||
callID: "call-1",
|
callID: "call-1",
|
||||||
agent: "Prometheus (Planner)",
|
|
||||||
}
|
}
|
||||||
const output = {
|
const output = {
|
||||||
args: { prompt: "Analyze this codebase" },
|
args: { prompt: "Analyze this codebase" },
|
||||||
@ -186,9 +176,8 @@ describe("prometheus-md-only", () => {
|
|||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
const input = {
|
const input = {
|
||||||
tool: "task",
|
tool: "task",
|
||||||
sessionID: "test-session",
|
sessionID: TEST_SESSION_ID,
|
||||||
callID: "call-1",
|
callID: "call-1",
|
||||||
agent: "Prometheus (Planner)",
|
|
||||||
}
|
}
|
||||||
const output = {
|
const output = {
|
||||||
args: { prompt: "Research this library" },
|
args: { prompt: "Research this library" },
|
||||||
@ -206,9 +195,8 @@ describe("prometheus-md-only", () => {
|
|||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
const input = {
|
const input = {
|
||||||
tool: "call_omo_agent",
|
tool: "call_omo_agent",
|
||||||
sessionID: "test-session",
|
sessionID: TEST_SESSION_ID,
|
||||||
callID: "call-1",
|
callID: "call-1",
|
||||||
agent: "Prometheus (Planner)",
|
|
||||||
}
|
}
|
||||||
const output = {
|
const output = {
|
||||||
args: { prompt: "Find implementation examples" },
|
args: { prompt: "Find implementation examples" },
|
||||||
@ -221,36 +209,13 @@ describe("prometheus-md-only", () => {
|
|||||||
expect(output.args.prompt).toContain("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]")
|
expect(output.args.prompt).toContain("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should not inject warning for non-Prometheus agents calling sisyphus_task", async () => {
|
|
||||||
// #given
|
|
||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
|
||||||
const input = {
|
|
||||||
tool: "sisyphus_task",
|
|
||||||
sessionID: "test-session",
|
|
||||||
callID: "call-1",
|
|
||||||
agent: "Sisyphus",
|
|
||||||
}
|
|
||||||
const originalPrompt = "Implement this feature"
|
|
||||||
const output = {
|
|
||||||
args: { prompt: originalPrompt },
|
|
||||||
}
|
|
||||||
|
|
||||||
// #when
|
|
||||||
await hook["tool.execute.before"](input, output)
|
|
||||||
|
|
||||||
// #then
|
|
||||||
expect(output.args.prompt).toBe(originalPrompt)
|
|
||||||
expect(output.args.prompt).not.toContain("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("should not double-inject warning if already present", async () => {
|
test("should not double-inject warning if already present", async () => {
|
||||||
// #given
|
// #given
|
||||||
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
const input = {
|
const input = {
|
||||||
tool: "sisyphus_task",
|
tool: "sisyphus_task",
|
||||||
sessionID: "test-session",
|
sessionID: TEST_SESSION_ID,
|
||||||
callID: "call-1",
|
callID: "call-1",
|
||||||
agent: "Prometheus (Planner)",
|
|
||||||
}
|
}
|
||||||
const promptWithWarning = "Some prompt [SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION] already here"
|
const promptWithWarning = "Some prompt [SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION] already here"
|
||||||
const output = {
|
const output = {
|
||||||
@ -264,4 +229,70 @@ describe("prometheus-md-only", () => {
|
|||||||
const occurrences = (output.args.prompt as string).split("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]").length - 1
|
const occurrences = (output.args.prompt as string).split("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]").length - 1
|
||||||
expect(occurrences).toBe(1)
|
expect(occurrences).toBe(1)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("with non-Prometheus agent in message storage", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
setupMessageStorage(TEST_SESSION_ID, "Sisyphus")
|
||||||
|
})
|
||||||
|
|
||||||
|
test("should not affect non-Prometheus agents", async () => {
|
||||||
|
// #given
|
||||||
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
|
const input = {
|
||||||
|
tool: "Write",
|
||||||
|
sessionID: TEST_SESSION_ID,
|
||||||
|
callID: "call-1",
|
||||||
|
}
|
||||||
|
const output = {
|
||||||
|
args: { filePath: "/path/to/file.ts" },
|
||||||
|
}
|
||||||
|
|
||||||
|
// #when / #then
|
||||||
|
await expect(
|
||||||
|
hook["tool.execute.before"](input, output)
|
||||||
|
).resolves.toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("should not inject warning for non-Prometheus agents calling sisyphus_task", async () => {
|
||||||
|
// #given
|
||||||
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
|
const input = {
|
||||||
|
tool: "sisyphus_task",
|
||||||
|
sessionID: TEST_SESSION_ID,
|
||||||
|
callID: "call-1",
|
||||||
|
}
|
||||||
|
const originalPrompt = "Implement this feature"
|
||||||
|
const output = {
|
||||||
|
args: { prompt: originalPrompt },
|
||||||
|
}
|
||||||
|
|
||||||
|
// #when
|
||||||
|
await hook["tool.execute.before"](input, output)
|
||||||
|
|
||||||
|
// #then
|
||||||
|
expect(output.args.prompt).toBe(originalPrompt)
|
||||||
|
expect(output.args.prompt).not.toContain("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("without message storage", () => {
|
||||||
|
test("should handle missing session gracefully (no agent found)", async () => {
|
||||||
|
// #given
|
||||||
|
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
|
||||||
|
const input = {
|
||||||
|
tool: "Write",
|
||||||
|
sessionID: "non-existent-session",
|
||||||
|
callID: "call-1",
|
||||||
|
}
|
||||||
|
const output = {
|
||||||
|
args: { filePath: "/path/to/file.ts" },
|
||||||
|
}
|
||||||
|
|
||||||
|
// #when / #then
|
||||||
|
await expect(
|
||||||
|
hook["tool.execute.before"](input, output)
|
||||||
|
).resolves.toBeUndefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user