Skip to content

feat: polls on commits - #114

Merged
brendt merged 31 commits into
dev-null-sh:productionfrom
xHeaven:feat/polls
Oct 16, 2026
Merged

brendt merged 31 commits into
dev-null-sh:productionfrom
xHeaven:feat/polls

Conversation

@xHeaven

@xHeaven xHeaven commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

feat: polls on commits

git bisect for opinions. A top-level commit can now carry a poll: the commit body is the question, with 2 to 4 short options (50 characters each) and a length of 1 hour, 1 day, 3 days or 7 days. Signed-in developers pick an option and vote once. Results appear as soon as they have voted, when the poll closes, or straight away for the author.

The composer gets an "Add poll" button next to the image button. Replies can't have polls. Moderators see the poll in the queue, so they review the options together with the question.

Behavior and decisions

  • Images or a poll, not both. A commit carries either images or a poll. While a poll is attached, the image button is disabled and paste/drop of images is ignored. While images are attached, "Add poll" is disabled with a tooltip explaining why. The server enforces the same rule: poll is prohibits:parent_id,images in CreateCommitRequest. This keeps the card to one attachment and avoids deciding how a poll and an image grid stack.
  • Votes are final. There is no changing or retracting a vote, the same as most polls on social networks. A unique (poll_id, user_id) index enforces one vote per person. A second vote is refused by CreateCommitPollVoteRequest with "You have already voted on this poll.". If two requests race past validation, CreateCommitPollVote writes with insertOrIgnore and returns false for the loser, so the first vote stands and the response is the poll as it is, never a 500.
  • Authors can't vote on their own poll. Instead they see live results from the start, which is what they want to know anyway, and it keeps them from skewing their own question.
  • Results are hidden server-side until they may be seen. Before a viewer votes, the JSON contains the options with votes_count: null and total_votes: null. Counts are serialized only for voters, the author, or anyone once the poll has closed. No voter identity is ever serialized. Votes stay private, and only the voter's own choice is marked (with a check and a screen-reader "your vote").
  • The clock starts at approval. polls.opened_at is set when the commit is approved, or on creation for admins, whose commits skip moderation. Time spent in the moderation queue doesn't eat into a 1-hour poll. Rejecting and re-approving keeps the original opened_at. Pending polls show "Voting opens once approved".
  • Voting rules live in CreateCommitPollVoteRequest, following the form-request rule in ArchTest. CreateCommitPollVote only records the vote. authorize() returns 403 for commits the viewer can't see (same rule as stars), and route binding returns 404 for deleted commits. The option must belong to this commit's poll, and the OpenPoll rule (in App\Rules) refuses with a 422 on option: "This poll is not open for votes." (pending, rejected or not yet opened), "You can't vote on your own poll.", "This poll has closed." or "You have already voted on this poll.".
  • Creating a poll is part of CreateCommit, in the same transaction as the commit. CreateCommitRequest validates poll.options (a list of 2 to 4, required, max 50, distinct ignoring case), poll.duration (the PollDuration enum, in minutes) and prohibits:parent_id,images. Like the rest of the actions, CreateCommit trusts its caller and does no checks of its own. Emoji shortcodes in options are expanded like the body.
  • Schema. Three tables: polls (one per commit, commit_id unique, cascade on delete), poll_options (ordered by position) and poll_votes (FKs to poll, option and user, all cascading). Deleting an account removes that user's votes and, through their commits, their polls. Soft-deleted commits are tombstones, and the existing Commit::toArray tombstone rule already drops every relation, poll included.
  • No N+1. CommitBuilder::withPollFor($viewer) eager loads polls and their options with withCount('votes') plus a voted exists flag for the viewer. That is two queries for any page size, covered by a query-count test (1 vs 20 polls with votes). The author flag is set in an afterQuery callback from the already loaded commits.user_id, so the polls query has no exists/count subqueries. The existing "partial reloads don't count anything" assertions stay as they are. Polls load on the logs, the commit page and its ancestors, profiles (pinned and list), saved commits, and moderation. Suggestions only render a truncated body, so they don't load polls.
  • Guests see nothing. Guest commit URLs still render only the landing page with link-preview meta (body only). No poll options or results reach guest props, HTML, or the OG image.
  • Personal data export (CreateExport) gains polls (polls on the user's live commits: duration, opened_at, option labels) and poll_votes (the user's own choices). It never includes other voters.
  • UI and accessibility. Options are a native radio group inside a <fieldset>, so arrow keys work and the global j/k shortcuts don't interfere. An explicit "Vote" button prevents accidental final votes. Results are a list with percentages and an sr-only vote count per option. The summary line (39 votes · 2d left / Final results) is a role="status" region, so the result is announced after voting. Bars respect prefers-reduced-motion. Voting goes through useHttp (like Save) and swaps in the server's results. I didn't do an optimistic update: counts are hidden until the vote lands, so the button shows "Voting…" for that round trip instead.

Screenshots

All content is fictional demo data from a separate local SQLite database.

Composer with a poll

Desktop light Desktop dark
Composer light Composer dark
Mobile light Mobile dark
Composer mobile light Composer mobile dark

Open poll, before voting (an option selected, no counts shown)

Desktop light Desktop dark
Open poll light Open poll dark
Mobile light Mobile dark
Open poll mobile light Open poll mobile dark

Results after voting (own choice checked, time left)

Desktop light Desktop dark
Results light Results dark
Mobile light Mobile dark
Results mobile light Results mobile dark

Closed poll, final results for a viewer who never voted

Desktop light Desktop dark
Closed light Closed dark
Mobile light Mobile dark
Closed mobile light Closed mobile dark

Moderation queue (pending poll, voting not open yet)

Light Dark
Moderation light Moderation dark

Everyone log with every state: open, author's own live results, voted, closed

Full-page captures
Light Dark
Log light Log dark

Interactive flow

An admin (no moderation wait) writes a question, adds a poll with three options, picks 1 hour and commits. The poll appears with the author's live 0 votes · 1h left. Then they vote on someone else's poll and the results replace the options. This is the real UI and HTTP flow.

Creating a poll and voting

Watch the MP4

Validation

  • Merged production four times with merge commits:
    • Through f81720b (mentions and image uploads): resolved conflicts in CreateCommit, CreateCommitRequest, CommitController, Commit, CommitAncestorsQuery, the composer, the commit card and the commit types. Polls and images now load side by side on every commit query.
    • Through 9ccb16a (authorization and validation only in form requests): the merge was clean. Afterwards the poll checks moved out of the vote action and CreateCommit into the vote form request plus the OpenPoll rule, and into CreateCommitRequest.
    • Through db106cc (CRUD-by-design naming): resolved conflicts in CreateCommit, UpdateCommitStatuses (previously ModerateCommits, which opens the poll clock on approval) and CreateCommitRequest. Renamed VoteOnPoll to CreateCommitPollVote and CreatePollVoteRequest to CreateCommitPollVoteRequest to mirror CommitPollVoteController@store. Moved the two approval-clock tests from the deleted ApproveCommitTest into UpdateCommitStatusTest. Pointed the export test at the renamed export route. The export additions now live in CreateExport.
    • Through b403add (Octane, plus inline code and highlighted code blocks): the merge was clean. Poll questions get the same body_segments highlighting as any other commit, and a feature test covers it. Polls are Octane-safe: there are no static properties or singletons. withPollFor captures the viewer per query, and OpenPoll is built for each request in rules(). bun.lock and composer.lock are identical to production's.
  • Strict TDD: Pest tests were written first and failed before implementation. New tests cover the poll model (serialization rules, closing time, cascades, unique vote), CreateCommitPollVote (records a vote, keeps the first vote on a repeat), CreateCommit and UpdateCommitStatus (poll creation, admin opening, approval clock, re-approval), the vote endpoint (JSON results, every refusal reason, 403/404/422, guests), poll validation (including replies and images plus poll) and display on logs, commit and ancestors, profile, saved and moderation, the query-count bound, guest non-exposure, and the export.
  • tests/Unit and tests/Feature (the whole suite now that browser tests are gone) passed after the latest merge: 1,004 tests / 5,646 assertions, including every ArchTest rule.
  • Production removed tests/Browser, so I dropped the browser test I had written for the composer and voting flow. Its backend behavior is covered by the feature tests above. The UI flow is shown in the recording below, which was re-captured after the merge.
  • pest --type-coverage --min=100: 100%. PHPStan (project config, level max), Rector dry run, Pint, bun run test:lint, bun run test:types, bun run build and git diff --check all passed. All media was re-captured after the latest merge, so it shows the new action row and the poll length chevron fix. bun run lint also reformatted two lines production had left unformatted (resources/css/app.css, commit-thread.tsx). That fix is needed for test:lint to pass.
  • Not run: line coverage. This machine's PHP has no Xdebug/PCOV, so I couldn't measure 100% line coverage locally. I checked by hand that every new branch in app/ is hit by a test, and CI's --exactly=100.0 will confirm.

Deployment and limits

  • Three new create-table migrations, no changes to existing tables. No new dependencies.
  • Polls can't be created from the devnull commit CLI script. The shared form request accepts them, but the CLI controller ignores them.
  • Votes can't be changed or retracted (by design, see above). If a voter deletes their account, their vote goes with it, so totals on old polls can drop.
  • If a poll closes while the page is open, it switches to "Poll closed" and disables voting. Final counts appear on the next load.
  • Captures use Chrome with mobile viewport emulation on a separate local SQLite database on port 8135. No production or staging data was touched. The temporary login route was removed before pushing, and the demo seed and capture scripts stayed outside the repository.

# Conflicts:
#	app/Actions/CreateCommit.php
#	app/Http/Controllers/CommitController.php
#	app/Http/Requests/CreateCommitRequest.php
#	app/Models/Commit.php
#	app/Queries/CommitAncestorsQuery.php
#	resources/js/components/commit-card.tsx
#	resources/js/components/commit-composer.tsx
#	resources/js/types/commit.ts
#	tests/Unit/Actions/CreateCommitTest.php
# Conflicts:
#	app/Actions/CreateCommit.php
#	app/Actions/UpdateCommitStatuses.php
#	app/Http/Requests/CreateCommitRequest.php
#	tests/Unit/Actions/ApproveCommitTest.php
@brendt
brendt merged commit 41dfff3 into dev-null-sh:production Oct 16, 2026
4 checks passed
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