Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .agents/skills/verify-toolkit/scripts/mcp-call.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ try {
);
for (const [n, [name, toolArgs]] of opts.calls.entries()) {
const file = `call-${n + 1}-${name}.json`;
// oxlint-disable-next-line no-await-in-loop -- calls run in the order given, since a later call can depend on an earlier one's side effects
const result = await client.callTool({ name, arguments: toolArgs });
write(file, { request: { name, arguments: toolArgs }, result });
const shape = result.structuredContent
Expand Down
13 changes: 13 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
],
"typescript/no-unnecessary-type-constraint": "error",
"prefer-const": "error",
"no-await-in-loop": "error",
"no-else-return": ["error", { "allowElseIf": false }],
"no-new-wrappers": "error",
"no-new": "error",
Expand Down Expand Up @@ -508,6 +509,18 @@
"no-restricted-imports": "off",
"no-restricted-globals": "off"
}
},
{
"files": [
"**/*.test.ts",
"**/*.test.tsx",
"**/*.test.mjs",
"**/test-utils/**",
"packages/cli/test/**"
],
"rules": {
"no-await-in-loop": "off"
}
}
Comment thread
sentry-junior[bot] marked this conversation as resolved.
Resolved
]
}
1 change: 1 addition & 0 deletions apps/docs-mcp/src/agent/features-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export async function parseFeaturesOutput(
`Structured output was truncated because the model finished with reason "${finishReason}".`,
);
}
// oxlint-disable-next-line no-await-in-loop -- steps parse in order: a cut-off step throws before later steps are read, and the last valid output wins
const { value } = await parsePartialJson(preprocessJsonText(text));
const parsed = featuresOutputSchema.safeParse(value);
if (!parsed.success) {
Expand Down
2 changes: 2 additions & 0 deletions apps/docs-mcp/src/agent/model-fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function createFallbackModel(
for (const [index, model] of models.entries()) {
for (;;) {
try {
// oxlint-disable-next-line no-await-in-loop -- tries one model at a time and falls back only after it fails
return { model, result: await call(model) };
} catch (error) {
lastError = error;
Expand All @@ -202,6 +203,7 @@ function createFallbackModel(
break;
}
retryCount++;
// oxlint-disable-next-line no-await-in-loop -- backs off before retrying the same model
await wait(delay, signal);
}
}
Expand Down
29 changes: 18 additions & 11 deletions apps/local/scripts/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,20 @@ async function envelopeFiles(path: string): Promise<string[]> {
const info = await stat(path);
if (info.isFile()) return [path];
const entries = await readdir(path, { withFileTypes: true });
const files: string[] = [];
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
const child = join(path, entry.name);
if (entry.isDirectory()) files.push(...(await envelopeFiles(child)));
else if (
entry.isFile() &&
[".txt", ".bin", ".envelope"].includes(extname(entry.name))
)
files.push(child);
}
return files;
// Sorted, and flattened in that order, so envelopes replay in a stable order.
const nested = await Promise.all(
entries
.sort((a, b) => a.name.localeCompare(b.name))
.map(async (entry) => {
const child = join(path, entry.name);
if (entry.isDirectory()) return await envelopeFiles(child);
return entry.isFile() &&
[".txt", ".bin", ".envelope"].includes(extname(entry.name))
? [child]
: [];
}),
);
return nested.flat();
}
/** Replay raw bytes through the public receiver endpoint; never bypass ingestion. */
export async function replayEnvelopes({
Expand Down Expand Up @@ -69,14 +72,17 @@ export async function replayEnvelopes({
let sent = 0;
for (let cycle = 0; cycle < repeat; cycle++)
for (const file of files) {
// oxlint-disable-next-line no-await-in-loop -- replays envelopes one at a time, spaced by --interval
if (sent && interval) await delay(interval);
// oxlint-disable-next-line no-await-in-loop -- replays envelopes one at a time, spaced by --interval
const raw = await readFile(file);
const body =
compression === "gzip"
? gzipSync(raw)
: compression === "br"
? brotliCompressSync(raw)
: raw;
// oxlint-disable-next-line no-await-in-loop -- replays envelopes one at a time, spaced by --interval
const response = await fetch(target, {
method: "POST",
headers: {
Expand All @@ -89,6 +95,7 @@ export async function replayEnvelopes({
redirect: "error",
signal: AbortSignal.timeout(10_000),
});
// oxlint-disable-next-line no-await-in-loop -- replays envelopes one at a time, spaced by --interval
await response.body?.cancel();
if (!response.ok)
throw new Error(`Receiver rejected ${file}: HTTP ${response.status}`);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ Don't copy a pattern from a neighboring file without this check. The wizards wer
| Absolute date/time display | `src/lib/formatters/time-utils.ts` (`formatLocalDateTime` and `formatLocalTime` for epoch ms or ISO strings, `formatUtcTimestamp`, `formatAxisTimestamp` for chart axes). `sentry-cli/no-inline-date-format` rejects `new Date(x).toLocale*String()` elsewhere in `src/`. |
| Table/markdown output | `src/lib/formatters/` directory |
| Pagination | `src/lib/db/pagination.ts`, `src/lib/list-command.ts` |
| Independent async work over a list (instead of `await` in a loop) | `src/lib/fan-out.ts` (`mapBounded(items, fn, concurrency)`): pass `ORG_FANOUT_CONCURRENCY` for API calls, `CONCURRENCY_LIMIT` (`src/lib/scan/constants.ts`) for local files. Oxlint's `no-await-in-loop` is on for the whole repo except test files. A loop that must stay sequential (cursor pages, polling, retries, ordered writes, first match wins) gets `// oxlint-disable-next-line no-await-in-loop -- <reason>`. |
| Error classes | `src/lib/errors.ts` (never create ad-hoc error types) |
| Search query building | `src/lib/search-query.ts` (wraps `@sentry/toolkit-core/search-query`), `src/lib/arg-parsing.ts` |

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/script/bench-sweep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ async function runSweep(args: SweepArgs): Promise<SweepResult[]> {
if (!args.json) {
logger.log(`\n${fx.label} (${fx.rootDir})`);
}
// oxlint-disable-next-line no-await-in-loop -- benchmarks run one fixture at a time so runs do not skew each other's timings
await withBenchDb(async () => {
await sweepFixture(fx, ops, args, results);
});
Expand All @@ -263,6 +264,7 @@ async function sweepFixture(
for (const op of ops) {
for (const concurrency of args.values) {
const setup = op.setup;
// oxlint-disable-next-line no-await-in-loop -- benchmarks run one sample at a time so runs do not skew each other's timings
const samples = await measure(() => op.run(fx.rootDir, concurrency), {
runs: args.runs,
warmup: args.warmup,
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/script/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ async function roughFileCount(root: string): Promise<number> {
for (const entry of entries) {
if (entry.isDirectory()) {
if (!skip.has(entry.name)) {
// oxlint-disable-next-line no-await-in-loop -- walks a large fixture tree one directory at a time to keep open handles bounded
await walk(join(dir, entry.name));
}
} else if (entry.isFile()) {
Expand Down Expand Up @@ -541,9 +542,11 @@ async function runAll(
if (!args.json) {
logger.log(`${fx.label} (${fx.fileCount} files @ ${fx.rootDir})`);
}
// oxlint-disable-next-line no-await-in-loop -- benchmarks run one fixture at a time so runs do not skew each other's timings
await withBenchDb(async () => {
for (const op of ops) {
const setup = op.setup;
// oxlint-disable-next-line no-await-in-loop -- benchmarks run one operation at a time so runs do not skew each other's timings
const samples = await measure(
async () => {
await op.run(fx.rootDir);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ async function compileAllTargets(
let failures = 0;
for (const target of targets) {
try {
// oxlint-disable-next-line no-await-in-loop -- each target compresses a full binary; one at a time keeps memory bounded
await postProcessTarget(target);
successes += 1;
} catch (error) {
Expand Down
16 changes: 12 additions & 4 deletions packages/cli/script/check-doc-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import {
} from "./sdk-run-calls.js";
import { shellCommands } from "./shell-words.js";
import { logger } from "../src/lib/logger.js";
import { mapBounded } from "../src/lib/fan-out.js";
import { CONCURRENCY_LIMIT } from "../src/lib/scan/constants.js";

await writeRouteTreeStubs();

Expand Down Expand Up @@ -399,8 +401,11 @@ for (const { source, invocation } of commandExamples(
findings.push({ file: source, example: invocation, problem });
}
}
for (const file of [...files, ...SDK_EXAMPLE_FILES]) {
const content = await readFile(file, "utf-8");
for (const { file, content } of await mapBounded(
[...files, ...SDK_EXAMPLE_FILES],
async (file) => ({ file, content: await readFile(file, "utf-8") }),
CONCURRENCY_LIMIT,
)) {
const invocations = file.endsWith(".ts") ? [] : extractInvocations(content);
for (const invocation of invocations) {
checked += 1;
Expand All @@ -418,8 +423,11 @@ for (const file of [...files, ...SDK_EXAMPLE_FILES]) {
}

const sourceFiles = listSource(SOURCE_DIR);
for (const file of sourceFiles) {
const content = await readFile(file, "utf-8");
for (const { file, content } of await mapBounded(
sourceFiles,
async (file) => ({ file, content: await readFile(file, "utf-8") }),
CONCURRENCY_LIMIT,
)) {
if (!content.includes("sentry`")) {
continue;
}
Expand Down
30 changes: 20 additions & 10 deletions packages/cli/script/check-env-coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { ENV_VAR_REGISTRY } from "../src/lib/env-registry.js";
import { logger } from "../src/lib/logger.js";
import { mapBounded } from "../src/lib/fan-out.js";
import { CONCURRENCY_LIMIT } from "../src/lib/scan/constants.js";

/**
* Well-known env vars that don't start with `SENTRY_` but are still part of the
Expand Down Expand Up @@ -134,8 +136,11 @@ const files = globSync("src/**/*.ts", {
// bracket reads indexed by a constant can be mapped back to a literal name.
const constMap = new Map<string, string>();
const fileContents = new Map<string, string>();
for (const file of files) {
const content = await readFile(file, "utf-8");
for (const { file, content } of await mapBounded(
files,
async (file) => ({ file, content: await readFile(file, "utf-8") }),
CONCURRENCY_LIMIT,
)) {
fileContents.set(file, content);
for (const match of content.matchAll(ENV_CONST_RE)) {
const [, name] = match;
Expand Down Expand Up @@ -192,8 +197,11 @@ const INSTALLERS: readonly { file: string; read: RegExp; assign?: RegExp }[] = [
/** name -> first "file:line" where an installer reads it. */
const installerReads = new Map<string, string>();

for (const { file, read, assign } of INSTALLERS) {
const content = await readFile(file, "utf-8");
const installerContents = await Promise.all(
INSTALLERS.map(({ file }) => readFile(file, "utf-8")),
);
for (const [index, { file, read, assign }] of INSTALLERS.entries()) {
const content = installerContents[index] ?? "";
const assigned = new Set(
assign ? [...content.matchAll(assign)].map((m) => m[1]) : [],
);
Expand Down Expand Up @@ -252,12 +260,14 @@ for (const name of INTERNAL_ENV_VARS.keys()) {

// Every file type under src/, generated files included, not just the env
// reads above: a retired name in a string or a comment fails too.
for (const entry of globSync("src/**/*", { withFileTypes: true })) {
if (!entry.isFile()) {
continue;
}
const file = join(entry.parentPath, entry.name);
const content = await readFile(file, "utf-8");
const srcFiles = globSync("src/**/*", { withFileTypes: true })
.filter((entry) => entry.isFile())
.map((entry) => join(entry.parentPath, entry.name));
for (const { file, content } of await mapBounded(
srcFiles,
async (file) => ({ file, content: await readFile(file, "utf-8") }),
CONCURRENCY_LIMIT,
)) {
for (const [prefix, reason] of RETIRED_ENV_PREFIXES) {
const index = content.indexOf(prefix);
if (index !== -1) {
Expand Down
11 changes: 9 additions & 2 deletions packages/cli/script/check-error-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import { globSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { logger } from "../src/lib/logger.js";
import { mapBounded } from "../src/lib/fan-out.js";
import { CONCURRENCY_LIMIT } from "../src/lib/scan/constants.js";

export type Violation = { file: string; line: number; message: string };

Expand Down Expand Up @@ -271,8 +273,13 @@ export function findAdHocTryPatterns(
/** Scan the given files and collect violations. */
export async function scanFiles(files: string[]): Promise<Violation[]> {
const violations: Violation[] = [];
for (const filePath of files) {
const content = await readFile(filePath, "utf-8");
const contents = await mapBounded(
files,
(filePath) => readFile(filePath, "utf-8"),
CONCURRENCY_LIMIT,
);
for (const [index, filePath] of files.entries()) {
const content = contents[index] ?? "";
violations.push(...findContextErrorNewlines(content, filePath));
violations.push(...findAdHocTryPatterns(content, filePath));
}
Expand Down
57 changes: 41 additions & 16 deletions packages/cli/script/check-fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { writeRouteTreeStubs } from "./lib/route-tree-stubs.js";
import { markdownHeadings } from "./markdown.js";
import { DOCS_FRAGMENTS } from "./paths.js";
import { logger } from "../src/lib/logger.js";
import { mapBounded } from "../src/lib/fan-out.js";
import { CONCURRENCY_LIMIT } from "../src/lib/scan/constants.js";

await writeRouteTreeStubs();

Expand Down Expand Up @@ -90,9 +92,14 @@ for (const name of actualFragments) {
const EXAMPLES_HEADING_RE = /^examples?\b/i;

// Check 3: Fragment content validation
for (const file of fragmentFiles) {
const content = await readFile(`${FRAGMENTS_DIR}/${file}`, "utf-8");

for (const { file, content } of await mapBounded(
fragmentFiles,
async (file) => ({
file,
content: await readFile(`${FRAGMENTS_DIR}/${file}`, "utf-8"),
}),
CONCURRENCY_LIMIT,
)) {
if (content.includes("---\ntitle:") || content.startsWith("---\n")) {
errors.push(
`Fragment contains frontmatter: ${FRAGMENTS_DIR}/${file} (fragments should only contain custom content, not YAML frontmatter)`,
Expand Down Expand Up @@ -129,13 +136,17 @@ const TOP_LEVEL_FRAGMENTS_DIR = DOCS_FRAGMENTS;
/** Top-level fragment files that must exist (for generated doc pages) */
const REQUIRED_TOP_LEVEL_FRAGMENTS = ["configuration"];

for (const name of REQUIRED_TOP_LEVEL_FRAGMENTS) {
const requiredFragmentsExist = await Promise.all(
REQUIRED_TOP_LEVEL_FRAGMENTS.map((name) =>
access(`${TOP_LEVEL_FRAGMENTS_DIR}/${name}.md`).then(
() => true,
() => false,
),
),
);
for (const [index, name] of REQUIRED_TOP_LEVEL_FRAGMENTS.entries()) {
const path = `${TOP_LEVEL_FRAGMENTS_DIR}/${name}.md`;
const exists = await access(path).then(
() => true,
() => false,
);
if (!exists) {
if (!requiredFragmentsExist[index]) {
errors.push(
`Missing top-level fragment: ${path} (required for generated ${name}.md page)`,
);
Expand Down Expand Up @@ -253,13 +264,27 @@ function getDefaultCommandName(routeName: string): string | undefined {

const multiCommandRoutes = getMultiCommandRoutes();

for (const [routeName, route] of multiCommandRoutes) {
const fragmentPath = `${FRAGMENTS_DIR}/${routeName}.md`;
let content: string;
try {
content = await readFile(fragmentPath, "utf-8");
} catch {
// Fragment doesn't exist — already caught by Check 1
const multiCommandFragments = await mapBounded(
multiCommandRoutes,
async ([routeName, route]) => ({
routeName,
route,
fragmentPath: `${FRAGMENTS_DIR}/${routeName}.md`,
// A missing fragment is already caught by Check 1.
content: await readFile(`${FRAGMENTS_DIR}/${routeName}.md`, "utf-8").catch(
() => undefined,
),
}),
CONCURRENCY_LIMIT,
);

for (const {
routeName,
route,
fragmentPath,
content,
} of multiCommandFragments) {
if (content === undefined) {
continue;
}

Expand Down
Loading
Loading