test: cover runtime regression scenarios
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseEnvelopeJSON } from "../protocol";
|
||||
import { InteractionKernel } from "./interaction-kernel";
|
||||
|
||||
function envelope(overrides: Record<string, unknown> = {}): string {
|
||||
return JSON.stringify({
|
||||
v: 1,
|
||||
id: "evt_kernel_001",
|
||||
type: "lineup.v1.text",
|
||||
conversation_id: "conversation_kernel_test",
|
||||
sender: { kind: "agent", id: "agent_test" },
|
||||
payload: { markdown: "# Hello\n\n**trusted**" },
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
describe("InteractionKernel", () => {
|
||||
it("accepts a valid typed envelope and projects its trusted markdown item", () => {
|
||||
const kernel = new InteractionKernel();
|
||||
const result = kernel.ingest({ raw: envelope(), source: "sync", transport_id: "41" });
|
||||
|
||||
expect(result.disposition).toBe("accepted");
|
||||
expect(result.items).toEqual([expect.objectContaining({
|
||||
kind: "markdown",
|
||||
id: "evt_kernel_001",
|
||||
markdown: "# Hello\n\n**trusted**",
|
||||
})]);
|
||||
expect(result.snapshot.seen_envelope_ids).toBe(1);
|
||||
});
|
||||
|
||||
it("rejects invalid protocol JSON while preserving legacy plain text as safe markdown", () => {
|
||||
const kernel = new InteractionKernel();
|
||||
const invalidProtocol = parseEnvelopeJSON("{");
|
||||
const legacyText = kernel.ingest({ raw: "{", source: "sync" });
|
||||
const unknown = kernel.ingest({
|
||||
raw: envelope({ id: "evt_kernel_unknown", type: "lineup.v1.unknown" }),
|
||||
source: "live",
|
||||
});
|
||||
|
||||
expect(invalidProtocol).toMatchObject({ ok: false, fallback: { code: "invalid_json" } });
|
||||
expect(legacyText.items).toEqual([expect.objectContaining({ kind: "markdown", markdown: "{" })]);
|
||||
expect(unknown.items).toEqual([expect.objectContaining({ kind: "fallback", reason: "unsupported_type", id: "evt_kernel_unknown" })]);
|
||||
});
|
||||
|
||||
it("deduplicates one envelope id across sync and live transport sources", () => {
|
||||
const kernel = new InteractionKernel();
|
||||
const first = kernel.ingest({ raw: envelope(), source: "sync" });
|
||||
const duplicate = kernel.ingest({ raw: envelope(), source: "live" });
|
||||
|
||||
expect(first.disposition).toBe("accepted");
|
||||
expect(duplicate).toMatchObject({ disposition: "duplicate", items: [] });
|
||||
expect(duplicate.snapshot.seen_envelope_ids).toBe(1);
|
||||
});
|
||||
|
||||
it("projects the latest agent status by actor and retains a bounded dedupe set", () => {
|
||||
const kernel = new InteractionKernel(2);
|
||||
const thinking = kernel.ingest({
|
||||
raw: envelope({ id: "evt_status_thinking", type: "lineup.v1.agent.status", payload: { status: "thinking", detail: "planning" } }),
|
||||
source: "sync",
|
||||
received_at: "2026-08-03T00:00:00.000Z",
|
||||
});
|
||||
kernel.ingest({ raw: envelope({ id: "evt_other", payload: { markdown: "one" } }), source: "sync" });
|
||||
kernel.ingest({ raw: envelope({ id: "evt_newer", payload: { markdown: "two" } }), source: "sync" });
|
||||
|
||||
expect(thinking.snapshot.agent_presence).toEqual([expect.objectContaining({
|
||||
status: "thinking",
|
||||
detail: "planning",
|
||||
envelope_id: "evt_status_thinking",
|
||||
updated_at: "2026-08-03T00:00:00.000Z",
|
||||
})]);
|
||||
// The first id has expired from the bounded set and is accepted again.
|
||||
expect(kernel.ingest({ raw: envelope({ id: "evt_status_thinking" }), source: "live" }).disposition).toBe("accepted");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user