feat: snip a region into chat, and make links clickable (#14)
This commit was merged in pull request #14.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { readSnipContext, snipDirectory } from "../lib/snip";
|
||||
|
||||
/**
|
||||
* The snip handoff crosses a command boundary as a serialized launch context, so
|
||||
* every field arrives as unknown. This is the boundary where a wrong type would
|
||||
* otherwise reach the file system as a path.
|
||||
*/
|
||||
|
||||
describe("readSnipContext", () => {
|
||||
it("reads the fields the snip command writes", () => {
|
||||
expect(
|
||||
readSnipContext({
|
||||
snipPath: "/tmp/snip.png",
|
||||
snipError: "no tool",
|
||||
sessionId: "abc123",
|
||||
}),
|
||||
).toEqual({ snipPath: "/tmp/snip.png", snipError: "no tool", sessionId: "abc123" });
|
||||
});
|
||||
|
||||
it("returns nothing for a launch with no context at all", () => {
|
||||
expect(readSnipContext(undefined)).toEqual({});
|
||||
expect(readSnipContext(null)).toEqual({});
|
||||
});
|
||||
|
||||
it("ignores a context that is not an object", () => {
|
||||
expect(readSnipContext("snip.png")).toEqual({});
|
||||
expect(readSnipContext(42)).toEqual({});
|
||||
expect(readSnipContext(["/tmp/snip.png"])).toEqual({});
|
||||
});
|
||||
|
||||
it("drops a value that is not a string rather than passing it on", () => {
|
||||
// A number or object here would reach `readAttachment` as a path.
|
||||
expect(readSnipContext({ snipPath: 42, sessionId: { id: "x" } })).toEqual({});
|
||||
});
|
||||
|
||||
it("treats an empty string as absent", () => {
|
||||
expect(readSnipContext({ snipPath: "", sessionId: "" })).toEqual({});
|
||||
});
|
||||
|
||||
it("ignores unknown keys, so a stray field cannot widen the contract", () => {
|
||||
expect(readSnipContext({ snipPath: "/tmp/snip.png", somethingElse: "/etc/passwd" })).toEqual({
|
||||
snipPath: "/tmp/snip.png",
|
||||
});
|
||||
});
|
||||
|
||||
it("reads a payload that only names a conversation, which is a cancelled snip", () => {
|
||||
expect(readSnipContext({ sessionId: "abc123" })).toEqual({ sessionId: "abc123" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("snipDirectory", () => {
|
||||
it("keeps snips under the extension's support directory, not a temp directory", () => {
|
||||
// A stored conversation holds the path, so it has to survive a reboot.
|
||||
expect(snipDirectory()).toBe("/tmp/lam-agent-support/snips");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user