Skip to content

fix(people): honest vote counts, admin company source, attribute errors and segment evaluation - #1203

Open
mortondev wants to merge 3 commits into
mainfrom
fix/people-votes-segments
Open

mortondev wants to merge 3 commits into
mainfrom
fix/people-votes-segments

Conversation

@mortondev

Copy link
Copy Markdown
Member

Fixes product bugs found by the people e2e journeys quarantined in #1156 and #1170.

Fixed journeys

  • PPL-U-43: removing a voter now takes their vote off posts.vote_count, in the same transaction as the delete.
  • PPL-U-31: when a lead's vote collides with the user's vote during a merge, the dropped vote now comes off the count. The fix sits in the post_votes re-point step, so the admin lead merge, the anonymous sign-in or identify merge, and the signup absorb all get it.
  • PPL-C-03: companies created in the admin (the directory's "New company" and a person's Company card) are saved as manual. API callers keep the api default.
  • PPL-C-31 (the same component backs PPL-U-51): the user and company attribute dialogs show why a create or edit was refused, for example "An attribute with that key already exists", and keep the dialog open. A refused delete shows a toast and keeps the row.
  • PPL-G-06: vote_count and comment_count segment rules now count post_votes (hard-deleted) and live post_comments (deleted_at IS NULL). Before, they queried votes and comments, which do not exist. The table parameter is now a union type, so a wrong name fails typecheck.
  • PPL-G-50: when every segment is evaluated at once, each segment succeeds or fails on its own. A failure is logged with pino and reported as { segmentId, error: 'Evaluation failed' }, and the remaining segments still run. Successful entries keep the { segmentId, added, removed } shape.
  • PPL-G-11: evaluation compares matches against every member row, so a person already held by api, widget, manual or sso is no longer reported as added on every run. Removal still applies only to rows that evaluation added (dynamic).
  • PPL-G-28: removeMember now reports whether it deleted a row, and REST DELETE /api/v1/segments/:slug/members counts only real removals.
  • PPL-G-13: a schedule is accepted only if the scheduler's own parseCron accepts it. The check runs in the segment service, because the server function schema is part of the client entry and validating there would ship the parser to every page. 99 99 * * * and six-field patterns are now refused. */15-style steps are now accepted; the old regex refused them although the scheduler supports them. The message is unchanged: "Must be a valid cron expression".
  • PPL-G-15: updateSegment refuses rules: null or an empty condition list on a dynamic segment (the same VALIDATION_ERROR as create), so the segment keeps its members.

Notes

  • The vote counts use a delta, not a recount. An imported post can store a vote count with no post_votes rows behind it (import-service.ts), so a recount would erase it. The delta applies to the thread's canonical post and counts each voter once per merged thread, and test customers' votes, which were never counted, are skipped. This also covers a merge where the lead voted a merged duplicate and the user voted its canonical post.
  • The PPL-G-28 audit behaviour is unchanged: a no-op removal still records segment.member.removed, which an existing test pins as intentional.
  • The quarantine tags and QUARANTINE.md entries live on test(e2e): people journeys (users and companies) #1156 and test(e2e): people journeys (segments) #1170. Un-quarantine them there once this merges.
  • This branch may conflict textually with fix/rest-people-errors (removePortalUser) and fix/rest-input-errors ($slug.members.ts). Neither change is repeated here.

Tests

Each fix has a test that failed on main first:

  • Real-DB tests:
    • remove-portal-user.db.test.ts: counts drop, including on a merged thread.
    • user-merge.db.test.ts: a collision, a moved vote, and a collision across the same thread.
    • merge-anonymous.db.test.ts: a collision.
    • New segment-evaluation.db.test.ts: covers G-06, G-11, G-50 (a forced failure), G-15 and G-13.
  • Unit tests:
    • segment-membership.test.ts: removeMember returns a boolean.
    • New routes/api/v1/segments/__tests__/segment-members.test.ts: the removed count.
    • New companies-create.test.ts: the company source.
    • scalar-attribute-list.test.tsx: refused create, edit and delete.

Local checks: oxlint, prettier, typecheck, bun run build, check:server-fn-manifest and check:widget-bundle.

- Removing a person, or merging a lead or visitor whose vote collides with
  the person's, takes the vote off the post's stored vote_count (on the
  canonical post of a merged thread) in the same transaction.
- Companies created in the admin are 'manual', not 'api'.
- The user and company attribute dialogs show a refused create or edit
  (for example a duplicate key) and toast a refused delete.
- vote_count and comment_count segment rules count post_votes and live
  post_comments instead of tables that do not exist.
- Evaluating every segment isolates each one: a failure is logged and
  reported and the rest still run.
- Evaluation no longer reports a person held by another source as added.
- REST DELETE segment members counts only rows it removed.
- A schedule is accepted only if the scheduler's cron parser accepts it.
- A dynamic segment's rules cannot be cleared.
…raph

The createSegment/updateSegment schema is part of the client entry, so
validating with the scheduler's cron parser there shipped that parser to
every page. The segment service now refuses a pattern the parser rejects,
with the same message.

This branch has not been deployed

No deployments
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