Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
777b04a
feat(artifacts): add dry-run extraction plan without destination writ…
hannesstrydom664-hash Oct 25, 2026
47f478c
fix(artifacts): address dry-run extraction plan review feedback (#5489)
hannesstrydom664-hash Oct 25, 2026
93c3ab3
fix(artifacts): preserve unknown mount case sensitivity and use desti…
hannesstrydom664-hash Oct 26, 2026
74029e0
fix(artifacts): handle hardlinked entries and leave non-ASCII case fo…
hannesstrydom664-hash Oct 26, 2026
77f9884
fix(artifacts): bound case-sensitivity probes and observe Windows dir…
hannesstrydom664-hash Oct 26, 2026
545c4e3
fix(artifacts): verify dry-run directory freshness, over-limit paths,…
hannesstrydom664-hash Oct 26, 2026
20ae0c4
fix(artifacts): resolve canonical output path limits and full Unicode…
hannesstrydom664-hash Oct 26, 2026
a0bf542
fix(artifacts): revalidate unpacked ASAR companions and qualify unres…
hannesstrydom664-hash Oct 26, 2026
8f417b4
fix(artifacts): reconcile non-file entries against the inventory snap…
hannesstrydom664-hash Oct 26, 2026
041f0ef
fix(artifacts): scope non-file reconciliation to active reader and ve…
hannesstrydom664-hash Oct 26, 2026
f2305a1
fix(artifacts): distinguish limitation-only non-file drift and select…
hannesstrydom664-hash Oct 26, 2026
4c411c0
fix(artifacts): reject unpaired UTF-16 destination paths and probe co…
hannesstrydom664-hash Oct 26, 2026
38a8e9d
docs(artifacts): document dry_run extraction planning and share limit…
hannesstrydom664-hash Oct 26, 2026
e37d5ef
fix(extraction): revalidate dry-run ZIP bytes, bound component probes…
hannesstrydom664-hash Oct 26, 2026
2f987e4
fix(extraction): guard transferred ZIP source and cancel after final …
hannesstrydom664-hash Oct 27, 2026
e29807d
fix(artifacts): unify dry-run plan paging cache, byte budgets, and po…
hannesstrydom664-hash Oct 27, 2026
8facdbb
fix(artifacts): budget raw dry-run occurrence limitations and skip en…
hannesstrydom664-hash Oct 27, 2026
0ffad06
Merge remote-tracking branch 'origin/main' into feat/artifact-extract…
hannesstrydom664-hash Nov 1, 2026
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
Prev Previous commit
Next Next commit
fix(artifacts): preserve unknown mount case sensitivity and use desti…
…nation case folding in dry-run (#5489)

Why:
- Probing parent directories when a destination parent directory is empty (such as an empty mount point) tests the host directory rather than the mounted filesystem and can misclassify a case-insensitive mount as case-sensitive.
- English (en-US) locale lowercasing is a logical-name diagnostic and does not fold Greek final/medial sigma variants (`σ` and `ς`) to the same key on Windows case-insensitive destinations.

What:
- Return `DestinationCaseSensitivity` (`"case-sensitive" | "case-insensitive" | "unknown"`) from `SafeOutputTree.checkDestination` by probing only cased entries inside the destination parent directory itself without walking parent directories.
- Add 1-to-1 platform/Unicode `destinationCaseFold` and `destinationCaseCollisions` in `ArtifactPaths.ts` and use them for destination case-collision checks.
- Mark case-colliding selected occurrences as `status: "unresolved"` in the dry-run plan when destination directory case sensitivity is `"unknown"`, and add regression coverage for Greek sigma collisions and empty mount parents.
  • Loading branch information
hannesstrydom664-hash committed Oct 27, 2026
commit 93c3ab39534cdeb61e3359d0cb0963e42b80cb5a
23 changes: 23 additions & 0 deletions src/artifacts/ArtifactPaths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,26 @@ it.each([["app.js"], ["app.js", "App.js"], ["other.js"]])(
expect(destinationCaseCollision("res/app.js", names)).toBeUndefined();
},
);

it("detects Greek final-sigma destination collisions under platform case mapping without 1-to-many expansion", () => {
const winCollision = destinationCaseCollision("res/ς.txt", ["σ.txt"], {
platform: "win32",
});
expect(winCollision).toBeInstanceOf(DestinationCaseCollisionFailure);
expect(winCollision).toMatchObject({
reason: "path",
requestedPath: "res/ς.txt",
existingPath: "res/σ.txt",
});

const registry = new ArtifactPathRegistry({
caseInsensitive: true,
platform: "win32",
});
registry.add("σ.txt", "file");
expect(() => registry.add("ς.txt", "file")).toThrow(
DestinationCaseCollisionFailure,
);
registry.add("ß.txt", "file");
expect(() => registry.add("SS.txt", "file")).not.toThrow();
});
84 changes: 72 additions & 12 deletions src/artifacts/ArtifactPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,28 @@ export const normalizeArtifactPath = (input: string): string => {
* Reject exact and same-spelling prefix collisions. Case-distinct names stay
* distinct unless destination case-folding rules are enabled.
*/
export type DestinationCaseSensitivity =
| "case-sensitive"
| "case-insensitive"
| "unknown";

export class ArtifactPathRegistry {
readonly #root: PathTrieNode = {
kind: undefined,
children: new Map(),
spellingsByFold: new Map(),
};
readonly #caseInsensitive: boolean;
readonly #platform: NodeJS.Platform;

constructor(options: { readonly caseInsensitive?: boolean } = {}) {
constructor(
options: {
readonly caseInsensitive?: boolean;
readonly platform?: NodeJS.Platform;
} = {},
) {
this.#caseInsensitive = options.caseInsensitive === true;
this.#platform = options.platform ?? process.platform;
}

add(path: string, kind: ArtifactEntry["kind"]): void {
Expand All @@ -101,9 +113,11 @@ export class ArtifactPathRegistry {
`Artifact prefix conflict: ${pathDiagnostic(path)}`,
);
if (this.#caseInsensitive) {
const folded = destinationCaseFold(part, this.#platform);
const collision = destinationCaseCollision(
currentPath,
node.spellingsByFold.get(englishCaseFold(part)) ?? [],
node.spellingsByFold.get(folded) ?? [],
{ platform: this.#platform },
);
if (collision !== undefined) throw collision;
}
Expand All @@ -116,7 +130,7 @@ export class ArtifactPathRegistry {
};
node.children.set(part, child);
if (this.#caseInsensitive) {
const folded = englishCaseFold(part);
const folded = destinationCaseFold(part, this.#platform);
const spellings = node.spellingsByFold.get(folded);
if (spellings === undefined) node.spellingsByFold.set(folded, [part]);
else spellings.push(part);
Expand Down Expand Up @@ -162,6 +176,33 @@ const emptyCaseNode = (): CaseNode => ({
const englishCaseFold = (part: string): string =>
part.toLocaleLowerCase("en-US");

const foldDestinationCodePoint = (
char: string,
platform: NodeJS.Platform,
): string => {
const lower = char.toLowerCase();
const singleLower = [...lower].length === 1 ? lower : char;
const upper = singleLower.toUpperCase();
const singleUpper = [...upper].length === 1 ? upper : singleLower;
if (platform === "win32") return singleUpper;
const folded = singleUpper.toLowerCase();
return [...folded].length === 1 ? folded : singleUpper;
};

/**
* Fold a path segment using 1-to-1 platform/Unicode case mapping (`toUpperCase`
* on Windows so pairs such as `σ` and `ς` both map to `Σ`, and simple Unicode
* case folding on POSIX).
*/
export const destinationCaseFold = (
part: string,
platform: NodeJS.Platform = process.platform,
): string => {
let folded = "";
for (const char of part) folded += foldDestinationCodePoint(char, platform);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid Unicode code-point folding for NTFS names

When dry-running onto NTFS, an archive with 𐐀.txt and 𐐨.txt is rejected here because for...of feeds whole Unicode code points to JavaScript casing and both fold to U+10400. NTFS compares names through its 16-bit $UpCase table, so supplementary surrogate pairs are not case-mapped and real extraction can keep those two names distinct; this makes the plan falsely refuse a valid extraction. Fresh evidence beyond the earlier sigma report is that the replacement code-point loop now over-folds supplementary characters even though it handles sigma. Use the destination's comparison table, or leave unsupported folds unresolved.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

return folded;
};

/**
* Record English (en-US) Unicode case collisions on each affected occurrence.
* Returns the inventory limitation when any logical names collide.
Expand Down Expand Up @@ -189,7 +230,7 @@ export const annotateEnglishUnicodeCaseCollisions = (
};

/** One logical path segment whose spelling folds to another sibling's. */
interface CaseCollision {
export interface CaseCollision {
/** Logical path through the colliding segment. */
readonly prefix: string;
/** First other sibling spelling, as a logical path, in code-point order. */
Expand All @@ -213,33 +254,53 @@ const caseCollisionLimitation = (
return `${subject} under English (en-US) Unicode case folding with ${others}; a case-insensitive destination cannot store both. ${ENGLISH_UNICODE_CASE_NOTE}`;
};

export interface DestinationCaseCollisionOptions extends ErrorOptions {
readonly platform?: NodeJS.Platform;
}

/**
* Name the directory-listing spelling that differs from the requested segment
* only by English (en-US) Unicode case. Exact matches are the same logical name.
* only by destination case folding. Exact matches are the same logical name.
*/
export const destinationCaseCollision = (
requestedPath: string,
existingNames: readonly string[],
options?: ErrorOptions,
options?: DestinationCaseCollisionOptions,
): DestinationCaseCollisionFailure | undefined => {
const slash = requestedPath.lastIndexOf("/");
const segment = slash < 0 ? requestedPath : requestedPath.slice(slash + 1);
if (existingNames.includes(segment)) return undefined;
const folded = englishCaseFold(segment);
const platform = options?.platform ?? process.platform;
const folded = destinationCaseFold(segment, platform);
const existing = existingNames
.filter((name) => englishCaseFold(name) === folded)
.filter((name) => destinationCaseFold(name, platform) === folded)
.sort(compareUnicodeCodePoints)[0];
if (existing === undefined) return undefined;
const parent = slash < 0 ? "" : requestedPath.slice(0, slash + 1);
return new DestinationCaseCollisionFailure(
requestedPath,
`${parent}${existing}`,
options,
options?.cause === undefined ? undefined : { cause: options.cause },
);
};

/**
* Find destination paths that collide under platform/Unicode case folding.
*/
export const destinationCaseCollisions = (
paths: readonly string[],
platform: NodeJS.Platform = process.platform,
): ReadonlyMap<string, readonly CaseCollision[]> =>
caseCollisionsByFold(paths, (part) => destinationCaseFold(part, platform));

const englishUnicodeCaseCollisions = (
paths: readonly string[],
): ReadonlyMap<string, readonly CaseCollision[]> =>
caseCollisionsByFold(paths, englishCaseFold);

const caseCollisionsByFold = (
paths: readonly string[],
foldSegment: (part: string) => string,
): ReadonlyMap<string, readonly CaseCollision[]> => {
const root = emptyCaseNode();
for (const path of paths) {
Expand All @@ -248,7 +309,7 @@ const englishUnicodeCaseCollisions = (
for (const part of path.split("/")) {
let child = node.bySpelling.get(part);
if (child === undefined) {
const folded = englishCaseFold(part);
const folded = foldSegment(part);
const spellings = node.spellingsByFold.get(folded);
if (spellings === undefined) node.spellingsByFold.set(folded, [part]);
else spellings.push(part);
Expand Down Expand Up @@ -280,8 +341,7 @@ const englishUnicodeCaseCollisions = (
for (const [spelling, child] of node.bySpelling) {
const childPrefix =
prefix === undefined ? spelling : `${prefix}/${spelling}`;
const spellings =
node.spellingsByFold.get(englishCaseFold(spelling)) ?? [];
const spellings = node.spellingsByFold.get(foldSegment(spelling)) ?? [];
const other = spellings[0] === spelling ? spellings[1] : spellings[0];
pending.push({
node: child,
Expand Down
87 changes: 37 additions & 50 deletions src/artifacts/SafeOutputTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
ArtifactPathRegistry,
destinationCaseCollision,
normalizeArtifactPath,
type DestinationCaseSensitivity,
} from "./ArtifactPaths.js";
import { absoluteCallerPath } from "../filesystem/callerPath.js";
import { ArtifactReaderFailure } from "./ArtifactReader.js";
Expand Down Expand Up @@ -149,7 +150,7 @@ export class SafeOutputTree {
static async checkDestination(
outputRoot: string,
platform: NodeJS.Platform = process.platform,
): Promise<{ readonly caseInsensitive: boolean }> {
): Promise<{ readonly caseSensitivity: DestinationCaseSensitivity }> {
const { canonicalOutput } = await this.resolveDestination(outputRoot);
const existing = await lstat(canonicalOutput).catch((cause: unknown) => {
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
Expand Down Expand Up @@ -185,8 +186,10 @@ export class SafeOutputTree {
},
);
return {
caseInsensitive:
platform === "win32" || (await isCaseInsensitiveDirectory(parent)),
caseSensitivity:
platform === "win32"
? "case-insensitive"
: await observeDirectoryCaseSensitivity(parent),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Observe case-sensitive Windows destination directories

When the chosen parent is an NTFS directory with per-directory case sensitivity enabled (for example, a WSL-managed tree), this hard-coded branch reports it as case-insensitive; planSelectedEntries then rejects Foo.txt/foo.txt, even though a newly created child inherits the case-sensitive setting and real extraction can materialize both names. Probe the parent on Windows too, or leave the result unknown when it cannot be observed.

AGENTS.md reference: AGENTS.md:L21-L21

Useful? React with 👍 / 👎.

};
}

Expand Down Expand Up @@ -277,7 +280,12 @@ export class SafeOutputTree {
0o600,
).catch(async (cause: unknown) => {
if (isAlreadyExists(cause))
await throwIfDestinationCaseCollision(parent.path, path, cause);
await throwIfDestinationCaseCollision(
parent.path,
path,
cause,
this.platform,
);
throw new ArtifactReaderFailure(
"path",
`Could not exclusively create extraction path: ${path}`,
Expand Down Expand Up @@ -587,6 +595,7 @@ export class SafeOutputTree {
parent.path,
logicalPath,
creation.cause,
this.platform,
);
const identity = this.#nestedDirectories.get(current);
if (identity === undefined) throw replacedDirectory(current);
Expand Down Expand Up @@ -778,65 +787,43 @@ export const normalizeDestinationPath = (
return path;
};

const toggleFirstCasedCodePoint = (value: string): string | undefined => {
const toggleFirstAsciiLetter = (value: string): string | undefined => {
for (let index = 0; index < value.length; index += 1) {
const char = value[index]!;
const upper = char.toLocaleUpperCase("en-US");
const lower = char.toLocaleLowerCase("en-US");
if (upper === lower) continue;
const toggled = char === lower ? upper : lower;
return `${value.slice(0, index)}${toggled}${value.slice(index + 1)}`;
const code = value.charCodeAt(index);
if (code >= 0x41 && code <= 0x5a) {
return `${value.slice(0, index)}${String.fromCharCode(code + 0x20)}${value.slice(index + 1)}`;
}
if (code >= 0x61 && code <= 0x7a) {
return `${value.slice(0, index)}${String.fromCharCode(code - 0x20)}${value.slice(index + 1)}`;
}
}
return undefined;
};

/**
* Observe whether an existing directory resolves case-folded entry lookups to
* the same inode without creating or modifying any filesystem entries.
* the same inode without creating entries or inferring from parent mounts.
*/
const isCaseInsensitiveDirectory = async (
const observeDirectoryCaseSensitivity = async (
directory: string,
): Promise<boolean> => {
const entries = await readdir(directory).catch((): readonly string[] => []);
): Promise<DestinationCaseSensitivity> => {
const entries = await readdir(directory).catch(() => undefined);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bound destination case-sensitivity scans

When a destination parent contains a very large number of entries, readdir(directory) materializes every name and the following Set retains additional state just to classify case sensitivity. Because the modified checkDestination is also used by existing firmware and environment preflights, those operations can now consume memory proportional to an unrelated shared parent such as a crowded /tmp, or stall before their real work; stream with opendir and bounded state, or return unknown after a bounded probe.

AGENTS.md reference: AGENTS.md:L53-L54

Useful? React with 👍 / 👎.

if (entries === undefined) return "unknown";
for (const entry of entries) {
const toggled = toggleFirstCasedCodePoint(entry);
if (toggled === undefined || entries.includes(toggled)) continue;
const toggled = toggleFirstAsciiLetter(entry);
if (toggled === undefined) continue;
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
const [original, candidate] = await Promise.all([
lstat(join(directory, entry), { bigint: true }).catch(() => undefined),
lstat(join(directory, toggled), { bigint: true }).catch(() => undefined),
]);
if (original === undefined) continue;
return (
candidate !== undefined &&
return candidate !== undefined &&
candidate.dev === original.dev &&
candidate.ino === original.ino
);
}
let current = directory;
for (;;) {
const parent = dirname(current);
if (parent === current) return false;
const segment = basename(current);
const toggled = toggleFirstCasedCodePoint(segment);
if (toggled !== undefined && toggled !== segment) {
const siblingEntries = await readdir(parent).catch(
(): readonly string[] => [],
);
if (!siblingEntries.includes(toggled)) {
const [original, candidate] = await Promise.all([
lstat(current, { bigint: true }).catch(() => undefined),
lstat(join(parent, toggled), { bigint: true }).catch(() => undefined),
]);
if (original !== undefined)
return (
candidate !== undefined &&
candidate.dev === original.dev &&
candidate.ino === original.ino
);
}
}
current = parent;
? "case-insensitive"
: "case-sensitive";
}
return "unknown";
};

const abortIfNeeded = (signal?: AbortSignal): void => {
Expand All @@ -861,13 +848,13 @@ const throwIfDestinationCaseCollision = async (
parentDirectory: string,
logicalPath: string,
cause?: unknown,
platform: NodeJS.Platform = process.platform,
): Promise<void> => {
const names = await readdir(parentDirectory).catch(() => undefined);
if (names === undefined) return;
const failure = destinationCaseCollision(
logicalPath,
names,
cause === undefined ? undefined : { cause },
);
const failure = destinationCaseCollision(logicalPath, names, {
...(cause === undefined ? {} : { cause }),
platform,
});
if (failure !== undefined) throw failure;
};
Loading