Back to Plate

ai chat specs must not hardcode local plate dist paths

docs/solutions/test-failures/2026-03-26-ai-chat-specs-must-not-hardcode-local-plate-dist-paths.md

53.0.51.3 KB
Original Source

Summary

Five AI chat specs were loading the real platejs/react bundle through a hardcoded absolute path to one developer machine.

That made local runs look fine while CI exploded during @platejs/ai typecheck, because /Users/zbeyens/... obviously does not exist on GitHub runners.

What Happened

These specs partially mocked platejs/react so they could spy on the real hook exports while still falling back to the actual implementation.

The fallback import used this shape:

ts
await import("packages/plate/dist/react/index.js");

TypeScript tried to resolve that literal during package typecheck. On CI, it failed immediately with TS2307.

Fix

Load the built platejs/react bundle through a repo-relative URL computed from the spec file instead of a hardcoded machine path:

ts
await import(
  new URL("../../../../../plate/dist/react/index.js", import.meta.url).href
);

That keeps the import stable across local machines and CI workspaces while still bypassing the mocked platejs/react module.

Rule

If a spec needs the real built output of another workspace package, never bake one machine's absolute path into the test.

Use a repo-relative new URL(..., import.meta.url) path or another workspace- portable resolver. Local green on your laptop means nothing if the import string contains your home directory.