hazo_testing 0.1.0 → 0.1.1

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.
package/CHANGE_LOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # hazo_testing changelog
2
2
 
3
+ ## 0.1.1 — 2026-05-31
4
+
5
+ ### Changed — consume hazo_llm_api 2.1.0 public API (FR-001 + FR-002 resolved)
6
+
7
+ - **`wireHazoLlmApi` now uses the public `hazo_llm_api/server` API.** hazo_llm_api
8
+ 2.1.0 publicly exports the provider registry (`clear_registry`,
9
+ `register_provider`, `set_enabled_llms`, `set_primary_llm`, …) and provider
10
+ classes (`GeminiProvider`, `QwenProvider`) — so the wiring no longer resolves
11
+ internal `dist/` paths via `import.meta.resolve`. Removes the FR-001 fragility.
12
+ Peer dep bumped: `hazo_llm_api ^2.0.0` → `^2.1.0`.
13
+ - **Dropped the Jest `forceExit` workaround.** A new `jest.setup.cjs` sets
14
+ `HAZO_LLM_API_NO_AUTO_INIT=1` (FR-002, hazo_llm_api 2.1.0) so importing
15
+ `hazo_llm_api/server` no longer fires an orphaned import-time DB init that
16
+ "require()s after the jest environment is torn down". The suite now exits 0 on
17
+ its own. (A `prompt_library.sqlite` is still created by the explicit
18
+ `initialize_llm_api()` call inside the llm wiring test — still gitignored.)
19
+
3
20
  ## 0.1.0 — 2026-05-31
4
21
 
5
22
  ### Initial release
@@ -1,69 +1,23 @@
1
1
  // src/wiring/llm.ts
2
- // Purpose: wire the REAL hazo_llm_api service + provider registry.
2
+ // Purpose: wire the REAL hazo_llm_api service + provider registry against a test
3
+ // setup, using the PUBLIC hazo_llm_api/server API.
3
4
  //
4
- // Key adaptations vs. the plan (verified against hazo_llm_api v2.0.0 source):
5
- //
6
- // 1. clear_registry / register_provider / set_enabled_llms / set_primary_llm
7
- // are NOT exported from "hazo_llm_api/server". They live in the internal
8
- // registry module (src/lib/providers/registry.ts). We reach them via a
9
- // dynamic import of the compiled dist path, resolved from the server entry.
10
- //
11
- // 2. GeminiProvider / QwenProvider are NOT exported from "hazo_llm_api/server"
12
- // either. They are in dist/lib/providers/gemini/index.js and
13
- // dist/lib/providers/qwen/index.js respectively. Same resolution technique.
14
- //
15
- // 3. Provider constructors require { api_key, logger, ... }. We read the API key
16
- // from process.env at call time. With an empty api_key (no creds), the
17
- // constructor does NOT throw — validation only fails at actual API call time.
18
- // This lets test 1 (no creds) assert "run is a function" without credentials.
19
- //
20
- // 4. hazo_llm_text_text IS exported from "hazo_llm_api/server" with signature:
21
- // (params: TextTextParams, llm?: ProviderName) => Promise<LLMResponse>
22
- // TextTextParams: { prompt?: string, ... }
23
- // LLMResponse: { success: boolean, text?: string, error?: string, ... }
24
- //
25
- // 5. hazo_llm_text_text calls check_initialized() internally, which requires
26
- // initialize_llm_api() to have been called. We call it with a stub hazo_connect
27
- // (api_log disabled) to set initialized=true without touching SQLite.
28
- // After initialize_llm_api returns, we override the registry with our
29
- // manually-constructed providers.
30
- //
31
- // All imports are deferred to dynamic import() inside wireHazoLlmApi to avoid the
32
- // "require() of ES module being import()ed" CJS/ESM race under Jest ESM mode
33
- // (same technique used in Tasks 6 & 7).
34
- import { fileURLToPath } from "node:url";
35
- import { dirname } from "node:path";
5
+ // As of hazo_llm_api 2.1.0 (FR-001) the registry functions and provider classes
6
+ // are public exports of `hazo_llm_api/server`, so this no longer resolves
7
+ // internal dist paths via import.meta.resolve — it imports them directly. The
8
+ // import stays a deferred dynamic import() (canonical-import exemption per D-022)
9
+ // to avoid the CJS/ESM module-load race under Jest's --experimental-vm-modules
10
+ // runner. hazo_llm_api 2.1.0 also makes the import hermetic when
11
+ // HAZO_LLM_API_NO_AUTO_INIT=1 is set (see jest.setup.cjs) — no orphaned DB init.
36
12
  export async function wireHazoLlmApi(opts) {
37
- // Step 1: Import hazo_llm_api/server — deferred to avoid CJS/ESM jest race.
38
- const llmServer = await import("hazo_llm_api/server");
39
- const { initialize_llm_api, hazo_llm_text_text, default_logger } = llmServer;
40
- // Step 2: Resolve the dist root by stripping "server.js" from the resolved path.
41
- // import.meta.resolve gives us the file:// URL of the server entry point.
42
- const serverFileUrl = await import.meta.resolve("hazo_llm_api/server");
43
- // serverFileUrl → file:///…/hazo_llm_api/dist/server.js
44
- const distRoot = dirname(fileURLToPath(serverFileUrl));
45
- // distRoot → /…/hazo_llm_api/dist
46
- // Step 3: Import internal registry functions from the dist (not in exports map).
47
- const registryPath = `file://${distRoot}/lib/providers/registry.js`;
48
- const registry = await import(registryPath);
49
- const { clear_registry, register_provider, set_enabled_llms, set_primary_llm } = registry;
50
- // Step 4: Import provider classes from their internal dist paths.
51
- const geminiPath = `file://${distRoot}/lib/providers/gemini/index.js`;
52
- const qwenPath = `file://${distRoot}/lib/providers/qwen/index.js`;
53
- const { GeminiProvider } = await import(geminiPath);
54
- const { QwenProvider } = await import(qwenPath);
55
- // Step 5: Call initialize_llm_api with a no-op hazo_connect stub so
56
- // (a) initialized = true is set (required by check_initialized),
57
- // (b) SQLite is never touched,
58
- // (c) api_log table setup is skipped.
59
- // initialize_llm_api will also call load_and_register_providers internally —
60
- // that may or may not register providers depending on env/config. We override
61
- // the registry immediately afterwards.
13
+ const { initialize_llm_api, hazo_llm_text_text, default_logger, clear_registry, register_provider, set_enabled_llms, set_primary_llm, GeminiProvider, QwenProvider, } = await import("hazo_llm_api/server");
14
+ // Initialize with a no-op hazo_connect stub (api_log disabled) so
15
+ // check_initialized() passes without touching SQLite. We then override the
16
+ // registry with our manually-constructed providers.
62
17
  await initialize_llm_api({
63
18
  hazo_connect: {},
64
19
  api_log: { enabled: false },
65
20
  });
66
- // Step 6: Reset registry and wire it up for the requested providers.
67
21
  clear_registry();
68
22
  set_enabled_llms(opts.providers);
69
23
  set_primary_llm(opts.primary);
@@ -71,7 +25,7 @@ export async function wireHazoLlmApi(opts) {
71
25
  if (name === "gemini") {
72
26
  const api_key = process.env.GEMINI_API_KEY ?? "";
73
27
  // Constructor does NOT throw on empty api_key — error only surfaces at
74
- // call time, which lets test 1 (no creds) assert typeof run === "function".
28
+ // call time, which lets the no-creds test assert typeof run === "function".
75
29
  register_provider(new GeminiProvider({ api_key, logger: default_logger }));
76
30
  }
77
31
  if (name === "qwen") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hazo_testing",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Shared test infrastructure for hazo apps: SQLite test DB, real-package wiring, auth factories, apiTestClient, fixtures, Jest preset.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -27,7 +27,7 @@
27
27
  "hazo_auth": "^9.0.0",
28
28
  "hazo_jobs": "^0.12.0",
29
29
  "hazo_notify": "^6.1.0",
30
- "hazo_llm_api": "^2.0.0",
30
+ "hazo_llm_api": "^2.1.0",
31
31
  "react": "^18.0.0 || ^19.0.0",
32
32
  "react-dom": "^18.0.0 || ^19.0.0",
33
33
  "@playwright/test": "^1.0.0",