diff --git a/src/infra/path-safety.test.ts b/src/infra/path-safety.test.ts index b05eeced172..9c85fbac63e 100644 --- a/src/infra/path-safety.test.ts +++ b/src/infra/path-safety.test.ts @@ -3,14 +3,20 @@ import { describe, expect, it } from "vitest"; import { isWithinDir, resolveSafeBaseDir } from "./path-safety.js"; describe("path-safety", () => { - it("resolves safe base dir with trailing separator", () => { - const base = resolveSafeBaseDir("/tmp/demo"); - expect(base.endsWith(path.sep)).toBe(true); + it.each([ + { rootDir: "/tmp/demo", expected: `${path.resolve("/tmp/demo")}${path.sep}` }, + { rootDir: `/tmp/demo${path.sep}`, expected: `${path.resolve("/tmp/demo")}${path.sep}` }, + ])("resolves safe base dir for %j", ({ rootDir, expected }) => { + expect(resolveSafeBaseDir(rootDir)).toBe(expected); }); - it("checks directory containment", () => { - expect(isWithinDir("/tmp/demo", "/tmp/demo")).toBe(true); - expect(isWithinDir("/tmp/demo", "/tmp/demo/sub/file.txt")).toBe(true); - expect(isWithinDir("/tmp/demo", "/tmp/demo/../escape.txt")).toBe(false); + it.each([ + { rootDir: "/tmp/demo", targetPath: "/tmp/demo", expected: true }, + { rootDir: "/tmp/demo", targetPath: "/tmp/demo/sub/file.txt", expected: true }, + { rootDir: "/tmp/demo", targetPath: "/tmp/demo/../escape.txt", expected: false }, + { rootDir: "/tmp/demo", targetPath: "/tmp/demo-sibling/file.txt", expected: false }, + { rootDir: "/tmp/demo", targetPath: "sub/file.txt", expected: false }, + ])("checks containment for %j", ({ rootDir, targetPath, expected }) => { + expect(isWithinDir(rootDir, targetPath)).toBe(expected); }); }); diff --git a/src/infra/plain-object.test.ts b/src/infra/plain-object.test.ts index b87e555b21a..892e5c89fab 100644 --- a/src/infra/plain-object.test.ts +++ b/src/infra/plain-object.test.ts @@ -2,17 +2,17 @@ import { describe, expect, it } from "vitest"; import { isPlainObject } from "./plain-object.js"; describe("isPlainObject", () => { - it("accepts plain objects", () => { - expect(isPlainObject({})).toBe(true); - expect(isPlainObject({ a: 1 })).toBe(true); - }); + it.each([{}, { a: 1 }, Object.create(null), new (class X {})()])( + "accepts object-tag values: %j", + (value) => { + expect(isPlainObject(value)).toBe(true); + }, + ); - it("rejects non-plain values", () => { - expect(isPlainObject(null)).toBe(false); - expect(isPlainObject([])).toBe(false); - expect(isPlainObject(new Date())).toBe(false); - expect(isPlainObject(/re/)).toBe(false); - expect(isPlainObject("x")).toBe(false); - expect(isPlainObject(42)).toBe(false); - }); + it.each([null, [], new Date(), /re/, "x", 42, () => null, new Map()])( + "rejects non-plain values: %j", + (value) => { + expect(isPlainObject(value)).toBe(false); + }, + ); }); diff --git a/src/infra/system-message.test.ts b/src/infra/system-message.test.ts index b0c32f31c35..5cb1d4be87f 100644 --- a/src/infra/system-message.test.ts +++ b/src/infra/system-message.test.ts @@ -2,8 +2,21 @@ import { describe, expect, it } from "vitest"; import { SYSTEM_MARK, hasSystemMark, prefixSystemMessage } from "./system-message.js"; describe("system-message", () => { - it("prepends the system mark once", () => { - expect(prefixSystemMessage("thread notice")).toBe(`${SYSTEM_MARK} thread notice`); + it.each([ + { input: "thread notice", expected: `${SYSTEM_MARK} thread notice` }, + { input: ` thread notice `, expected: `${SYSTEM_MARK} thread notice` }, + { input: " ", expected: "" }, + ])("prefixes %j", ({ input, expected }) => { + expect(prefixSystemMessage(input)).toBe(expected); + }); + + it.each([ + { input: `${SYSTEM_MARK} already prefixed`, expected: true }, + { input: ` ${SYSTEM_MARK} hello`, expected: true }, + { input: "", expected: false }, + { input: "hello", expected: false }, + ])("detects marks for %j", ({ input, expected }) => { + expect(hasSystemMark(input)).toBe(expected); }); it("does not double-prefix messages that already have the mark", () => { @@ -11,9 +24,4 @@ describe("system-message", () => { `${SYSTEM_MARK} already prefixed`, ); }); - - it("detects marked system text after trim normalization", () => { - expect(hasSystemMark(` ${SYSTEM_MARK} hello`)).toBe(true); - expect(hasSystemMark("hello")).toBe(false); - }); });