mirror of
https://github.com/hanzoai/chat.git
synced 2026-09-30 20:51:17 +00:00
Two independent defects met in one feature, and either one alone made `BAN_VIOLATIONS=true` a trap. The store. `keyvMongo` backed `ViolationTypes.BAN` and `CacheKeys.ENCODED_DOMAINS` and threw `Mongoose connection not ready` the moment either was touched — `MONGO_URI` is unset and every collection is served from SQLite. Both namespaces hold state that must outlive the process: forgetting a ban un-bans a banned user, forgetting an encoded domain orphans every action tool that used it, so `standardCache`'s process memory is not a substitute. `durableCache` adds SQLite as the fallback store instead — a two-column `keyv` table on the one `sharedDatabase()` connection the document store already holds, so there is no second writer racing for the WAL lock. Redis still wins when it is configured; nothing about that path changes. The middleware. Upstream #12324 fixed `checkBan`'s `!!(ipBan||userBan)` coercion and the four defects it hid. The fork took that commit's tests and lost its implementation, so `checkBan.js` still read `Number(true.expiresAt)` → `NaN`: expired bans were never cleaned up, the memo was written with no expiry at all, and an IP-keyed entry blocked whoever next inherited that address — permanently. The test suite did not merely fail, it crashed the runner on an unhandled rejection from the un-awaited `banCache.set`. Restored, on the hanzo imports. Also: `redisClients.ts` imported `KV` twice, once as a value and once as a type. tsc tolerates it (separate declaration spaces); babel rejects it outright, which took every jest suite whose graph reached `~/utils` down with it — together with the untransformed ESM in `@mistralai`. Both fixed, which is what lets `durableCache` be tested at all: 37 suites in `packages/api` went from never loading to running. Proof: 25/25 checkBan, 6/6 keyv store (incl. durableCache resolving to the file and surviving a reopen). End-to-end against the built bundles with mongoose at readyState 0 — write via banLogs, reopen, read back, three rows in `keyv`, namespaces disjoint. Co-authored-by: Hanzo Dev <[email protected]>
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
export default {
|
|
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!<rootDir>/node_modules/'],
|
|
coveragePathIgnorePatterns: ['/node_modules/', '/dist/'],
|
|
testPathIgnorePatterns: [
|
|
'/node_modules/',
|
|
'/dist/',
|
|
'\\.dev\\.ts$',
|
|
'\\.helper\\.ts$',
|
|
'\\.helper\\.d\\.ts$',
|
|
],
|
|
coverageReporters: ['text', 'cobertura'],
|
|
testResultsProcessor: 'jest-junit',
|
|
transform: {
|
|
'\\.[jt]sx?$': [
|
|
'babel-jest',
|
|
{
|
|
presets: [
|
|
['@babel/preset-env', { targets: { node: 'current' } }],
|
|
'@babel/preset-typescript',
|
|
],
|
|
},
|
|
],
|
|
},
|
|
// `@hanzochat/agents` reaches `@langchain/mistralai` -> `@mistralai/mistralai`,
|
|
// which ships ESM only. Untransformed, `export *` is a SyntaxError and every
|
|
// suite whose import graph touches `~/utils` (the cache config among them)
|
|
// fails to LOAD — reported as zero tests, not as a failure. Transform them.
|
|
transformIgnorePatterns: ['/node_modules/(?!(@mistralai|@langchain)/)'],
|
|
moduleNameMapper: {
|
|
'^@src/(.*)$': '<rootDir>/src/$1',
|
|
'~/(.*)': '<rootDir>/src/$1',
|
|
},
|
|
// coverageThreshold: {
|
|
// global: {
|
|
// statements: 58,
|
|
// branches: 49,
|
|
// functions: 50,
|
|
// lines: 57,
|
|
// },
|
|
// },
|
|
restoreMocks: true,
|
|
testTimeout: 15000,
|
|
};
|