test: migrate AVA→Vitest with event-based waits (stacked on #131)#132
Draft
zeevmoney wants to merge 6 commits into
Draft
test: migrate AVA→Vitest with event-based waits (stacked on #131)#132zeevmoney wants to merge 6 commits into
zeevmoney wants to merge 6 commits into
Conversation
Replace AVA 3 with Vitest 4.1 (vitest.config.ts with unit / module-imports
/ integration / e2e projects; backend projects run serially via forks +
maxWorkers=1 to avoid shared-env collisions). Keep test:ci:unit /
test:ci:full names so the CI workflow is unchanged.
Remove every timer-based propagation wait: a new waitFor/waitForCheck
helper polls the actual permit.check() until it converges, bounded by a
timeout, replacing the fixed sleep(10s) waits in the e2e suites.
Rewrite fixtures to a createTestClient() factory (handleApiError now
throws). Migrate all t.* assertions to expect. Module-import specs load
the built bundle (build/index.{js,mjs}) to keep packaging-regression
coverage. Wire in the two previously orphaned specs (bulk, lists) with
proper setup/cleanup; preserve bulkRelationshipTuples coverage. Keep the
inherently racy local_facts "skip wait" case as it.skip and add a
deterministic waitForSync header unit test. Drop ava/nyc/codecov/ts-node;
add vitest/@vitest/coverage-v8; bump @types/node to ^20; skipLibCheck for
Vitest's d.ts.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
3 tasks
…test-event-based-tests * per-15306/ci-pin-actions-tests-on-pr: ci: run unit/integration/module-imports on PR, defer e2e to next PR # Conflicts: # package.json
…test-event-based-tests * per-15306/ci-pin-actions-tests-on-pr: ci: run on all pull requests, not only those targeting main
…test-event-based-tests * per-15306/ci-pin-actions-tests-on-pr: ci: pin PDP connection to IPv4 (127.0.0.1) in the backend test run
The dockerized PDP in CI doesn't expose OPA (port 8181), so rbac's direct useOpa checks hit ECONNREFUSED. Gate them behind PERMIT_RUN_OPA_E2E (default off) so they only run against an OPA-exposed setup. Raise the rebac convergence gate to 150s and the e2e test timeout to 300s, since the heavy ReBAC graph needs longer to propagate cloud->PDP on a cold env. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bulkCheck and getUserPermissions query separate PDP endpoints that can lag a single permit.check, so the direct assertions raced cloud->PDP propagation and flaked on the slower matrix leg. Gate the complete-user read and poll bulkCheck/getUserPermissions until they converge before asserting. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Test infrastructure modernization. PR#2 of a 3-PR stack — stacked on ci: pin actions to SHA and run full test suite on PRs #131 (base branch
per-15306/ci-pin-actions-tests-on-pr, notmain). No shipped SDK source changes. Linear: PER-15315.What is the current behavior?
build/**then run from the built JS.sleep(10s)/setTimeout, which is slow and flaky once they run in CI.bulk_test.spec.ts,e2e/lists.e2e.spec.ts) are orphaned — run by no script.What is the new behavior?
vitest.config.tswith four projects:unit(parallel),module-imports,integration(serial),e2e(serial). Backend projects run single-fork /maxWorkers:1and as separatevitestinvocations so they never collide on the shared env.test:ci:unit/test:ci:fullscript names are unchanged, so PR#1'sci.yamlneeds no edit.waitFor/waitForCheckhelper polls the actualpermit.check()until it converges (bounded timeout) — replacing everysleep. The rebac gate now waits until all step assertions converge (positives true and negatives false);listswaits until the bulk-created users are listable before asserting counts.fixtures.tsis now acreateTestClient()factory;handleApiErrorthrows (fail-fast);try/catch(t.fail)/finally→try/finally; allt.*→expect. Every e2e spec now fully and tolerantly cleans up what it creates inafterAll, so the serial suite is order-independent.bulk_test.spec.ts→e2e/bulk.e2e.spec.ts(self-contained schema + full cleanup; preserves the onlybulkRelationshipTuplescoverage).lists.e2e.spec.tsis prefix-scoped + cleaned up (no more absolute-count coupling).build/index.{js,mjs}) to keep packaging/entry-point regression coverage; those scripts retain abuildprerequisite.ava,@ava/typescript,nyc,@istanbuljs/nyc-config-typescript,codecov,ts-node,open-cli; addvitest@^4.1,@vitest/coverage-v8@^4.1;@types/node@^20;skipLibCheckfor Vitest's d.ts.Other information:
How it was tested
yarn test:ci:unit(the no-backend gate: unit + module-imports) — 60 tests pass.yarn build+tscclean,yarn lintclean.test:ci:fullpath in CI (this PR's CI run validates them end-to-end). They could not be run on a live backend locally.unit/wait-for-sync.spec.tspins thewaitForSyncheader contract (X-Wait-Timeout/X-Timeout-Policy, PDP basePath, no-op withoutproxyFactsViaPdp) with no network.Notable decisions
local_facts"Check skip wait" asserted a result before propagation — inherently racy. It's nowit.skipwith an explanatory comment, and its contract is covered deterministically by the new unit test.@vitest/coverage-v8is available viayarn coverage, scoped to the unit-covered modules.Known limitation
listssearch-match semantics), expect a small follow-up commit.Deferred to PR#3 (coverage expansion)
waitForSyncedge branches.Generated with Claude Code