nats-tools: a durable beginning <node>_<module>_ is the module's too
Builds: design 47 H H-A-128 Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -377,7 +377,7 @@ func removalTools(bus Bus, said Said, newForm heldEntries, record Recorded) []st
|
||||
}
|
||||
return []stdio.Tool{
|
||||
{Name: "nats_consumer_remove",
|
||||
Description: "Removes (deletes) one named JetStream consumer of one stream, e.g. a consumer the controller left, such as `controller` of DEAD_LETTER_NOTICES or `controller-merges` of EVENTS (novox/hq ADR 0590 §6), or an orphan on a module's kept-data stream. Refuses a durable named <node>_<module> for a module of an accepted manifest, on any stream; any other durable goes. Needs `why`, its warrant, kept in the audit trail and recorded as a hand act through mesh-hand-acts (design 47 H, H-A-127); refuses an unknown stream or consumer; reads the consumer first and answers what it was (filters, pending, unacknowledged); the stream and its other consumers are not touched. The bus refuses any consumer the module's credential is not granted.",
|
||||
Description: "Removes (deletes) one named JetStream consumer of one stream, e.g. a consumer the controller left, such as `controller` of DEAD_LETTER_NOTICES or `controller-merges` of EVENTS (novox/hq ADR 0590 §6), or an orphan on a module's kept-data stream. Refuses a durable named <node>_<module> or beginning <node>_<module>_ for a module of an accepted manifest, on any stream; any other durable goes. Needs `why`, its warrant, kept in the audit trail and recorded as a hand act through mesh-hand-acts (design 47 H, H-A-127); refuses an unknown stream or consumer; reads the consumer first and answers what it was (filters, pending, unacknowledged); the stream and its other consumers are not touched. The bus refuses any consumer the module's credential is not granted.",
|
||||
Input: map[string]any{"stream": str("the stream, e.g. DEAD_LETTER_NOTICES"), "consumer": str("the consumer's name, e.g. controller"), "why": str("why it is removed, for the audit trail (required)")},
|
||||
Run: removeConsumer},
|
||||
{Name: "nats_stream_remove",
|
||||
@@ -397,8 +397,8 @@ func removalTools(bus Bus, said Said, newForm heldEntries, record Recorded) []st
|
||||
}
|
||||
}
|
||||
|
||||
// refuseAcceptedDurable refuses a durable named <node>_<module> for a module of the keeper's accepted set (design 47 H,
|
||||
// H-A-127); a set that cannot be read refuses too: what cannot be told apart is not removed.
|
||||
// refuseAcceptedDurable refuses a durable named <node>_<module>, or beginning <node>_<module>_, for a module of the
|
||||
// keeper's accepted set, on any node (design 47 H, H-A-127, H-A-128); a set that cannot be read refuses too: what cannot be told apart is not removed.
|
||||
func refuseAcceptedDurable(newForm heldEntries, consumer string) error {
|
||||
if newForm == nil {
|
||||
return nil
|
||||
@@ -411,8 +411,10 @@ func refuseAcceptedDurable(newForm heldEntries, consumer string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("whether %s is the durable of a module of an accepted manifest cannot be read (%v), so nothing was removed", consumer, err)
|
||||
}
|
||||
if _, ok := held[module]; ok {
|
||||
return fmt.Errorf("%s is %s's durable on %s, a module of an accepted manifest: it is not removed; nothing was removed", consumer, module, node)
|
||||
for m := range held {
|
||||
if module == m || strings.HasPrefix(module, m+"_") {
|
||||
return fmt.Errorf("%s is %s's durable on %s, a module of an accepted manifest: it is not removed; nothing was removed", consumer, m, node)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -258,6 +258,8 @@ func TestTheRemovalToolsRefuseBeforeTheyReachTheBus(t *testing.T) {
|
||||
// Design 47 H, H-A-127: a consumer is judged by its name: an accepted module's durable is refused on any stream.
|
||||
{"nats_consumer_remove", map[string]any{"stream": "EVENTS", "consumer": "novox_m", "why": "x"}, "a module of an accepted manifest"},
|
||||
{"nats_consumer_remove", map[string]any{"stream": "m_log", "consumer": "ace_m", "why": "x"}, "a module of an accepted manifest"},
|
||||
// H-A-128: a durable beginning <node>_<module>_ is the module's too.
|
||||
{"nats_consumer_remove", map[string]any{"stream": "EVENTS", "consumer": "novox_m_keeper", "why": "x"}, "a module of an accepted manifest"},
|
||||
} {
|
||||
var run func(map[string]any) (any, error)
|
||||
for _, tl := range removalTools(bus, said, newForm, nil) {
|
||||
@@ -280,8 +282,10 @@ func TestTheRemovalToolsRefuseBeforeTheyReachTheBus(t *testing.T) {
|
||||
if tl.Name != "nats_consumer_remove" {
|
||||
continue
|
||||
}
|
||||
if _, err := tl.Run(map[string]any{"stream": "m_log", "consumer": "c", "why": "an orphan"}); err == nil || !strings.Contains(err.Error(), "not reached") {
|
||||
t.Errorf("an orphan on m_log: %v, want the call to reach the bus", err)
|
||||
for _, orphan := range []string{"c", "novox_mx", "novox_mx_keeper"} {
|
||||
if _, err := tl.Run(map[string]any{"stream": "m_log", "consumer": orphan, "why": "an orphan"}); err == nil || !strings.Contains(err.Error(), "not reached") {
|
||||
t.Errorf("the orphan %s on m_log: %v, want the call to reach the bus", orphan, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
// The read tools stay read tools: none of the first ten takes a `why`, and the list is these ten.
|
||||
|
||||
Reference in New Issue
Block a user