src / mcp / sourceNotation.test.ts
src / mcp / sourceNotation.test.ts
import assert from "node:assert/strict";
import test from "node:test";
import { assertNoAttachmentNotation, collectAttachmentTokens, UnsupportedAttachmentNotationError } from "./sourceNotation.js";
import type { McpResultPreset } from "./core-bundle.mjs";
const bionicPreset: McpResultPreset = { name: "bionic", includeBase64Preview: false, writeHtmlReportForMultipleResults: true, scratchpadFolderRequired: true };
const unslothPreset: McpResultPreset = { name: "unsloth", includeBase64Preview: true, writeHtmlReportForMultipleResults: false, scratchpadFolderRequired: true };
test("rejects aN inside a targets array", () => {
assert.throws(() => assertNoAttachmentNotation({ targets: ["a1"] }, bionicPreset), UnsupportedAttachmentNotationError);
});
test("rejects aN case-insensitively and the bare shorthand form", () => {
assert.throws(() => assertNoAttachmentNotation({ targets: ["A5"] }, bionicPreset), UnsupportedAttachmentNotationError);
assert.throws(() => assertNoAttachmentNotation({ targets: ["a"] }, bionicPreset), UnsupportedAttachmentNotationError);
});
test("rejects aN inside a comma/space-separated targets string", () => {
assert.throws(() => assertNoAttachmentNotation({ targets: "i1, a3" }, bionicPreset), UnsupportedAttachmentNotationError);
assert.throws(() => assertNoAttachmentNotation({ targets: "i1 a3" }, bionicPreset), UnsupportedAttachmentNotationError);
});
test("passes vN/pN/iN, filenames, and absolute paths through unchanged", () => {
assert.doesNotThrow(() => assertNoAttachmentNotation({ targets: ["v1", "p2", "i3"] }, bionicPreset));
assert.doesNotThrow(() => assertNoAttachmentNotation({ targets: "source.png" }, bionicPreset));
assert.doesNotThrow(() => assertNoAttachmentNotation({ targets: "/abs/path/source.png" }, bionicPreset));
});
test("tolerates missing targets", () => {
assert.doesNotThrow(() => assertNoAttachmentNotation({}, bionicPreset));
});
test("no-ops entirely for the unsloth preset", () => {
assert.doesNotThrow(() => assertNoAttachmentNotation({ targets: ["a1", "aN"] }, unslothPreset));
});
test("collectAttachmentTokens gathers deduplicated aN-shaped tokens from targets", () => {
assert.deepEqual(collectAttachmentTokens({ targets: ["a1", "a2", "a1"] }), ["a1", "a2"]);
assert.deepEqual(collectAttachmentTokens({ targets: "a3, a4 a3" }), ["a3", "a4"]);
assert.deepEqual(collectAttachmentTokens({ targets: ["v1"] }), []);
});
test("collectAttachmentTokens accepts the bare 'a' and literal 'aN' placeholder", () => {
assert.deepEqual(collectAttachmentTokens({ targets: ["aN"] }), ["aN"]);
assert.deepEqual(collectAttachmentTokens({ targets: ["a"] }), ["a"]);
});
import assert from "node:assert/strict";
import test from "node:test";
import { assertNoAttachmentNotation, collectAttachmentTokens, UnsupportedAttachmentNotationError } from "./sourceNotation.js";
import type { McpResultPreset } from "./core-bundle.mjs";
const bionicPreset: McpResultPreset = { name: "bionic", includeBase64Preview: false, writeHtmlReportForMultipleResults: true, scratchpadFolderRequired: true };
const unslothPreset: McpResultPreset = { name: "unsloth", includeBase64Preview: true, writeHtmlReportForMultipleResults: false, scratchpadFolderRequired: true };
test("rejects aN inside a targets array", () => {
assert.throws(() => assertNoAttachmentNotation({ targets: ["a1"] }, bionicPreset), UnsupportedAttachmentNotationError);
});
test("rejects aN case-insensitively and the bare shorthand form", () => {
assert.throws(() => assertNoAttachmentNotation({ targets: ["A5"] }, bionicPreset), UnsupportedAttachmentNotationError);
assert.throws(() => assertNoAttachmentNotation({ targets: ["a"] }, bionicPreset), UnsupportedAttachmentNotationError);
});
test("rejects aN inside a comma/space-separated targets string", () => {
assert.throws(() => assertNoAttachmentNotation({ targets: "i1, a3" }, bionicPreset), UnsupportedAttachmentNotationError);
assert.throws(() => assertNoAttachmentNotation({ targets: "i1 a3" }, bionicPreset), UnsupportedAttachmentNotationError);
});
test("passes vN/pN/iN, filenames, and absolute paths through unchanged", () => {
assert.doesNotThrow(() => assertNoAttachmentNotation({ targets: ["v1", "p2", "i3"] }, bionicPreset));
assert.doesNotThrow(() => assertNoAttachmentNotation({ targets: "source.png" }, bionicPreset));
assert.doesNotThrow(() => assertNoAttachmentNotation({ targets: "/abs/path/source.png" }, bionicPreset));
});
test("tolerates missing targets", () => {
assert.doesNotThrow(() => assertNoAttachmentNotation({}, bionicPreset));
});
test("no-ops entirely for the unsloth preset", () => {
assert.doesNotThrow(() => assertNoAttachmentNotation({ targets: ["a1", "aN"] }, unslothPreset));
});
test("collectAttachmentTokens gathers deduplicated aN-shaped tokens from targets", () => {
assert.deepEqual(collectAttachmentTokens({ targets: ["a1", "a2", "a1"] }), ["a1", "a2"]);
assert.deepEqual(collectAttachmentTokens({ targets: "a3, a4 a3" }), ["a3", "a4"]);
assert.deepEqual(collectAttachmentTokens({ targets: ["v1"] }), []);
});
test("collectAttachmentTokens accepts the bare 'a' and literal 'aN' placeholder", () => {
assert.deepEqual(collectAttachmentTokens({ targets: ["aN"] }), ["aN"]);
assert.deepEqual(collectAttachmentTokens({ targets: ["a"] }), ["a"]);
});