Skip to content

test(stack): use unique table name to avoid transient race condition#488

Merged
auxesis merged 1 commit into
mainfrom
test/avoid-shared-pg-table-race
May 25, 2026
Merged

test(stack): use unique table name to avoid transient race condition#488
auxesis merged 1 commit into
mainfrom
test/avoid-shared-pg-table-race

Conversation

@auxesis
Copy link
Copy Markdown
Contributor

@auxesis auxesis commented May 25, 2026

Summary

Both packages/protect/__tests__/searchable-json-pg.test.ts and packages/stack/__tests__/searchable-json-pg.test.ts ran beforeAll's CREATE TABLE IF NOT EXISTS "protect-ci-jsonb" (... GENERATED ALWAYS AS IDENTITY) against the same Postgres service container, and Turbo schedules the two packages' test tasks in parallel.

PostgreSQL's CREATE TABLE is not atomic w.r.t. its implicit IDENTITY sequence. Two racing sessions can both see "table doesn't exist", both proceed past the IF NOT EXISTS guard, and one fails on duplicate key value violates unique constraint "pg_class_relname_nsp_index" for protect-ci-jsonb_id_seq.

Seen on https://github.com/cipherstash/stack/actions/runs/26382743607/job/77655050703 — surfaced by the timing shift from the turbo/vitest bumps in #487.

The race has been latent since the stack test was ported (aa5a2d0, March 2026). Rename the stack-side table to protect-ci-jsonb-stack so the two suites own disjoint relations.

Test plan

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Enhanced test infrastructure with improved PostgreSQL test data management and isolation for encrypted data testing.

Review Change Stack

Both packages/protect/__tests__/searchable-json-pg.test.ts and
packages/stack/__tests__/searchable-json-pg.test.ts ran beforeAll
"CREATE TABLE IF NOT EXISTS protect-ci-jsonb (... IDENTITY)" against
the same Postgres service container, and Turbo schedules the two
package's test tasks in parallel. CREATE TABLE is not atomic w.r.t.
its implicit IDENTITY sequence, so a concurrent run could see "table
doesn't exist" but then fail on "sequence protect-ci-jsonb_id_seq
already exists". The bumped turbo+vitest in this group shifted timing
enough to surface the latent race.

Rename stack's table to "protect-ci-jsonb-stack" so the two suites
own disjoint relations.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@auxesis auxesis requested a review from a team as a code owner May 25, 2026 05:04
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 25, 2026

⚠️ No Changeset found

Latest commit: 713d259

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9bcff210-1e8e-494f-8d80-41649fd0d28d

📥 Commits

Reviewing files that changed from the base of the PR and between cc96153 and 713d259.

📒 Files selected for processing (1)
  • packages/stack/__tests__/searchable-json-pg.test.ts

📝 Walkthrough

Walkthrough

This PR updates the PostgreSQL test suite for encrypted JSON searchability to target a new table protect-ci-jsonb-stack instead of protect-ci-jsonb. The encrypted table binding, test helpers, setup/teardown hooks, and 30+ test queries are updated consistently to use the new table name across all query types.

Changes

PostgreSQL encrypted test table migration

Layer / File(s) Summary
Test infrastructure setup
packages/stack/__tests__/searchable-json-pg.test.ts
Encrypted table binding, insert helper function, and beforeAll/afterAll hooks are updated to create the new protect-ci-jsonb-stack table and manage its lifecycle for the test run.
Basic round-trip and path selector tests
packages/stack/__tests__/searchable-json-pg.test.ts
Round-trip encrypt/decrypt tests and all fundamental jsonb_path_query selector tests updated to query from the new table, covering simple path matching, nested paths, deep nesting, and non-matching cases.
Advanced scenarios: mixed queries, LockContext, concurrent execution
packages/stack/__tests__/searchable-json-pg.test.ts
Mixed selector+containment operations, escaped composite literals, LockContext integration, parallel concurrent queries, eql return-type tests, and concurrent encrypt+decrypt stress tests updated to query the new table.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • freshtonic

Poem

🐰 A thousand queries, one new home,
protect-ci-jsonb-stack awaits the roam,
From setUp to tearDown, each test now knows,
The encrypted path where the JSON flows.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: updating the test to use a unique table name ('protect-ci-jsonb-stack' instead of 'protect-ci-jsonb') to avoid a transient race condition caused by parallel test execution.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/avoid-shared-pg-table-race

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@auxesis auxesis changed the title test(stack): use unique pg table name to avoid race with protect's suite test(stack): use unique table name to avoid transient race condition May 25, 2026
@auxesis auxesis merged commit ff43a3e into main May 25, 2026
6 checks passed
@auxesis auxesis deleted the test/avoid-shared-pg-table-race branch May 25, 2026 05:38
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