fix(plugin): harden metadata recovery and extraction

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-16 13:52:12 +09:00
parent 80d3339c4c
commit 4da3005797
7 changed files with 158 additions and 75 deletions
+61 -1
View File
@@ -1,7 +1,13 @@
import { describe, expect, it } from "bun:test"
import { beforeEach, describe, expect, it } from "bun:test"
import { clearPendingStore, storeToolMetadata } from "../features/tool-metadata-store"
import { createToolExecuteAfterHandler } from "./tool-execute-after"
describe("createToolExecuteAfterHandler", () => {
beforeEach(() => {
clearPendingStore()
})
it("#given truncator changes output #when tool.execute.after runs #then claudeCodeHooks receives truncated output", async () => {
const callOrder: string[] = []
let claudeSawOutput = ""
@@ -32,4 +38,58 @@ describe("createToolExecuteAfterHandler", () => {
expect(callOrder).toEqual(["truncator", "claude"])
expect(claudeSawOutput).toBe("truncated output")
})
it("#given stored metadata with legacy call id casing #when tool.execute.after runs #then it restores the stored metadata", async () => {
// given
storeToolMetadata("ses_parent", "call_legacy", {
title: "stored title",
metadata: { sessionId: "ses_child", agent: "oracle" },
})
const handler = createToolExecuteAfterHandler({
ctx: { directory: "/repo" } as never,
hooks: {} as never,
})
const output = { title: "result", output: "original output", metadata: { truncated: true } }
// when
await handler(
{ tool: "hashline_edit", sessionID: "ses_parent", callId: " call_legacy " },
output
)
// then
expect(output.title).toBe("stored title")
expect(output.metadata).toEqual({ truncated: true, sessionId: "ses_child", agent: "oracle" })
})
it("#given native session metadata #when stored metadata exists #then stored metadata does not overwrite native session linkage", async () => {
// given
storeToolMetadata("ses_parent", "call_native", {
title: "stored title",
metadata: { sessionId: "ses_stored", agent: "oracle" },
})
const handler = createToolExecuteAfterHandler({
ctx: { directory: "/repo" } as never,
hooks: {} as never,
})
const output = {
title: "result",
output: "original output",
metadata: { sessionId: "ses_native", agent: "hephaestus" },
}
// when
await handler(
{ tool: "hashline_edit", sessionID: "ses_parent", callID: "call_native" },
output
)
// then
expect(output.title).toBe("stored title")
expect(output.metadata).toEqual({ sessionId: "ses_native", agent: "hephaestus" })
})
})