This commit is contained in:
2025-12-11 21:06:25 +01:00
parent c49ea2598d
commit ec3ddc3a5c
227 changed files with 3496 additions and 2083 deletions

View File

@@ -39,8 +39,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
}
throw reason;
};
const anyProcess = process as any;
anyProcess.on('unhandledRejection', unhandledRejectionHandler);
process.on('unhandledRejection', unhandledRejectionHandler);
});
afterEach(async () => {
@@ -54,8 +53,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
afterAll(() => {
if (unhandledRejectionHandler) {
const anyProcess = process as any;
anyProcess.removeListener('unhandledRejection', unhandledRejectionHandler);
process.removeListener('unhandledRejection', unhandledRejectionHandler);
unhandledRejectionHandler = null;
}
});
@@ -177,12 +175,19 @@ describe('Browser Mode Integration - GREEN Phase', () => {
it('should log browser mode configuration with NODE_ENV source in production', async () => {
process.env.NODE_ENV = 'production';
const logSpy: Array<{ level: string; message: string; context?: any }> = [];
const mockLogger = {
debug: (msg: string, ctx?: any) => logSpy.push({ level: 'debug', message: msg, context: ctx }),
info: (msg: string, ctx?: any) => logSpy.push({ level: 'info', message: msg, context: ctx }),
warn: (msg: string, ctx?: any) => logSpy.push({ level: 'warn', message: msg, context: ctx }),
error: (msg: string, ctx?: any) => logSpy.push({ level: 'error', message: msg, context: ctx }),
const logSpy: Array<{ level: string; message: string; context?: Record<string, unknown> }> = [];
type LoggerLike = {
debug: (msg: string, ctx?: Record<string, unknown>) => void;
info: (msg: string, ctx?: Record<string, unknown>) => void;
warn: (msg: string, ctx?: Record<string, unknown>) => void;
error: (msg: string, ctx?: Record<string, unknown>) => void;
child: () => LoggerLike;
};
const mockLogger: LoggerLike = {
debug: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'debug', message: msg, context: ctx }),
info: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'info', message: msg, context: ctx }),
warn: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'warn', message: msg, context: ctx }),
error: (msg: string, ctx?: Record<string, unknown>) => logSpy.push({ level: 'error', message: msg, context: ctx }),
child: () => mockLogger,
};
@@ -192,7 +197,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
adapter = new PlaywrightAutomationAdapter(
{ mode: 'mock' },
mockLogger as any
mockLogger
);
await adapter.connect();
@@ -250,19 +255,23 @@ describe('Browser Mode Integration - GREEN Phase', () => {
loader.setDevelopmentMode('headed');
// Capture launch options
const launches: Array<{ type: string; opts?: any; userDataDir?: string }> = [];
type LaunchOptions = { headless?: boolean; [key: string]: unknown };
const launches: Array<{ type: string; opts?: LaunchOptions; userDataDir?: string }> = [];
const mockLauncher = {
launch: async (opts: any) => {
launch: async (opts: LaunchOptions) => {
launches.push({ type: 'launch', opts });
return {
newContext: async () => ({ newPage: async () => ({ setDefaultTimeout: () => {}, close: async () => {} }), close: async () => {} }),
newContext: async () => ({
newPage: async () => ({ setDefaultTimeout: () => {}, close: async () => {} }),
close: async () => {},
}),
newPage: async () => ({ setDefaultTimeout: () => {}, close: async () => {} }),
close: async () => {},
newContextSync: () => {},
};
},
launchPersistentContext: async (userDataDir: string, opts: any) => {
launchPersistentContext: async (userDataDir: string, opts: LaunchOptions) => {
launches.push({ type: 'launchPersistent', userDataDir, opts });
return {
pages: () => [{ setDefaultTimeout: () => {}, close: async () => {} }],
@@ -273,9 +282,12 @@ describe('Browser Mode Integration - GREEN Phase', () => {
};
// Inject test launcher
(PlaywrightAutomationAdapter as any).testLauncher = mockLauncher;
const AdapterWithTestLauncher = PlaywrightAutomationAdapter as typeof PlaywrightAutomationAdapter & {
testLauncher?: typeof mockLauncher;
};
AdapterWithTestLauncher.testLauncher = mockLauncher;
adapter = new PlaywrightAutomationAdapter({ mode: 'mock' }, undefined as any, loader as any);
adapter = new PlaywrightAutomationAdapter({ mode: 'mock' }, undefined, loader);
// First connect => loader says headed => headless should be false
const r1 = await adapter.connect();
@@ -296,7 +308,7 @@ describe('Browser Mode Integration - GREEN Phase', () => {
expect(secondLaunch!.opts.headless).toBe(true);
// Cleanup test hook
(PlaywrightAutomationAdapter as any).testLauncher = undefined;
AdapterWithTestLauncher.testLauncher = undefined;
await adapter.disconnect();
});
});

View File

@@ -3,12 +3,14 @@ import { PlaywrightAutomationAdapter } from 'packages/automation/infrastructure/
describe('CarsFlow integration', () => {
test('adapter emits panel-attached then action-started then action-complete for performAddCar', async () => {
const adapter = new PlaywrightAutomationAdapter({} as any)
const received: any[] = []
adapter.onLifecycle?.((e: any) => { received.push(e) })
const adapter = new PlaywrightAutomationAdapter({})
const received: Array<{ type: string }> = []
adapter.onLifecycle?.((e) => {
received.push({ type: (e as { type: string }).type })
})
// Use mock page fixture: minimal object with required methods
const mockPage: any = {
const mockPage = {
waitForSelector: async () => {},
evaluate: async () => {},
waitForTimeout: async () => {},
@@ -20,11 +22,13 @@ describe('CarsFlow integration', () => {
await adapter.attachPanel(mockPage, 'add-car')
// simulate complete event via internal lifecycle emitter
await (adapter as any).emitLifecycle({
type: 'action-complete',
actionId: 'add-car',
timestamp: Date.now(),
} as any)
await (adapter as unknown as { emitLifecycle: (ev: { type: string; actionId: string; timestamp: number }) => Promise<void> }).emitLifecycle(
{
type: 'action-complete',
actionId: 'add-car',
timestamp: Date.now(),
},
)
const types = received.map(r => r.type)
expect(types.indexOf('panel-attached')).toBeGreaterThanOrEqual(0)

View File

@@ -40,7 +40,13 @@ describe('Overlay lifecycle (integration)', () => {
it('emits modal-opened and confirms after action-started in sane order', async () => {
const lifecycleEmitter = new TestLifecycleEmitter();
const publisher = new RecordingPublisher();
const logger = console as any;
type LoggerLike = {
debug: (...args: unknown[]) => void;
info: (...args: unknown[]) => void;
warn: (...args: unknown[]) => void;
error: (...args: unknown[]) => void;
};
const logger = console as unknown as LoggerLike;
const service = new OverlaySyncService({
lifecycleEmitter,
@@ -85,7 +91,13 @@ describe('Overlay lifecycle (integration)', () => {
it('emits panel-missing when cancelAction is called', async () => {
const lifecycleEmitter = new TestLifecycleEmitter();
const publisher = new RecordingPublisher();
const logger = console as any;
type LoggerLike = {
debug: (...args: unknown[]) => void;
info: (...args: unknown[]) => void;
warn: (...args: unknown[]) => void;
error: (...args: unknown[]) => void;
};
const logger = console as unknown as LoggerLike;
const service = new OverlaySyncService({
lifecycleEmitter,