fix: line-cap checks skip files in ignored temporary directories (#151748)

This commit is contained in:
Peter Steinberger 2026-09-18 04:53:42 -07:00 • committed by GitHub
parent 47a02a38ff
commit a20d73abff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 2 deletions

View file

@ -173,6 +173,8 @@ export function main(root = process.cwd(), argv = process.argv.slice(2)) {
throw new Error("No max-lines overrides found in .oxlintrc.json");
}
scratch = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-line-cap-"));
// Stop ancestor Git ignores at the snapshot; explicit lint exclusions still apply.
fs.mkdirSync(path.join(scratch, ".git"));
const after = collectViolations(path.join(scratch, "head"), headSources, config);
// Only over-cap head files need an inherited allowance. A broken base must
// not block a valid repair that already satisfies the current cap.

View file

@ -6,7 +6,10 @@ import { compareLineCapViolations, main } from "../../scripts/check-line-cap-rat
import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
afterEach(() => vi.restoreAllMocks());
afterEach(() => {
vi.restoreAllMocks();
vi.unstubAllEnvs();
});
function git(root: string, ...args: string[]) {
return execFileSync(
@ -28,12 +31,13 @@ function source(lines: number) {
);
}
function fixture(lines = 5, severity = "warn") {
function fixture(lines = 5, severity = "warn", ignorePatterns: string[] = []) {
const root = tempDirs.make("openclaw-line-cap-test-");
fs.mkdirSync(path.join(root, "src"));
fs.writeFileSync(
path.join(root, ".oxlintrc.json"),
JSON.stringify({
ignorePatterns,
overrides: [
{
files: ["src/**/*.ts"],
@ -53,6 +57,32 @@ function fixture(lines = 5, severity = "warn") {
}
describe("line-cap growth ratchet", () => {
it("measures ignored repository-contained scratch while preserving explicit exclusions", () => {
const root = fixture(5, "warn", ["src/ignored/**"]);
fs.writeFileSync(path.join(root, ".gitignore"), ".artifacts/\n");
const scratch = path.join(root, ".artifacts", "scratch");
fs.mkdirSync(scratch, { recursive: true });
vi.stubEnv("TMPDIR", scratch);
vi.stubEnv("TMP", scratch);
vi.stubEnv("TEMP", scratch);
const errors = vi.spyOn(console, "error").mockImplementation(() => {});
vi.spyOn(console, "log").mockImplementation(() => {});
const target = path.join(root, "src/file.ts");
fs.writeFileSync(target, source(6));
expect(main(root, ["--base", "HEAD"])).toBe(1);
expect(errors).toHaveBeenCalledWith(
expect.stringContaining("src/file.ts: 5 -> 6 counted lines (cap 3)"),
);
fs.writeFileSync(target, source(4));
for (const directory of ["ignored", "generated"]) {
fs.mkdirSync(path.join(root, "src", directory));
fs.writeFileSync(path.join(root, "src", directory, "excluded.ts"), source(8));
}
errors.mockClear();
expect(main(root, ["--base", "HEAD"])).toBe(0);
expect(errors).not.toHaveBeenCalled();
});
it.each([
{ label: "over-cap shrinking", before: 705, after: 703, fails: false },
{ label: "over-cap growing", before: 705, after: 706, fails: true },