Public: anyone can read this; the crew can change it.

Red after landing: test/worker-database-opens.test.ts fails on main #12825

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/12806-red-after-landing-test-worker-database-o → main 1 commit fork

  • Merged. scout/12806-red-after-landing-test-worker-database-o was merged into main as 9d9e266.

Review

Sign in to review this change.
1 file changed +30 −10
test/worker-database-opens.test.ts +30 −10
@@ -76,18 +76,20 @@ const NAMED = /(?:\bnew Worker|\bworkerAsker(?:<[^(]*>)?)\(\s*new URL\(\s*["']([
7676 const TYPE_ONLY = /^\s*(?:import|export)\s+type\s[^;]*?from\s*["'][^"']+["'];?\s*$/gm;
7777
7878 /** `text` without its comment lines. */
79 const stripped = new Map<string, string>();
7980 function code(text: string): string {
80 return text
81 .split("\n")
82 .filter((raw) => {
83 const line = raw.trim();
84 return !(line.startsWith("//") || line.startsWith("*") || line.startsWith("/*"));
85 })
86 .map((raw) => raw.replace(/\s\/\/.*$/, ""))
87 .join("\n");
81 const seen = stripped.get(text);
82 if (seen !== undefined) return seen;
83 const out = strip(text);
84 stripped.set(text, out);
85 return out;
8886 }
8987
90 const opensIn = (text: string): number => [...code(text).matchAll(OPEN)].length;
88 function strip(text: string): string {
89 return text.replace(/^[ \t]*(?:\/\/|\*|\/\*).*$/gm, "").replace(/\s\/\/.*$/gm, "");
90 }
91
92 const opensIn = (text: string): number => (text.includes("Database") ? [...code(text).matchAll(OPEN)].length : 0);
9193
9294 /**
9395 * The Worker modules under `files` and the file that starts each; `unnamed` are Workers made
@@ -97,6 +99,7 @@ function workers(files: ReadonlyMap<string, string>): { entries: Map<string, str
9799 const entries = new Map<string, string>();
98100 const unnamed: string[] = [];
99101 for (const [path, text] of files) {
102 if (!text.includes("Worker") && !text.includes("workerAsker")) continue;
100103 const body = code(text);
101104 const named = [...body.matchAll(NAMED)];
102105 for (const match of named) {
@@ -110,6 +113,17 @@ function workers(files: ReadonlyMap<string, string>): { entries: Map<string, str
110113 return { entries, unnamed };
111114 }
112115
116 const imported = new Map<string, string[]>();
117 function importsFrom(file: string, text: string): string[] {
118 let found = imported.get(`${file}\0${text}`);
119 if (found === undefined) {
120 const body = code(text);
121 found = importsOf(/\b(?:import|export)\s+type\s/.test(body) ? body.replace(TYPE_ONLY, "") : body, file);
122 imported.set(`${file}\0${text}`, found);
123 }
124 return found;
125 }
126
113127 /** Every file `entry` loads when it runs: its imports and theirs, types aside. */
114128 function reach(entry: string, files: ReadonlyMap<string, string>): Set<string> {
115129 const seen = new Set<string>([entry]);
@@ -117,7 +131,7 @@ function reach(entry: string, files: ReadonlyMap<string, string>): Set<string> {
117131 for (let file = todo.pop(); file !== undefined; file = todo.pop()) {
118132 const text = files.get(file);
119133 if (text === undefined) continue;
120 for (const found of importsOf(code(text).replace(TYPE_ONLY, ""), file)) {
134 for (const found of importsFrom(file, text)) {
121135 const path = files.has(found) ? found : `${found}.ts`;
122136 if (seen.has(path)) continue;
123137 seen.add(path);
@@ -186,7 +200,13 @@ function audit(files: ReadonlyMap<string, string>, lists: Lists): string[] {
186200 return problems;
187201 }
188202
203 let scanned: Map<string, string> | undefined;
189204 function srcFiles(): Map<string, string> {
205 scanned ??= readSrc();
206 return scanned;
207 }
208
209 function readSrc(): Map<string, string> {
190210 const root = join(import.meta.dir, "..");
191211 const files = new Map<string, string>();
192212 for (const path of new Bun.Glob("src/**/*.{ts,tsx}").scanSync({ cwd: root })) {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs