Skip to content

Commit a076df4

Browse files
committed
test: add formatError and isStructuredDocumentPath edge case tests
- formatError: Error message extraction, non-Error coercion, empty message - isStructuredDocumentPath: files without extensions, dotfiles, empty string Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
1 parent 29e343c commit a076df4

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

test/unit/initializeProject.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@ import { MINIMUM_SUPPORTED_PATCHLOOM_VERSION } from "../../src/binary/patchloom.
44
import { classifyAgentsFile } from "../../src/commands/initializeProject.js";
55
import { buildStatusDetails, preferredStatusAction } from "../../src/commands/showStatus.js";
66
import { buildPatchloomMcpEntry, configureMcpTargets, inspectMcpTargets } from "../../src/mcp/config.js";
7+
import { formatError } from "../../src/util.js";
8+
9+
test("formatError extracts message from Error instances", () => {
10+
assert.equal(formatError(new Error("disk full")), "disk full");
11+
});
12+
13+
test("formatError converts non-Error values to strings", () => {
14+
assert.equal(formatError("raw string"), "raw string");
15+
assert.equal(formatError(42), "42");
16+
assert.equal(formatError(null), "null");
17+
assert.equal(formatError(undefined), "undefined");
18+
});
19+
20+
test("formatError falls back to String for Error with empty message", () => {
21+
const err = new Error("");
22+
assert.equal(formatError(err), String(err));
23+
});
724

825
test("classifyAgentsFile returns missing when AGENTS.md does not exist", () => {
926
assert.equal(classifyAgentsFile(undefined, "# Rules\n"), "missing");

test/unit/quickActions.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ test("isStructuredDocumentPath handles uppercase extensions", () => {
9393
assert.equal(isStructuredDocumentPath("README.MD"), false);
9494
});
9595

96+
test("isStructuredDocumentPath rejects files without extensions", () => {
97+
assert.equal(isStructuredDocumentPath("Makefile"), false);
98+
assert.equal(isStructuredDocumentPath(""), false);
99+
assert.equal(isStructuredDocumentPath("file."), false);
100+
});
101+
102+
test("isStructuredDocumentPath rejects dotfiles without basenames", () => {
103+
assert.equal(isStructuredDocumentPath(".json"), false);
104+
assert.equal(isStructuredDocumentPath(".yaml"), false);
105+
assert.equal(isStructuredDocumentPath(".env"), false);
106+
});
107+
96108
test("buildTidyQuickAction with a single fix omits unselected flags", () => {
97109
const action = buildTidyQuickAction("/workspace/demo/file.txt", ["normalize-eol-lf"]);
98110

0 commit comments

Comments
 (0)