Files
hyperframes/packages/cli/src/cliDispatchTestUtils.ts
T
Miguel Ángel de9206e0f8 fix(cli): detect a missing or stale studio build before it crashes (#4076)
* fix(cli): name the missing or stale workspace package before preview crashes

Running hyperframes preview from source with an unbuilt or stale
package previously crashed deep inside that package's own import
graph with a raw resolver error naming neither the package nor the
fix. Add a preflight that runs before the preview command's own
module import, so it also catches the crash that happens at CLI load
time before the studio dev server ever spawns.

* test(cli): cover the preview workspace-build gate wiring

Adds a test that exercises the real CLI dispatch path (mocked module
loaders, not source-text matching) to prove the preview command's
build-check runs before its module loads and that a failure exits
non-zero without double-printing. Also guards the exports-map reader
against a malformed package.json instead of crashing raw.

* fix(cli): correct why the audio-fx generated file is checked

The comment claimed core/src/index.ts imports both generated files
directly. Only runtime-inline.ts is; audio-fx-runtime-inline.ts is
reachable solely via core's own audio-fx-runtime export subpath,
which the engine package imports. The check itself was already
correct to require both, only the stated reason was wrong.
2026-09-18 09:27:39 -04:00

27 lines
853 B
TypeScript

import { vi } from "vitest";
// Shared by every test that drives the real `cli.js` dispatch path
// (dynamic import + process.argv) instead of source-text matching.
export function mockTelemetry(
overrides: {
flushSync?: ReturnType<typeof vi.fn>;
trackCommandResult?: ReturnType<typeof vi.fn>;
trackCommandFailure?: ReturnType<typeof vi.fn>;
} = {},
): void {
vi.doMock("./telemetry/index.js", () => ({
flush: vi.fn(async () => {}),
flushSync: overrides.flushSync ?? vi.fn(),
incrementCommandCount: vi.fn(),
showTelemetryNotice: vi.fn(),
shouldTrack: () => false,
trackCliError: vi.fn(),
trackCommand: vi.fn(),
trackCommandResult: overrides.trackCommandResult ?? vi.fn(),
}));
vi.doMock("./telemetry/events.js", () => ({
trackCommandFailure: overrides.trackCommandFailure ?? vi.fn(),
}));
}