Skip to content

feat(#977): local data-subject DPI export + fix anonymization-cascade erasure gap - #3139

Merged
Thomas Jung (jung-thomas) merged 14 commits into
DEVfrom
worktree-977-dpi-minimal-set
Nov 16, 2026
Merged

Thomas Jung (jung-thomas) merged 14 commits into
DEVfrom
worktree-977-dpi-minimal-set

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

What & why (#977)

Enables Data Privacy Integration (DPI) for the end-of-July PROD cutover, as a local build rather than adopting @cap-js/data-privacy. The plugin couldn't do selective exposure (all three consumers — data-privacy, audit-logging, and the custom anonymization-cascade.js — gate on the same shared @PersonalData.EntitySemantics, and CAP gives them one shared CSN), and the confirmed need is export + erasure only (no SAP ILM retention, no Fiori DPP app). We already own erasure; this adds the export and fixes a real gap in the erasure.

Design + plan: docs/superpowers/specs/2026-11-13-dpi-local-export-design.md, docs/superpowers/plans/2026-11-16-dpi-local-export.md.

Changes

  • New DataPrivacyService (@path:/admin/data-privacy, @requires:'Admin') — exportDataSubject(userId) returns LargeString: a JSON document of all personal data held for a Users subject, assembled by walking the existing @PersonalData annotations via getCascadePlan() (single source of truth). Admin/DPO-only; emits a SecurityEvent audit (DataSubjectExport).
  • Shared srv/lib/data-subject-resolver.js — maps a Users row to the three DataSubjectID shapes (user_ID; the Users scalar ID; the non-user cases authorId and nested tab_ID). Reused by both the export and the cascade.
  • Fixed a live GDPR erasure gap in anonymization-cascade.js — AuthorAiRequests (keyed on authorId, an XSUAA-id string) and DeveloperEnvironmentLinks (keyed via parent tab_ID) were never matched by the old WHERE <field> = user.ID logic, so their personal data survived user anonymization. Now resolved correctly on both read (export) and erase (cascade), through the one shared resolver.
  • Guarded a latent crash — a user with null sapId AND null uuid previously produced WHERE … IN (), a HANA syntax error that would abort the whole anonymization cascade mid-run. Now an empty-candidates guard + LOG.warn on both the cascade and export paths.
  • Dropped @cap-js/data-privacy entirely — no dependency, no import, no cds.requires entry (confirmed by whole-branch review). No @PersonalData annotation weakened — audit-logging + cascade keep reading them unchanged.

Testing

  • 31 unit tests across 4 files (in-memory SQLite), all green; cds build --production exit 0.
  • Whole-branch review (opus) confirmed no read/erase asymmetry across all 17 @PersonalData entities — export and cascade agree on subject keying for every one.
  • Hybrid NCLOB read is covered by precedent, not a dedicated DPI hybrid test: existing test/hybrid/ tests already exercise these exact LargeString columns against real HANA — code-check.test.js (submittedCode), validate-answer-anonymize.test.js (submittedAnswer + anonymization cascade), author-service-os-variants.test.js (sourceMarkdown/variants).

Follow-up (non-blocking)

  • Add a dedicated test/hybrid/dpi-export.test.js exercising the export + authorId-cascade fix against real HANA (template: validate-answer-anonymize.test.js). Deferred by agreement; existing hybrid coverage de-risks the NCLOB/cascade paths in the meantime.
  • Already-orphaned AuthorAiRequests rows (anonymized before this fix) may warrant a one-off repair sweep — flag if PROD data shows any.

Built via subagent-driven development: Task 4 took one fix round (GDPR silent-drop → LOG.warn); Task 5 took two (the IN () crash guard, then isolation-testing the nested DELETE). Full decision ledger available on request.

…-pass resolvedMap, pass definitions param

- LOG.warn when _selectRows finds a declared personalField not in entity elements (GDPR safety, fix 1)
- Build resolvedMap in pre-scan and reuse in main loop to avoid double resolveSubjectKeys calls (fix 2)
- Resolve definitions once in _handleExport and pass as parameter to _selectRows (fix 3)
- Add unit test asserting LOG.warn fires AND row still exports with real columns (fix 1 test)
- Add DataPrivacyService rows to testing-endpoints.md (path /admin/data-privacy,
  auth XSUAA + Admin, exportDataSubject(userId) function)
- srv-qa cp-list audit: check-srv-qa-cp-list.ts reports OK — 0 transitive
  srv/* dependencies from srv-qa entry points; new files (data-subject-resolver.js,
  data-privacy-service.js) are not reachable from srv-qa/server.js via static
  import analysis. No mta.yaml change needed.
@jung-thomas

Copy link
Copy Markdown
Contributor Author

⚠️ The failing CDS build staging check on this PR is a pre-existing toolchain drift, not a defect in this change.

The CI diff is entirely:

  • "creator": "CDS Compiler v7.0.1" → v7.2.1 — CI's @sap/cds-dk was upgraded, but the checked-in db/last-dev/csn.json on DEV was baked with the older compiler.
  • "namespace": "...ims" → "...ims.shared" — a root namespace stamp the staging-check's existing namespace noise-filter doesn't cover.

No DataPrivacyService / DPI content appears in the diff. This PR adds a service projection + function with no new DB table, so it does not touch the HANA persistence snapshot that db/last-dev/ records. A local cds build --production on the matching v7.0.1 toolchain reproduces the committed file byte-for-byte — so this check fails on any PR opened against current DEV, not just this one.

Fix tracked separately (regenerate the snapshot with the new compiler, direct to DEV): see the linked infra issue. This check should go green on rebase once that lands. Everything else here is sound — PR is MERGEABLE and the unit check passed.

@jung-thomas

Copy link
Copy Markdown
Contributor Author

Tracking issue for the staging-check toolchain drift: #3140

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant