mirror of
https://github.com/bitbaum/botsmann.git
synced 2026-12-03 23:37:02 +01:00
* fix(ai): pick chain vendors by id, and make main green again main has been red since #203 bumped @bitbaum/ai-kit to 1.10, which put Gemini second in freeChain('BOTSMANN'). vendorChain() indexed [1] for OpenRouter, so a BYOK OpenRouter user's key would have been sent down the Gemini link. Look vendors up by id instead (code and both tests). Also clears the rest of the red verify from the same bump: prettier 3.x reformat of six files and the new next lint rule on relative window.location.href assignments (sign-out keeps its full reload). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Cato <41178744+catomean@users.noreply.github.com> * fix(ai): context extraction runs only on the user's own key Every professional-chat turn fired a second, unasked model call (extractAndSaveContext, fire-and-forget after the answer) on the shared free-tier Groq key. Standing rule (2026-09-25): free-tier keys are spent only when a person deliberately asks. Extraction now requires the user's own key and uses their provider; without one it returns before any call. Adds tests/__tests__/no-free-background-ai.test.ts: walks the import graph from the timer route (/api/rebuild, appcron-botsmann-rebuild), /api/warmup and /api/health and fails if any reaches a model client. Proven by mutation: importing lib/nlp into /api/rebuild fails it, and dropping the own-key guard fails the three new extractor cases. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Cato <41178744+catomean@users.noreply.github.com> --------- Signed-off-by: Cato <41178744+catomean@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
// Migrated from jest.setup.ts. `globals: true` in vitest.config.ts keeps
|
|
// describe/it/expect/beforeEach/vi available without imports, so this file
|
|
// changed only where the jest API name did.
|
|
import '@testing-library/jest-dom/vitest';
|
|
import { TextEncoder, TextDecoder } from 'util';
|
|
|
|
// Polyfill TextEncoder/TextDecoder for Node test environment
|
|
global.TextEncoder = TextEncoder;
|
|
global.TextDecoder = TextDecoder as typeof global.TextDecoder;
|
|
|
|
// Mock fetch globally
|
|
const mockFetch = vi.fn().mockImplementation((): Promise<Partial<Response>> =>
|
|
Promise.resolve({
|
|
ok: true,
|
|
json: () => Promise.resolve({}),
|
|
}),
|
|
);
|
|
|
|
global.fetch = mockFetch;
|
|
|
|
// Store original env and test env vars
|
|
const testEnvVars = {
|
|
OPENAI_API_KEY: 'test_openai_key',
|
|
AMAZON_API_KEY: 'test_amazon_key',
|
|
AMAZON_SECRET_KEY: 'test_amazon_secret',
|
|
RICARDO_API_KEY: 'test_ricardo_key',
|
|
};
|
|
|
|
// Set initial test environment variables
|
|
Object.assign(process.env, testEnvVars);
|
|
|
|
// Reset mocks and env vars between tests
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
// Restore test env vars that may have been modified by tests
|
|
Object.assign(process.env, testEnvVars);
|
|
});
|