refactor: remove dead _routeName param, eliminate two ! non-null assertions
- with-timing: drop unused `_routeName` parameter from withTiming() and all test call sites; the path is taken from the live request URL and normalized later in computeApiStats — the explicit name was dead weight - log-reader: extract `entries[i].cacheStats` to a temp variable so TypeScript can narrow the type; removes the `!` assertion - retrospective: destructure `opts.sessionId` before use in filter callback; removes the `!` assertion on an optional-chained value No behaviour change — all 508 core tests and 413 passing web tests green. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9e78ec6c2b
commit
92564487cf
|
|
@ -261,8 +261,9 @@ export function computeApiStats(entries: ApiLogEntry[]): ApiPerfResult {
|
|||
|
||||
let latestCacheStats: ApiLogEntry["cacheStats"] | null = null;
|
||||
for (let i = entries.length - 1; i >= 0; i--) {
|
||||
if (entries[i].cacheStats) {
|
||||
latestCacheStats = entries[i].cacheStats!;
|
||||
const stats = entries[i].cacheStats;
|
||||
if (stats) {
|
||||
latestCacheStats = stats;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,8 +113,9 @@ export function loadRetrospectives(
|
|||
}
|
||||
|
||||
// Filter by session ID — match exact session followed by timestamp delimiter
|
||||
if (opts?.sessionId) {
|
||||
files = files.filter((f) => f.startsWith(`${opts.sessionId!}-`));
|
||||
const sessionIdFilter = opts?.sessionId;
|
||||
if (sessionIdFilter) {
|
||||
files = files.filter((f) => f.startsWith(`${sessionIdFilter}-`));
|
||||
}
|
||||
|
||||
const results: Retrospective[] = [];
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ describe("withTiming", () => {
|
|||
new Response(JSON.stringify({ ok: true }), { status: 200 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions");
|
||||
await wrapped(req);
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ describe("withTiming", () => {
|
|||
);
|
||||
const ctx = { params: { id: "abc" } };
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions/abc");
|
||||
await wrapped(req, ctx);
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ describe("withTiming", () => {
|
|||
});
|
||||
const innerHandler = vi.fn().mockResolvedValue(originalResponse);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions");
|
||||
const result = await wrapped(req);
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ describe("withTiming", () => {
|
|||
new Response("ok", { status: 200 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions");
|
||||
await wrapped(req);
|
||||
|
||||
|
|
@ -91,7 +91,7 @@ describe("withTiming", () => {
|
|||
new Response("created", { status: 201 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/spawn", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ session: "ao-1" }),
|
||||
|
|
@ -108,7 +108,7 @@ describe("withTiming", () => {
|
|||
new Response("not found", { status: 404 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions/unknown");
|
||||
await wrapped(req);
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ describe("withTiming", () => {
|
|||
new Response("internal error", { status: 500 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions");
|
||||
await wrapped(req);
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ describe("withTiming", () => {
|
|||
new Error("database connection failed"),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions");
|
||||
const result = await wrapped(req);
|
||||
|
||||
|
|
@ -155,7 +155,7 @@ describe("withTiming", () => {
|
|||
it("handles non-Error thrown values", async () => {
|
||||
const innerHandler = vi.fn().mockRejectedValue("string error");
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions");
|
||||
const result = await wrapped(req);
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ describe("withTiming", () => {
|
|||
return new Response("ok", { status: 200 });
|
||||
});
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions");
|
||||
await wrapped(req);
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ describe("extractSessionId (indirect via withTiming)", () => {
|
|||
new Response("ok", { status: 200 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions/abc123");
|
||||
await wrapped(req);
|
||||
|
||||
|
|
@ -201,7 +201,7 @@ describe("extractSessionId (indirect via withTiming)", () => {
|
|||
new Response("ok", { status: 200 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions/ao-1/kill");
|
||||
await wrapped(req);
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ describe("extractSessionId (indirect via withTiming)", () => {
|
|||
new Response("ok", { status: 200 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/sessions");
|
||||
await wrapped(req);
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ describe("extractSessionId (indirect via withTiming)", () => {
|
|||
new Response("ok", { status: 200 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/prs/42/merge");
|
||||
await wrapped(req);
|
||||
|
||||
|
|
@ -240,7 +240,7 @@ describe("extractSessionId (indirect via withTiming)", () => {
|
|||
new Response("ok", { status: 200 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request("http://localhost:3000/api/config");
|
||||
await wrapped(req);
|
||||
|
||||
|
|
@ -253,7 +253,7 @@ describe("extractSessionId (indirect via withTiming)", () => {
|
|||
new Response("ok", { status: 200 }),
|
||||
);
|
||||
|
||||
const wrapped = withTiming(innerHandler, "test-route");
|
||||
const wrapped = withTiming(innerHandler);
|
||||
const req = new Request(
|
||||
"http://localhost:3000/api/sessions/session%20with%20spaces",
|
||||
);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ function extractSessionId(path: string): string | null {
|
|||
* Wrap a route handler with timing instrumentation.
|
||||
* Logs method, path, status code, and duration for every request.
|
||||
*/
|
||||
export function withTiming(handler: RouteHandler, _routeName: string): RouteHandler {
|
||||
export function withTiming(handler: RouteHandler): RouteHandler {
|
||||
return async (req: Request, ctx?: unknown) => {
|
||||
const start = Date.now();
|
||||
const url = new URL(req.url);
|
||||
|
|
|
|||
Loading…
Reference in New Issue