Skip to content

Survey import stress test: delete created users - #4356

Merged
SteRiccio merged 10 commits into
masterfrom
fix/stress-test-user-delete
Aug 14, 2026
Merged

Survey import stress test: delete created users#4356
SteRiccio merged 10 commits into
masterfrom
fix/stress-test-user-delete

Conversation

@SteRiccio

Copy link
Copy Markdown
Member

No description provided.

SteRiccio and others added 8 commits August 13, 2026 16:17
Covers the DB-level relationships (blocking vs. cascade-deleted) that
constrain deleting a user, the new deleteUser service/endpoint, and
wiring the survey-import stress test to clean up its throwaway users.
DELETE /user/:userUuid (system-admin only) reassigns the target's
records to the acting admin, blocks on owned surveys/messages
(both a hard DB constraint), and rejects self-delete and deleting
the last system admin.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
_userFetcher wraps fetchUserByEmail/fetchUserByUuid/fetchUserByUuidWithPassword
and updateUser, then calls _attachAuthGroupsAndInvitationToUser to fetch auth
groups and invitation status. It previously dropped the caller's client/tx,
so that read always ran on a separate `db` connection outside any transaction
the caller had opened -- a TOCTOU gap surfaced by deleteUser's last-system-admin
check, which reads isSystemAdmin() off a user fetched inside its own tx.

_userFetcher now takes a clientArgIndex (default 1, matching every wrapped
fetchFn's own `(id, client = db)` shape) and forwards args[clientArgIndex] as
`t`. updateUser is wired with index 4, since its wrapped _updateUser has a
different signature (user, surveyId, userToUpdate, profilePicture, client) --
using the default index 1 there would have misread surveyId as the client.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Needed so the stress test can clean up the throwaway accounts it
provisions, via the new DELETE /api/user/:userUuid endpoint.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
createUser's uuid is now captured as soon as creation succeeds (not
just on overall success) and carried through to the run's results,
so cleanupUsers can delete every account the run created, mirroring
the existing survey cleanup and gated by the same --keep flag.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The warning still claimed throwaway accounts "cannot be deleted
afterward" and pointed at test/load/README.md for details -- both
now wrong/misleading since this same feature branch made account
cleanup automatic and updated the README to say so.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- deleteUser now uses SurveyManager.countOwnedSurveys/fetchAllSurveyIds
  (unfiltered, FK-scoped) instead of the UI listing query
  (fetchUserSurveys), which excluded templates/temporary surveys and
  required current auth-group membership -- letting owned surveys/records
  slip past the pre-delete checks and hit raw FK-violation 500s instead of
  a clean 409.
- Add the five appErrors i18n keys deleteUser throws (EN only, matching
  existing unregistered-key precedent for other locales).
- Update the design spec's key names (flat, not dotted) and the
  owns-surveys error's params to match the fix above.
- Log an audit line in deleteUser recording who deleted whom.
- test/load/README.md: move the no-longer-a-limitation cleanup paragraph
  out of Limitations; fix stray "--" to em dash.
- surveyImportStressTest.ts: fail CI when post-run survey/user cleanup
  doesn't fully succeed (not just when imports fail), skipped when --keep
  is passed.
Committing alongside the design spec it implements, for the same
reason the spec is tracked: a durable record of what was planned.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an admin-only user-account deletion capability on the backend and wires the load/stress-test tooling to capture and delete the throwaway users it creates, preventing user-row buildup across runs.

Changes:

  • Add UserService.deleteUser and expose it via DELETE /api/user/:userUuid (admin-only), with checks for owned surveys/messages and record-owner reassignment.
  • Update the survey import stress test to capture created userUuids, delete users after the run (unless --keep), and reflect the new behavior in docs/config.
  • Extend load-test HTTP client helpers and tests to support deleteUser and return uuid from createUser.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/modules/user/service/userService.js Implements transactional admin delete logic with ownership checks and record reassignment.
server/modules/user/api/userApi.js Adds admin-only DELETE /user/:userUuid API route.
server/modules/user/manager/userManager.js Ensures user “enrichment” runs with the correct transaction client.
server/modules/survey/manager/surveyManager.js Re-exports fetchUserSurveys from SurveyRepository.
core/i18n/resources/en/appErrors.js Adds new appErrors strings for delete-user failure cases.
test/load/lib/httpApi.ts Makes createUser return uuid; adds deleteUser client call.
test/load/lib/httpApi.test.ts Updates/extends tests for createUser uuid parsing and deleteUser.
test/load/lib/report.ts Extends load-test result type to include optional userUuid.
test/load/surveyImportStressTest.ts Captures userUuid, adds cleanupUsers, and cleans up users after runs.
test/load/surveyImportStressTest.test.ts Adds regression coverage for userUuid reporting and cleanupUsers.
test/load/lib/config.ts Updates --keep help text and notes to include user cleanup.
test/load/README.md Updates documentation to reflect user cleanup behavior and limitations.
docs/superpowers/specs/2026-08-13-user-account-deletion-design.md Adds design spec for admin user deletion and stress-test cleanup.
docs/superpowers/plans/2026-08-13-user-account-deletion.md Adds detailed implementation/verification plan for the feature.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread server/modules/user/service/userService.js
SteRiccio and others added 2 commits August 14, 2026 08:03
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

@mergify

mergify Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@SteRiccio
SteRiccio merged commit ba3aa09 into master Aug 14, 2026
6 checks passed
@SteRiccio
SteRiccio deleted the fix/stress-test-user-delete branch August 14, 2026 06:35
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.

2 participants