Skip to content

Claude Code. Any Model. The most powerful AI coding agent now speaks every language.

build(cli): type-check the blind hook tests in their own project

Jack Rudenko0dd941862fb3
diff --git a/packages/cli/scripts/typecheck-blind.ts b/packages/cli/scripts/typecheck-blind.ts
new file mode 100644
index 00000000..a57756c5
--- /dev/null
+++ b/packages/cli/scripts/typecheck-blind.ts
@@ -0,0 +1,82 @@
+/**
+ * Type-check the blind hook tests (tsconfig.blind.json), allowing exactly one thing the
+ * locked bun-types rejects: Bun's label-only `test.todo("name")` / `it.todo("name")`.
+ *
+ * Bun runs a body-less todo (it lists the test and calls nothing), but bun-types declares
+ * `todo` with the full `Test` signature, so the call is TS2554 "Expected 2-3 arguments,
+ * but got 1". The blind tests use that form and are written by another model, so they are
+ * not edited to suit the checker. A declaration-merging shim cannot narrow `todo` alone —
+ * `todo` is typed as `Test<T>` itself, so any extra call signature also lets a body-less
+ * `test("x")` or `it("x")` through — hence this filter: a TS2554 is accepted only when it
+ * sits on the `todo` of a one-argument `test.todo(…)` / `it.todo(…)` call. Every other
+ * diagnostic fails the check.
+ *
+ * bun run scripts/typecheck-blind.ts [tsconfig] default: tsconfig.blind.json
+ */
+import { dirname, join, resolve } from "node:path";
+import ts from "typescript";
+
+const root = join(import.meta.dir, "..");
+const projectPath = resolve(root, process.argv[2] ?? "tsconfig.blind.json");
+
+const read = ts.readConfigFile(projectPath, ts.sys.readFile);
+if (read.error) {
+ console.error(ts.formatDiagnostics([read.error], host()));
+ process.exit(1);
+}
+const parsed = ts.parseJsonConfigFileContent(read.config, ts.sys, dirname(projectPath));
+const program = ts.createProgram({ rootNames: parsed.fileNames, options: parsed.options });
+
+const TODO_RECEIVERS = new Set(["test", "it"]);
+
+/** Spans of the `todo` name in every `test.todo(x)` / `it.todo(x)` call with one argument. */
+function labelOnlyTodoSpans(file: ts.SourceFile): Array<[number, number]> {
+ const spans: Array<[number, number]> = [];
+ const visit = (node: ts.Node): void => {
+ if (
+ ts.isCallExpression(node) &&
+ node.arguments.length === 1 &&
+ ts.isPropertyAccessExpression(node.expression) &&
+ node.expression.name.text === "todo" &&
+ ts.isIdentifier(node.expression.expression) &&
+ TODO_RECEIVERS.has(node.expression.expression.text)
+ ) {
+ spans.push([node.expression.name.getStart(file), node.expression.name.getEnd()]);
+ }
+ ts.forEachChild(node, visit);
+ };
+ visit(file);
+ return spans;
+}
+
+const spansByFile = new Map<string, Array<[number, number]>>();
+function isLabelOnlyTodo(d: ts.Diagnostic): boolean {
+ if (d.code !== 2554 || !d.file || d.start === undefined) return false;
+ let spans = spansByFile.get(d.file.fileName);
+ if (!spans) {
+ spans = labelOnlyTodoSpans(d.file);
+ spansByFile.set(d.file.fileName, spans);
+ }
+ const start = d.start;
+ return spans.some(([from, to]) => start >= from && start < to);
+}
+
+function host(): ts.FormatDiagnosticsHost {
+ return {
+ getCanonicalFileName: (f) => f,
+ getCurrentDirectory: () => root,
+ getNewLine: () => "\n",
+ };
+}
+
+const all = ts.getPreEmitDiagnostics(program);
+const failing = all.filter((d) => !isLabelOnlyTodo(d));
+const allowed = all.length - failing.length;
+if (failing.length > 0) {
+ console.error(ts.formatDiagnostics(failing, host()));
+ console.error(
+ `[typecheck-blind] ${failing.length} error(s); ${allowed} label-only test.todo call(s) allowed`
+ );
+ process.exit(1);
+}
+console.log(`[typecheck-blind] ok; ${allowed} label-only test.todo call(s) allowed`);
diff --git a/packages/cli/tsconfig.blind.json b/packages/cli/tsconfig.blind.json
new file mode 100644
index 00000000..78534ccb
--- /dev/null
+++ b/packages/cli/tsconfig.blind.json
@@ -0,0 +1,10 @@
+{
+ "extends": "./tsconfig.json",
+ "compilerOptions": {
+ "noEmit": true,
+ "rootDir": ".",
+ "allowImportingTsExtensions": true
+ },
+ "include": ["src/hooks/blind/**/*"],
+ "exclude": ["node_modules", "dist"]
+}
diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json
index ad16820b..aaafc5b8 100644
--- a/packages/cli/tsconfig.json
+++ b/packages/cli/tsconfig.json
@@ -23,5 +23,5 @@
"skipLibCheck": true
},
"include": ["src/**/*"],
- "exclude": ["node_modules", "dist"]
+ "exclude": ["node_modules", "dist", "src/hooks/blind"]
}