Skip to content

Commit 4bd4e6d

Browse files
juliusmarmingecodex
andcommitted
Redact manifest conflict diagnostics
Co-authored-by: codex <[email protected]>
1 parent 29b2d0a commit 4bd4e6d

2 files changed

Lines changed: 103 additions & 16 deletions

File tree

‎scripts/lib/update-manifest.ts‎

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as Effect from "effect/Effect";
22
import * as Schema from "effect/Schema";
33

4+
import { getUrlDiagnostics } from "@t3tools/shared/urlDiagnostics";
5+
46
export interface UpdateManifestFile {
57
readonly url: string;
68
readonly sha512: string;
@@ -10,6 +12,9 @@ export interface UpdateManifestFile {
1012
export const UpdateManifestScalar = Schema.Union([Schema.String, Schema.Number, Schema.Boolean]);
1113
export type UpdateManifestScalar = typeof UpdateManifestScalar.Type;
1214

15+
export const UpdateManifestScalarType = Schema.Literals(["string", "number", "boolean"]);
16+
export type UpdateManifestScalarType = typeof UpdateManifestScalarType.Type;
17+
1318
export const UpdateManifestParseReason = Schema.Literals([
1419
"incomplete file entry",
1520
"sha512 without a file entry",
@@ -59,30 +64,40 @@ export class UpdateManifestExtraConflictError extends Schema.TaggedErrorClass<Up
5964
{
6065
platformLabel: Schema.String,
6166
key: Schema.String,
62-
primaryValue: UpdateManifestScalar,
63-
secondaryValue: UpdateManifestScalar,
67+
primaryValueType: UpdateManifestScalarType,
68+
primaryValueLength: Schema.optionalKey(Schema.Number),
69+
secondaryValueType: UpdateManifestScalarType,
70+
secondaryValueLength: Schema.optionalKey(Schema.Number),
6471
},
6572
) {
6673
override get message(): string {
67-
return `Cannot merge ${this.platformLabel} update manifests: conflicting '${this.key}' values ('${this.primaryValue}' vs '${this.secondaryValue}').`;
74+
return `Cannot merge ${this.platformLabel} update manifests: conflicting '${this.key}' ${this.primaryValueType} and ${this.secondaryValueType} values.`;
6875
}
6976
}
7077

7178
export class UpdateManifestFileConflictError extends Schema.TaggedErrorClass<UpdateManifestFileConflictError>()(
7279
"UpdateManifestFileConflictError",
7380
{
7481
platformLabel: Schema.String,
75-
url: Schema.String,
82+
urlInputLength: Schema.Number,
83+
urlProtocol: Schema.optionalKey(Schema.String),
84+
urlHostname: Schema.optionalKey(Schema.String),
7685
existingManifest: Schema.Literals(["primary", "secondary"]),
77-
existingSha512: Schema.String,
86+
existingSha512Length: Schema.Number,
7887
existingSize: Schema.Number,
7988
conflictingManifest: Schema.Literals(["primary", "secondary"]),
80-
conflictingSha512: Schema.String,
89+
conflictingSha512Length: Schema.Number,
8190
conflictingSize: Schema.Number,
91+
sha512Conflict: Schema.Boolean,
92+
sizeConflict: Schema.Boolean,
8293
},
8394
) {
8495
override get message(): string {
85-
return `Cannot merge ${this.platformLabel} update manifests: conflicting file entry for ${this.url}.`;
96+
const origin =
97+
this.urlProtocol === undefined || this.urlHostname === undefined
98+
? ""
99+
: ` at ${this.urlProtocol}//${this.urlHostname}`;
100+
return `Cannot merge ${this.platformLabel} update manifests: conflicting file entry${origin} (URL input length: ${this.urlInputLength}).`;
86101
}
87102
}
88103

@@ -327,6 +342,12 @@ export function parseUpdateManifest(
327342
};
328343
}
329344

345+
function getScalarType(value: UpdateManifestScalar): UpdateManifestScalarType {
346+
if (typeof value === "string") return "string";
347+
if (typeof value === "number") return "number";
348+
return "boolean";
349+
}
350+
330351
function mergeExtras(
331352
primary: Readonly<Record<string, UpdateManifestScalar>>,
332353
secondary: Readonly<Record<string, UpdateManifestScalar>>,
@@ -340,8 +361,10 @@ function mergeExtras(
340361
throw new UpdateManifestExtraConflictError({
341362
platformLabel,
342363
key,
343-
primaryValue: existing,
344-
secondaryValue: value,
364+
primaryValueType: getScalarType(existing),
365+
...(typeof existing === "string" ? { primaryValueLength: existing.length } : {}),
366+
secondaryValueType: getScalarType(value),
367+
...(typeof value === "string" ? { secondaryValueLength: value.length } : {}),
345368
});
346369
}
347370
merged[key] = value;
@@ -374,15 +397,24 @@ export function mergeUpdateManifests(
374397
for (const file of files) {
375398
const existing = filesByUrl.get(file.url);
376399
if (existing && (existing.file.sha512 !== file.sha512 || existing.file.size !== file.size)) {
400+
const urlDiagnostics = getUrlDiagnostics(file.url);
377401
throw new UpdateManifestFileConflictError({
378402
platformLabel,
379-
url: file.url,
403+
urlInputLength: urlDiagnostics.inputLength,
404+
...(urlDiagnostics.protocol === undefined
405+
? {}
406+
: { urlProtocol: urlDiagnostics.protocol }),
407+
...(urlDiagnostics.hostname === undefined
408+
? {}
409+
: { urlHostname: urlDiagnostics.hostname }),
380410
existingManifest: existing.manifest,
381-
existingSha512: existing.file.sha512,
411+
existingSha512Length: existing.file.sha512.length,
382412
existingSize: existing.file.size,
383413
conflictingManifest: manifest,
384-
conflictingSha512: file.sha512,
414+
conflictingSha512Length: file.sha512.length,
385415
conflictingSize: file.size,
416+
sha512Conflict: existing.file.sha512 !== file.sha512,
417+
sizeConflict: existing.file.size !== file.size,
386418
});
387419
}
388420
filesByUrl.set(file.url, { manifest, file });

‎scripts/merge-update-manifests.test.ts‎

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ releaseDate: '2026-03-07T10:36:07.540Z'
195195
});
196196

197197
it("identifies both sources when duplicate primary file entries conflict", () => {
198+
const privateUrl =
199+
"https://user:[email protected]/releases/private/app.exe?token=secret-token#fragment";
200+
const firstSha512 = "first-private-sha";
201+
const secondSha512 = "second-private-sha";
198202
const manifest = {
199203
version: "1.0.0",
200204
releaseDate: "2026-06-20T00:00:00.000Z",
@@ -206,8 +210,8 @@ releaseDate: '2026-03-07T10:36:07.540Z'
206210
{
207211
...manifest,
208212
files: [
209-
{ url: "app.exe", sha512: "first", size: 1 },
210-
{ url: "app.exe", sha512: "second", size: 2 },
213+
{ url: privateUrl, sha512: firstSha512, size: 1 },
214+
{ url: privateUrl, sha512: secondSha512, size: 2 },
211215
],
212216
},
213217
{ ...manifest, files: [] },
@@ -217,9 +221,60 @@ releaseDate: '2026-03-07T10:36:07.540Z'
217221
assert.equal(error._tag, "UpdateManifestFileConflictError");
218222
if (error._tag === "UpdateManifestFileConflictError") {
219223
assert.equal(error.existingManifest, "primary");
220-
assert.equal(error.existingSha512, "first");
221224
assert.equal(error.conflictingManifest, "primary");
222-
assert.equal(error.conflictingSha512, "second");
225+
assert.equal(error.urlInputLength, privateUrl.length);
226+
assert.equal(error.urlProtocol, "https:");
227+
assert.equal(error.urlHostname, "example.test");
228+
assert.equal(error.existingSha512Length, firstSha512.length);
229+
assert.equal(error.existingSize, 1);
230+
assert.equal(error.conflictingSha512Length, secondSha512.length);
231+
assert.equal(error.conflictingSize, 2);
232+
assert.isTrue(error.sha512Conflict);
233+
assert.isTrue(error.sizeConflict);
234+
assert.notProperty(error, "url");
235+
assert.notProperty(error, "existingSha512");
236+
assert.notProperty(error, "conflictingSha512");
237+
238+
const diagnostics = [error.message, ...Object.values(error).map(String)].join("\n");
239+
assert.notInclude(diagnostics, "user");
240+
assert.notInclude(diagnostics, "password");
241+
assert.notInclude(diagnostics, "/releases/private/app.exe");
242+
assert.notInclude(diagnostics, "secret-token");
243+
assert.notInclude(diagnostics, firstSha512);
244+
assert.notInclude(diagnostics, secondSha512);
245+
}
246+
});
247+
248+
it("reports extra conflicts without retaining arbitrary scalar values", () => {
249+
const primaryValue = "primary-private-value";
250+
const secondaryValue = "secondary-private-value";
251+
const manifest = {
252+
version: "1.0.0",
253+
releaseDate: "2026-06-20T00:00:00.000Z",
254+
files: [{ url: "app.exe", sha512: "sha", size: 1 }],
255+
};
256+
257+
const error = captureUpdateManifestError(() =>
258+
mergePlatformUpdateManifests(
259+
"win",
260+
{ ...manifest, extras: { releaseNotes: primaryValue } },
261+
{ ...manifest, extras: { releaseNotes: secondaryValue } },
262+
),
263+
);
264+
265+
assert.equal(error._tag, "UpdateManifestExtraConflictError");
266+
if (error._tag === "UpdateManifestExtraConflictError") {
267+
assert.equal(error.key, "releaseNotes");
268+
assert.equal(error.primaryValueType, "string");
269+
assert.equal(error.primaryValueLength, primaryValue.length);
270+
assert.equal(error.secondaryValueType, "string");
271+
assert.equal(error.secondaryValueLength, secondaryValue.length);
272+
assert.notProperty(error, "primaryValue");
273+
assert.notProperty(error, "secondaryValue");
274+
275+
const diagnostics = [error.message, ...Object.values(error).map(String)].join("\n");
276+
assert.notInclude(diagnostics, primaryValue);
277+
assert.notInclude(diagnostics, secondaryValue);
223278
}
224279
});
225280

0 commit comments

Comments
 (0)