Capture the pre-migration snapshot from 0.15.x, and stop claiming counts match when none were compared
Found by running preflight against a real Stalwart 0.15.5 in a VM. Two defects, the second worse than the first. 1. AccountSnapshot could not read the version this tool migrates FROM. 0.15.5 advertises no urn:stalwart:jmap capability and POST /api returns 404 - the JMAP management API and x:Account are 0.16 features. 0.15.x exposes a REST API at GET /api/principal instead. So preflight's account-snapshot check warned and moved on, and every run against a real source instance had no "before" data at all. AccountSnapshot now dispatches on the capability the session document advertises - a positive signal, not an inference from a failed call - and internal/stalwartapi/principal.go implements the 0.15.x REST path, including its 1-based page/limit pagination so an install larger than one page isn't silently truncated. 2. With no "before" counts, the content-integrity comparison iterated an empty map, checked nothing, and reported "all message counts match". That is the strongest claim this tool makes - ARCHITECTURE 4.7 calls it the actual no-data-loss guarantee - made vacuously, and it would have passed on a migration that lost every message. The comparison now derives its account set from whatever the source could report, verifies every account and domain survived either way, and carries MessageCountsCompared so the report says plainly "MESSAGE COUNTS NOT COMPARED ... no-data-loss is NOT verified here" rather than implying otherwise. What can and cannot be checked across the 0.15/0.16 boundary, now that a real server has answered: 0.15.x has no per-mailbox message count at any endpoint, and the impersonation login 0.16 offers returns 401 there, so before/after message counts are impossible for the boundary migration this tool exists for. Both versions do report per-account used quota (usedQuota in 0.15's REST list, usedDiskQuota on 0.16's x:Account), so that is captured on both sides. It is recorded and reported, not asserted on: 4.5 notes the 0.16 migration resets quotas to zero pending recalculation, so comparing those bytes across the boundary would be a false alarm generator. Test servers across preflight, validate and stalwartapi now advertise urn:stalwart:jmap, since they stand in for 0.16 instances and that capability is what says so. Verified end to end against the smoke VM: all nine preflight checks pass, and the checkpoint records 2 accounts, 1 domain and per-account used quota where it previously recorded nothing.
This commit is contained in:
@@ -104,6 +104,10 @@ type account struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
DomainID string `json:"domainId"`
|
||||
// UsedDiskQuota is 0.16's name for what 0.15's REST API calls
|
||||
// usedQuota - the same per-account byte count, which is what makes a
|
||||
// cross-boundary content comparison possible at all.
|
||||
UsedDiskQuota int64 `json:"usedDiskQuota"`
|
||||
}
|
||||
|
||||
// AccountSnapshot enumerates every account on the instance via Stalwart's
|
||||
@@ -124,6 +128,22 @@ type account struct {
|
||||
// exactly what's missing rather than silently treating an unreachable
|
||||
// account's mailboxes as having zero messages.
|
||||
func (c *Client) AccountSnapshot(ctx context.Context) (*Snapshot, error) {
|
||||
isJMAP, err := c.hasJMAPManagement(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("stalwartapi: discover which management API this instance speaks: %w", err)
|
||||
}
|
||||
if !isJMAP {
|
||||
// No urn:stalwart:jmap: this is a 0.15.x instance, whose
|
||||
// management API is REST. Confirmed against a live 0.15.5 server -
|
||||
// see principal.go.
|
||||
return c.principalSnapshotREST(ctx)
|
||||
}
|
||||
return c.accountSnapshotJMAP(ctx)
|
||||
}
|
||||
|
||||
// accountSnapshotJMAP is the 0.16+ path, via Stalwart's JMAP management
|
||||
// objects.
|
||||
func (c *Client) accountSnapshotJMAP(ctx context.Context) (*Snapshot, error) {
|
||||
ids, err := c.AccountIDs(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -133,7 +153,7 @@ func (c *Client) AccountSnapshot(ctx context.Context) (*Snapshot, error) {
|
||||
}
|
||||
|
||||
getResp, err := c.call(ctx, managementCapabilities, []any{
|
||||
[]any{"x:Account/get", map[string]any{"ids": ids, "properties": []string{"id", "name", "domainId"}}, "g"},
|
||||
[]any{"x:Account/get", map[string]any{"ids": ids, "properties": []string{"id", "name", "domainId", "usedDiskQuota"}}, "g"},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("stalwartapi: Account/get: %w", err)
|
||||
@@ -169,11 +189,19 @@ func (c *Client) AccountSnapshot(ctx context.Context) (*Snapshot, error) {
|
||||
}
|
||||
sort.Strings(domains)
|
||||
|
||||
usedQuota := make(map[string]int64, len(accounts))
|
||||
for _, a := range accounts {
|
||||
if a.Name != "" {
|
||||
usedQuota[a.Name] = a.UsedDiskQuota
|
||||
}
|
||||
}
|
||||
|
||||
return &Snapshot{
|
||||
AccountCount: len(accounts),
|
||||
Domains: domains,
|
||||
MailboxCounts: mailboxCounts,
|
||||
MailboxErrors: mailboxErrors,
|
||||
UsedQuota: usedQuota,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user