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): verify dry-run directory freshness, over-limit paths,…
… and case-probe close ownership

Refs #5489
  • Loading branch information
hannesstrydom664-hash committed Oct 27, 2026
commit 545c4e3e70149edb29e6d9f6a8d53d8e31005298
18 changes: 18 additions & 0 deletions src/application/environment/environmentBundleTool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { AnalysisError } from "../../domain/analysisErrorBase.js";
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
import { bindArtifactFileCleanup } from "../../artifacts/ArtifactFileOperation.js";
import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
import { SafeOutputTree } from "../../artifacts/SafeOutputTree.js";
import { outputDirectoryAdmissionRefusal } from "../../artifacts/SafeOutputTreeAdmission.js";
import type {
Expand Down Expand Up @@ -63,6 +66,21 @@ export const exportEnvironmentBundleTool = async (
cause,
);
if (refusal instanceof AnalysisError) return err(refusal);
if (
refusal instanceof ArtifactReaderFailure &&
refusal.cleanup !== undefined
) {
const error = new AnalysisOutputError(
EXPORT_ENVIRONMENT_BUNDLE_OPERATION,
refusal.message,
{
cause: refusal,
cleanup: refusal.cleanup,
},
);
bindArtifactFileCleanup(refusal, error);
return err(error);
}
throw refusal;
}
const capture = await captureFile(input.source, lookup);
Expand Down
43 changes: 34 additions & 9 deletions src/artifacts/SafeOutputTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {
} from "node:fs/promises";
import { basename, dirname, isAbsolute, join } from "node:path";
import type { Readable } from "node:stream";
import { OwnedDirectoryHandle } from "../filesystem/OwnedDirectoryHandle.js";
import { OwnedFileHandle } from "../filesystem/OwnedFileHandle.js";
import { ArtifactResourceScope } from "./ArtifactResourceScope.js";
import { streamChunkToBuffer } from "./StreamBytes.js";

import {
Expand Down Expand Up @@ -150,6 +152,7 @@ export class SafeOutputTree {
/** Read-only early admission; create() still rechecks and acquires exclusively. */
static async checkDestination(
outputRoot: string,
options: { readonly resourceScope?: ArtifactResourceScope } = {},
): Promise<{ readonly caseSensitivity: DestinationCaseSensitivity }> {
const { canonicalOutput } = await this.resolveDestination(outputRoot);
const existing = await lstat(canonicalOutput).catch((cause: unknown) => {
Expand Down Expand Up @@ -186,7 +189,10 @@ export class SafeOutputTree {
},
);
return {
caseSensitivity: await observeDirectoryCaseSensitivity(parent),
caseSensitivity: await observeDirectoryCaseSensitivity(
parent,
options.resourceScope,
),
};
}

Expand Down Expand Up @@ -799,21 +805,32 @@ const MAX_CASE_PROBE_ENTRIES = 256;
*/
const observeDirectoryCaseSensitivity = async (
directory: string,
resourceScope?: ArtifactResourceScope,
): Promise<DestinationCaseSensitivity> => {
const dir = await opendir(directory).catch(() => undefined);
if (dir === undefined) return "unknown";
const owner = new OwnedDirectoryHandle(dir);
let caseSensitivity: DestinationCaseSensitivity = "unknown";
try {
let scanned = 0;
let remainingMatch: string | undefined;
while (true) {
const dirent = await dir.read();
const dirent = await owner.handle.read();
if (dirent === null) {
return remainingMatch === undefined ? "unknown" : "case-insensitive";
caseSensitivity =
remainingMatch === undefined ? "unknown" : "case-insensitive";
break;
}
if (scanned >= MAX_CASE_PROBE_ENTRIES) {
caseSensitivity = "unknown";
break;
}
if (scanned >= MAX_CASE_PROBE_ENTRIES) return "unknown";
scanned += 1;
if (remainingMatch !== undefined) {
if (dirent.name === remainingMatch) return "case-sensitive";
if (dirent.name === remainingMatch) {
caseSensitivity = "case-sensitive";
break;
}
continue;
}
const toggled = toggleFirstAsciiLetter(dirent.name);
Expand All @@ -832,15 +849,23 @@ const observeDirectoryCaseSensitivity = async (
candidate.dev !== original.dev ||
candidate.ino !== original.ino
) {
return "case-sensitive";
caseSensitivity = "case-sensitive";
break;
}
remainingMatch = toggled;
}
} catch {
return "unknown";
} finally {
await dir.close().catch(() => undefined);
caseSensitivity = "unknown";
}
const scope = resourceScope ?? new ArtifactResourceScope();
const cleanup = await scope.release({
kind: "directory-handle",
resource: directory,
handle: owner,
});
if (cleanup.kind === "failed")
throw scope.cleanupFailure({ kind: "completed" }, [cleanup]);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
return caseSensitivity;
};

const abortIfNeeded = (signal?: AbortSignal): void => {
Expand Down
126 changes: 126 additions & 0 deletions src/artifacts/extraction/ArtifactExtraction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { asarHeaderBytes } from "../../../tests/fixtures/asarHeader.js";
import { DestinationCaseCollisionFailure } from "../ArtifactPaths.js";
import { ArtifactReaderFailure } from "../ArtifactReader.js";
import { ArtifactResourceScope } from "../ArtifactResourceScope.js";
import { OwnedDirectoryHandle } from "../../filesystem/OwnedDirectoryHandle.js";
import { OwnedFileHandle } from "../../filesystem/OwnedFileHandle.js";
import { openRegularFile } from "../../filesystem/RegularFile.js";
import { SafeOutputTree } from "../SafeOutputTree.js";
Expand Down Expand Up @@ -1010,3 +1011,128 @@ it("retains observed_bytes on unsupported nested ASAR members without adding the
await resourceScope.close();
}
});

it("rejects directory source content modified between inventory and dry-run planning", async () => {
const directory = await createTestTempDirectory(
"rea-extraction-dry-run-dir-freshness-",
);
const source = join(directory, "source");
await mkdir(source, { recursive: true });
const targetFile = join(source, "alpha.txt");
await writeFile(targetFile, "alpha-v1");
const originalClose = DirectoryArtifactReader.prototype.close;
let inventoryClosed = false;
const closeSpy = vi
.spyOn(DirectoryArtifactReader.prototype, "close")
.mockImplementation(async function (this: DirectoryArtifactReader) {
await originalClose.call(this);
if (!inventoryClosed) {
inventoryClosed = true;
await writeFile(targetFile, "alpha-v2");
}
});
const resourceScope = new ArtifactResourceScope();
try {
await expect(
extractArtifact({
inputPath: source,
inputFormat: "asar",
outputRoot: join(directory, "dry-out"),
dryRun: true,
environment: {},
integrityPolicy: "fail",
resourceScope,
}),
).rejects.toMatchObject({
reason: "integrity",
message: "Extracted content disagrees with inventory: alpha.txt",
});
} finally {
closeSpy.mockRestore();
await resourceScope.close();
}
});

it("classifies over-limit destination path segments as unresolved in dry-run plans", async () => {
const directory = await createTestTempDirectory(
"rea-extraction-dry-run-over-limit-segment-",
);
const archive = join(directory, "over-limit.zip");
const overLimitName = `${"a".repeat(256)}.txt`;
const writer = new ZipWriter(new Uint8ArrayWriter());
await writer.add(overLimitName, new TextReader("payload"));
await writer.add("short.txt", new TextReader("ok"));
await writeFile(archive, Buffer.from(await writer.close()));
const resourceScope = new ArtifactResourceScope();
try {
const outputRoot = join(directory, "dry-out");
const planned = await extractArtifact({
...zipInput(archive, outputRoot, resourceScope),
dryRun: true,
});
expect(planned.artifacts).toEqual([
expect.objectContaining({
relative_path: "short.txt",
bytes_written: 0,
created: false,
}),
]);
expect(planned.plan?.totals).toMatchObject({
planned_files: 1,
unsupported_entries: 0,
unresolved_entries: 1,
observed_bytes_estimate: 2,
declared_bytes_estimate: 2,
});
expect(
planned.plan?.entries.map(({ logical_path, status }) => ({
logical_path,
status,
})),
).toEqual([
{ logical_path: overLimitName, status: "unresolved" },
{ logical_path: "short.txt", status: "planned" },
]);
expect(planned.limitations).toContain(
"Destination filesystem component and path length limits (such as 255-byte NAME_MAX) cannot be verified without creating files; over-limit paths remain unresolved in the dry-run plan.",
);
await expect(stat(outputRoot)).rejects.toMatchObject({ code: "ENOENT" });
} finally {
await resourceScope.close();
}
});

it("retains ownership and surfaces an owned cleanup failure when the case-probe directory close fails", async () => {
const directory = await createTestTempDirectory(
"rea-extraction-dry-run-case-probe-close-",
);
const archive = join(directory, "archive.zip");
await writeFile(archive, await zipBytes("alpha"));
const parentDir = join(directory, "parent");
await mkdir(parentDir, { recursive: true });
await writeFile(join(parentDir, "ProbeFile"), "probe");
const closeFailure = new Error("case-probe directory close failed");
const closeSpy = vi
.spyOn(OwnedDirectoryHandle.prototype, "close")
.mockRejectedValueOnce(closeFailure);
const resourceScope = new ArtifactResourceScope();
try {
const error = await extractArtifact({
...zipInput(archive, join(parentDir, "dry-out"), resourceScope),
dryRun: true,
}).catch((cause: unknown) => cause);
expect(error).toBeInstanceOf(ArtifactReaderFailure);
expect((error as ArtifactReaderFailure).cleanup).toEqual({
reason: "case-probe directory close failed",
resources: [expect.stringContaining("parent")],
});
expect((error as ArtifactReaderFailure).cleanupLeases).toHaveLength(1);
expect(resourceScope.hasPending).toBe(true);
expect(resourceScope.cleanupResources).toEqual([
expect.stringContaining("parent"),
]);
} finally {
closeSpy.mockRestore();
await resourceScope.close().catch(() => undefined);
}
});
Loading