Repository navigation
fix(test): preserve @stellar/stellar-sdk Networks in vitest mocks #146 - #158
therealbibson wants to merge 7 commits into
Conversation
|
@therealbibson Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Flagging rather than closing, since it is yours — but I do not think this should merge, and the reason is worth having in writing. The problem it fixes does not exist. The helper's premise is that "spreading an ESM module namespace (
And issue #146 is already fixed on main, by commits Your PR is green and merges clean — it is harmless, just solving something already solved. It also adds no new test, so it does not meet the fail-before/pass-after rule with no docs or CI exemption to fall back on. I am closing #146 as already-resolved, citing those commits. That issue should not have been sitting open sending people at a fixed bug — that is on us, not you. If you want something real in the same area, #151 is genuinely broken — I reproduced it three times. The root cause nobody has addressed is |
Miracle656
left a comment
There was a problem hiding this comment.
Thank you for the careful write-up on this one — and I'm sorry to be the bearer of awkward news: #146 no longer reproduces, and I measured this branch rather than assuming. Here is what I found, because I think the detail matters more than the verdict.
The stated root cause isn't what's happening. src/__tests__/helpers/stellarSdkMock.ts:3-5 says spreading the namespace "drops non-enumerable named exports such as Networks". I probed that directly against the installed @stellar/stellar-sdk in a scratch vitest file on current origin/main:
spreadCount=74 ownCount=75
onlyOwn=["__esModule"] onlySpread=[] hasNetworksInSpread=true
Object.keys({...ns}) and Object.getOwnPropertyNames(ns) differ by exactly one key, __esModule. Networks is enumerable and survives a plain spread — a mock built with nothing but {...await importOriginal()} resolves Networks.TESTNET to 'Test SDF Network ; September 2015'. So mockStellarSdk is functionally identical to the spread it replaces, except that the mock object now also carries __esModule.
What actually fixed #146 was 7e2716a ("feat(api): add network selector on routes"), which added the explicit Networks fallback to src/__tests__/bestRoute.test.ts and tests/aggregator.property.test.ts when getBestRoute started resolving a per-network Horizon client. The issue is closed and origin/main is green: 538 passed, 1 skipped across 56 files, tsc --noEmit clean.
I verified the branch itself is sound, not broken. I merged it onto current main (one conflict in tests/aggregator.property.test.ts, comment text only) and ran the five touched suites: 39 passed (5 files). So this is a no-op refactor, not a regression — the code works, it just isn't buying anything.
Why I'm not merging it as-is: the net effect would be a new shared test helper whose doc comment records an incorrect explanation of a bug that is already fixed. That comment is the part that worries me — it will be read as authoritative by the next person who hits a mock problem here, and it will send them down the wrong path. Removing the explicit Networks: {...} blocks is also a small net loss of a safety net, since those lines document why getNetworkConfig() needs a passphrase in these two suites.
If you want to keep this alive, the version I would merge is much smaller: drop helpers/stellarSdkMock.ts and the four call-site rewrites, keep only the comment refresh in tests/aggregator.property.test.ts that stops describing the timeout as a consequence of the (now fixed) Networks problem. If you'd rather not, say so and I'll mark it superseded with full credit — the diagnosis work was real even though main moved under it.
One thing genuinely worth your time if you're looking for a real flake in this area: src/__tests__/pairIssuerMatch.test.ts:18 uses beforeAll for a vi.resetModules() + await import('../config'). I caught that hook failing on a full local run of main. #161 raised testTimeout to 20s but not hookTimeout, which is still the 10s default — so a cold import inside a hook has no headroom. That's an actual open problem.
…-vitest-mock Resolves the merge conflicts with main.
|
@Miracle656 I've resolved the merge conflicts with All other changes from Merge commit: Could you take another look when you have a moment? Thanks! |
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| 37768935 | Triggered | Generic High Entropy Secret | 837bc0e | src/tests/toid.test.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
|
@Miracle656 Understood — and thanks for measuring it rather than just closing it. I re-checked the helper's premise against current So there's nothing here that should merge, and I won't push anything further to it — marking it superseded with the credit is fine by me. Thanks also for pointing at the |
Overview
This PR fixes the broken
@stellar/stellar-sdkvitest mocks that omitted theNetworksexport (ESM module-namespace spread drops non-enumerable bindings). That failure made Typecheck & build look permanently red on every PR — including markdown-only ones — training reviewers to ignore the check.Related Issue
Closes #146
Changes
🧩 Durable stellar-sdk mock helper
[ADD]
src/__tests__/helpers/stellarSdkMock.tsimportOriginal()before applying overrides, so exports likeNetworkssurvive vitest's mock interop.[MODIFY]
src/__tests__/bestRoute.test.tsNetworks: { PUBLIC, TESTNET }withmockStellarSdk(...).[MODIFY]
tests/aggregator.property.test.ts[MODIFY]
src/__tests__/networkClients.test.ts,src/__tests__/sdexIngester.test.ts,src/__tests__/facilitatorSettle.test.ts@stellar/stellar-sdkpartial mocks through the same helper so future SDK upgrades do not re-break CI.Verification Results
npm testhas no@stellar/stellar-sdkmock errorsNetworksexportmockStellarSdkhelper