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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes are documented here. This project follows Semantic Versionin

### Fixed

- Preserved trailing whitespace in Git repository-root paths. `findRepository()` now removes only Git's record line terminator instead of applying JavaScript `String.trim()`, preventing a repository such as `repository ` from being silently redirected to a sibling path with the trimmed spelling.
- Tightened Python test-runner exit-code 5 handling. Pytest and the stdlib `unittest` CLI use code 5 for no-test outcomes, but repository-local modules can also terminate runner imports with code 5 before trustworthy lifecycle observation. ProofDiff now accepts exit 5 as non-failing only when high-confidence exact zero-test observer data corroborates it: directly for targeted pytest, or through the paired targeted observer for opaque pytest/unittest commands. Uncorroborated exit-5 failures remain verification failures.
- Preserved LCOV `SF:` source paths exactly instead of applying JavaScript-style whitespace trimming. Leading or trailing spaces and Unicode whitespace are valid path characters, so silently erasing them could alias artifact coverage for one path onto a different changed repository file and overstate changed-line evidence.
- Restricted recognized Node/Jest/Vitest package-script trimming to ASCII spaces and tabs. JavaScript `String.trim()` also removes non-ASCII whitespace such as NBSP, which shells do not treat as ordinary script separators; leading or trailing Unicode whitespace can therefore no longer be erased into a different executable command and accidentally qualify for exact targeted evidence.
Expand Down
2 changes: 1 addition & 1 deletion dist/git.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion dist/git.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/git.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ export async function findRepository(value: string): Promise<string> {
const candidate = await resolveRepositoryPath(value);
const result = await gitResult(candidate, ["rev-parse", "--show-toplevel"]);
if (result.exitCode !== 0) throw new GitError(`Not a Git repository: ${candidate}`);
return (await resolveRepositoryPath(result.stdout.trim()));
const lineEndingLength = process.platform === "win32" && result.stdout.endsWith("\r\n")
? 2
: result.stdout.endsWith("\n") ? 1 : 0;
const topLevel = lineEndingLength === 0 ? result.stdout : result.stdout.slice(0, -lineEndingLength);
return await resolveRepositoryPath(topLevel);
}

async function hasHead(root: string): Promise<boolean> {
Expand Down
13 changes: 12 additions & 1 deletion tests/git.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from "node:assert/strict";
import { rm, symlink, writeFile } from "node:fs/promises";
import { mkdir, rm, symlink, writeFile } from "node:fs/promises";
import test from "node:test";
import path from "node:path";
import { changedFiles, findRepository, gitNullDevice, repositoryInfo, selectDiff } from "../src/git.js";
Expand Down Expand Up @@ -43,6 +43,17 @@ test("findRepository accepts a nested directory", async (context) => {
assert.equal(await findRepository(`${root}/src`), root);
});

test("findRepository preserves trailing whitespace in the repository root", { skip: process.platform === "win32" }, async (context) => {
const parent = await temporaryDirectory("proofdiff-root-space-");
const root = path.join(parent, "repository ");
const trimmedSibling = path.join(parent, "repository");
context.after(() => rm(parent, { recursive: true, force: true }));
await mkdir(path.join(root, "src"), { recursive: true });
await mkdir(trimmedSibling, { recursive: true });
git(root, "init", "-q");
assert.equal(await findRepository(path.join(root, "src")), root);
});

test("revision-like options are rejected before reaching git", async (context) => {
const root = await initializeRepository({ "a.js": "export const a = 1;\n" });
context.after(() => rm(root, { recursive: true, force: true }));
Expand Down