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
19 changes: 19 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,25 @@ of scope for #1873, and a starting point.*
reading `applyRenewalsForEntries` in `src/shared/webhook.ts` to confirm it
calls `console.error` (or `logError`) on a missing site-token match.

- **Extract scanning helpers from `test/lib/code-quality.test.ts` into a
focused module.** CodeRabbit suggested (PR #1872 review) pulling
`forEachScannedFile`, `collectLineViolations`, `collectFileViolations`,
`scanSourceLines`, `scanSourceFiles`, `ensureLoaded`, the `getAll*Files`
helpers, `repoRelative`/`getRelativePath`/`isCodeQualityFile`, and the
`SRC_DIR`/`TEST_DIR`/`SCRIPTS_DIR`/`CLI_DIR`/`E2E_PAYMENTS_DIR`/`REPO_ROOT`
path constants out of the test file — they're file-discovery and scanning
plumbing, not test assertions. The file is currently 699 lines (under the
Biome 1,000-line hard ceiling but over the 400-line soft target). A
`test/lib/code-quality/scan-context.ts` module exporting `ScanContext`,
`loadScanContext`, `collectLineViolations`, `collectFileViolations`, and
the path constants would let the test file import them and keep only the
assertions and per-rule config. Start from the file-discovery helpers
already at the top of `code-quality.test.ts` (lines 295–360) and the
`ensureLoaded`/`forEachScannedFile`/`collect*Violations`/`scanSource*`
helpers inside the `describe("code quality", …)` block (lines 360–540).
This is a structural refactor (no behavior change); add a regression test
that re-runs the no-`../` rule against a fixture file via the extracted
helpers to prove parity with the inline implementation.
---

## Admin debug test coverage follow-ups
Expand Down
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"#src/": "./src/",
"#test/": "./test/",
"#cli/": "./cli/",
"#scripts/": "./scripts/",
"@libsql/client": "npm:@libsql/client@^0.17.2",
"fast-check": "npm:fast-check@^3.23.0",
"intl-messageformat": "npm:intl-messageformat@^10",
Expand Down
5 changes: 4 additions & 1 deletion e2e-payments/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"e2e": "deno run -A src/main.ts"
},
"imports": {
"playwright": "npm:playwright@1.61.1"
"playwright": "npm:playwright@1.61.1",
"#scripts/": "../scripts/",
"#src/": "../src/",
"#e2e/": "./src/"
},
"compilerOptions": {
"strict": true,
Expand Down
2 changes: 1 addition & 1 deletion e2e-payments/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { type Browser, chromium, type Locator, type Page } from "playwright";
import { browserLaunchOptions } from "../../scripts/browser-options.ts";
import { browserLaunchOptions } from "#scripts/browser-options.ts";
import { config } from "./config.ts";
import { log } from "./log.ts";
import { repoRoot } from "./server.ts";
Expand Down
2 changes: 1 addition & 1 deletion e2e-payments/src/providers/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import type { Frame, Locator, Page } from "playwright";
import { log, warn } from "../log.ts";
import { log, warn } from "#e2e/log.ts";

const FILL_TIMEOUT = 8_000;

Expand Down
2 changes: 1 addition & 1 deletion e2e-payments/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ProviderName } from "../config.ts";
import type { ProviderName } from "#e2e/config.ts";
import { square } from "./square.ts";
import { stripe } from "./stripe.ts";
import { sumup } from "./sumup.ts";
Expand Down
8 changes: 4 additions & 4 deletions e2e-payments/src/providers/shared.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* jscpd:ignore-start */
import type { BrowserSession } from "../browser.ts";
import type { ProviderName } from "../config.ts";
import { config } from "../config.ts";
import { log } from "../log.ts";
import type { BrowserSession } from "#e2e/browser.ts";
import type { ProviderName } from "#e2e/config.ts";
import { config } from "#e2e/config.ts";
import { log } from "#e2e/log.ts";
import type { ConfigureProvider, PayHostedCheckout } from "./types.ts";

/* jscpd:ignore-end */
Expand Down
4 changes: 2 additions & 2 deletions e2e-payments/src/providers/square.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { readFileSync } from "node:fs";
import type { Page } from "playwright";
import { log } from "#e2e/log.ts";
import { sleep } from "#e2e/util.ts";
import { squareRequestInit } from "#shared/square.ts";
import { log } from "../log.ts";
import { sleep } from "../util.ts";
import { configureProvider, hostedCheckout } from "./shared.ts";
import type { HostedCheckoutContext, PaymentProvider } from "./types.ts";

Expand Down
53 changes: 43 additions & 10 deletions e2e-payments/src/providers/stripe.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* jscpd:ignore-start */
import { type BrowserSession, requirePageText } from "../browser.ts";
import { config } from "../config.ts";
import { BOOKER_NAME } from "../flow.ts";
import { log, warn } from "../log.ts";
import { type BrowserSession, requirePageText } from "#e2e/browser.ts";
import { config } from "#e2e/config.ts";
import { BOOKER_NAME } from "#e2e/flow.ts";
import { log, warn } from "#e2e/log.ts";
import { clickFirst, fillFirst } from "./card.ts";
import { configureProvider, hostedCheckout } from "./shared.ts";
import type { PaymentProvider } from "./types.ts";
Expand Down Expand Up @@ -95,6 +95,27 @@ const exerciseStripeRefund = async (session: BrowserSession): Promise<void> => {
log(" Stripe PaymentIntent lookup and full refund passed");
};

/**
* Whether `url` points at a cloudflared quick-tunnel host
* (`trycloudflare.com` or any `*.trycloudflare.com` subdomain). Substring
* matching also catches a URL that just happens to mention the tunnel domain
* in its query string, which would delete an unrelated webhook endpoint, so
* the hostname is parsed and matched explicitly. Invalid or missing URLs are
* left alone.
*/
const isTrycloudflareTunnelUrl = (raw: string | undefined): boolean => {
if (!raw) return false;
try {
const { hostname } = new URL(raw);
return (
hostname === "trycloudflare.com" ||
hostname.endsWith(".trycloudflare.com")
);
} catch {
return false;
}
};

/**
* Stripe. Configuring the key registers a webhook endpoint against the site's
* public HTTPS URL, so this provider REQUIRES the cloudflared tunnel.
Expand Down Expand Up @@ -130,14 +151,26 @@ export const stripe: PaymentProvider = {
data?: { id: string; url?: string }[];
};
const stale = (body.data ?? []).filter((e) =>
e.url?.includes("trycloudflare.com"),
isTrycloudflareTunnelUrl(e.url),
);
for (const endpoint of stale) {
await fetch(
`https://api.stripe.com/v1/webhook_endpoints/${endpoint.id}`,
{ headers, method: "DELETE" },
).catch(() => {});
log(` deleted stale Stripe webhook endpoint ${endpoint.id}`);
try {
const del = await fetch(
`https://api.stripe.com/v1/webhook_endpoints/${endpoint.id}`,
{ headers, method: "DELETE" },
);
if (del.ok) {
log(` deleted stale Stripe webhook endpoint ${endpoint.id}`);
} else {
warn(
` failed to delete stale Stripe webhook endpoint ${endpoint.id} (HTTP ${del.status})`,
);
}
} catch (err) {
warn(
` failed to delete stale Stripe webhook endpoint ${endpoint.id}: ${String(err)}`,
);
}
}
if (stale.length === 0) {
log(" no stale Stripe webhook endpoints to clean");
Expand Down
2 changes: 1 addition & 1 deletion e2e-payments/src/providers/sumup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* jscpd:ignore-start */
import type { Page } from "playwright";
import { log, warn } from "../log.ts";
import { log, warn } from "#e2e/log.ts";
import { clickFirst, fillCard, fillFirst, fillFrameInput } from "./card.ts";
import { configureProvider, hostedCheckout } from "./shared.ts";
import type { PaymentProvider } from "./types.ts";
Expand Down
4 changes: 2 additions & 2 deletions e2e-payments/src/providers/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* jscpd:ignore-start */
import type { Page } from "playwright";
import type { BrowserSession } from "../browser.ts";
import type { ProviderName } from "../config.ts";
import type { BrowserSession } from "#e2e/browser.ts";
import type { ProviderName } from "#e2e/config.ts";
/* jscpd:ignore-end */

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/bench/bundle-composition/model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { decode } from "@jridgewell/sourcemap-codec";
import { utf8ByteLength } from "../../../src/shared/bytes.ts";
import { utf8ByteLength } from "#src/shared/bytes.ts";

export interface BundleSourceMap {
mappings: string;
Expand Down
19 changes: 11 additions & 8 deletions scripts/bench/bundle-composition/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@
*/

import { stop, transform } from "esbuild";
import { utf8ByteLength } from "../../../src/shared/bytes.ts";
import { ASSETS } from "../../../src/shared/images/wasm-assets.ts";
import { minifyCss } from "../../css-minify.ts";
import { readStaticAssets } from "../../edge-bundle-lib.ts";
import { minifyCss } from "#scripts/css-minify.ts";
import { readStaticAssets } from "#scripts/edge-bundle-lib.ts";
import {
buildAssetPathsModule,
buildAssetsModule,
type PublishedAssetUrls,
} from "../../edge-bundle-modules.ts";
} from "#scripts/edge-bundle-modules.ts";
import {
ASSET_DEFS,
buildCdnAssets,
CDN_ASSET_DEFS,
} from "../../edge-cdn-assets.ts";
import { buildRemoteModule, wasmFilename } from "../../inline-jsquash-wasm.ts";
import { cleanCdnUrl } from "../../static-cdn.ts";
} from "#scripts/edge-cdn-assets.ts";
import {
buildRemoteModule,
wasmFilename,
} from "#scripts/inline-jsquash-wasm.ts";
import { cleanCdnUrl } from "#scripts/static-cdn.ts";
import { utf8ByteLength } from "#src/shared/bytes.ts";
import { ASSETS } from "#src/shared/images/wasm-assets.ts";
import { countJavaScriptAstNodes } from "./javascript-ast.ts";
import {
applicationArea,
Expand Down
2 changes: 1 addition & 1 deletion scripts/bench/cold-start/bundle-load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import { encodeBase64 } from "jsr:@std/encoding@^1.0.0/base64";
import { buildEdgeBundle } from "../../edge-bundle-lib.ts";
import { buildEdgeBundle } from "#scripts/edge-bundle-lib.ts";
import { spawnChildJson } from "./spawn-child.ts";
import { median, stripBase64Payloads, strippedChars } from "./strip-lib.ts";
import {
Expand Down
2 changes: 1 addition & 1 deletion scripts/bench/cold-start/first-request-child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
type Transaction,
type TransactionMode,
} from "@libsql/client";
import { timedRunner } from "#scripts/timed-run.ts";
import { setDb } from "#shared/db/client.ts";
import { beginTransaction, wrapExecute } from "#shared/db/libsql-call.ts";
import { setSuppressDebugLogs } from "#shared/log-settings.ts";
Expand All @@ -23,7 +24,6 @@ import {
setBuildTimestampForTest,
} from "#shared/update.ts";
import { serveHandler } from "#src/serve-app.ts";
import { timedRunner } from "../../timed-run.ts";
import { serveAndDrain } from "./serve-request.ts";
import { requireBenchmarkCatalogue, requiredEnv } from "./support.ts";

Expand Down
2 changes: 1 addition & 1 deletion scripts/edge-bundle-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { denoPlugins } from "@luca/esbuild-deno-loader";
import { fromFileUrl } from "@std/path";
import type { Plugin } from "esbuild";
import * as esbuild from "esbuild";
import { ASSETS } from "../src/shared/images/wasm-assets.ts";
import { ASSETS } from "#src/shared/images/wasm-assets.ts";
import { buildStaticAssets } from "./build-static-assets.ts";
import { minifyCss } from "./css-minify.ts";
import {
Expand Down
4 changes: 2 additions & 2 deletions scripts/edge-cdn-assets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CSS, JS, SVG, TEXT } from "../src/shared/content-types.ts";
import { ASSETS, readAsset } from "../src/shared/images/wasm-assets.ts";
import { CSS, JS, SVG, TEXT } from "#src/shared/content-types.ts";
import { ASSETS, readAsset } from "#src/shared/images/wasm-assets.ts";
import type { AssetDef } from "./edge-bundle-modules.ts";
import { wasmFilename } from "./inline-jsquash-wasm.ts";
import type { StaticCdnAsset } from "./static-cdn.ts";
Expand Down
2 changes: 1 addition & 1 deletion scripts/inline-jsquash-wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { encodeBase64 } from "jsr:@std/encoding@^1.0.0/base64";
import { fromFileUrl } from "@std/path";
import type { OnLoadResult, OnResolveResult, Plugin } from "esbuild";
import { map } from "#fp";
import { ASSETS, readAsset } from "../src/shared/images/wasm-assets.ts";
import { ASSETS, readAsset } from "#src/shared/images/wasm-assets.ts";
import { STATIC_CDN_REQUEST_TIMEOUT_MS } from "./static-cdn.ts";

type ExportAsset = Pick<(typeof ASSETS)[number], "exportName">;
Expand Down
2 changes: 1 addition & 1 deletion scripts/mutation/build-test-state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { writeTestState } from "../../test/test-utils/test-state.ts";
import { writeTestState } from "#test/test-utils/test-state.ts";

const dir = Deno.args[0];
if (!dir) throw new Error("A test-state output directory is required.");
Expand Down
2 changes: 1 addition & 1 deletion scripts/mutation/child-process.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { extendedBy } from "#fp";
import { commandExitCode } from "../deno-command.ts";
import { commandExitCode } from "#scripts/deno-command.ts";

/** Run `deno <args>` to completion and return its exit code. An explicit env
* is the child's complete environment, so removing a parent variable works. */
Expand Down
8 changes: 4 additions & 4 deletions scripts/mutation/evaluate.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { resolve } from "@std/path";
import { withCleanup } from "../cleanup.ts";
import { dim, yellow } from "../precommit/colors.ts";
import { projectRoot } from "../project-root.ts";
import type { StaticAssetBuild } from "../static-assets/session.ts";
import { withCleanup } from "#scripts/cleanup.ts";
import { dim, yellow } from "#scripts/precommit/colors.ts";
import { projectRoot } from "#scripts/project-root.ts";
import type { StaticAssetBuild } from "#scripts/static-assets/session.ts";
import {
mutantTestEnv,
runTests,
Expand Down
8 changes: 4 additions & 4 deletions scripts/mutation/execution.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TEST_STATE_DIR_ENV } from "../../test/test-utils/test-state-env.ts";
import { commandExitCode } from "../deno-command.ts";
import { projectRoot } from "../project-root.ts";
import { stripeMockEnv } from "../stripe-mock.ts";
import { commandExitCode } from "#scripts/deno-command.ts";
import { projectRoot } from "#scripts/project-root.ts";
import { stripeMockEnv } from "#scripts/stripe-mock.ts";
import { TEST_STATE_DIR_ENV } from "#test/test-utils/test-state-env.ts";
import { batchTestFiles } from "./batch.ts";
import { denoExitCode, envWith } from "./child-process.ts";
import type { Status } from "./summary.ts";
Expand Down
2 changes: 1 addition & 1 deletion scripts/mutation/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import { parseSync } from "npm:oxc-parser@0.132.0";
import { flatMap, unique } from "#fp";
import { lineColumnAt } from "../line-column.ts";
import { lineColumnAt } from "#scripts/line-column.ts";
import {
assignmentOperators,
assignmentOperatorsExhaustive,
Expand Down
6 changes: 3 additions & 3 deletions scripts/mutation/isolation-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import {
resolve,
SEPARATOR,
} from "@std/path";
import { openLockFile } from "../lock-file.ts";
import { rethrowUnlessNotFound } from "../not-found.ts";
import { projectRoot } from "../project-root.ts";
import { openLockFile } from "#scripts/lock-file.ts";
import { rethrowUnlessNotFound } from "#scripts/not-found.ts";
import { projectRoot } from "#scripts/project-root.ts";
import { denoExitCode } from "./child-process.ts";

export const MUTATION_RUNS_DIR = ".mutation-runs";
Expand Down
6 changes: 3 additions & 3 deletions scripts/mutation/isolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/

import { relative } from "@std/path";
import { errorMessage } from "#shared/error-message.ts";
import {
INHERIT_STDIO,
processExists,
stopProcess,
stopProcessNow,
} from "../process.ts";
import { projectRoot } from "../project-root.ts";
} from "#scripts/process.ts";
import { projectRoot } from "#scripts/project-root.ts";
import { errorMessage } from "#shared/error-message.ts";
import {
envWith,
offTerminationSignals,
Expand Down
4 changes: 2 additions & 2 deletions scripts/mutation/run-file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dim, green, red, yellow } from "../precommit/colors.ts";
import { write } from "../precommit/write.ts";
import { dim, green, red, yellow } from "#scripts/precommit/colors.ts";
import { write } from "#scripts/precommit/write.ts";
import { evaluateMutant, type FileMutationPlan } from "./evaluate.ts";
import { type StaticGate, type TestRunConfig, testEnv } from "./execution.ts";
import { type IgnoreList, isIgnored } from "./ignore.ts";
Expand Down
12 changes: 6 additions & 6 deletions scripts/mutation/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
* detected).
*/

import { TEST_STATE_DIR_ENV } from "../../test/test-utils/test-state-env.ts";
import { dim, red, yellow } from "../precommit/colors.ts";
import { write } from "../precommit/write.ts";
import { projectRoot } from "../project-root.ts";
import type { StaticAssetBuild } from "../static-assets/session.ts";
import { withTestHarness } from "../test-harness.ts";
import { dim, red, yellow } from "#scripts/precommit/colors.ts";
import { write } from "#scripts/precommit/write.ts";
import { projectRoot } from "#scripts/project-root.ts";
import type { StaticAssetBuild } from "#scripts/static-assets/session.ts";
import { withTestHarness } from "#scripts/test-harness.ts";
import { TEST_STATE_DIR_ENV } from "#test/test-utils/test-state-env.ts";
import {
offTerminationSignals,
onTerminationSignals,
Expand Down
2 changes: 1 addition & 1 deletion scripts/mutation/state-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import { fromFileUrl } from "@std/path";
import * as v from "valibot";
import { runCommand } from "../precommit/git.ts";
import { runCommand } from "#scripts/precommit/git.ts";

/** The module whose import graph produces the prebuilt test state. */
export const STATE_BUILDER_ROOT = "test/test-utils/test-state.ts";
Expand Down
Loading