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 ab98cc3719
commit bce7dbd96f
232 changed files with 1311 additions and 26008 deletions

View File

@@ -2,25 +2,15 @@
* Pi Module Seam
*
* Provides a mockable import path for pi functions used by the PaperclipRuntimeAdapter.
* This module creates a seam that Vitest can intercept via vi.mock().
*
* ## Why a Seam Module?
*
* The pi functions (createFnAgent, promptWithFallback, describeModel) are defined
* in packages/engine/src/pi.ts but are not exported from the @fusion/engine public API.
* This seam provides a controlled import path that can be mocked in tests.
*
* ## Mocking in Tests
*
* Vitest can mock this module using:
* ```typescript
* vi.mock("../pi-module.js", () => ({
* createFnAgent: mockCreateFnAgent,
* promptWithFallback: mockPromptWithFallback,
* describeModel: mockDescribeModel,
* }));
* ```
* Tests intercept this module via `vi.mock("../pi-module.js", ...)`. The runtime
* implementations come from @fusion/engine; the local types provide a loose
* surface so the adapter doesn't have to depend on @fusion/engine's full types.
*/
import {
createFnAgent as _createFnAgent,
promptWithFallback as _promptWithFallback,
describeModel as _describeModel,
} from "@fusion/engine";
// ── Type Declarations ─────────────────────────────────────────────────────────
@@ -55,24 +45,19 @@ export interface PiAgentOptions {
skills?: string[];
}
// ── Module Export (runtime resolution) ────────────────────────────────────────
// Use CommonJS require at runtime, which Vitest can mock when using
// vi.mock() with a factory function. The key is that Vitest hoists vi.mock
// calls before module evaluation, so the mock is active when require() runs.
//
// eslint-disable-next-line @typescript-eslint/no-require-imports
const _piModule = require("../../../packages/engine/src/pi.js") as {
createFnAgent: (options: PiAgentOptions) => Promise<PiAgentResult>;
promptWithFallback: (session: PiAgentSession, prompt: string, options?: unknown) => Promise<void>;
describeModel: (session: PiAgentSession) => string;
};
// ── Module Exports ────────────────────────────────────────────────────────────
/** Create a new agent session using the pi backend */
export const createFnAgent = _piModule.createFnAgent;
export const createFnAgent = _createFnAgent as unknown as (
options: PiAgentOptions,
) => Promise<PiAgentResult>;
/** Prompt the session with automatic retry and fallback */
export const promptWithFallback = _piModule.promptWithFallback;
export const promptWithFallback = _promptWithFallback as unknown as (
session: PiAgentSession,
prompt: string,
options?: unknown,
) => Promise<void>;
/** Get a human-readable model description from a session */
export const describeModel = _piModule.describeModel;
export const describeModel = _describeModel as unknown as (session: PiAgentSession) => string;