fix(control-plane): unify validation for the domain-managed kinds

The control-plane catalog advertises identities, capture-events,
capture-mappings and capture-bindings as domain-managed: the domain API
validates their writes, not the generic resource store. Two of those
paths did not hold.

Identities: the file loader judged an identity name with its own
`name == ""` test, while the store derives the same string through
identity.New, whose rule rejects an empty-after-trim name. A
whitespace-only name passed the file and then failed State Store boot
(or was silently skipped by BootstrapIdentities). The loader now calls
identity.ValidDisplayName, the feature's own rule, and
BootstrapIdentities derives legacy names through
identity.FromLegacyName rather than dropping one it cannot build.

Capture mappings and bindings: mapping.Validate and binding.Validate
ran only in the archie-ui handlers, so any other client of the RPCs the
catalog names could store a mapping or binding the feature refuses.
The staterpc write handlers now apply the feature's rule before the
store, per runtime-control-plane.md ("the server validates the change,
then writes it"). The rule stays in the domain package; the handlers
only translate its refusal.

Capture-events has no file-side copy and no feature rule for a captured
event's content, so there is nothing to unify there.

Tests: identity_agreement_test.go ties the file loader's name rule to
the store constructor; domain_validation_test.go proves the mapping and
binding RPCs refuse an invalid value before it reaches the store.
This commit is contained in:
sam committed 2026-10-02 10:50:52 +10:00
1 parent ff3f80e4c1
commit ef203ce30a
6 files changed
+285 -37

No files matched your search

+18 -30
View File
@@ -232,47 +232,35 @@ func (s *Store) BindSubject(ctx context.Context, id identity.IdentityID, subject
// BootstrapIdentities seeds the system identity and the configured legacy
// names idempotently, migrating any forge tasks that still carry a legacy
// name to the stable id.
// name to the stable id. Each legacy name is derived through
// identity.FromLegacyName, so a name this store cannot turn into an identity is
// reported rather than silently skipped -- the file loader refuses the same
// names (configuration.validateIdentities).
func (s *Store) BootstrapIdentities(ctx context.Context, legacyNames []string) error {
values := append([]struct {
id identity.IdentityID
kind identity.Kind
name string
}{{identity.SystemID, identity.KindSystem, "System"}}, make([]struct {
id identity.IdentityID
kind identity.Kind
name string
}, len(legacyNames))...)
for i, name := range legacyNames {
name = strings.TrimSpace(name)
values[i+1] = struct {
id identity.IdentityID
kind identity.Kind
name string
}{identity.StableID(name), identity.KindBot, name}
}
for _, seed := range values {
if seed.name == "" {
continue
}
value, err := identity.New(seed.id, seed.kind, seed.name)
values := make([]identity.Identity, 0, len(legacyNames)+1)
values = append(values, identity.System())
for _, name := range legacyNames {
value, err := identity.FromLegacyName(name)
if err != nil {
return err
return fmt.Errorf("bootstrap identity %q: %w", name, err)
}
_, err = s.Create(ctx, value, identity.Audit{
ActorID: identity.SystemID, Source: "legacy-config", RequestID: "identity-import:" + string(seed.id),
values = append(values, value)
}
for _, value := range values {
_, err := s.Create(ctx, value, identity.Audit{
ActorID: identity.SystemID, Source: "legacy-config", RequestID: "identity-import:" + string(value.ID),
})
if err != nil && !isUniqueViolation(err) {
return fmt.Errorf("bootstrap identity %q: %w", seed.name, err)
return fmt.Errorf("bootstrap identity %q: %w", value.DisplayName, err)
}
if err := s.queries().InsertIdentityAliasIgnoreConflict(ctx, postgresdb.InsertIdentityAliasIgnoreConflictParams{
Alias: seed.name, IdentityID: string(seed.id),
Alias: value.DisplayName, IdentityID: string(value.ID),
}); err != nil {
return err
}
if seed.kind != identity.KindSystem {
if value.Kind != identity.KindSystem {
if err := s.queries().UpdateTaskIdentity(ctx, postgresdb.UpdateTaskIdentityParams{
Identity: string(seed.id), Identity_2: seed.name,
Identity: string(value.ID), Identity_2: value.DisplayName,
}); err != nil {
return err
}