Skip to content

fix(api): repair profiles fixture and the public-profile reads it masked - #479

Merged
thinkclay merged 1 commit into
mainfrom
claude/blissful-kalam-9bd0b0
Jul 30, 2026
Merged

thinkclay merged 1 commit into
mainfrom
claude/blissful-kalam-9bd0b0

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Fixes #464.

The reported bug

Confirmed before changing anything — createTestUserProfile inserts a core.users row the core.handle_new_user trigger has already created:

INSERT ERROR: {"code":"23505","details":"Key (id)=(be93...) already exists.",
               "message":"duplicate key value violates unique constraint \"users_pkey\""}

Unchecked, so every seeded value was discarded and the tests asserted against the trigger's defaults.

The issue undercounts it by one: the core.profile insert fails identically (profile_pkey), so location was never seeded either. Both writes are now error-checked upserts.

The helper also drops a leftover fixed-email auth user and retries once. [email protected] survives any run that dies before cleanupCurrentTestData, and then breaks every later run at user creation — this happened twice during verification, once from a concurrent run in another worktree.

The reported fix was not sufficient

Repairing the fixture moved test 1's failure from display_name to location and left tests 2 and 3 failing. Three further defects, all in the route rather than the fixture:

Defect Effect on every request
skills select("skill:skills(name)") — no user_skills → skills FK exists (PGRST200), and core.skills has no non-test references anywhere in the repo skills: []
certifications embed targeted core.certifications, but certification_id references data.certifications — which carries no issuer column at all certifications: []
location core.profile, core.user_skills and core.user_certifications were read with the caller's client; anon holds no grant on any of them location: null

So GET /v1/profiles/:username was returning empty skills, empty certifications and a null location to every anonymous viewer. Verified on a local database — prod grants are worth confirming separately, I did not check them.

Changes

  • User-owned rows are read with a service client, projecting only the fields ProfileSchema already declares public. Catalogs stay on the caller's client: they already grant SELECT to anon, and core.soft_skills grants nothing to service_role.
  • Skills resolve against whichever taxonomy each row names (data.masterformat / onet.occupation_data / core.soft_skills), batched one query per catalog.
  • Certification name/issuer come from the freeform columns, falling back to the catalog title when a row only carries certification_id.
  • The skills and certifications fixtures no longer write catalog rows, so consecutive runs stop poisoning each other.

Verification

6 passed | 0 failed    # the :username group, run with leftover johndoe deliberately in place
17 passed | 10 failed  # full file — was 14/13 on main

The 10 are the core.organizations / core.employers schema-cache failures the issue scopes out. All 11 slug tests, which share the helper, still pass. deno fmt and deno lint clean.

pnpm prepush did not run: this worktree has no node_modules, so nx affected -t build/test could not execute. The change is Deno-only edge-function code that nx does not build; the suite load-probe, lint, fmt and the full touched suite all pass. Flagging it rather than papering over it.

🤖 Generated with Claude Code

…ked (#464)

createTestUserProfile inserted core.users and core.profile rows that the
core.handle_new_user trigger had already created. Both inserts failed with
duplicate-key errors that were never checked, so every seeded value was
silently discarded and the trigger's defaults were asserted against instead.

Both writes are now error-checked upserts. The helper also drops a leftover
fixed-email auth user and retries once: [email protected] survives any run
that dies before cleanupCurrentTestData, and then breaks every later run.

Fixing the fixture exposed three real defects in GET /v1/profiles/:username,
which had been returning empty skills, empty certifications and a null
location to every anonymous caller:

- The skills embed selected skill:skills(name), but no user_skills -> skills
  FK exists and core.skills has no non-test references. core.user_skills is a
  taxonomy table, so names are now resolved against data.masterformat,
  onet.occupation_data or core.soft_skills per row.
- The certifications embed targeted core.certifications while
  certification_id references data.certifications, which carries no issuer
  column. name/issuer now come from the freeform columns, falling back to the
  catalog title.
- location, user_skills and user_certifications were read with the caller's
  client, but anon holds no grant on any of them. They are now read with the
  service client, projecting only the fields ProfileSchema declares public.

The catalogs stay on the caller's client: they already grant SELECT to anon,
and core.soft_skills grants nothing to service_role.

The skills and certifications fixtures no longer write catalog rows, so
consecutive runs no longer poison each other.

Fixes #464

Co-Authored-By: Claude Opus 5 <[email protected]>
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.

profiles.test.ts fixture silently discards seeded values, failing 3 tests on main

1 participant