Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions __tests__/keep-lint-item.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,36 @@ describe("keepLintItem", () => {
expect(keepLintItem(baseItem({ executionErrors: [] }))).toBe(false);
expect(keepLintItem(baseItem({ executionErrors: undefined }))).toBe(false);
});

test("drops compact fixedResult items (no notAppliedFixes)", () => {
expect(
keepLintItem({
path: "clean.md",
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: { convergence: "stable" },
})
).toBe(false);
});

test("keeps compact fixedResult items with cycle convergence", () => {
expect(
keepLintItem({
path: "cycle.md",
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: { convergence: "cycle" },
})
).toBe(true);
});
});
153 changes: 153 additions & 0 deletions __tests__/lint-worker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { jest } from "@jest/globals";
jest.mock("@lint-md/core", () => ({
fixMarkdown: jest.fn(),
lintMarkdown: jest.fn(),
FixConvergence: {
STABLE: "stable",
CYCLE_DETECTED: "cycle",
MAX_ROUNDS: "max",
},
}));

import { fixMarkdown, lintMarkdown } from "@lint-md/core";
Expand Down Expand Up @@ -118,4 +123,152 @@ describe("lintWorker executionErrors passthrough", () => {
);
expect(mockedLintMarkdown).not.toHaveBeenCalled();
});

test("returns compact fixedResult for clean fix items", async () => {
const file = path.join(tmpDir, "clean-fix.md");
await writeFile(file, "# Clean\n", "utf8");

mockedFixMarkdown.mockReturnValue({
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: {
result: "# Clean\n",
notAppliedFixes: [],
convergence: "stable",
metrics: { rounds: 1, wallTime: 0.5, perRound: [0.5] },
},
executionErrors: [],
} as any);

const result = await lintWorker({
filePath: file,
rules: {},
isFixMode: true,
});

// Compact form: convergence and metrics preserved, result and notAppliedFixes dropped
expect(result.fixedResult).toEqual({
convergence: "stable",
metrics: { rounds: 1, wallTime: 0.5, perRound: [0.5] },
});
expect(result.fixedResult).not.toHaveProperty("result");
expect(result.fixedResult).not.toHaveProperty("notAppliedFixes");
});

test("returns full fixedResult for actionable fix items (diagnostics)", async () => {
const file = path.join(tmpDir, "actionable-fix.md");
await writeFile(file, "1. hello\n2.\n", "utf8");

mockedFixMarkdown.mockReturnValue({
lintResult: [],
diagnostics: [
{
ruleId: "no-empty-list",
message: "empty list item",
line: 2,
column: 1,
severity: 2,
},
],
summary: {
errorCount: 1,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: {
result: "1. hello\n2. item\n",
notAppliedFixes: [],
convergence: "stable",
},
executionErrors: [],
} as any);

const result = await lintWorker({
filePath: file,
rules: {},
isFixMode: true,
});

// Full form preserved because item has diagnostics
expect(result.fixedResult).toHaveProperty("result", "1. hello\n2. item\n");
expect(result.fixedResult).toHaveProperty("notAppliedFixes");
});

test("returns full fixedResult when convergence is cycle", async () => {
const file = path.join(tmpDir, "cycle-fix.md");
await writeFile(file, "# Title\n", "utf8");

mockedFixMarkdown.mockReturnValue({
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: {
result: "# Title\n",
notAppliedFixes: [],
convergence: "cycle",
metrics: {
rounds: 5,
wallTime: 1.0,
perRound: [0.2, 0.2, 0.2, 0.2, 0.2],
},
},
executionErrors: [],
} as any);

const result = await lintWorker({
filePath: file,
rules: {},
isFixMode: true,
});

// Full form preserved because isIncompleteFix(item) is true
expect(result.fixedResult).toHaveProperty("result", "# Title\n");
expect(result.fixedResult).toHaveProperty("notAppliedFixes");
});

test("returns full fixedResult when notAppliedFixes is non-empty", async () => {
const file = path.join(tmpDir, "unapplied-fix.md");
await writeFile(file, "# Title\n", "utf8");

mockedFixMarkdown.mockReturnValue({
lintResult: [],
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: {
result: "# Title\n",
notAppliedFixes: [
{ targetRule: "r", range: [0, 1], text: "x", reason: "overlap" },
],
convergence: "stable",
},
executionErrors: [],
} as any);

const result = await lintWorker({
filePath: file,
rules: {},
isFixMode: true,
});

// Full form preserved because notAppliedFixes is non-empty
expect(result.fixedResult).toHaveProperty("result", "# Title\n");
expect(result.fixedResult).toHaveProperty("notAppliedFixes");
});
});
32 changes: 32 additions & 0 deletions __tests__/report-incomplete-fixes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,38 @@ describe("report-incomplete-fixes", () => {
test("returns false when fixedResult is null", () => {
expect(isIncompleteFix(makeItem({ fixedResult: null }))).toBe(false);
});

test("works with compact fixedResult (convergence only)", () => {
expect(
isIncompleteFix({
path: "compact.md",
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: { convergence: FixConvergence.CYCLE_DETECTED },
})
).toBe(true);
});

test("returns false for compact fixedResult with stable convergence", () => {
expect(
isIncompleteFix({
path: "compact-stable.md",
diagnostics: [],
summary: {
errorCount: 0,
warningCount: 0,
fixableErrorCount: 0,
fixableWarningCount: 0,
},
fixedResult: { convergence: FixConvergence.STABLE },
})
).toBe(false);
});
});

describe("getIncompleteFixWarnings", () => {
Expand Down
Loading