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
17 changes: 17 additions & 0 deletions src/signals/test-evidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@
);
}

export function hasLocalTestEvidence(input: { tests?: string[] | undefined; testFiles?: string[] | undefined }): boolean {

Check notice on line 11 in src/signals/test-evidence.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 11 in src/signals/test-evidence.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Open PR queue is busy

This repo has a busy open PR queue in the local Gittensory cache.
return (input.tests ?? []).length > 0 || (input.testFiles ?? []).some((file) => isTestPath(file));
}

/**
* Coarse classification of how much test coverage accompanies a set of changed paths.
* Used by slop signals to weight diffs that touch source but include no tests differently
* from those with proportionally strong test changes.
*/
export type TestCoverageClassification = "strong" | "adequate" | "weak" | "absent";

export function classifyTestCoverage(changedPaths: string[]): TestCoverageClassification {
if (changedPaths.length === 0) return "absent";
const testCount = changedPaths.filter(isTestPath).length;
if (testCount === 0) return "absent";
const ratio = testCount / changedPaths.length;
if (ratio >= 0.4) return "strong";
if (ratio >= 0.2) return "adequate";
return "weak";
}
28 changes: 27 additions & 1 deletion test/unit/test-evidence.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";

Check notice on line 1 in test/unit/test-evidence.test.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 1 in test/unit/test-evidence.test.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Open PR queue is busy

This repo has a busy open PR queue in the local Gittensory cache.
import { hasLocalTestEvidence, isTestPath } from "../../src/signals/test-evidence";
import { classifyTestCoverage, hasLocalTestEvidence, isTestPath } from "../../src/signals/test-evidence";

describe("test evidence helpers", () => {
it("detects common test path conventions", () => {
Expand All @@ -17,3 +17,29 @@
expect(hasLocalTestEvidence({})).toBe(false);
});
});

describe("classifyTestCoverage", () => {
it("classifies an empty path list as absent", () => {
expect(classifyTestCoverage([])).toBe("absent");
});

it("classifies a list with no test files as absent", () => {
expect(classifyTestCoverage(["src/auth.ts", "src/utils.ts"])).toBe("absent");
});

it("classifies >= 40% test ratio as strong", () => {
// 2 source + 2 test = 50%
expect(classifyTestCoverage(["src/a.ts", "src/b.ts", "test/a.test.ts", "test/b.test.ts"])).toBe("strong");
});

it("classifies 20%–39% test ratio as adequate", () => {
// 3 source + 1 test = 25%
expect(classifyTestCoverage(["src/a.ts", "src/b.ts", "src/c.ts", "test/a.test.ts"])).toBe("adequate");
});

it("classifies > 0% but < 20% test ratio as weak", () => {
// 9 source + 1 test ≈ 10%
const sources = Array.from({ length: 9 }, (_, i) => `src/file${i}.ts`);
expect(classifyTestCoverage([...sources, "test/single.test.ts"])).toBe("weak");
});
});
Loading