diff --git a/src/android/AndroidJniLibraries.ts b/src/android/AndroidJniLibraries.ts index 9ab519130f..1e3e30e0d0 100644 --- a/src/android/AndroidJniLibraries.ts +++ b/src/android/AndroidJniLibraries.ts @@ -153,6 +153,7 @@ export const readAndroidJniLibraries = async (input: { throw new ArtifactReaderFailure( "integrity", "Native library exceeds its declared ZIP size", + { integrityCheck: "declared-size" }, ); data.copy(bytes, offset); offset += data.length; @@ -164,6 +165,7 @@ export const readAndroidJniLibraries = async (input: { throw new ArtifactReaderFailure( "integrity", "Native library is shorter than its declared ZIP size", + { integrityCheck: "declared-size" }, ); throwIfJadxInterrupted(input.signal); const sha256 = createHash("sha256").update(bytes).digest("hex"); diff --git a/src/artifacts/ArtifactFileAdmission.ts b/src/artifacts/ArtifactFileAdmission.ts index fa18c998e0..159a869612 100644 --- a/src/artifacts/ArtifactFileAdmission.ts +++ b/src/artifacts/ArtifactFileAdmission.ts @@ -28,7 +28,7 @@ export const artifactFileAdmissionFailure = ( return new ArtifactReaderFailure( "integrity", `${diagnosticLabel} source changed during admission: ${path}`, - { cause }, + { cause, integrityCheck: "container-identity" }, ); if (cause instanceof NonRegularFileReadError) return new ArtifactReaderFailure( diff --git a/src/artifacts/ArtifactFileSource.ts b/src/artifacts/ArtifactFileSource.ts index db53d88d7d..ab0d18ce7c 100644 --- a/src/artifacts/ArtifactFileSource.ts +++ b/src/artifacts/ArtifactFileSource.ts @@ -33,7 +33,7 @@ export const assertArtifactFileSelectedSource = async ( throw new ArtifactReaderFailure( "integrity", `${diagnosticLabel} source identity changed: ${path}`, - { cause }, + { cause, integrityCheck: "container-identity" }, ); throw cause; }), @@ -45,6 +45,7 @@ export const assertArtifactFileSelectedSource = async ( throw new ArtifactReaderFailure( "integrity", `${diagnosticLabel} source identity changed: ${path}`, + { integrityCheck: "container-identity" }, ); }; @@ -147,7 +148,7 @@ export class ArtifactFileSource { throw new ArtifactReaderFailure( "integrity", `${this.diagnosticLabel} carrier changed after inventory`, - undefined, + { integrityCheck: "container-identity" }, artifactIntegrityDetails( ".", { algorithm: "sha256", digest: expectedSha256 }, @@ -167,6 +168,7 @@ export class ArtifactFileSource { throw new ArtifactReaderFailure( "integrity", `${this.diagnosticLabel} source identity changed: ${this.path}`, + { integrityCheck: "container-identity" }, ); assertArtifactReadActive(signal); return source; diff --git a/src/artifacts/ArtifactSelectedSource.ts b/src/artifacts/ArtifactSelectedSource.ts index 734c2f5105..1f7dbc27bf 100644 --- a/src/artifacts/ArtifactSelectedSource.ts +++ b/src/artifacts/ArtifactSelectedSource.ts @@ -26,6 +26,7 @@ export const assertArtifactSelectedSource = async ( { userMessage: "The selected artifact path no longer names the opened file. Reopen the selected artifact, then retry.", + integrityCheck: "container-identity", ...(cause === undefined ? {} : { cause }), }, ); diff --git a/src/artifacts/inventory/scanCanonical.ts b/src/artifacts/inventory/scanCanonical.ts index d1cd27c997..9ca466ace1 100644 --- a/src/artifacts/inventory/scanCanonical.ts +++ b/src/artifacts/inventory/scanCanonical.ts @@ -527,6 +527,7 @@ const buildInventorySnapshot = async ( throw new ArtifactReaderFailure( "integrity", "Missing iNES reconstruction scan", + { integrityCheck: "inventory-node" }, ); ines = await reader.verifyReconstruction( rootDigest.sha256, @@ -620,6 +621,7 @@ const verifyRootDigest = async ( throw new ArtifactReaderFailure( "integrity", "Root artifact changed during inventory", + { integrityCheck: "container-identity" }, ); }; diff --git a/src/artifacts/readStableArtifact.ts b/src/artifacts/readStableArtifact.ts index 6a6225dde2..ae20430970 100644 --- a/src/artifacts/readStableArtifact.ts +++ b/src/artifacts/readStableArtifact.ts @@ -62,7 +62,7 @@ const afterValidation = async ( throw new ArtifactReaderFailure( "integrity", `Artifact changed ${stage}: ${path}`, - { cause }, + { cause, integrityCheck: "container-identity" }, ); throw cause; } @@ -119,6 +119,7 @@ export const readStableArtifact = async ( throw new ArtifactReaderFailure( "integrity", `Artifact changed before open: ${path}`, + { integrityCheck: "container-identity" }, ); assertArtifactReadActive(signal); // A raced descriptor size must not allocate beyond the selected budget. @@ -172,6 +173,7 @@ export const readStableArtifact = async ( throw new ArtifactReaderFailure( "integrity", `Artifact changed during read: ${path}`, + { integrityCheck: "container-identity" }, ); assertArtifactReadActive(signal); onValidatedState?.(initial); @@ -197,6 +199,7 @@ export const assertStableArtifactState = async ( throw new ArtifactReaderFailure( "integrity", `Artifact changed since acquisition: ${path}`, + { integrityCheck: "container-identity" }, ); assertArtifactReadActive(signal); }; diff --git a/src/browser/assets/LocalWebScriptArtifacts.ts b/src/browser/assets/LocalWebScriptArtifacts.ts index 22a422fb37..b6d9ed8150 100644 --- a/src/browser/assets/LocalWebScriptArtifacts.ts +++ b/src/browser/assets/LocalWebScriptArtifacts.ts @@ -145,7 +145,7 @@ export class LocalWebScriptArtifacts implements WebScriptArtifactPort { throw new ArtifactReaderFailure( "integrity", `Selected source identity mismatch: ${sourcePath}; expected sha256=${selected.content.sha256}, bytes=${String(selected.content.bytes)}; observed sha256=${sourceBytes.sha256}, bytes=${String(sourceBytes.bytes.length)}.`, - undefined, + { integrityCheck: "member-identity" }, { logicalPath: selected.content.relative_path, declaredSha256: selected.content.sha256, diff --git a/src/browser/assets/WebArtifactReads.ts b/src/browser/assets/WebArtifactReads.ts index ddb3f6d76e..0ffddf8473 100644 --- a/src/browser/assets/WebArtifactReads.ts +++ b/src/browser/assets/WebArtifactReads.ts @@ -213,6 +213,9 @@ const webArtifactPrimaryError = ( ...(cause.reason === "limit" && context.limitRecovery !== undefined ? { remediationAction: context.limitRecovery } : {}), + ...(cause.integrityCheck === undefined + ? {} + : { integrityCheck: cause.integrityCheck }), }, ); if ( diff --git a/src/gpu/GpuCodeObjectsProvider.ts b/src/gpu/GpuCodeObjectsProvider.ts index 03d1b2e4b8..0635134ae8 100644 --- a/src/gpu/GpuCodeObjectsProvider.ts +++ b/src/gpu/GpuCodeObjectsProvider.ts @@ -276,7 +276,7 @@ export class GpuCodeObjectsProvider implements GpuCodeObjectsPort { throw new ArtifactReaderFailure( "integrity", "Selected GPU path changed during inspection", - { cause }, + { cause, integrityCheck: "container-identity" }, ); throw cause; }, @@ -285,6 +285,7 @@ export class GpuCodeObjectsProvider implements GpuCodeObjectsPort { throw new ArtifactReaderFailure( "integrity", "GPU source changed during inspection", + { integrityCheck: "container-identity" }, ); const leaves = inventory.objects.filter( (row) => diff --git a/src/gpu/GpuSource.ts b/src/gpu/GpuSource.ts index f2e43d839d..2745b267f7 100644 --- a/src/gpu/GpuSource.ts +++ b/src/gpu/GpuSource.ts @@ -80,6 +80,7 @@ export class GpuFileSource implements GpuSource { throw new ArtifactReaderFailure( "integrity", "GPU source was truncated during inspection", + { integrityCheck: "read-coverage" }, ); position += result.bytesRead; this.bytesRead += result.bytesRead; diff --git a/src/model/ModelArtifactProvider.ts b/src/model/ModelArtifactProvider.ts index 2eb0047f9f..d5c2a61cc2 100644 --- a/src/model/ModelArtifactProvider.ts +++ b/src/model/ModelArtifactProvider.ts @@ -332,7 +332,7 @@ export class ModelArtifactProvider implements ModelArtifactPort { throw new ArtifactReaderFailure( "integrity", "Selected model path changed during inspection", - { cause }, + { cause, integrityCheck: "container-identity" }, ); throw cause; }, @@ -341,6 +341,7 @@ export class ModelArtifactProvider implements ModelArtifactPort { throw new ArtifactReaderFailure( "integrity", "Model file changed during inspection", + { integrityCheck: "container-identity" }, ); const groups = new Map< string, diff --git a/src/model/ModelHeaderReader.ts b/src/model/ModelHeaderReader.ts index 139753747a..c229f8e1c2 100644 --- a/src/model/ModelHeaderReader.ts +++ b/src/model/ModelHeaderReader.ts @@ -92,6 +92,7 @@ export class ModelHeaderReader { throw new ArtifactReaderFailure( "integrity", "Model header ended before its admitted file extent", + { integrityCheck: "read-coverage" }, ); this.#hash.update(next.subarray(offset, offset + result.bytesRead)); offset += result.bytesRead; @@ -141,6 +142,7 @@ export class ModelHeaderReader { throw new ArtifactReaderFailure( "integrity", "Model ended before its admitted extent during full-file hashing", + { integrityCheck: "read-coverage" }, ); this.#hash.update(buffer.subarray(0, bytesRead)); position += bytesRead; diff --git a/src/native/NativePlistSource.ts b/src/native/NativePlistSource.ts index 6a131d851a..5accabf72b 100644 --- a/src/native/NativePlistSource.ts +++ b/src/native/NativePlistSource.ts @@ -332,6 +332,7 @@ export const readNativePlistBytes = ( throw new ArtifactReaderFailure( "integrity", `Selected plist changed during read: ${input.selection.path}`, + { integrityCheck: "container-identity" }, ); assertArtifactReadActive(input.signal); return bytes; diff --git a/tests/boundary/filesystem/artifactAdmittedIdentity.test.ts b/tests/boundary/filesystem/artifactAdmittedIdentity.test.ts index c4713753f8..bd604f09c6 100644 --- a/tests/boundary/filesystem/artifactAdmittedIdentity.test.ts +++ b/tests/boundary/filesystem/artifactAdmittedIdentity.test.ts @@ -65,9 +65,7 @@ it.skipIf(process.platform === "win32").each(["zip", "asar"])( ok: false, error: { reason: "integrity", - detail: expect.stringContaining( - "no longer resolves to its admitted source", - ), + integrityCheck: "container-identity", }, }); await expect(access(output)).rejects.toMatchObject({ code: "ENOENT" }); @@ -237,9 +235,7 @@ it.skipIf(process.platform === "win32")( ok: false, error: { reason: "integrity", - detail: expect.stringContaining( - "no longer resolves to its admitted source", - ), + integrityCheck: "container-identity", }, }); await expect(access(output)).rejects.toMatchObject({ code: "ENOENT" }); diff --git a/tests/boundary/filesystem/asarSelectedCompanion.test.ts b/tests/boundary/filesystem/asarSelectedCompanion.test.ts index c03bc8328a..4c965f6ef2 100644 --- a/tests/boundary/filesystem/asarSelectedCompanion.test.ts +++ b/tests/boundary/filesystem/asarSelectedCompanion.test.ts @@ -180,9 +180,7 @@ it.skipIf(process.platform === "win32")( throw new Error("Retargeted archive was unexpectedly admitted"); expect(result.error).toMatchObject({ reason: "integrity", - detail: expect.stringContaining( - "no longer resolves to its admitted source", - ), + integrityCheck: "container-identity", }); }); }, diff --git a/tests/boundary/filesystem/godotPckIdentity.test.ts b/tests/boundary/filesystem/godotPckIdentity.test.ts index ba4a012eba..635d389b4d 100644 --- a/tests/boundary/filesystem/godotPckIdentity.test.ts +++ b/tests/boundary/filesystem/godotPckIdentity.test.ts @@ -66,7 +66,7 @@ it.each( expect(failure).toMatchObject({ reason: "integrity", details: undefined, - message: expect.stringContaining("source identity changed"), + integrityCheck: "container-identity", }); else if (matchingDigest) expect(failure).toMatchObject({ reason: "cancelled", cause: reason }); diff --git a/tests/boundary/filesystem/webArtifactAcquisition.test.ts b/tests/boundary/filesystem/webArtifactAcquisition.test.ts index 79eac049c1..7211c37403 100644 --- a/tests/boundary/filesystem/webArtifactAcquisition.test.ts +++ b/tests/boundary/filesystem/webArtifactAcquisition.test.ts @@ -72,8 +72,14 @@ it.each([ }) : await reader.load(input); if (result.ok) throw new Error("Expected acquisition failure"); + const projected = projectAnalysisError(result.error); + if (variant === "source-mismatch") + expect(projected).toMatchObject({ + category: "integrity_mismatch", + details: { integrity_check: "member-identity" }, + }); const observation = webArtifactAcquisitionSchema.parse( - projectAnalysisError(result.error).details?.partial_observation, + projected.details?.partial_observation, ); expect(observation.files).toHaveLength( variant === "invalid-import-map" diff --git a/tests/composition/analysis-sessions/binarySessionAsarSelectedPath.test.ts b/tests/composition/analysis-sessions/binarySessionAsarSelectedPath.test.ts index ec7f1b199c..ce11a45036 100644 --- a/tests/composition/analysis-sessions/binarySessionAsarSelectedPath.test.ts +++ b/tests/composition/analysis-sessions/binarySessionAsarSelectedPath.test.ts @@ -70,9 +70,7 @@ it.skipIf(process.platform === "win32")( expect(retargeted.error).toMatchObject({ _tag: "ArtifactOperationError", reason: "integrity", - detail: expect.stringContaining( - "no longer resolves to its admitted source", - ), + integrityCheck: "container-identity", }); } finally { await session.close(); diff --git a/tests/process-global/artifactFileSourceLifecycle.test.ts b/tests/process-global/artifactFileSourceLifecycle.test.ts index 4f23fd690e..bd7bce2f96 100644 --- a/tests/process-global/artifactFileSourceLifecycle.test.ts +++ b/tests/process-global/artifactFileSourceLifecycle.test.ts @@ -123,7 +123,7 @@ it.each(carriers)( await writeFile(path, carrier.bytes(BODY.repeat(3))); await expect(reader.prepareContainer(sha256)).rejects.toMatchObject({ reason: "integrity", - message: `${carrier.name} source identity changed: ${path}`, + integrityCheck: "container-identity", }); } finally { await reader.close(); diff --git a/tests/process-global/selectedArtifactSourceLifecycle.test.ts b/tests/process-global/selectedArtifactSourceLifecycle.test.ts index c6d2536e80..23f6989900 100644 --- a/tests/process-global/selectedArtifactSourceLifecycle.test.ts +++ b/tests/process-global/selectedArtifactSourceLifecycle.test.ts @@ -332,10 +332,10 @@ it.each([false, true])( const failure = await binding; if (!(failure instanceof ArtifactReaderFailure)) throw new Error("Expected a selected-path identity failure"); - expect(failure.reason).toBe("integrity"); - expect(failure.message).toBe( - `Selected carrier source identity changed: ${fixture.path}`, - ); + expect(failure).toMatchObject({ + reason: "integrity", + integrityCheck: "container-identity", + }); expect(failure.cancellation).toBeUndefined(); await source.close(); expect(handle.fd).toBe(-1);