Repository navigation
feat(artifacts): add dry-run plan for artifact extraction #7177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
777b04a
47f478c
93c3ab3
74029e0
77f9884
545c4e3
20ae0c4
a0bf542
8f417b4
041f0ef
f2305a1
4c411c0
38a8e9d
e37d5ef
2f987e4
e29807d
8facdbb
0ffad06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…close
Replace the undeclared zipSource lookup with isStableRegularFileDescriptor.
Unexpected admissions throw ArtifactReaderFailure("integrity") instead of
skipping. Move abortIfNeeded into finally so directory, ASAR, and ZIP
sources check cancellation after the last close without masking an error
already propagating. Drop the duplicate asarHeaderBytes import.- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { expect, it } from "vitest"; | ||
|
|
||
| import { ArtifactReaderFailure } from "../ArtifactReader.js"; | ||
| import { isStableRegularFileDescriptor } from "./ArtifactExtraction.js"; | ||
|
|
||
| it("accepts a descriptor with the members sameRegularFileState and revalidation read", () => { | ||
| const descriptor = { | ||
| handle: { | ||
| read: () => undefined, | ||
| stat: () => undefined, | ||
| }, | ||
| initial: { | ||
| size: 4, | ||
| dev: 1, | ||
| ino: 2, | ||
| mode: 0o100644, | ||
| mtimeMs: 3, | ||
| ctimeMs: 4, | ||
| }, | ||
| }; | ||
| expect(isStableRegularFileDescriptor(descriptor)).toBe(true); | ||
| }); | ||
|
|
||
| it.each([ | ||
| null, | ||
| undefined, | ||
| "zip", | ||
| { handle: { read: () => undefined } }, | ||
| { | ||
| handle: { read: () => undefined, stat: () => undefined }, | ||
| initial: { size: 1 }, | ||
| }, | ||
| ])("rejects an unexpected transferred source shape", (value) => { | ||
| expect(isStableRegularFileDescriptor(value)).toBe(false); | ||
| }); | ||
|
|
||
| it("names integrity when a caller treats a rejected shape as a ZIP admission", () => { | ||
| const admission: unknown = { kind: "node-sea" }; | ||
| if (isStableRegularFileDescriptor(admission)) | ||
| throw new Error("guard accepted a non-file admission"); | ||
| const failure = new ArtifactReaderFailure( | ||
| "integrity", | ||
| "Transferred ZIP source is not a stable regular-file descriptor: /tmp/source.zip", | ||
| ); | ||
| expect(failure.reason).toBe("integrity"); | ||
| }); | ||
|
|
||
| // Integration coverage of a live transferred ZIP rewrite still needs a fixture | ||
| // that can mutate an admitted descriptor between inventory and dry-run. | ||
| it.skip("revalidates a live transferred ZIP descriptor after inventory", () => { | ||
| expect(true).toBe(true); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,10 @@ import { | |
| } from "../ArtifactEmbeddedFormatProbes.js"; | ||
| import { withArtifactRegularFile } from "../ArtifactFileOperation.js"; | ||
| import { readArtifactFileChunks } from "../readArtifactFileChunks.js"; | ||
| import { sameRegularFileState } from "../../filesystem/RegularFile.js"; | ||
| import { | ||
| sameRegularFileState, | ||
| type StableRegularFileDescriptor, | ||
| } from "../../filesystem/RegularFile.js"; | ||
| import type { | ||
| ArtifactCleanupAttempt, | ||
| ArtifactResourceOwner, | ||
|
|
@@ -365,6 +368,7 @@ const materializeSelection = async ({ | |
| let localReaderOwner: ArtifactResourceOwner | undefined = readerOwner; | ||
| let output: SafeOutputTree | undefined; | ||
| let completed: ArtifactExtractionResult | undefined; | ||
| let pendingFailure: unknown; | ||
| const extracted: ExtractedOccurrence[] = []; | ||
| try { | ||
| await reader.prepareContainer?.(inventory.manifest.root_sha256, signal); | ||
|
|
@@ -410,13 +414,20 @@ const materializeSelection = async ({ | |
| traversal, | ||
| signal, | ||
| }); | ||
| if (zipSource !== undefined) | ||
| if (isZipPackageFormat(inventory.manifest.root_format)) { | ||
| const admission = transferredSource?.admission; | ||
| if (!isStableRegularFileDescriptor(admission)) | ||
| throw new ArtifactReaderFailure( | ||
| "integrity", | ||
| `Transferred ZIP source is not a stable regular-file descriptor: ${sourcePath}`, | ||
| ); | ||
| await revalidateTransferredZipSource( | ||
| sourcePath, | ||
| zipSource.source, | ||
| admission, | ||
| inventory.manifest.root_sha256, | ||
| signal, | ||
| ); | ||
| } | ||
| } else { | ||
| await writeSelectedEntries({ | ||
| reader, | ||
|
|
@@ -445,7 +456,6 @@ const materializeSelection = async ({ | |
| [sourceClose], | ||
| { kind: "artifact-inventory", inventory }, | ||
| ); | ||
| if (transferredSource !== undefined) abortIfNeeded(signal); | ||
| extracted.sort((left, right) => | ||
| compareUnicodeCodePoints(left.relative_path, right.relative_path), | ||
| ); | ||
|
|
@@ -463,6 +473,7 @@ const materializeSelection = async ({ | |
| if (output !== undefined) await output.commit(signal); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For a dry-run on a non-ZIP source such as a directory or ASAR, cancellation that arrives while AGENTS.md reference: AGENTS.md:L23-L23 Useful? React with 👍 / 👎. |
||
| return completed; | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| } catch (cause: unknown) { | ||
| pendingFailure = cause; | ||
| const cleanupFailures = await releaseExtractionOwners( | ||
| input.resourceScope, | ||
| localReaderOwner, | ||
|
|
@@ -481,6 +492,19 @@ const materializeSelection = async ({ | |
| } | ||
| if (output?.published === true && completed !== undefined) return completed; | ||
| throw cause; | ||
| } finally { | ||
| // Cancellation must run after the last close for every source. A pure | ||
| // check throw must not mask an error already propagating from the try. | ||
| try { | ||
| abortIfNeeded(signal); | ||
| } catch (abortCause: unknown) { | ||
| if ( | ||
| pendingFailure === undefined && | ||
| abortCause instanceof ArtifactReaderFailure && | ||
| abortCause.reason === "cancelled" | ||
| ) | ||
| throw abortCause; | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
| }; | ||
|
|
||
|
|
@@ -530,9 +554,36 @@ export const formatDryRunPlanPageLimitation = ( | |
| ? `Dry-run plan entries are paged (${String(returnedEntries)} of ${String(totalEntries)} entries returned at offset ${String(offset)}; pass plan_offset=${String(nextOffset)} to inspect remaining entries).` | ||
| : `Dry-run plan entries are paged (${String(returnedEntries)} of ${String(totalEntries)} entries returned at offset ${String(offset)}).`; | ||
|
|
||
| export const isStableRegularFileDescriptor = ( | ||
| value: unknown, | ||
| ): value is StableRegularFileDescriptor => { | ||
| if (value === null || typeof value !== "object") return false; | ||
| const candidate = value as { | ||
| readonly handle?: { readonly read?: unknown; readonly stat?: unknown }; | ||
| readonly initial?: { | ||
| readonly size?: unknown; | ||
| readonly dev?: unknown; | ||
| readonly ino?: unknown; | ||
| readonly mode?: unknown; | ||
| readonly mtimeMs?: unknown; | ||
| readonly ctimeMs?: unknown; | ||
| }; | ||
| }; | ||
| return ( | ||
| typeof candidate.handle?.read === "function" && | ||
| typeof candidate.handle?.stat === "function" && | ||
| typeof candidate.initial?.size === "number" && | ||
| typeof candidate.initial?.dev === "number" && | ||
| typeof candidate.initial?.ino === "number" && | ||
| typeof candidate.initial?.mode === "number" && | ||
| typeof candidate.initial?.mtimeMs === "number" && | ||
| typeof candidate.initial?.ctimeMs === "number" | ||
| ); | ||
| }; | ||
|
|
||
| const revalidateTransferredZipSource = async ( | ||
| path: string, | ||
| source: TransferredZipInventorySource["source"], | ||
| source: StableRegularFileDescriptor, | ||
| expectedSha256: string, | ||
| signal?: AbortSignal, | ||
| ): Promise<void> => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.