diff --git a/modules/mesh-grants/internal/buscompose/buscompose_test.go b/modules/mesh-grants/internal/buscompose/buscompose_test.go index c78a43f1a..c52b5fb52 100644 --- a/modules/mesh-grants/internal/buscompose/buscompose_test.go +++ b/modules/mesh-grants/internal/buscompose/buscompose_test.go @@ -1130,8 +1130,12 @@ func aLedgerIsWrittenByItsLedgerAccountAlone(t *testing.T) { if got := ledgers(assigned("a")); !slices.Equal(got, []string{"ledger.a.m"}) { t.Fatalf("after m left b: ledger accounts %v, want ledger.a.m alone", got) } + // H-A-693, H-A-717 (DQ-47): beside its publishes, the account holds the purge request of each ledger's snapshot store and of + // its history stream, its answer on its own inbox. want := []string{"mesh.ledger.m.audit.history.>", "mesh.ledger.m.audit.snapshot.>", - "mesh.ledger.m.records.history.>", "mesh.ledger.m.records.snapshot.>"} + "mesh.ledger.m.records.history.>", "mesh.ledger.m.records.snapshot.>", + "$JS.API.STREAM.PURGE.m_audit", "$JS.API.STREAM.PURGE.m_audit_snapshot", + "$JS.API.STREAM.PURGE.m_records", "$JS.API.STREAM.PURGE.m_records_snapshot"} raw := []string{"mesh.ledger.m.records.history.decision/0290", "mesh.ledger.m.records.snapshot.decision/0290"} for _, p := range both { perms, err := PermissionsFor(p) @@ -1141,6 +1145,8 @@ func aLedgerIsWrittenByItsLedgerAccountAlone(t *testing.T) { if p.Kind == KindLedger { if !slices.Equal(perms.Publish, want) || len(perms.PublishDeny) != 0 { t.Errorf("%s may publish %v, want %v alone", p.Username(), perms.Publish, want) + } else if !slices.Equal(perms.Subscribe, []string{p.inbox()}) { + t.Errorf("%s hears %v, want its own inbox %s for the purge's answer", p.Username(), perms.Subscribe, p.inbox()) } continue } diff --git a/modules/mesh-grants/internal/buscompose/ledger.go b/modules/mesh-grants/internal/buscompose/ledger.go index c34119e42..4d1ca1f83 100644 --- a/modules/mesh-grants/internal/buscompose/ledger.go +++ b/modules/mesh-grants/internal/buscompose/ledger.go @@ -29,6 +29,20 @@ func LedgerPublishGrants(module string, locals []string) []string { return out } +// LedgerPurgeGrants are the purge requests a module's ledger account is granted, beside its publishes: of each ledger's snapshot +// store `__snapshot` and of its history stream `_`, one subject each; the answer comes on the +// account's own inbox (design 47 H2 H-A-693, H-A-717 (DQ-47): the tool runner's purge of a snapshot, and of a history, are the +// account's own grants). Sorted. +func LedgerPurgeGrants(module string, locals []string) []string { + var out []string + for _, local := range locals { + stream := module + "_" + local + out = append(out, "$JS.API.STREAM.PURGE."+stream, "$JS.API.STREAM.PURGE."+stream+"_snapshot") + } + sort.Strings(out) + return out +} + // writesLedger is a module's ledger account publishing on that module's own ledgers' histories and snapshots, and no other // principal (ADR 0597 ยง9). func writesLedger(p Principal, pattern string) bool { @@ -53,5 +67,5 @@ func ledgerPermissions(p Principal) (Permissions, error) { if err := CheckWriters(p, pub); err != nil { return Permissions{}, err } - return Permissions{Publish: pub, Subscribe: []string{p.inbox()}}, nil + return Permissions{Publish: append(slices.Clone(pub), LedgerPurgeGrants(p.Module, p.Ledgers)...), Subscribe: []string{p.inbox()}}, nil }