feat(channel): Pinterest board sections (#1120) #1127
All Vouch review confidence checks passed
Residual risk 0.32 = Change Risk (0.52) × (1 − Review Confidence (0.38)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 81% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #1127"
general
weight: 0.35
claude[bot]
Closes #1120. Step 2 of 3: the RLS matrix factory landed in #1123, and step 3 drops the
PENDING_TABLESentry after this merges.Teams pin into board sections, and Tailwind and Later let them pick one. Crove connects each board as a channel (#812) and pinned at the board level only. Only the worker may open a channel's token (ADR-0025), so the composer cannot ask Pinterest itself. The worker fills a cache that the composer reads, following the link preview pattern (#641). The cache is the generic table planned in #1123, so #1030 (the YouTube playlist picker) can use it later.
Pinterest API v5, as confirmed in the docs
Sources: the official OpenAPI description (
pinterest/api-description,v5/openapi.yaml) and Pinterest's generated client docs (pinterest/pinterest-python-generated-api-client:docs/BoardsApi.md,docs/PinCreate.md,docs/PinsApi.md,docs/Error.md). developers.pinterest.com renders in the browser only and could not be read directly.GET /v5/boards/{board_id}/sections(board_sections/list):- takes
bookmarkandpage_size(default 25), and answers{ items: BoardSection[] (required), bookmark: string | null };- needs scope
boards:read, which Crove already requests, so there is no new consent;- can answer 400, 401, 403, 404 and 429, all as
Pinterest.Lib.Error.PinCreate.board_section_id: an optional string or null, "The board section to which this Pin belongs."POST /v5/pins404: "Board or section not found".{ code: int, message: string }, whichPinterestErroralready reads.page_size. Crove asks for 250 per page, as it already does for boards.What it does
packages/channel/src/pinterest.ts,options.ts):- Listing sections:
options({ kind: 'pinterest_section' })lists the board's sections, following the bookmark from page to page, at most 500. It cleans names: one line, no control, zero-width or direction marks, at most 200 characters. It tells a dead token, a refusal, a gone board and an outage apart.- Pinning into a section: with
settings.pinterest.sectionIdset,publishlists the sections again before any visible call and before a video's upload. It sendsboard_section_idonly for a section the board still has.- Refusals, with nothing posted:
- an unknown or deleted section, or a 404 from
POST /v5/pinsafter the check:PINTEREST_SECTION_NOT_FOUND(bad_request);- settings it cannot read:
PINTEREST_SECTION_INVALID;- a list that does not come:
PINTEREST_SECTIONS_UNREADABLE(transient, so the attempt is retried);- a token or permission refusal while listing:
token_expiredorpermission;- a board that is gone:
BOARD_NOT_FOUND.- No section: a pin without one is sent exactly as before, with no extra call. The existing recorded-answer test still checks the body with
toEqual.modules/social/src/domain/channels.ts,validate.ts):settings.pinterest = { sectionId }, a numeric id with the same shape and reading as the adapter's. It is refused on other channels (PINTEREST_NOT_SUPPORTED) and when malformed (PINTEREST_SECTION_INVALID). It is not stored without a section, so content hashes do not change.modules/social/src/channel-options.ts):-
social.channel_option.request(members): checks the caller's channel scope (#1081) and an active Pinterest connection. A fresh answer (under a day old) or a pending request (under 2 minutes old) is returned as it is. Otherwise the request is queued, within 20 requests per org per minute counted under an advisory lock.-
social.channel_option.get(members): the same checks; options are returned only when the list isready.-
social.channel_option.loadandsocial.channel_option.record(system only):- load reads the connection and kind from the pending row, on a connection that is still active;
- record updates only
WHERE status = 'pending', zod-checks ids, names (trimmed, no invisible marks, at most 200 characters), distinct ids and the 500 cap, and a failure storesitems = '[]'.- Worker (
runChannelOptionJob, queuesocial-channel-option, one job per request): opens the token only throughkernel.channel.credential(credential_get) in the org's system context and hands it to the adapter. A credential that will not open is recorded aspermission. No token reaches a command input, an event payload, an error or an answer, and the DB test checks the event and the stored row for it.apps/app/src/routes/social-post.tsx, vi and en):- a "Phần trong bảng" (Board section) picker on Pinterest variants: none (the board itself) or one of the listed sections;
- while the list loads it says so, then it shows the reason a list failed, with a reload button;
- it warns when the chosen section is no longer on the board;
- names are rendered as text only, and only design tokens are used;
- the post page words
PINTEREST_SECTION_NOT_FOUND, and the kernel's new codes (CHANNEL_OPTION_LIMIT,CHANNEL_OPTIONS_NOT_OFFERED) are worded in both languages.Migration
20261029060000_crove_social_channel_option.sqlchannel_option_before_update, asportal_invoice_list_before_updatedoes it:- the list's org, id, connection, kind and
created_atnever change;- an update that changes nothing passes, as the matrix's
status = statusprobe needs;- outside the system context, the only change allowed is asking again:
pending,errornull, a laterrequested_at, withitemsandfetched_atunchanged;- a
failedanswer keeps no items, in any context.channel_option_before_insert: a row of the context's own org startspendingwith no items, error orfetched_at. Another org's row is left to RLS, which refuses it. A pending insert passes in the system context too.social-channel-option.crove_kernel.org_purge: regenerated withpurge-add.mjs 1120 crove_social.channel_option, copied verbatim from20261029050000_crove_social_weekly_digest.sql. The only line that differs:SOCIAL_CHANNEL_OPTION_KINDS,_STATUSESand_ERRORSare inpackages/db/src/schema.tsand mapped incheck-unions.db.test.ts.pnpm db:typeswas regenerated and is unchanged on a second run.node tools/ci/migration-order.mjs origin/main: OK, newest on main is 20261029050000.Checks
pnpm -s lint: pass.pnpm -s typecheck: pass.pnpm docs:check: 82 files OK.pnpm exec vitest run packages/channel/test modules/social/test apps/app/test: 147 files, 1222 passed.vitest run --project unit): 2474 passed, 14 failed. All 14 failures are in the known Windows-only files (tools/test/invariant-summary,backup-lib,apps/kernel/test/status-page,invariant/route-coverage).- Pinterest adapter, recorded answers: 16 in
pinterest.test.ts, 6 of them new. They cover paging by bookmark, the 500 cap, name cleaning, the error mapping,board_section_idon image and video pins, the refusals with noPOST /v5/pins, and an unchanged pin without a section.- Domain: 1 test of the settings shape, checked against the adapter's reading.
main:| Test file | Passed |
| --- | --- |
|
apps/kernel/test/social-channel-option.db.test.ts(new) | 8 ||
apps/kernel/test/invariant/rls-matrix.db.test.ts| 542 ||
apps/kernel/test/invariant/org-purge.db.test.ts| 3 ||
apps/kernel/test/org-purge.db.test.ts| 7 ||
packages/db/test/invariant/migrate.db.test.ts| 9 ||
packages/db/test/check-unions.db.test.ts| 3 ||
apps/kernel/test/social-publish.db.test.ts| 54 ||
apps/kernel/test/social-link-preview.db.test.ts| 3 |The new DB test covers:
- a request, a repeat, the worker's record with the board's own token, freshness;
- failures by kind, no items kept on failure, asking again, a credential that will not open;
- refusals for a viewer, a channel outside the member's scope, another org, an expired connection, a channel that lists nothing;
- the per-minute budget and that other orgs are unaffected;
- the guard refusals and a member asking again;
- the system-only, pending-only, zod-checked record;
- publishing: listing the sections again, pinning into the section, refusing a gone section with nothing pinned, retrying when the list is down, and a pin without a section unchanged.
Protected path: migration; needs an independent security review.
test/invariantis untouched; the protected-path script lists onlysupabase/migrations/20261029060000_crove_social_channel_option.sql.Not tried in a browser: it needs a connected Pinterest board, and a real Pinterest app and account are not available here. The picker is covered by typecheck and by the API and DB tests only.
Notes:
modules/social/src/posts.tshas onmain. The first commit had rewritten them; the net change to that file is 3 lines.mainhas git's default message, without the Co-Authored-By trailer.🤖 Generated with Claude Code
---
<!-- dos-pr-summary -->
📌 TL;DR
This PR introduces a "Channel Options" feature that allows users to select specific Pinterest board sections when composing a social post. It implements a secure, worker-driven architecture where the frontend requests options, the backend worker fetches them using the channel's token, and the publishing process validates the section's existence before posting.
🎯 Type of Change
🔍 Changes Walkthrough
| File | Summary of Changes |
| :--- | :--- |
|
apps/app/src/i18n/messages/en.ts| Added English translations for Pinterest section selection UI, error states (e.g., section not found, permission errors), and new channel option limits. ||
apps/app/src/i18n/messages/vi.ts| Added Vietnamese translations corresponding to the new English strings. ||
apps/app/src/lib/kernel-errors.ts| Registered new error codesCHANNEL_OPTION_LIMITandCHANNEL_OPTIONS_NOT_OFFEREDin the kernel error list. ||
apps/app/src/routes/social-post.tsx| AddedPinterestSettingscomponent to the social post composer. This component handles fetching board sections via the newchannelOptionsAPI, displays a dropdown for selection, and handles loading/error states. Integrated into theProviderSettingsflow. ||
apps/kernel/src/jobs-schema.ts| Defined a new job queuesocialChannelOptionfor processing channel option requests. ||
apps/kernel/src/rpc.ts| Exposed new RPC endpointssocial.channelOptions.requestandsocial.channelOptions.getto the frontend. ||
apps/kernel/src/worker.ts| Implemented the worker logic to processsocialChannelOptionjobs. It listens forsocial.channel_option.requestedevents, executes the job with the channel's token, and handles retries. ||
apps/kernel/test/social-channel-option.db.test.ts| Added comprehensive integration tests for the channel option feature, covering permission checks, rate limiting, token security, and publishing validation against live (mocked) Pinterest API responses. ||
modules/social/src/channel-options.ts| Core business logic module. Defines thesocial.channel_option.requestcommand (with rate limiting and freshness checks) andsocial.channel_option.recordcommand (worker-only). Ensures tokens never leave the worker context. |📊 Architectural Flow
<!-- /dos-pr-summary -->