Skip to content

feat(office): connect the ATS — employer read path, status mapping, and truthful placeholder screens - #543

Merged
thinkclay merged 11 commits into
mainfrom
claude/office-ats-audit-ad657a
Aug 5, 2026
Merged

thinkclay merged 11 commits into
mainfrom
claude/office-ats-audit-ad657a

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes the v1.17.0 milestone from the /office ATS audit (#539).

The problem

The ATS had a good database, a good UI, and no wire between them. Migrations 099–152 and 301/305 cover nearly everything a real ATS needs. The UI has a kanban, a six-tab candidate modal, a metrics dashboard, filters. Between them sat useApplications(), returning a hardcoded [].

Every applications screen in /office rendered zero rows, and had since the tRPC→SDK migration.

What's in here

Nothing lies to the user any more (#524, #525)

  • EEO report — presented fabricated adverse-impact ratios as a compliance record, plus a green "Compliance Status: Active" banner with nothing behind it. Now carries a persistent sample-data notice, the false claim is gone, and Export is disabled.
  • Interview scheduling — the placeholder lists were the smaller half. "Propose Time" opened a full form whose submit only called setShowAddSlotModal(false), so a user could believe they had scheduled an interview with a candidate who would never hear about it. Every write action is disabled.
  • Both derive their summary tiles now. The EEO flag count was hardcoded 0; the scheduling tiles read 3/1/12 with the 12 invented outright.

The pipeline reads real data (#527, #528)

  • Extracted the employer access decision the message handlers already got right into lib/application-access.ts, and put both on it.
  • New GET /v1/employer/applications — org-scoped, candidate and job embedded, filtering by org/job/status/assignee/score/date.
  • GET /{id} and GET /{id}/activity now admit the hiring side; a recruiter previously could not see stage history at all.
  • useApplications() unstubbed; transform rewritten against the real schema.
  • Requires feat(applications): listForOrganization — the hiring-side pipeline sdk#13 (merged) — submodule pointer bumped to c7c9884.

Status vocabulary (#529)

core.applications.status is constrained to the DB vocabulary; the REST surface publishes a different one. Read translated, write did not — so PATCH {status:"pending"} wrote "pending" and violated the CHECK constraint. Three of the seven kanban stages were unreachable by name; the other four worked only because both vocabularies spell them identically.

Routing debt (#526)

Duplicate /office/ats ↔ /office/applications, a dead ATS.DETAIL route, a _layout.tsx whose every Stack.Screen named a route that had moved, three routes reachable only by typing the URL, and a "List" toggle leading to "coming soon".

Verification

Beyond typecheck and tests, the endpoint was exercised against a live local API served from this worktree — the running edge runtime serves a different worktree, so hitting it would have tested the wrong code:

  • org admin → 8 applications with candidate names and correctly mapped statuses
  • a candidate → 0, not everyone's pipeline
  • another org's id → 403; unknown org id → 403
  • status, pagination and score filters checked against real rows

That found a bug review would not have: min_score=0 returned none of the eight applications, because score_total is nullable and NULL >= 0 is NULL, not true. The board's slider defaults to 0, so the pipeline would have opened empty for a brand-new reason. Fixed and covered.

Access control was mutation-tested: removing the role filter turns the member-vs-admin test red, and cross-org denial is a separate control with its own test that survives that mutation.

One decision worth your eye

The access block I extracted accepted any org-scoped role_assignments row, with no role filter. That means "org admin" today because admin is the only org-scoped role with assignments — but member exists in core.roles, and the day someone assigns it, that check silently widens to the full candidate pipeline including screening answers.

I made the requirement explicit per call site: message handlers keep the permissive behaviour, pipeline endpoints pass PIPELINE_ROLES (admin only). If recruiters are meant to hold member, that is a one-line change at PIPELINE_ROLES — I took the conservative reading rather than guessing.

Not addressed

  • #541 — webhooks still emit DB status names while REST emits API names. Breaking for existing consumers, so it needs a deliberate call.
  • #542 — the scf-core office suite fails ~1 run in 3 on unchanged code. Found while verifying this work; pre-existing.
  • Formatting is split into its own commits (style(...)) where files had never satisfied biome check, so the behavioural diffs stay readable.

🤖 Generated with Claude Code

thinkclay and others added 10 commits August 4, 2026 02:53
Audits and reviews were producing markdown plan docs under docs/plans/,
which go stale in the repo and never get triaged off a board. Document
the issue-first shape instead: survey for dupes, one issue per
self-contained finding with file:line evidence, a rollup epic carrying
the narrative and dependency graph, and milestones for the version plan.

Design specs and architecture proposals stay as markdown — the rule is
about findings, not intent.

Reference example: the 2026-08-03 /office ATS audit, epic #539.

Co-Authored-By: Claude Opus 5 <[email protected]>
This file has never satisfied `biome check` — the MOCK_JOB_GROUPS entries
were written as long single-line object literals. Formatting it in its own
commit so the behavioural change that follows stays readable; the diff here
is 934 lines and none of it changes what renders.

Co-Authored-By: Claude Opus 5 <[email protected]>
…ce record

The EEO/OFCCP screen has no data hooks. MOCK_JOB_GROUPS, GENDER_SUMMARY and
VETERAN_SUMMARY are hardcoded, and the four-fifths-rule adverse-impact
analysis runs real math over those invented headcounts. Nothing on screen
said so. An EEO report is an artifact people file, so a screenshot of this
page would have circulated fabricated adverse-impact figures.

Behind a single USES_SAMPLE_DATA flag that #535 deletes when real data lands:

- Add a persistent, non-dismissible "Sample data — not a compliance record"
  notice above everything else. Not dismissible on purpose: the point is that
  it survives into a screenshot.
- Hide the green "Compliance Status: Active / Next filing deadline" banner.
  That was an affirmative claim about compliance posture with nothing behind
  it — worse than the invented numbers.
- Disable Export. Export is how fabricated figures stop being a screen and
  become a document someone might file.

Also derives the "Adverse Impact — flags detected" tile from the computed
ratios instead of hardcoding "0". It agreed with the ratios only by
coincidence, and would have kept reading 0 after real data arrived.

Tests assert the notice renders, the compliance claim is absent, and export
is disabled. Verified they fail when USES_SAMPLE_DATA is flipped off.

Refs #524
Same situation as EEOReportScreen: the file has never satisfied
`biome check` because the MOCK_* entries are long single-line literals.
Formatting in its own commit so the behavioural change that follows is
readable. Nothing here changes what renders.

Co-Authored-By: Claude Opus 5 <[email protected]>
The scheduling screen has no data hooks — MOCK_CONNECTIONS, MOCK_AVAILABILITY,
MOCK_SLOTS and MOCK_LINKS are rendered directly, though migration 146 created
core.interview_slots / interview_availability / interview_bookings and both an
API route and an SDK resource already exist.

The placeholder lists were the smaller half. The larger half is that every
action is inert: "Propose Time" opens a full form whose submit button only
calls setShowAddSlotModal(false). A user could fill it in, click through, and
believe they had scheduled an interview with a candidate who will never hear
about it. "Create Link", "Connect Google/Outlook", "Add Availability" and
"Copy" are all no-op onPress handlers too.

Behind a USES_SAMPLE_DATA flag that #540 deletes when the wiring lands:

- Add the sample-data notice, stating plainly that nothing is saved and no
  candidate is contacted.
- Disable every write action, so input is refused rather than silently
  discarded. Refusing is honest; accepting and dropping is not.
- Derive the Upcoming/Confirmed/Completed tiles from the slot list. They were
  hardcoded "3" / "1" / "12"; the first two matched the mock by coincidence
  and "12 completed" was invented outright.

Extracts SampleDataNotice into features/office/components now that a second
screen needs it, and moves EEOReportScreen onto it. Each caller keeps its own
USES_SAMPLE_DATA flag so deleting the flag is the last step of wiring that
screen to real data.

Tests assert the notice renders, every write action is disabled, and the tiles
are derived. Verified the first two fail when the flag is flipped off.

Refs #525
…ust read

core.applications.status is TEXT constrained by applications_status_check
(migration 112) to the DB vocabulary: new, screen, inquired, interview, offer,
hired, rejected, withdrawn. The REST surface publishes a different one, where
new is "pending" and screen is "reviewing".

The read path translated via STATUS_API_TO_DB. The write path spread the
validated body straight into .update(), so an API name reached the column:

  PATCH {status:"pending"}   -> writes "pending"   -> CHECK violation, 500
  PATCH {status:"reviewing"} -> writes "reviewing" -> CHECK violation, 500
  PATCH {status:"inquired"}  -> 400, missing from the update schema enum
  the other five                                   -> worked only because both
                                                      vocabularies spell them
                                                      identically

Three of the office kanban's seven stages were unreachable by name, and the
four that worked did so by luck. Confirmed against the local database:
UPDATE ... SET status='pending' and 'reviewing' both raise check_violation,
while 'new' and 'inquired' are accepted.

- Extract buildApplicationUpdatePayload() and translate status through
  STATUS_API_TO_DB before writing.
- Add `inquired` to applicationUpdateSchema. The SDK's Application union
  already declared it and the DB already accepted it; only the server schema
  disagreed, so the request never reached the handler.
- Add withApiStatus() and use it on every response. POST, PATCH and withdraw
  all returned raw DB names while applicationResponseSchema declares the API
  enum — responses violating their own published contract. Read handlers did
  this inline; folded them into the helper too.
- Type the kanban's STATUS_MAP against the SDK union so the call sites need no
  casts. The two casts had drifted: confirmChange omitted `inquired`, so the
  path handling critical hire/reject confirmations disagreed with the one that
  does not.

12 tests. The four covering buildApplicationUpdatePayload fail when it is
reverted to the old spread; the rest guard the vocabulary invariants.

Not addressed here: triggerWebhook still emits raw DB status names, so webhook
consumers see `new` where the REST API says `pending`. Changing that is a
breaking change for anyone already consuming them — filing separately.

`deno check` on this file reports 75 errors before and after this change; they
are all c.get() returning never, tracked in #477.

Refs #529
Every handler on /v1/applications is the candidate's view — it filters or gates
on `user_id === auth user`. A recruiter had no way to read the pipeline for
their own organisation's jobs, which is why the office kanban has rendered zero
rows since the tRPC→SDK migration.

- Extract the access decision the two message handlers already got right into
  lib/application-access.ts, and put both of them on it. Behaviour there is
  unchanged by construction: they pass no role allow-list, which reproduces
  "any org-scoped assignment" exactly.
- Add GET /v1/employer/applications: org-scoped list with candidate and job
  embedded, filtering by organization_id, job_id, status, assigned_to,
  min_score and a created_at range, with real pagination.
- Admit the hiring side to GET /{id} and GET /{id}/activity, which previously
  403'd anyone but the applicant. The activity log is where stage history
  lives, so a recruiter could not see it at all.

On the role allow-list. The extracted block accepted *any* role_assignments row
scoped to the org, with no role filter. Today that happens to mean "org admin",
because admin is the only org-scoped role with assignments — but `member`
exists in core.roles, and the day someone assigns it that check silently
widens. Reading a thread you are party to is a narrow grant; listing every
applicant's profile and screening answers is not. So the helper takes an
explicit allow-list per call site: the message handlers keep the permissive
behaviour, the pipeline endpoints pass PIPELINE_ROLES (admin only). If
recruiters are meant to hold `member`, widening is one line at PIPELINE_ROLES —
but that should be a decision rather than an inherited default.

Column names here are the real ones. There is no `applied_at`,
`application_score` or `auto_rejected` column on core.applications; scores are
`score_total` and the flat screening fields live inside the `screening_answers`
JSONB. The office transform assumes otherwise — reconciling it is #528.

Every PostgREST select was validated against the live local database rather
than by inspection, including the users!user_id and jobs!job_id embeds and the
roles!role_id join the allow-list depends on.

24 tests. Verified the allow-list check is load-bearing by removing it and
watching the member-vs-admin test go red; cross-org denial is a separate
control with its own test, and survives that mutation as it should.

`deno check` on applications.ts drops from 75 pre-existing errors to 69 — the
inline access blocks were themselves untyped c.get() sites (#477).

Refs #527
Bumps @scaffald/sdk to c7c9884 (Scaffald/sdk#13, listForOrganization) and puts
the office applications screen on it. The board has rendered zero rows since
the tRPC→SDK migration because useApplications() returned a hardcoded [] with
its filter argument discarded.

- useApplications() now queries GET /v1/employer/applications and passes its
  filters through. ApplicationsListItem is the SDK's EmployerApplication rather
  than a hand-maintained restatement; the local interface had drifted to
  declare applied_at and application_score, neither of which is a column, and
  nothing caught it because the hook it typed always returned [].
- Rewrite the transform against the real schema: score_total not
  application_score, created_at not applied_at, attachment_metadata not
  attachments, and screening_answers.* rather than flat columns. It was written
  against a v_applications_with_user_profiles view that exists in no migration.
- Status, job and score filters now go to the server. The status filter was
  *cast* from the kanban vocabulary to the API's — which satisfied the compiler
  while sending a value the API enum rejects. It is mapped now, via the same
  STATUS_MAP the write path uses.
- Drop the client-side score filter. With server pagination it would have been
  wrong rather than redundant, silently hiding matches beyond page one.

Also fixes a bug the end-to-end check caught: min_score=0 returned none of the
eight seeded applications. score_total is nullable and nothing populates it
yet, so `.gte("score_total", 0)` drops every row — NULL >= 0 is NULL, not true.
The board's slider defaults to 0, so opening the pipeline would have shown an
empty board for a different reason than before. Extracted as
shouldApplyScoreFilter() with tests.

Verified against a live local API served from this worktree, since the running
edge runtime serves a different one: an org admin gets 8 applications with
candidate names and correctly mapped statuses; a candidate gets 0 rather than
everyone's pipeline; requesting another org's id is 403, as is an unknown org
id. Status, pagination and score filters all checked against real rows.

Team assignment is left null rather than invented — it lives in
core.job_team_assignments, which the list endpoint does not join yet.
stageHistory/notes/messages stay empty for the same reason (#531).

Refs #527, #528
Six unrelated bits of routing debt found in the /office audit.

- /office/ats rendered the applications pipeline, making it a second URL for
  /office/applications — the same screen behind two drawer entries. ATS is a
  section, not a screen, so its index now redirects and the duplicate drawer
  entry is gone.
- /office/ats/metrics rendered the same screen on its default kanban view; its
  own comment said the user could "switch to Metrics tab". The screen now takes
  an initialView and the route passes 'metrics'.
- ROUTES.OFFICE.ATS.DETAIL declared /office/ats/:id, which no file backed.
  Removed; a real detail route is #537.
- office/_layout.tsx named jobs/, teams/, organizations/, universities/ and
  background-checks/ at the top level. Those moved under cms/ and ats/ some
  time ago, so every Stack.Screen entry was a silent no-op while the routes
  that do exist had none. Rewritten against the actual files, and checked in
  both directions: no name without a file, no file without a name.
- ID Verifications, Hiring Metrics and Self-Schedule existed as routes but
  appeared in no navigation, so they were reachable only by typing the URL.
  Added to the office CMS nav.
- Removed the "List" view toggle. It rendered "List view coming soon..." — a
  shipped nav control leading to a placeholder. #537 covers the real thing.

Refs #526
The "Lint REST API Code" job runs `deno fmt --check` and was already failing on
main: routes/inquiries.ts, routes/work-logs.ts, __tests__/contract/sdk-routes
and __tests__/routes/inquiries-by-application were all unformatted before this
branch. Two more were mine — routes/employer-applications.ts and the new
application-access test.

Formatting all six rather than only my own, since `deno fmt` is mechanical and
it takes the check from red to green instead of red-for-fewer-reasons.

No behavioural change; the 27 backend tests pass unchanged.
…ests)

Picks up Scaffald/sdk#14, which drops the non-null assertions the monorepo's
biome config rejects but the SDK package's own lint does not.

Deliberately NOT bumping to sdk main (e4a47e5). That tip includes sdk#12, which
drops the phantom prerequisites endpoints and breaks scf-core typecheck in 17
places — prerequisites-sdk-hooks.ts and PrerequisiteWidget.tsx still use the
removed types. The matching client changes live in #519, not here, so this
branch pins to the commit before that break.

Verified: scf-core typechecks clean at this pointer and fails at e4a47e5.
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