fix(quality): normalize symlinked cwd in new-code mode gates (#14744) (#14849)

Validated in the 2026-09-28 merge-batch: all 38 PRs of this wave boarded together on release/v3.8.51 (a58000c) — typecheck:core and open-sse typecheck clean, focused tests of the whole board 429/434 (the remaining reds belong to PRs held for rework or already fail on the tip), static gates green apart from file-size/docs-count reconciliation landed in the wave follow-up. Thank you @HouMinXi!
This commit is contained in:
Bob.Hou
2026-09-28 16:57:39 -04:00
committed by GitHub
parent 7f5de7ba62
commit 2ed8797b37
3 changed files with 61 additions and 3 deletions

View File

@@ -0,0 +1 @@
- **quality:** normalize symlinked worktree directories and report paths in new-code mode gates so macOS base violations match accurately (#14744).

View File

@@ -97,11 +97,25 @@ export function withBaseWorktree(sha, fn) {
* `filePath` is made relative to `cwd` so HEAD and base reports share keys.
*/
export function perFileRuleCounts(report, rules, cwd) {
let realCwd = cwd;
try {
realCwd = fs.realpathSync(cwd);
} catch {
/* fallback to cwd */
}
const counts = new Map();
for (const entry of report || []) {
const rel = path.isAbsolute(entry.filePath)
? path.relative(cwd, entry.filePath).split(path.sep).join("/")
: entry.filePath;
let filePath = entry.filePath;
if (path.isAbsolute(filePath)) {
try {
filePath = fs.realpathSync(filePath);
} catch {
/* fallback */
}
}
const rel = path.isAbsolute(filePath)
? path.relative(realCwd, filePath).split(path.sep).join("/")
: filePath;
let n = 0;
for (const m of entry.messages || []) if (rules.has(m.ruleId)) n++;
counts.set(rel, (counts.get(rel) || 0) + n);

View File

@@ -1,4 +1,7 @@
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import test from "node:test";
import {
@@ -127,3 +130,43 @@ test("newDeadSymbols reports only symbols that are new on HEAD, in touched files
]);
assert.deepEqual(newDeadSymbols(base, head, ["src/a.ts"]), []);
});
test("perFileRuleCounts normalizes symlinked cwd so canonical paths match (#14744)", () => {
const realBase = fs.realpathSync(os.tmpdir());
const realDir = fs.mkdtempSync(path.join(realBase, "omni-test-real-"));
const symDir = path.join(realBase, `omni-test-symlink-${Date.now()}-${Math.random().toString(36).slice(2)}`);
fs.symlinkSync(realDir, symDir, "dir");
const report = [
{
filePath: path.join(realDir, "open-sse/executors/commandCode.ts"),
messages: [{ ruleId: "complexity" }, { ruleId: "max-lines-per-function" }],
},
{
filePath: "src/relative.ts",
messages: [{ ruleId: "complexity" }],
},
];
try {
const counts = perFileRuleCounts(report, new Set(["complexity", "max-lines-per-function"]), symDir);
assert.equal(counts.size, 2);
assert.equal(counts.get("open-sse/executors/commandCode.ts"), 2);
assert.equal(counts.get("src/relative.ts"), 1);
// Fallback when cwd does not exist on disk
const fallbackCounts = perFileRuleCounts(
[{ filePath: "/nonexistent/repo/src/a.ts", messages: [{ ruleId: "complexity" }] }],
new Set(["complexity"]),
"/nonexistent/repo"
);
assert.equal(fallbackCounts.get("src/a.ts"), 1);
} finally {
try {
fs.unlinkSync(symDir);
} catch {}
try {
fs.rmSync(realDir, { recursive: true, force: true });
} catch {}
}
});