|
| 1 | +// Import smoke test for the raw-TSX TUI entry (`./tui` export). |
| 2 | +// |
| 3 | +// The TUI entry (src/tui/index.tsx) uses `/** @jsxImportSource @opentui/solid */`, |
| 4 | +// so loading it requires @opentui/solid + solid-js to resolve from the plugin |
| 5 | +// package itself. When those weren't declared as deps, OpenCode 1.17.10's |
| 6 | +// OpenTUI 0.4.2 bump surfaced an immediate load failure: |
| 7 | +// Cannot find module '@opentui/solid/jsx-dev-runtime' |
| 8 | +// `bun test` doesn't catch this because no suite imports the TSX entry. This |
| 9 | +// script imports it exactly like OpenCode loads the `./tui` export, so a missing |
| 10 | +// or version-mismatched OpenTUI/Solid runtime fails the smoke instead of shipping |
| 11 | +// a TUI that won't load. Run: bun packages/plugin/scripts/smoke-tui-import.ts |
| 12 | +import { dirname, join } from "node:path"; |
| 13 | +import { fileURLToPath } from "node:url"; |
| 14 | + |
| 15 | +const here = dirname(fileURLToPath(import.meta.url)); |
| 16 | +const entry = join(here, "../src/tui/index.tsx"); |
| 17 | + |
| 18 | +let failures = 0; |
| 19 | +function check(name: string, cond: boolean, detail?: string): void { |
| 20 | + if (cond) { |
| 21 | + console.log(` ok ${name}`); |
| 22 | + } else { |
| 23 | + failures++; |
| 24 | + console.log(`FAIL ${name}${detail ? ` — ${detail}` : ""}`); |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +try { |
| 29 | + // Resolving the OpenTUI JSX runtime the TSX entry compiles against is the |
| 30 | + // exact thing that broke; importing the entry exercises it end to end. |
| 31 | + const mod = (await import(entry)) as { default?: { id?: string; tui?: unknown } }; |
| 32 | + check("TUI entry imports without a missing-runtime error", true); |
| 33 | + check( |
| 34 | + "exports the { id, tui } plugin shape", |
| 35 | + mod.default?.id === "opencode-magic-context" && typeof mod.default?.tui === "function", |
| 36 | + `got id=${mod.default?.id} tui=${typeof mod.default?.tui}`, |
| 37 | + ); |
| 38 | +} catch (error) { |
| 39 | + check( |
| 40 | + "TUI entry imports without a missing-runtime error", |
| 41 | + false, |
| 42 | + error instanceof Error ? error.message : String(error), |
| 43 | + ); |
| 44 | +} |
| 45 | + |
| 46 | +if (failures > 0) { |
| 47 | + console.error(`\nsmoke-tui-import: ${failures} check(s) failed`); |
| 48 | + process.exit(1); |
| 49 | +} |
| 50 | +console.log("\nsmoke-tui-import: all checks passed"); |
0 commit comments