wishforge-ide/tests/telemetry.test.ts
eust-w 0ef99b1e6d style: add Prettier and EditorConfig, format the codebase
Adds prettier 3.9.8 (exact) with a shared config (single quotes,
120 columns, trailing commas), .prettierignore, .editorconfig and the
`format` / `format:check` scripts, then formats all TypeScript,
JavaScript, CSS, JSON and YAML sources.

Purely mechanical: no behaviour change. Typecheck passes, the vitest
suite and the 74 IDE node tests produce the same results as before
(socket-binding tests still cannot run inside this sandbox).
Previously the longest source line was ~3000 characters; reviewing the
following semantic changes now produces readable diffs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:32:43 +08:00

52 lines
1.6 KiB
TypeScript

import { EventEmitter } from 'node:events';
import { expect, it } from 'vitest';
import type { Request, Response } from 'express';
import { observability } from '../apps/api/src/telemetry.js';
it('protects metrics and uses route templates without query strings or tokens', async () => {
const telemetry = await observability({ WF_METRICS_TOKEN: 'm'.repeat(40) });
try {
const response = Object.assign(new EventEmitter(), { statusCode: 200 });
telemetry.middleware(
{
path: '/v1/runs/secret-id',
method: 'GET',
headers: { authorization: 'Bearer secret-value' },
route: { path: '/v1/runs/:id' },
} as Request,
response as Response,
() => {},
);
response.emit('finish');
let body = '';
let status = 200;
const output = {
status(code: number) {
status = code;
return this;
},
end() {
return this;
},
type() {
return this;
},
setHeader() {
return this;
},
send(value: string) {
body = value;
return this;
},
} as unknown as Response;
await telemetry.metrics({ header: () => undefined } as unknown as Request, output);
expect(status).toBe(401);
await telemetry.metrics({ header: () => `Bearer ${'m'.repeat(40)}` } as unknown as Request, output);
expect(body).toContain('wishforge_http_requests_total');
expect(body).toContain('/v1/runs/:id');
expect(body).not.toContain('secret-id');
expect(body).not.toContain('secret-value');
} finally {
await telemetry.close();
}
});