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
3 changes: 2 additions & 1 deletion .jscpd.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"minTokens": 23,
"path": [
"src",
"e2e-payments"
"e2e-payments",
"scripts"
]
}
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test:raw": "deno task build:static && deno test --no-check --allow-net --allow-env --allow-read --allow-write --allow-run --allow-sys --allow-ffi test/",
"lint": "deno run -A scripts/biome.ts check --write --error-on-warnings src test scripts cli",
"lint:ci": "deno run -A scripts/biome.ts check --error-on-warnings src test scripts cli",
"typecheck": "deno check src/**/*.ts src/**/*.tsx test/**/*.ts cli/**/*.ts && deno check --config=e2e-payments/deno.json e2e-payments/src/**/*.ts",
"typecheck": "deno check src/**/*.ts src/**/*.tsx test/**/*.ts cli/**/*.ts scripts/mutation.ts scripts/mutation/**/*.ts scripts/precommit.ts scripts/precommit/**/*.ts && deno check --config=e2e-payments/deno.json e2e-payments/src/**/*.ts",
"cpd": "deno run -A scripts/cpd.ts --config .jscpd.json && deno run -A scripts/cpd.ts --config .jscpd.test.json",
"precommit": "deno run -A scripts/precommit.ts",
"precommit:mutation": "deno run -A scripts/precommit-mutation.ts",
Expand Down
20 changes: 11 additions & 9 deletions scripts/bench/bunny-crypto-smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ const KEY = crypto.getRandomValues(new Uint8Array(32));
const SAMPLE = "attendee-pii-value-12345@example.com";
const ITERS = 2000;

/** Run `body` ITERS times and return the elapsed milliseconds. */
const timeLoop = async (body: () => Promise<void> | void): Promise<number> => {
const t0 = performance.now();
for (let i = 0; i < ITERS; i++) await body();
return performance.now() - t0;
};

// --- crypto.subtle (current approach) ---
const subtleKey = await crypto.subtle.importKey(
"raw",
Expand Down Expand Up @@ -85,19 +92,14 @@ const run = async (): Promise<Result> => {
out.subtleDecryptsNode = dec.decode(await subtleDec(n.iv, n.ct)) === SAMPLE;

// 4) Micro-bench (small payload, the hot path)
let t0 = performance.now();
for (let i = 0; i < ITERS; i++) {
const subtleMs = await timeLoop(async () => {
const x = await subtleEnc(pt);
await subtleDec(x.iv, x.ct);
}
const subtleMs = performance.now() - t0;

t0 = performance.now();
for (let i = 0; i < ITERS; i++) {
});
const nodeMs = await timeLoop(() => {
const x = nodeEnc(pt);
nodeDec(x.iv, x.ct);
}
const nodeMs = performance.now() - t0;
});

out.iterations = ITERS;
out.subtle_us_per_op = +((subtleMs * 1000) / ITERS).toFixed(2);
Expand Down
8 changes: 2 additions & 6 deletions scripts/build-site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

import { builderApi } from "#shared/builder.ts";
import { runBuildEdge } from "./run-build-edge.ts";

const [siteName] = Deno.args;
if (!siteName) {
Expand All @@ -29,12 +30,7 @@ const repoRoot = new URL("..", import.meta.url).pathname;
const bundlePath = `${repoRoot}bunny-script.ts`;

console.log("Building edge bundle…");
const build = await new Deno.Command(Deno.execPath(), {
args: ["task", "build:edge"],
cwd: repoRoot,
stderr: "inherit",
stdout: "inherit",
}).output();
const build = await runBuildEdge(repoRoot);
if (!build.success) {
console.error("build:edge failed");
Deno.exit(build.code);
Expand Down
57 changes: 4 additions & 53 deletions scripts/compact-test-reporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { isAbsolute, relative } from "node:path";
import { fileURLToPath } from "node:url";
import { toDisplayPath } from "./project-root.ts";
import { readStream } from "./stream-lines.ts";

type Location = {
file: string;
Expand Down Expand Up @@ -188,12 +190,6 @@ const countMatches = (text: string, re: RegExp): number => {
return count;
};

const toDisplayPath = (cwd: string, file: string): string => {
if (!isAbsolute(file)) return file.replace(/^\.\//, "");
const rel = relative(cwd, file);
return rel.startsWith("..") ? file : rel || ".";
};

const locationFromDiagnostic = (
cwd: string,
diagnostic: TapDiagnostic,
Expand Down Expand Up @@ -465,51 +461,6 @@ export class CompactTapReporter {
}
}

const readLines = async (
stream: ReadableStream<Uint8Array>,
onLine: (line: string) => void,
): Promise<void> => {
const reader = stream.getReader();
const decoder = new TextDecoder();
let buffered = "";

try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffered += decoder.decode(value, { stream: true });
const lines = buffered.split(/\r?\n/);
buffered = lines.pop() ?? "";
for (const line of lines) onLine(line);
}
} finally {
buffered += decoder.decode();
if (buffered) onLine(buffered);
reader.releaseLock();
}
};

const readText = async (
stream: ReadableStream<Uint8Array>,
): Promise<string> => {
const reader = stream.getReader();
const decoder = new TextDecoder();
let text = "";

try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
text += decoder.decode(value, { stream: true });
}
} finally {
text += decoder.decode();
reader.releaseLock();
}

return text;
};

const usefulStderr = (stderr: string): string =>
stderr
.split(/\r?\n/)
Expand Down Expand Up @@ -569,10 +520,10 @@ export const runCompactDenoTest = async (
hideProgress: Boolean(options.env.CI || options.env.GITHUB_ACTIONS),
});

const stdoutTask = readLines(child.stdout, (line) =>
const stdoutTask = readStream(child.stdout, (line) =>
reporter.consumeLine(line),
);
const stderrTask = readText(child.stderr);
const stderrTask = readStream(child.stderr);
const status = await child.status;
await stdoutTask;
const stderrText = await stderrTask;
Expand Down
32 changes: 20 additions & 12 deletions scripts/deploy-edge-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export type FetchText = (

export type BunnyDeployResult = { ok: true } | { error: string; ok: false };

/** Shared shape of the script-code operations (upload, deploy). */
type ScriptCodeFn = (
scriptId: string,
code: string,
accessKey: string,
fetchText: FetchText,
) => Promise<BunnyDeployResult>;

export interface BuildResult {
code: number;
success: boolean;
Expand Down Expand Up @@ -102,12 +110,12 @@ const postScriptAction = async (
};
};

export const uploadScriptCode = (
scriptId: string,
code: string,
accessKey: string,
fetchText: FetchText,
): Promise<BunnyDeployResult> =>
export const uploadScriptCode: ScriptCodeFn = (
scriptId,
code,
accessKey,
fetchText,
) =>
postScriptAction(
scriptId,
"code",
Expand All @@ -131,12 +139,12 @@ export const publishScript = (
fetchText,
);

export const deployScriptCode = async (
scriptId: string,
code: string,
accessKey: string,
fetchText: FetchText,
): Promise<BunnyDeployResult> => {
export const deployScriptCode: ScriptCodeFn = async (
scriptId,
code,
accessKey,
fetchText,
) => {
const upload = await uploadScriptCode(scriptId, code, accessKey, fetchText);
if (!upload.ok) return upload;
return publishScript(scriptId, accessKey, fetchText);
Expand Down
12 changes: 1 addition & 11 deletions scripts/deploy-edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { fromFileUrl } from "@std/path";
import { type FetchTextResult, runDeployEdge } from "./deploy-edge-lib.ts";
import { runBuildEdge } from "./run-build-edge.ts";

const repoRoot = fromFileUrl(new URL("..", import.meta.url));
const bundlePath = fromFileUrl(new URL("../bunny-script.ts", import.meta.url));
Expand All @@ -18,17 +19,6 @@ const fetchText = async (
};
};

const runBuildEdge = async (cwd: string) => {
const build = await new Deno.Command(Deno.execPath(), {
args: ["task", "build:edge"],
cwd,
stderr: "inherit",
stdout: "inherit",
}).output();

return { code: build.code, success: build.success };
};

const exitCode = await runDeployEdge({
args: Deno.args,
bundlePath,
Expand Down
10 changes: 2 additions & 8 deletions scripts/find-slow-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@
*/

import {
JUNIT_PATH,
readSlowTestsReport,
SLOW_TEST_THRESHOLD_MS,
} from "./test-durations.ts";
import { runTests, withTestHarness } from "./test-harness.ts";
import { runSuiteWithHarness } from "./test-harness.ts";

/** Main: run the suite, then fail if any test exceeded the slow-test threshold. */
const main = async (): Promise<void> => {
// Remove any stale JUnit file so a killed prior run can't surface its
// timings; `deno test --junit-path` rewrites it on a completed run.
await Deno.remove(JUNIT_PATH).catch(() => {});
const exitCode = await withTestHarness(() =>
runTests(["test/"], false, JUNIT_PATH),
);
const exitCode = await runSuiteWithHarness(false);

// Propagate a suite failure before judging timings: a failed run may have
// written an incomplete JUnit file, whose timings would be misleading.
Expand Down
Loading