fix(ndo): tenant-delete guard also scans tenant policy templates (F5b) (v0.26.0)

The in-use guard added in 0.22.0 (F5) only scanned SCHEMA templates'
tenantId, so a tenant referenced only by a tenant policy template
(tenant_policy_templates[*].tenantPolicyTemplate.template.tenantId — the
same field path _get_template_objects/_backfill_policy_uuids already
traverse) could be deleted, leaving a dangling reference. Real NDO refuses
to delete an in-use tenant regardless of which template type holds the
reference.

DELETE /mso/api/v1/tenants/{id} (and the bare /api/v1 twin) now scans
both. A policy-template-only reference returns 400 "Tenant '<id>' is
referenced by tenant policy template(s): <names> — delete those templates
first"; the wording is a format-mirrored approximation of the
hardware-grounded schema-template message (no real-NDO capture of this
specific rejection text exists yet — the code comment says so). The
schema-template message is byte-for-byte unchanged. Deleting the
referencing template still releases the guard. Malformed policy-template
entries default-allow (fail-safe, consistent with the sim's philosophy).

Verification: full pytest 1147 passed (1143 baseline + 4 new TDD tests,
red-phase confirmed pre-fix; all 8 pre-existing F5 tests intact);
independent opus review APPROVE (over-rejection trace: different-tenant
policy template still deletes clean; release-test proven non-vacuous);
live golden gate on restarted sim — create tenant -> create referencing
policy template -> DELETE 400 golden -> delete template -> DELETE 200.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017zdUTqU9fvCCvF3uVGZsu1
This commit is contained in:
dtzp555-max
2026-07-11 06:20:01 +10:00
co-authored by Claude Opus 4.8
parent c2959ab2cb
commit 4ca201085b
4 changed files with 241 additions and 9 deletions
+17
View File
@@ -6,6 +6,23 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
(pre-1.0: minor bumps may include breaking changes to the sim's behavior).
## [0.26.0] - 2026-07-11
### Fixed
- **NDO tenant-delete guard now covers tenant policy templates (F5b)** — the
in-use guard added in 0.22.0 only scanned SCHEMA templates' `tenantId`, so a
tenant referenced only by a tenant policy template
(`tenant_policy_templates[*].tenantPolicyTemplate.template.tenantId`) could
be deleted, leaving a dangling reference (fails-open). `DELETE
/mso/api/v1/tenants/{id}` now scans both: a tenant referenced by a policy
template returns `400 "Tenant '<id>' is referenced by tenant policy
template(s): <names> — delete those templates first"` (wording is a
format-mirrored approximation of the hardware-grounded schema-template
message — no real-NDO capture of this specific rejection text exists yet,
and the code comment says so). The schema-template message is byte-for-byte
unchanged; deleting the referencing template still releases the guard;
malformed policy-template entries default-allow (fail-safe). +4 tests.
## [0.25.0] - 2026-07-10
### Changed