LibreChat/e2e/specs/mock/scenarios/cache-audit-redaction.spec.ts
Marco Beretta f7a2ed1f97
🧹 fix: Stop Cache Audit From Logging Cache Keys and Values (#16995)
* fix: Stop Cache Audit From Logging Cache Keys and Values

* fix: Keep Cache Audit Output to Counts and TTL

* fix: Log Cache Audit at Info So the Debug Toggle Still Emits

* test: Cover Cache Audit Redaction in the Mock Lane

* test: Run Cache Audit Scenario Against In-Memory Stores

* test: Parse Cache Audit Probe Output Before Asserting

* fix: Render Cache Audit Statistics in the Message and Move Formatting to packages/api
2026-10-12 15:59:43 +02:00

49 lines
1.8 KiB
TypeScript

import { resolve } from 'node:path';
import { expect, test } from '@playwright/test';
import { run, repoRoot, inOneProject } from './lint.helpers';
/**
* The in-memory cache audit is an operator diagnostic behind
* DEBUG_MEMORY_CACHE. It reports how many entries each store holds and their
* TTL, which is what an operator needs to size a cache. The keys and values are
* what it must never print: they carry user identifiers, OAuth exchange
* tokens, and message content, and the log sink retains them.
*/
const PROBE = `
process.env.USE_REDIS = 'false';
const { logger } = require('@librechat/data-schemas');
const { CacheKeys } = require('librechat-data-provider');
const getLogStores = require('./cache/getLogStores');
(async () => {
const lines = [];
const capture = (...args) => lines.push(JSON.stringify(args));
logger.info = capture;
logger.debug = capture;
console.log = capture;
const store = getLogStores(CacheKeys.ADMIN_OAUTH_EXCHANGE);
await store.set('probe-user-key-1234', { access_token: 'probe-secret-token' });
getLogStores.auditCache();
process.stdout.write('RESULT' + JSON.stringify(lines));
process.exit(0);
})();
`;
test.describe('the cache audit log', () => {
test.beforeEach(() => inOneProject());
test('the cache audit logs entry counts without keys or values @scenario:the-cache-audit-logs-counts-without-keys-or-values', () => {
test.setTimeout(120_000);
const result = run('node', ['-e', PROBE], {
cwd: resolve(repoRoot, 'api'),
});
expect(result.status, result.output).toBe(0);
const lines: string[] = JSON.parse(
result.stdout.slice(result.stdout.indexOf('RESULT') + 'RESULT'.length),
);
const output = lines.join('\n');
expect(output).toContain('count=1');
expect(output).not.toContain('probe-secret-token');
expect(output).not.toContain('probe-user-key-1234');
});
});