Block ingest for retired WDMI slugs, purge project data via migration, remove WDMI runbooks, and add offboard-project helper for future retirements. Co-authored-by: Cursor <[email protected]>
593 lines
20 KiB
TypeScript
593 lines
20 KiB
TypeScript
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import mysql from "mysql2/promise";
|
|
import type { RowDataPacket } from "mysql2";
|
|
import { buildApp } from "./buildApp.js";
|
|
import type { IngestEnv } from "./config/env.js";
|
|
import { sha256Hex } from "./lib/hash.js";
|
|
|
|
const _testUrl = process.env.ERROR_REPORTING_TEST_DATABASE_URL;
|
|
|
|
describe.skipIf(!_testUrl)("two-project passive ingest (BIT-179)", () => {
|
|
let _pool: mysql.Pool;
|
|
let _app: Awaited<ReturnType<typeof buildApp>>;
|
|
const _tokenA = "er_tst_a_secret_one";
|
|
const _tokenB = "er_tst_b_secret_two";
|
|
const _tokenC = "er_tst_c_rate_limited_key";
|
|
let _projectIdA = "";
|
|
let _projectIdB = "";
|
|
|
|
beforeAll(async () => {
|
|
_pool = mysql.createPool({ uri: _testUrl!, connectionLimit: 4, waitForConnections: true });
|
|
const _c = await _pool.getConnection();
|
|
try {
|
|
await _c.query("SET FOREIGN_KEY_CHECKS = 0");
|
|
await _c.query(`TRUNCATE TABLE er_ingest_idempotency`);
|
|
await _c.query(`TRUNCATE TABLE er_incident_occurrences`);
|
|
await _c.query(`TRUNCATE TABLE er_incidents`);
|
|
await _c.query(`TRUNCATE TABLE er_ingest_keys`);
|
|
await _c.query(`TRUNCATE TABLE er_projects`);
|
|
await _c.query("SET FOREIGN_KEY_CHECKS = 1");
|
|
} finally {
|
|
_c.release();
|
|
}
|
|
await _pool.execute(`INSERT INTO er_projects (slug, name) VALUES ('pa', 'Project A')`);
|
|
await _pool.execute(`INSERT INTO er_projects (slug, name) VALUES ('pb', 'Project B')`);
|
|
const [rows] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT CAST(id AS CHAR) AS id, slug FROM er_projects WHERE slug IN ('pa', 'pb') ORDER BY slug`,
|
|
);
|
|
if (rows.length < 2) {
|
|
throw new Error("seed projects failed");
|
|
}
|
|
_projectIdA = String((rows[0] as { id: string }).id);
|
|
_projectIdB = String((rows[1] as { id: string }).id);
|
|
await _pool.execute(
|
|
`INSERT INTO er_ingest_keys (project_id, label, token_prefix, token_hash, status)
|
|
VALUES (?, 'default', 'tok_pr_a', ?, 'active')`,
|
|
[_projectIdA, sha256Hex(_tokenA)],
|
|
);
|
|
await _pool.execute(
|
|
`INSERT INTO er_ingest_keys (project_id, label, token_prefix, token_hash, status)
|
|
VALUES (?, 'default', 'tok_pr_b', ?, 'active')`,
|
|
[_projectIdB, sha256Hex(_tokenB)],
|
|
);
|
|
await _pool.execute(
|
|
`INSERT INTO er_ingest_keys (project_id, label, token_prefix, token_hash, status, rate_limit_max, rate_limit_window_ms)
|
|
VALUES (?, 'ratelimit', 'tok_rl_c', ?, 'active', 2, 60000)`,
|
|
[_projectIdA, sha256Hex(_tokenC)],
|
|
);
|
|
const _env: IngestEnv = {
|
|
PORT: 0,
|
|
DATABASE_URL: _testUrl!,
|
|
INGEST_RATE_LIMIT_MAX: 10_000,
|
|
INGEST_RATE_LIMIT_WINDOW_MS: 60_000,
|
|
INGEST_ANON_IP_MAX: 10_000,
|
|
INGEST_ANON_IP_WINDOW_MS: 60_000,
|
|
NODE_ENV: "test",
|
|
};
|
|
_app = await buildApp({ env: _env, pool: _pool });
|
|
await _app.ready();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await _app.close();
|
|
await _pool.end();
|
|
});
|
|
|
|
it("ingests distinct events for project A and B with separate keys", async () => {
|
|
const _resA = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: { authorization: `Bearer ${_tokenA}` },
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T10:00:00.000Z",
|
|
level: "error",
|
|
message: "failure from project A",
|
|
fingerprint: "fp-a-1",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_resA.statusCode).toBe(200);
|
|
const _bodyA = JSON.parse(_resA.body) as {
|
|
results: Array<{ incident_id: string; fingerprint: string }>;
|
|
};
|
|
expect(_bodyA.results).toHaveLength(1);
|
|
expect(_bodyA.results[0]?.fingerprint).toBe("fp-a-1");
|
|
|
|
const _resB = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: { "x-api-key": _tokenB },
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T10:00:01.000Z",
|
|
level: "warn",
|
|
message: "warning from project B",
|
|
fingerprint: "fp-b-1",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_resB.statusCode).toBe(200);
|
|
const _bodyB = JSON.parse(_resB.body) as {
|
|
results: Array<{ incident_id: string; fingerprint: string }>;
|
|
};
|
|
expect(_bodyB.results[0]?.fingerprint).toBe("fp-b-1");
|
|
expect(_bodyB.results[0]?.incident_id).not.toBe(_bodyA.results[0]?.incident_id);
|
|
|
|
const [checkA] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
expect(Number((checkA[0] as { c: number }).c)).toBe(1);
|
|
const [checkB] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdB],
|
|
);
|
|
expect(Number((checkB[0] as { c: number }).c)).toBe(1);
|
|
});
|
|
|
|
it("exposes error_hub_last_event_timestamp on /metrics after stored ingest (BIT-4903)", async () => {
|
|
const _occurredIso = "2026-04-21T12:00:00.000Z";
|
|
const _expectedSec = Math.floor(Date.parse(_occurredIso) / 1000);
|
|
const _res = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: { authorization: `Bearer ${_tokenA}` },
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: _occurredIso,
|
|
level: "error",
|
|
message: "error hub prometheus metric probe",
|
|
fingerprint: "fp-error-hub-metric-1",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_res.statusCode).toBe(200);
|
|
const _metrics = await _app.inject({ method: "GET", url: "/metrics" });
|
|
expect(_metrics.statusCode).toBe(200);
|
|
expect(_metrics.body).toContain(
|
|
`error_hub_last_event_timestamp{project_slug="pa"} ${_expectedSec}`,
|
|
);
|
|
});
|
|
|
|
it("accepts unknown event-level fields (forward-compatible for CRM / deploy smokes)", async () => {
|
|
const _res = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: { authorization: `Bearer ${_tokenA}` },
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T10:05:00.000Z",
|
|
level: "error",
|
|
message: "probe with extra keys",
|
|
fingerprint: "fp-extra-keys-1",
|
|
release: "1.0.0",
|
|
environment: "production",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_res.statusCode).toBe(200);
|
|
const _body = JSON.parse(_res.body) as {
|
|
results: Array<{ incident_id: string; fingerprint: string }>;
|
|
};
|
|
expect(_body.results).toHaveLength(1);
|
|
expect(_body.results[0]?.fingerprint).toBe("fp-extra-keys-1");
|
|
});
|
|
|
|
it("accepts unknown top-level batch fields (CRM direct-forward smokes)", async () => {
|
|
const _res = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: { authorization: `Bearer ${_tokenA}` },
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T10:06:00.000Z",
|
|
level: "error",
|
|
message: "probe with extra batch keys",
|
|
fingerprint: "fp-extra-batch-keys-1",
|
|
},
|
|
],
|
|
forward_source: "crm_smoke",
|
|
client_batch_id: "batch-xyz",
|
|
},
|
|
});
|
|
expect(_res.statusCode).toBe(200);
|
|
const _body = JSON.parse(_res.body) as {
|
|
results: Array<{ incident_id: string; fingerprint: string }>;
|
|
};
|
|
expect(_body.results).toHaveLength(1);
|
|
expect(_body.results[0]?.fingerprint).toBe("fp-extra-batch-keys-1");
|
|
});
|
|
|
|
it("skips known browser noise without inserting rows", async () => {
|
|
const [before] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
const _nBefore = Number((before[0] as { c: number }).c);
|
|
const _res = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: { authorization: `Bearer ${_tokenA}` },
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T10:30:00.000Z",
|
|
level: "error",
|
|
message: "ResizeObserver loop completed with undelivered notifications.",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_res.statusCode).toBe(200);
|
|
const _body = JSON.parse(_res.body) as {
|
|
noise_filtered_count: number;
|
|
results: Array<{ skipped?: boolean; rule_id?: string }>;
|
|
};
|
|
expect(_body.noise_filtered_count).toBe(1);
|
|
expect(_body.results[0]?.skipped).toBe(true);
|
|
expect(_body.results[0]?.rule_id).toBe("resize_observer_loop");
|
|
const [after] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
expect(Number((after[0] as { c: number }).c)).toBe(_nBefore);
|
|
});
|
|
|
|
it("skips BIT-SMOKE- intentional probe events without inserting rows", async () => {
|
|
const [before] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
const _nBefore = Number((before[0] as { c: number }).c);
|
|
const _res = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: { authorization: `Bearer ${_tokenA}` },
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-04-05T10:00:00.000Z",
|
|
level: "error",
|
|
message: "Error: BIT-SMOKE-CRM-DIRECT-INGEST",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_res.statusCode).toBe(200);
|
|
const _body = JSON.parse(_res.body) as {
|
|
noise_filtered_count: number;
|
|
results: Array<{ skipped?: boolean; rule_id?: string }>;
|
|
};
|
|
expect(_body.noise_filtered_count).toBe(1);
|
|
expect(_body.results[0]?.skipped).toBe(true);
|
|
expect(_body.results[0]?.rule_id).toBe("bitreport_smoke_marker");
|
|
const [after] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
expect(Number((after[0] as { c: number }).c)).toBe(_nBefore);
|
|
});
|
|
|
|
it("skips BIT-SMOKE- in stack_trace when message omits marker (CRM-style payload)", async () => {
|
|
const [before] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
const _nBefore = Number((before[0] as { c: number }).c);
|
|
const _res = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: { authorization: `Bearer ${_tokenA}` },
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-04-05T10:05:00.000Z",
|
|
level: "error",
|
|
message: "Exception",
|
|
stack_trace: "Error: BIT-SMOKE-CRM-MAIN-DIRECT\n#0 smoke",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_res.statusCode).toBe(200);
|
|
const _body = JSON.parse(_res.body) as {
|
|
noise_filtered_count: number;
|
|
results: Array<{ skipped?: boolean; rule_id?: string }>;
|
|
};
|
|
expect(_body.noise_filtered_count).toBe(1);
|
|
expect(_body.results[0]?.skipped).toBe(true);
|
|
expect(_body.results[0]?.rule_id).toBe("bitreport_smoke_marker");
|
|
const [after] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
expect(Number((after[0] as { c: number }).c)).toBe(_nBefore);
|
|
});
|
|
|
|
it("skips BIT-SMOKE-CRM-DIRECT-FWD from /smoke/crm.php without inserting rows (BIT-933)", async () => {
|
|
const [before] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
const _nBefore = Number((before[0] as { c: number }).c);
|
|
const _res = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: { authorization: `Bearer ${_tokenA}` },
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-04-05T10:07:00.000Z",
|
|
level: "error",
|
|
message: "BIT-SMOKE-CRM-DIRECT-FWD",
|
|
stack_trace: "Error: BIT-SMOKE-CRM-DIRECT-FWD\n#0 smoke",
|
|
context: { file_path: "/smoke/crm.php", line_number: "1" },
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_res.statusCode).toBe(200);
|
|
const _body = JSON.parse(_res.body) as {
|
|
noise_filtered_count: number;
|
|
results: Array<{ skipped?: boolean; rule_id?: string }>;
|
|
};
|
|
expect(_body.noise_filtered_count).toBe(1);
|
|
expect(_body.results[0]?.skipped).toBe(true);
|
|
expect(_body.results[0]?.rule_id).toBe("bitreport_smoke_marker");
|
|
const [after] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
expect(Number((after[0] as { c: number }).c)).toBe(_nBefore);
|
|
});
|
|
|
|
it("skips deploy ingest live-check failure ribbon without inserting rows", async () => {
|
|
const [before] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
const _nBefore = Number((before[0] as { c: number }).c);
|
|
const _res = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: { authorization: `Bearer ${_tokenA}` },
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-04-05T10:10:00.000Z",
|
|
level: "critical",
|
|
message: "BIT-SMOKE error hub ingest live check",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_res.statusCode).toBe(200);
|
|
const _body = JSON.parse(_res.body) as {
|
|
noise_filtered_count: number;
|
|
results: Array<{ skipped?: boolean; rule_id?: string }>;
|
|
};
|
|
expect(_body.noise_filtered_count).toBe(1);
|
|
expect(_body.results[0]?.skipped).toBe(true);
|
|
expect(_body.results[0]?.rule_id).toBe("bitreport_smoke_marker");
|
|
const [after] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
|
|
[_projectIdA],
|
|
);
|
|
expect(Number((after[0] as { c: number }).c)).toBe(_nBefore);
|
|
});
|
|
|
|
it("replays identical idempotent requests", async () => {
|
|
const _payload = {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T11:00:00.000Z",
|
|
level: "info",
|
|
message: "idempotent row",
|
|
fingerprint: "fp-idem-1",
|
|
},
|
|
],
|
|
};
|
|
const _headers = {
|
|
authorization: `Bearer ${_tokenA}`,
|
|
"idempotency-key": "idem-key-1",
|
|
};
|
|
const _first = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: _headers,
|
|
payload: _payload,
|
|
});
|
|
expect(_first.statusCode).toBe(200);
|
|
const _second = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: _headers,
|
|
payload: _payload,
|
|
});
|
|
expect(_second.statusCode).toBe(200);
|
|
expect(_second.body).toBe(_first.body);
|
|
const [occ] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c FROM er_incident_occurrences`,
|
|
);
|
|
expect(Number((occ[0] as { c: number }).c)).toBe(3);
|
|
});
|
|
|
|
it("parallel identical idempotent requests yield one stored occurrence", async () => {
|
|
const _payload = {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T14:00:00.000Z",
|
|
level: "info",
|
|
message: "parallel idempotent ingest probe",
|
|
fingerprint: "fp-parallel-idem-probe",
|
|
},
|
|
],
|
|
};
|
|
const _headers = {
|
|
authorization: `Bearer ${_tokenA}`,
|
|
"idempotency-key": "idem-parallel-probe-1",
|
|
};
|
|
const [_r1, _r2] = await Promise.all([
|
|
_app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: _headers,
|
|
payload: _payload,
|
|
}),
|
|
_app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: _headers,
|
|
payload: _payload,
|
|
}),
|
|
]);
|
|
expect(_r1.statusCode).toBe(200);
|
|
expect(_r2.statusCode).toBe(200);
|
|
expect(_r1.body).toBe(_r2.body);
|
|
const [occ] = await _pool.execute<RowDataPacket[]>(
|
|
`SELECT COUNT(*) AS c
|
|
FROM er_incident_occurrences o
|
|
INNER JOIN er_incidents i ON i.id = o.incident_id
|
|
WHERE i.project_id = ?
|
|
AND o.message = 'parallel idempotent ingest probe'`,
|
|
[_projectIdA],
|
|
);
|
|
expect(Number((occ[0] as { c: number }).c)).toBe(1);
|
|
});
|
|
|
|
it("returns 409 when idempotency key is reused with a different body", async () => {
|
|
const _headers = {
|
|
authorization: `Bearer ${_tokenA}`,
|
|
"idempotency-key": "idem-key-2",
|
|
};
|
|
const _r1 = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: _headers,
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T12:00:00.000Z",
|
|
level: "error",
|
|
message: "first",
|
|
fingerprint: "fp-conflict-a",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_r1.statusCode).toBe(200);
|
|
const _r2 = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: _headers,
|
|
payload: {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T12:00:00.000Z",
|
|
level: "error",
|
|
message: "second different",
|
|
fingerprint: "fp-conflict-b",
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(_r2.statusCode).toBe(409);
|
|
});
|
|
|
|
it("returns 429 when per-key ingest limit is exceeded (er_ingest_keys rate columns)", async () => {
|
|
const _payload = (fp: string) => ({
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T13:00:00.000Z",
|
|
level: "error",
|
|
message: "rate limit probe",
|
|
fingerprint: fp,
|
|
},
|
|
],
|
|
});
|
|
const _h = { authorization: `Bearer ${_tokenC}` };
|
|
const _r1 = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: _h,
|
|
payload: _payload("fp-rl-1"),
|
|
});
|
|
const _r2 = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: _h,
|
|
payload: _payload("fp-rl-2"),
|
|
});
|
|
const _r3 = await _app.inject({
|
|
method: "POST",
|
|
url: "/v1/ingest/events",
|
|
headers: _h,
|
|
payload: _payload("fp-rl-3"),
|
|
});
|
|
expect(_r1.statusCode).toBe(200);
|
|
expect(_r2.statusCode).toBe(200);
|
|
expect(_r3.statusCode).toBe(429);
|
|
const _j = JSON.parse(_r3.body) as { error?: string };
|
|
expect(_j.error).toBe("rate_limited");
|
|
});
|
|
|
|
it("returns 429 for anonymous callers after the IP budget (INGEST_ANON_*)", async () => {
|
|
const _env: IngestEnv = {
|
|
PORT: 0,
|
|
DATABASE_URL: _testUrl!,
|
|
INGEST_RATE_LIMIT_MAX: 10_000,
|
|
INGEST_RATE_LIMIT_WINDOW_MS: 60_000,
|
|
INGEST_ANON_IP_MAX: 2,
|
|
INGEST_ANON_IP_WINDOW_MS: 60_000,
|
|
NODE_ENV: "test",
|
|
};
|
|
const _anonApp = await buildApp({ env: _env, pool: _pool });
|
|
await _anonApp.ready();
|
|
const _payload = {
|
|
events: [
|
|
{
|
|
schema_version: 1,
|
|
occurred_at: "2026-03-22T14:00:00.000Z",
|
|
level: "error",
|
|
message: "no auth",
|
|
fingerprint: "fp-anon",
|
|
},
|
|
],
|
|
};
|
|
expect((await _anonApp.inject({ method: "POST", url: "/v1/ingest/events", payload: _payload })).statusCode).toBe(
|
|
401,
|
|
);
|
|
expect((await _anonApp.inject({ method: "POST", url: "/v1/ingest/events", payload: _payload })).statusCode).toBe(
|
|
401,
|
|
);
|
|
const _third = await _anonApp.inject({ method: "POST", url: "/v1/ingest/events", payload: _payload });
|
|
expect(_third.statusCode).toBe(429);
|
|
await _anonApp.close();
|
|
});
|
|
});
|