Check the migration actually kept everything, and let report say so

internal/validate was written and tested and then never called: `run` ended
at cutover, so the tool performed a migration and never confirmed it had
carried the data across, and `report` was an error message pointing at the
package that would have answered.

`run` now compares the migrated instance against the snapshot preflight took
and fails if an account or a domain that existed before is missing from it.
The comparison runs against the service cutover has just started, which is
the instance people will actually use - its real config, its real ports,
under its real service manager - and costs no extra downtime; booting a
second copy inside the maintenance window would. BootCheck stays as the
equivalent for an instance the tool boots itself.

The service is left running on a failure. By that point the store has been
migrated in place, so stopping it undoes nothing, and only the operator can
weigh the finding against their recovery point.

A check that could not run is reported as skipped, never as a pass. Preflight
only captures the "before" when it has an admin URL, and a run without one
has to say it compared nothing rather than imply everything survived - which
is the exact failure ARCHITECTURE.md §4.7 warns about. `report <run-id>`
re-reads the recorded verdict rather than re-checking: run again next week
and you would be asking how the instance looks now, not how it looked when
it was migrated.

§4.7 said validation ran after cutover while the only implementation booted
its own copy, and listed a suite far larger than what exists. It now says
which of the two happens, and which checks are real.
This commit is contained in:
2026-08-24 12:27:36 -07:00
parent 558af1005f
commit 28128633ef
9 changed files with 515 additions and 7 deletions
+19
View File
@@ -21,6 +21,7 @@ import (
"github.com/LINUXexpert-org/stalwart-migrator/internal/recovery"
"github.com/LINUXexpert-org/stalwart-migrator/internal/service"
"github.com/LINUXexpert-org/stalwart-migrator/internal/stage"
"github.com/LINUXexpert-org/stalwart-migrator/internal/validate"
)
// runRun implements `stalwart-migrate run`: the real migration.
@@ -334,6 +335,24 @@ func runRun(args []string) (err error) {
return fmt.Errorf("cutover failed: %w", err)
}
fmt.Println("\n--- validate ---")
valReport, valErr := validate.RunLive(ctx, store, rs, validate.LiveOptions{
AdminURL: *adminURL, AdminUser: *adminUser, AdminPassword: *adminPassword,
HTTPClient: httpClient, Before: rs.PreflightSnapshot,
})
fmt.Print(valReport.String())
if valErr != nil {
return fmt.Errorf("the migrated service is up, but validation could not complete - check it by hand before "+
"treating this migration as done: %w", valErr)
}
if valReport.Blocking() {
// The service is live and serving mail; that is deliberately not
// undone here. The operator has the finding and their recovery
// point, and only they can weigh one against the other.
return fmt.Errorf("the migrated service is up, but accounts or domains from before the migration are missing " +
"from it - see the FAIL line above. Your recovery point is the way back; this tool will not undo a migration")
}
fmt.Printf("\nMIGRATION COMPLETE for run %s. Mail was down for %s.\n",
rs.RunID, time.Since(windowStart).Round(time.Second))
fmt.Printf("Now: confirm you can log in as %s, send and receive a test message, and work through\n", *adminUser)