chore: consolidate test files into __tests__/ dirs and clean stray engine artifacts

- Move all co-located *.test.* files into sibling __tests__/ directories so the
  layout is consistent across packages (159 renames + content-rewrite moves).
  Updates relative imports, vi.mock specifiers, and __dirname/import.meta.url
  path resolutions where tests read fixtures from disk.
- Drop tracked tsc-emit alongside engine .ts sources (auth-storage/logger/
  skill-resolver/context-limit-detector/pi.{js,d.ts,*.map}). These were
  accidentally committed in a merge and the stale pi.js was masking a real
  test-mock vs source mismatch (tests imported "../pi.js" and vite preferred
  the stale build over pi.ts).
- Add packages/engine/.gitignore to block future src/*.{js,d.ts,map}.
- Refactor plugin pi-module seams (openclaw/paperclip/hermes) to ESM-import
  createFnAgent / promptWithFallback / describeModel from @fusion/engine
  instead of require()-ing packages/engine/src/pi.js. Adds @fusion/engine to
  the two plugin package.jsons that were missing it; exports describeModel
  from the engine public API.
- Fix engine test mocks now that they run against current pi.ts: add
  ModelRegistry.create static to mocks in pi.test.ts and pi-create-fn-agent
  .test.ts; switch three boundary-result toEqual assertions to toMatchObject
  so the new content/isError fields don't trip exact-match comparison.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-24 18:45:10 -07:00
parent 5ca0df728f
commit bdcb048e20
232 changed files with 1311 additions and 26008 deletions

View File

@@ -0,0 +1,43 @@
import { describe, expect, it } from "vitest";
import { probeClaudeCli } from "../claude-cli-probe.js";
/**
* These tests exercise the real probe — we deliberately do NOT mock
* `spawn`. The probe's job is to tell the truth about the local system,
* and mocking defeats that. Instead we:
*
* 1. Assert the shape is sound regardless of binary availability
* 2. Assert timeouts fire when the binary hangs (we don't have a
* hanging binary fixture, so we cover the structural case only)
* 3. Let the suite pass whether or not `claude` is installed on the
* test runner — both outcomes are legitimate.
*
* If you need mocked probe behavior for a higher-level route test, spy
* on `probeClaudeCli` at the import boundary rather than shimming spawn.
*/
describe("probeClaudeCli", () => {
it("returns a well-formed result whether or not claude is installed", async () => {
const result = await probeClaudeCli();
expect(typeof result.available).toBe("boolean");
expect(typeof result.probeDurationMs).toBe("number");
if (result.available) {
// When available: version string should come back populated.
expect(typeof result.version).toBe("string");
} else {
// When unavailable: reason must be populated so the UI can render.
expect(typeof result.reason).toBe("string");
}
});
it("respects a short timeout", async () => {
// Not a true hang test (we don't have a hanging binary), but
// confirms the timeoutMs option wires through and probe completes
// in a bounded window when using a very small timeout.
const result = await probeClaudeCli({ timeoutMs: 50 });
expect(result.probeDurationMs).toBeLessThan(5000);
// Either it completed fast enough or hit the timeout — both fine.
if (!result.available && result.reason?.includes("timed out")) {
expect(result.reason).toContain("50ms");
}
});
});