fix: accept published installer migration checksums

This commit is contained in:
Colin
2026-06-04 12:23:29 -04:00
parent e8dc420b4d
commit b8e15c7a98
12 changed files with 198 additions and 3 deletions

View File

@@ -208,12 +208,22 @@ function migrationChecksum(migration: MigrationRecord): string {
return `sha256:${sha256Text(JSON.stringify(serializable))}`;
}
function migrationLegacyChecksums(migration: MigrationRecord): string[] {
return Array.isArray(migration.legacyChecksums)
? migration.legacyChecksums.filter((checksum): checksum is string => typeof checksum === 'string' && checksum.length > 0)
: [];
}
function migrationAcceptedChecksums(migration: MigrationRecord): Set<string> {
return new Set([migrationChecksum(migration), ...migrationLegacyChecksums(migration)]);
}
function assertAppliedMigrationChecksums(applied: Map<string, Record<string, unknown>>, migrations: MigrationRecord[]): void {
for (const migration of migrations) {
const entry = applied.get(migration.id as string);
if (!entry || !entry.checksum) continue;
const checksum = migrationChecksum(migration);
if (entry.checksum !== checksum) {
const accepted = migrationAcceptedChecksums(migration);
if (!accepted.has(entry.checksum as string)) {
throw new Error(
`applied migration checksum changed for ${migration.id as string}; create a new fix-forward migration id`
);
@@ -923,6 +933,7 @@ export = {
acquireInstallMigrationLock,
applyInstallerMigrationPlan,
classifyArtifact,
computeInstallerMigrationChecksum: migrationChecksum,
discoverInstallerMigrations,
planInstallerMigrations,
readInstallManifest,