Skip to content

Commit 8b44c9d

Browse files
ci(studio): type-check Studio's dev server files and test helpers (#9105)
* ci(studio): type-check Studio's dev server files and test helpers * fix(studio): dev server types follow the producer and studio server they call * fix(studio): keep the .tsx tests in Studio's type check
1 parent 6f27ee6 commit 8b44c9d

10 files changed

Lines changed: 30 additions & 30 deletions

File tree

‎lefthook.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pre-commit:
2424
run: bun packages/cli/scripts/gen-skills-manifest.ts && git add skills-manifest.json
2525
- name: typecheck
2626
glob: "*.{ts,tsx}"
27-
run: cd packages/core && node_modules/.bin/tsc --noEmit && cd ../studio && node_modules/.bin/tsc --noEmit && cd ../.. && node_modules/.bin/tsc --noEmit -p scripts/tsconfig.json
27+
run: cd packages/core && node_modules/.bin/tsc --noEmit && cd ../studio && node_modules/.bin/tsc --noEmit -p tsconfig.check.json && cd ../.. && node_modules/.bin/tsc --noEmit -p scripts/tsconfig.json
2828
# Mirrors the CI gate (same `--base origin/main` so the local hook can't
2929
# pass on a branch CI would fail). Audits the working tree, which means
3030
# unstaged WIP in `packages/**` is part of the diff — stash before

‎packages/studio/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"scripts": {
8383
"dev": "bun --bun ./node_modules/.bin/vite --host 127.0.0.1",
8484
"build": "vite build && tsup",
85-
"typecheck": "tsc --noEmit",
85+
"typecheck": "tsc --noEmit -p tsconfig.check.json",
8686
"test": "vitest run",
8787
"test:edit-accuracy": "bun tests/e2e/edit-accuracy/run.mjs",
8888
"test:edit-accuracy:timings": "node tests/e2e/edit-accuracy/timings.mjs",

‎packages/studio/src/components/editor/useColorGradingScopes.test.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ function Harness({
3737

3838
function installPixelDecode() {
3939
vi.spyOn(HTMLImageElement.prototype, "decode").mockResolvedValue();
40-
vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue({
40+
vi.spyOn(
41+
HTMLCanvasElement.prototype as { getContext(id: "2d"): CanvasRenderingContext2D | null },
42+
"getContext",
43+
).mockReturnValue({
4144
drawImage: vi.fn(),
4245
getImageData: vi.fn().mockReturnValue({
4346
data: new Uint8ClampedArray([255, 255, 255, 255]),

‎packages/studio/src/player/components/AudioWaveform.test.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ function recordingCanvas() {
118118
clientWidth: { value: 6 },
119119
clientHeight: { value: 20 },
120120
});
121-
vi.spyOn(canvas, "getContext").mockReturnValue(context);
121+
vi.spyOn(
122+
canvas as { getContext(id: "2d"): CanvasRenderingContext2D | null },
123+
"getContext",
124+
).mockReturnValue(context);
122125
return { canvas, fills };
123126
}
124127

‎packages/studio/tests/inlineTextFixture.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ async function gesture(studioPage: Page, frame: Frame, step: Step, random: () =>
215215
const key = field(s.field);
216216
if (key) void text.commits().handleDomRemoveTextField(key);
217217
},
218-
step as Exclude<Step, { type: unknown }>,
218+
step as Extract<
219+
Step,
220+
{ open: true } | { end: unknown } | { cancel: true } | { panel: unknown }
221+
>,
219222
);
220223
}
221224

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"incremental": false
5+
},
6+
"include": ["src", "tests/*.ts", "*.ts"],
7+
"exclude": ["dist", "node_modules", "**/*.test.ts", "src/**/*.test-helpers.ts"]
8+
}

‎packages/studio/vite.adapter.ts‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { ViteDevServer } from "vite";
1414
import {
1515
type ResolvedProject,
1616
type RenderJobState,
17-
type StudioApiAdapter,
17+
type PreviewApiAdapter,
1818
type BackgroundRemovalRender,
1919
createBackgroundRemovalJob,
2020
createProjectSignature,
@@ -120,7 +120,7 @@ export function createViteAdapter(
120120
openHistory?: typeof openProjectHistory;
121121
onResolveProject?: (project: ResolvedProject) => void;
122122
} = {},
123-
): StudioApiAdapter {
123+
): PreviewApiAdapter {
124124
const histories = historyCache((projectDir) =>
125125
openHistory({ projectDir, historyRoot }).catch((error: unknown) => {
126126
console.warn(`[studio] Project history is off for ${basename(projectDir)}: ${String(error)}`);
@@ -133,24 +133,7 @@ export function createViteAdapter(
133133
// Commits any open edit when the dev server stops, so it keeps its label.
134134
server.httpServer?.on("close", () => void histories.closeAll());
135135
let _bundler: ((dir: string, options?: BundleOptions) => Promise<string>) | null = null;
136-
let _producerModuleLoader:
137-
| (() => Promise<{
138-
createRenderJob: (config: {
139-
fps: 24 | 30 | 60;
140-
quality: "draft" | "standard" | "high";
141-
format: string;
142-
renderBodyScripts?: string[];
143-
outputResolution?: "landscape" | "portrait" | "landscape-4k" | "portrait-4k";
144-
variables?: Record<string, unknown>;
145-
}) => unknown;
146-
executeRenderJob: (
147-
job: unknown,
148-
projectDir: string,
149-
outputPath: string,
150-
onProgress?: (job: { progress: number; currentStage?: string }) => void,
151-
) => Promise<void>;
152-
}>)
153-
| null = null;
136+
let _producerModuleLoader: (() => Promise<typeof import("@hyperframes/producer")>) | null = null;
154137

155138
const getBundler = async () => {
156139
if (!_bundler) {

‎packages/studio/vite.chrome.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export function findSystemChrome(
138138
env["PUPPETEER_EXECUTABLE_PATH"],
139139
env["CHROME_PATH"],
140140
env["CHROME_BIN"],
141-
].find((candidate): candidate is string => Boolean(candidate) && pathExists(candidate));
141+
].find((candidate): candidate is string => !!candidate && pathExists(candidate));
142142
return (
143143
override ??
144144
findPuppeteerCacheChrome(env, pathExists, platform, readDirectories) ??

‎packages/studio/vite.config.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { type FSWatcher, watch } from "chokidar";
1717
import { createProjectSignatureCache, createViteAdapter } from "./vite.adapter";
1818
import { previewConfigPayload } from "./vite.preview-config";
1919
import { loadStudioServerDevModule } from "./vite.studio-server-module";
20-
import type { openProjectHistory } from "@hyperframes/studio-server";
20+
import type { openProjectHistory, StudioApiOptions } from "@hyperframes/studio-server";
2121
import { previewChangeOwner } from "./vite.preview-watch";
2222
import {
2323
carriesOAuthReturn,
@@ -171,7 +171,7 @@ export function devProjectApi(): Plugin {
171171
let _studioServerModule: {
172172
createStudioApi: (
173173
adapter: ReturnType<typeof createViteAdapter>,
174-
options?: { allowedHosts?: readonly string[] },
174+
options?: StudioApiOptions,
175175
) => {
176176
fetch: (req: Request) => Promise<Response>;
177177
};
@@ -304,7 +304,7 @@ export function devProjectApi(): Plugin {
304304
const api = await getApi();
305305
const url = new URL(req.url, `http://${req.headers.host}`);
306306
url.pathname = url.pathname.slice(4);
307-
let body: Buffer | undefined;
307+
let body: Buffer<ArrayBuffer> | undefined;
308308
if (req.method !== "GET" && req.method !== "HEAD") {
309309
const bytes = await readNodeRequestBody(req);
310310
body = bytes.byteLength > 0 ? bytes : undefined;

‎packages/studio/vite.request-body.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export async function readNodeRequestBody(
22
req: AsyncIterable<string | Uint8Array>,
3-
): Promise<Buffer> {
3+
): Promise<Buffer<ArrayBuffer>> {
44
const chunks: Uint8Array[] = [];
55

66
for await (const chunk of req) {

0 commit comments

Comments
 (0)