TidGi-Desktop/features/stepDefinitions/logging.ts
lin onetwo b76fc17794
Chore/upgrade (#646)
* docs: deps

* Update dependencies and type usage for AI features

Upgraded multiple dependencies in package.json and pnpm-lock.yaml, including @ai-sdk, @mui, react, and others for improved compatibility and performance. Changed type usage from CoreMessage to ModelMessage in mockOpenAI.test.ts to align with updated ai package. No functional changes to application logic.

* feat: i18n

* feat: test oauth login and use PKCE

* fix: use ollama-ai-provider-v2

* test: github and mock oauth2 login

* test: gitea login

* Refactor context menu cleanup and error message

Moved context menu cleanup for OAuth window to a single closed event handler in Authentication service. Simplified error message formatting in ContextService for missing keys.

* lint: AI fix

* Add tsx as a dev dependency and update scripts

Replaced usage of 'pnpm dlx tsx' with direct 'tsx' command in development and test scripts for improved reliability. Added 'tsx' to devDependencies in package.json.
2025-10-23 23:42:06 +08:00

52 lines
2 KiB
TypeScript

import { After, DataTable, Then, When } from '@cucumber/cucumber';
import fs from 'fs';
import path from 'path';
import { MockOAuthServer } from '../supports/mockOAuthServer';
import { logsDirectory } from '../supports/paths';
import { ApplicationWorld } from './application';
Then('I should find log entries containing', async function(this: ApplicationWorld, dataTable: DataTable | undefined) {
const expectedRows = dataTable?.raw().map((r: string[]) => r[0]);
// Only consider normal daily log files like TidGi-2025-08-27.log and exclude exception logs
const files = fs.readdirSync(logsDirectory).filter((f) => /TidGi-\d{4}-\d{2}-\d{2}\.log$/.test(f));
const latestLogFilePath = files.length > 0 ? files.sort().reverse()[0] : null;
const content = latestLogFilePath ? fs.readFileSync(path.join(logsDirectory, latestLogFilePath), 'utf8') : '<no-log-found>';
const missing = expectedRows?.filter((r: string) => !content.includes(r));
if (missing?.length) {
throw new Error(`Missing expected log messages "${missing.map(item => item.slice(0, 10)).join('...", "')}..." on latest log file: ${latestLogFilePath}`);
}
});
// OAuth Server Steps
When('I start Mock OAuth Server on port {int}', async function(this: ApplicationWorld, port: number) {
this.mockOAuthServer = new MockOAuthServer(
{ clientId: 'test-client-id' },
port,
);
await this.mockOAuthServer.start();
});
When('I stop Mock OAuth Server', async function(this: ApplicationWorld) {
if (this.mockOAuthServer) {
await this.mockOAuthServer.stop();
this.mockOAuthServer = undefined;
}
});
// Clean up Mock OAuth Server after @oauth tests
After({ tags: '@oauth' }, async function(this: ApplicationWorld) {
if (this.mockOAuthServer) {
try {
await Promise.race([
this.mockOAuthServer.stop(),
new Promise<void>((resolve) => setTimeout(resolve, 2000)),
]);
} catch {
// Ignore errors during cleanup
} finally {
this.mockOAuthServer = undefined;
}
}
});