@jamesaphoenix/tx-test-utils 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +480 -0
  2. package/dist/adapters/better-sqlite3-adapter.d.ts +36 -0
  3. package/dist/adapters/better-sqlite3-adapter.d.ts.map +1 -0
  4. package/dist/adapters/better-sqlite3-adapter.js +78 -0
  5. package/dist/adapters/better-sqlite3-adapter.js.map +1 -0
  6. package/dist/chaos/chaos-utilities.d.ts +465 -0
  7. package/dist/chaos/chaos-utilities.d.ts.map +1 -0
  8. package/dist/chaos/chaos-utilities.js +791 -0
  9. package/dist/chaos/chaos-utilities.js.map +1 -0
  10. package/dist/chaos/chaos.test.d.ts +9 -0
  11. package/dist/chaos/chaos.test.d.ts.map +1 -0
  12. package/dist/chaos/chaos.test.js +498 -0
  13. package/dist/chaos/chaos.test.js.map +1 -0
  14. package/dist/chaos/index.d.ts +20 -0
  15. package/dist/chaos/index.d.ts.map +1 -0
  16. package/dist/chaos/index.js +39 -0
  17. package/dist/chaos/index.js.map +1 -0
  18. package/dist/database/index.d.ts +1 -1
  19. package/dist/database/index.d.ts.map +1 -1
  20. package/dist/database/index.js +1 -1
  21. package/dist/database/index.js.map +1 -1
  22. package/dist/database/test-database.d.ts +25 -5
  23. package/dist/database/test-database.d.ts.map +1 -1
  24. package/dist/database/test-database.js +62 -5
  25. package/dist/database/test-database.js.map +1 -1
  26. package/dist/factories/learning.factory.js +1 -1
  27. package/dist/factories/learning.factory.js.map +1 -1
  28. package/dist/helpers/index.d.ts +2 -0
  29. package/dist/helpers/index.d.ts.map +1 -1
  30. package/dist/helpers/index.js +4 -0
  31. package/dist/helpers/index.js.map +1 -1
  32. package/dist/helpers/shared-test-layer.d.ts +69 -0
  33. package/dist/helpers/shared-test-layer.d.ts.map +1 -0
  34. package/dist/helpers/shared-test-layer.js +107 -0
  35. package/dist/helpers/shared-test-layer.js.map +1 -0
  36. package/dist/helpers/sqlite-factory.d.ts +24 -0
  37. package/dist/helpers/sqlite-factory.d.ts.map +1 -0
  38. package/dist/helpers/sqlite-factory.js +36 -0
  39. package/dist/helpers/sqlite-factory.js.map +1 -0
  40. package/dist/index.d.ts +5 -1
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +29 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/singleton.d.ts +49 -0
  45. package/dist/singleton.d.ts.map +1 -0
  46. package/dist/singleton.js +66 -0
  47. package/dist/singleton.js.map +1 -0
  48. package/package.json +20 -10
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@
18
18
  // Fixtures - SHA256-based deterministic IDs
19
19
  export { fixtureId, namespacedFixtureId, sequentialFixtureIds, contentFixtureId } from "./fixtures/index.js";
20
20
  // Database helpers
21
- export { createTestDatabase, TestDatabaseService, TestDatabaseLive, createTestDatabaseLayer } from "./database/index.js";
21
+ export { createTestDatabase, TestDatabaseService, TestDatabaseLive, createTestDatabaseLayer, wrapDbAsTestDatabase } from "./database/index.js";
22
22
  // Factories
23
23
  export {
24
24
  // Task
@@ -39,6 +39,12 @@ hashInput, cachedLLMCall, withLLMCache, configureLLMCache, getCacheConfig, reset
39
39
  getCacheStats, clearCache, formatCacheStats, getCacheEntry, listCacheEntries } from "./llm-cache/index.js";
40
40
  // Effect Helpers
41
41
  export { runEffect, runEffectFail, runEffectEither, expectEffectSuccess, expectEffectFailure, mergeLayers, createTestContext } from "./helpers/index.js";
42
+ // Shared Test Layer - memory-efficient integration testing
43
+ export { createSharedTestLayer } from "./helpers/index.js";
44
+ // SQLite database factory for tests
45
+ export { createSqliteDatabase, createMigratedSqliteDatabase } from "./helpers/index.js";
46
+ // Singleton Test Database - ONE DB for entire test suite
47
+ export { getSharedTestLayer, resetTestDb, closeTestDb, isTestDbInitialized } from "./singleton.js";
42
48
  // Temp Files (to be implemented)
43
49
  // export { createTempDir, writeTestTypeScriptFile, createTestSourceFiles } from './helpers/index.js'
44
50
  // export type { TempDir } from './helpers/index.js'
@@ -49,4 +55,26 @@ export { createMockAnthropic, createMockAnthropicForExtraction, createMockOpenAI
49
55
  // export { MockFileSystem } from './mocks/index.js'
50
56
  // Setup (to be implemented)
51
57
  // export { default as vitestSetup } from './setup/index.js'
58
+ // Chaos Engineering Utilities
59
+ export {
60
+ // Namespace export
61
+ chaos,
62
+ // Process failure simulation
63
+ crashAfter, CrashSimulationError,
64
+ // Worker heartbeat manipulation
65
+ killHeartbeat, WorkerHeartbeatController,
66
+ // Race condition testing
67
+ raceWorkers,
68
+ // State corruption
69
+ corruptState,
70
+ // JSONL replay
71
+ replayJSONL,
72
+ // Double completion testing
73
+ doubleComplete,
74
+ // Partial write simulation
75
+ partialWrite,
76
+ // Delayed claim testing
77
+ delayedClaim,
78
+ // Stress testing
79
+ stressLoad } from "./chaos/index.js";
52
80
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,4CAA4C;AAC5C,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAE5B,mBAAmB;AACnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACxB,MAAM,qBAAqB,CAAA;AAG5B,YAAY;AACZ,OAAO;AACL,OAAO;AACP,WAAW,EACX,cAAc,EACd,eAAe;AAEf,WAAW;AACX,eAAe,EACf,kBAAkB,EAClB,mBAAmB;AAEnB,OAAO;AACP,WAAW,EACX,cAAc,EACd,0BAA0B;AAE1B,SAAS;AACT,aAAa,EACb,gBAAgB;AAEhB,YAAY;AACZ,gBAAgB,EAChB,mBAAmB,EAKpB,MAAM,sBAAsB,CAAA;AAE7B,4CAA4C;AAC5C,OAAO;AACL,iBAAiB;AACjB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,gBAAgB;AAChB,gBAAgB;AAChB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAS7B,iBAAiB;AACjB,OAAO,EACL,SAAS,EACT,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EAGlB,MAAM,oBAAoB,CAAA;AAE3B,iCAAiC;AACjC,qGAAqG;AACrG,oDAAoD;AAEpD,QAAQ;AACR,OAAO,EACL,mBAAmB,EACnB,gCAAgC,EAMhC,gBAAgB,EAChB,6BAA6B,EAC7B,gCAAgC,EAMjC,MAAM,kBAAkB,CAAA;AACzB,gDAAgD;AAChD,wDAAwD;AACxD,oDAAoD;AAEpD,4BAA4B;AAC5B,4DAA4D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,4CAA4C;AAC5C,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAE5B,mBAAmB;AACnB,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,qBAAqB,CAAA;AAG5B,YAAY;AACZ,OAAO;AACL,OAAO;AACP,WAAW,EACX,cAAc,EACd,eAAe;AAEf,WAAW;AACX,eAAe,EACf,kBAAkB,EAClB,mBAAmB;AAEnB,OAAO;AACP,WAAW,EACX,cAAc,EACd,0BAA0B;AAE1B,SAAS;AACT,aAAa,EACb,gBAAgB;AAEhB,YAAY;AACZ,gBAAgB,EAChB,mBAAmB,EAKpB,MAAM,sBAAsB,CAAA;AAE7B,4CAA4C;AAC5C,OAAO;AACL,iBAAiB;AACjB,SAAS,EACT,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,gBAAgB;AAChB,gBAAgB;AAChB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAS7B,iBAAiB;AACjB,OAAO,EACL,SAAS,EACT,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,iBAAiB,EAGlB,MAAM,oBAAoB,CAAA;AAE3B,2DAA2D;AAC3D,OAAO,EACL,qBAAqB,EAGtB,MAAM,oBAAoB,CAAA;AAE3B,oCAAoC;AACpC,OAAO,EACL,oBAAoB,EACpB,4BAA4B,EAC7B,MAAM,oBAAoB,CAAA;AAE3B,yDAAyD;AACzD,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,mBAAmB,EACpB,MAAM,gBAAgB,CAAA;AAEvB,iCAAiC;AACjC,qGAAqG;AACrG,oDAAoD;AAEpD,QAAQ;AACR,OAAO,EACL,mBAAmB,EACnB,gCAAgC,EAMhC,gBAAgB,EAChB,6BAA6B,EAC7B,gCAAgC,EAMjC,MAAM,kBAAkB,CAAA;AACzB,gDAAgD;AAChD,wDAAwD;AACxD,oDAAoD;AAEpD,4BAA4B;AAC5B,4DAA4D;AAE5D,8BAA8B;AAC9B,OAAO;AACL,mBAAmB;AACnB,KAAK;AACL,6BAA6B;AAC7B,UAAU,EACV,oBAAoB;AAGpB,gCAAgC;AAChC,aAAa,EACb,yBAAyB;AAEzB,yBAAyB;AACzB,WAAW;AAGX,mBAAmB;AACnB,YAAY;AAGZ,eAAe;AACf,WAAW;AAIX,4BAA4B;AAC5B,cAAc;AAGd,2BAA2B;AAC3B,YAAY;AAGZ,wBAAwB;AACxB,YAAY;AAGZ,iBAAiB;AACjB,UAAU,EAGX,MAAM,kBAAkB,CAAA"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Singleton test database for maximum memory efficiency.
3
+ *
4
+ * Instead of creating a new database per test or per describe block,
5
+ * this module provides a single shared database instance for the entire test suite.
6
+ *
7
+ * Usage:
8
+ * - Tests call `getSharedTestLayer()` to get the singleton
9
+ * - Global `afterEach` in vitest.setup.ts calls `resetTestDb()` for isolation
10
+ * - Global `afterAll` calls `closeTestDb()` for cleanup
11
+ *
12
+ * @module @tx/test-utils/singleton
13
+ */
14
+ import { type SharedTestLayerResult } from "./helpers/shared-test-layer.js";
15
+ /**
16
+ * Get the singleton test database layer.
17
+ * Creates it on first call, returns cached instance thereafter.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { getSharedTestLayer } from '@jamesaphoenix/tx-test-utils'
22
+ *
23
+ * it("test", async () => {
24
+ * const { layer } = await getSharedTestLayer()
25
+ * const result = await Effect.runPromise(
26
+ * myEffect.pipe(Effect.provide(layer))
27
+ * )
28
+ * })
29
+ * ```
30
+ */
31
+ export declare const getSharedTestLayer: () => Promise<SharedTestLayerResult>;
32
+ /**
33
+ * Reset all tables in the singleton DB.
34
+ * Call in afterEach to ensure test isolation.
35
+ * Safe to call even if DB hasn't been initialized.
36
+ */
37
+ export declare const resetTestDb: () => Promise<void>;
38
+ /**
39
+ * Close the singleton DB connection.
40
+ * Call in global teardown or afterAll.
41
+ * Resets the singleton so a new one can be created if needed.
42
+ */
43
+ export declare const closeTestDb: () => Promise<void>;
44
+ /**
45
+ * Check if the singleton has been initialized.
46
+ * Useful for debugging and conditional logic.
47
+ */
48
+ export declare const isTestDbInitialized: () => boolean;
49
+ //# sourceMappingURL=singleton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAyB,KAAK,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AAIlG;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,QAAa,OAAO,CAAC,qBAAqB,CAKxE,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CAIhD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAAa,OAAO,CAAC,IAAI,CAKhD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,QAAO,OAEtC,CAAA"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Singleton test database for maximum memory efficiency.
3
+ *
4
+ * Instead of creating a new database per test or per describe block,
5
+ * this module provides a single shared database instance for the entire test suite.
6
+ *
7
+ * Usage:
8
+ * - Tests call `getSharedTestLayer()` to get the singleton
9
+ * - Global `afterEach` in vitest.setup.ts calls `resetTestDb()` for isolation
10
+ * - Global `afterAll` calls `closeTestDb()` for cleanup
11
+ *
12
+ * @module @tx/test-utils/singleton
13
+ */
14
+ import { createSharedTestLayer } from "./helpers/shared-test-layer.js";
15
+ let instance = null;
16
+ /**
17
+ * Get the singleton test database layer.
18
+ * Creates it on first call, returns cached instance thereafter.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { getSharedTestLayer } from '@jamesaphoenix/tx-test-utils'
23
+ *
24
+ * it("test", async () => {
25
+ * const { layer } = await getSharedTestLayer()
26
+ * const result = await Effect.runPromise(
27
+ * myEffect.pipe(Effect.provide(layer))
28
+ * )
29
+ * })
30
+ * ```
31
+ */
32
+ export const getSharedTestLayer = async () => {
33
+ if (!instance) {
34
+ instance = await createSharedTestLayer();
35
+ }
36
+ return instance;
37
+ };
38
+ /**
39
+ * Reset all tables in the singleton DB.
40
+ * Call in afterEach to ensure test isolation.
41
+ * Safe to call even if DB hasn't been initialized.
42
+ */
43
+ export const resetTestDb = async () => {
44
+ if (instance) {
45
+ await instance.reset();
46
+ }
47
+ };
48
+ /**
49
+ * Close the singleton DB connection.
50
+ * Call in global teardown or afterAll.
51
+ * Resets the singleton so a new one can be created if needed.
52
+ */
53
+ export const closeTestDb = async () => {
54
+ if (instance) {
55
+ await instance.close();
56
+ instance = null;
57
+ }
58
+ };
59
+ /**
60
+ * Check if the singleton has been initialized.
61
+ * Useful for debugging and conditional logic.
62
+ */
63
+ export const isTestDbInitialized = () => {
64
+ return instance !== null;
65
+ };
66
+ //# sourceMappingURL=singleton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singleton.js","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,qBAAqB,EAA8B,MAAM,gCAAgC,CAAA;AAElG,IAAI,QAAQ,GAAiC,IAAI,CAAA;AAEjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,IAAoC,EAAE;IAC3E,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,MAAM,qBAAqB,EAAE,CAAA;IAC1C,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,IAAmB,EAAE;IACnD,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAA;IACxB,CAAC;AACH,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,IAAmB,EAAE;IACnD,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAA;QACtB,QAAQ,GAAG,IAAI,CAAA;IACjB,CAAC;AACH,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAY,EAAE;IAC/C,OAAO,QAAQ,KAAK,IAAI,CAAA;AAC1B,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,52 +1,66 @@
1
1
  {
2
2
  "name": "@jamesaphoenix/tx-test-utils",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "Test utilities, factories, fixtures, and helpers for tx monorepo",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
+ "bun": "./src/index.ts",
10
11
  "types": "./dist/index.d.ts",
11
12
  "import": "./dist/index.js"
12
13
  },
13
14
  "./database": {
15
+ "bun": "./src/database/index.ts",
14
16
  "types": "./dist/database/index.d.ts",
15
17
  "import": "./dist/database/index.js"
16
18
  },
17
19
  "./factories": {
20
+ "bun": "./src/factories/index.ts",
18
21
  "types": "./dist/factories/index.d.ts",
19
22
  "import": "./dist/factories/index.js"
20
23
  },
21
24
  "./fixtures": {
25
+ "bun": "./src/fixtures/index.ts",
22
26
  "types": "./dist/fixtures/index.d.ts",
23
27
  "import": "./dist/fixtures/index.js"
24
28
  },
25
29
  "./llm-cache": {
30
+ "bun": "./src/llm-cache/index.ts",
26
31
  "types": "./dist/llm-cache/index.d.ts",
27
32
  "import": "./dist/llm-cache/index.js"
28
33
  },
29
34
  "./mocks": {
35
+ "bun": "./src/mocks/index.ts",
30
36
  "types": "./dist/mocks/index.d.ts",
31
37
  "import": "./dist/mocks/index.js"
32
38
  },
33
39
  "./helpers": {
40
+ "bun": "./src/helpers/index.ts",
34
41
  "types": "./dist/helpers/index.d.ts",
35
42
  "import": "./dist/helpers/index.js"
36
43
  },
37
44
  "./setup": {
45
+ "bun": "./src/setup/index.ts",
38
46
  "types": "./dist/setup/index.d.ts",
39
47
  "import": "./dist/setup/index.js"
48
+ },
49
+ "./chaos": {
50
+ "bun": "./src/chaos/index.ts",
51
+ "types": "./dist/chaos/index.d.ts",
52
+ "import": "./dist/chaos/index.js"
40
53
  }
41
54
  },
42
55
  "files": [
43
- "dist"
56
+ "dist",
57
+ "README.md"
44
58
  ],
45
59
  "scripts": {
46
60
  "build": "tsc -b",
47
61
  "typecheck": "tsc --noEmit",
48
62
  "lint": "eslint src/",
49
- "test": "vitest run --passWithNoTests"
63
+ "test": "bunx --bun vitest run"
50
64
  },
51
65
  "dependencies": {
52
66
  "@jamesaphoenix/tx-core": "*",
@@ -54,21 +68,17 @@
54
68
  "effect": "^3.19.15"
55
69
  },
56
70
  "peerDependencies": {
57
- "better-sqlite3": "^11.0.0",
58
- "vitest": "^3.0.0"
71
+ "vitest": "^4.0.18"
59
72
  },
60
73
  "peerDependenciesMeta": {
61
- "better-sqlite3": {
62
- "optional": false
63
- },
64
74
  "vitest": {
65
75
  "optional": false
66
76
  }
67
77
  },
68
78
  "devDependencies": {
69
- "@types/better-sqlite3": "^7.6.0",
79
+ "@types/bun": "^1.2.0",
70
80
  "typescript": "^5.7.0",
71
- "vitest": "^3.0.0"
81
+ "vitest": "^4.0.18"
72
82
  },
73
83
  "repository": {
74
84
  "type": "git",