fix(companion): resolve fixtures path correctly in Electron runtime
This commit is contained in:
@@ -18,6 +18,33 @@ import type { IAutomationEngine } from '@/packages/application/ports/IAutomation
|
|||||||
import type { ILogger } from '@/packages/application/ports/ILogger';
|
import type { ILogger } from '@/packages/application/ports/ILogger';
|
||||||
import type { IFixtureServerService } from '@/packages/infrastructure/adapters/automation/FixtureServerService';
|
import type { IFixtureServerService } from '@/packages/infrastructure/adapters/automation/FixtureServerService';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the fixtures path relative to the monorepo root.
|
||||||
|
* In Electron, app.getAppPath() returns the path to the app's main directory
|
||||||
|
* (e.g., apps/companion/dist/main in development, or the asar in production).
|
||||||
|
* We navigate up to find the monorepo root and then join with the resources path.
|
||||||
|
*
|
||||||
|
* Path breakdown from apps/companion/dist/main:
|
||||||
|
* - Level 1: apps/companion/dist (../)
|
||||||
|
* - Level 2: apps/companion (../../)
|
||||||
|
* - Level 3: apps (../../../)
|
||||||
|
* - Level 4: gridpilot (monorepo root) (../../../../)
|
||||||
|
*
|
||||||
|
* @param configuredPath - The path configured (may be relative or absolute)
|
||||||
|
* @param appPath - The app path from electron (app.getAppPath())
|
||||||
|
* @returns Resolved absolute path
|
||||||
|
*/
|
||||||
|
export function resolveFixturesPath(configuredPath: string, appPath: string): string {
|
||||||
|
if (path.isAbsolute(configuredPath)) {
|
||||||
|
return configuredPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectRoot = path.resolve(appPath, '../../../../');
|
||||||
|
const resolvedPath = path.join(projectRoot, configuredPath);
|
||||||
|
|
||||||
|
return resolvedPath;
|
||||||
|
}
|
||||||
|
|
||||||
export interface BrowserConnectionResult {
|
export interface BrowserConnectionResult {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
error?: string;
|
error?: string;
|
||||||
@@ -169,20 +196,10 @@ export class DIContainer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve the fixtures path relative to the monorepo root.
|
* Resolve the fixtures path relative to the monorepo root.
|
||||||
* In Electron, app.getAppPath() returns the path to the app's main directory
|
* Uses the exported resolveFixturesPath function with app.getAppPath().
|
||||||
* (e.g., apps/companion/dist/main in development, or the asar in production).
|
|
||||||
* We navigate up to find the monorepo root and then join with the resources path.
|
|
||||||
*/
|
*/
|
||||||
private resolveFixturesPath(configuredPath: string): string {
|
private resolveFixturesPathInternal(configuredPath: string): string {
|
||||||
if (path.isAbsolute(configuredPath)) {
|
return resolveFixturesPath(configuredPath, app.getAppPath());
|
||||||
return configuredPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
const appPath = app.getAppPath();
|
|
||||||
const projectRoot = path.resolve(appPath, '../../../');
|
|
||||||
const resolvedPath = path.join(projectRoot, configuredPath);
|
|
||||||
|
|
||||||
return resolvedPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -205,7 +222,7 @@ export class DIContainer {
|
|||||||
|
|
||||||
this.fixtureServer = new FixtureServerService();
|
this.fixtureServer = new FixtureServerService();
|
||||||
const port = config.fixtureServer.port;
|
const port = config.fixtureServer.port;
|
||||||
const fixturesPath = this.resolveFixturesPath(config.fixtureServer.fixturesPath);
|
const fixturesPath = this.resolveFixturesPathInternal(config.fixtureServer.fixturesPath);
|
||||||
|
|
||||||
this.logger.debug('Fixture server path resolution', {
|
this.logger.debug('Fixture server path resolution', {
|
||||||
configuredPath: config.fixtureServer.fixturesPath,
|
configuredPath: config.fixtureServer.fixturesPath,
|
||||||
|
|||||||
66
tests/integration/companion/di-container.test.ts
Normal file
66
tests/integration/companion/di-container.test.ts
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import * as path from 'path';
|
||||||
|
import { resolveFixturesPath } from '@/apps/companion/main/di-container';
|
||||||
|
|
||||||
|
describe('DIContainer path resolution', () => {
|
||||||
|
describe('resolveFixturesPath', () => {
|
||||||
|
it('should resolve fixtures path to monorepo root when app path is apps/companion/dist/main', () => {
|
||||||
|
// Given: The app path as it would be in Electron runtime (apps/companion/dist/main)
|
||||||
|
const mockAppPath = '/Users/test/Projects/gridpilot/apps/companion/dist/main';
|
||||||
|
const relativePath = './resources/iracing-hosted-sessions';
|
||||||
|
|
||||||
|
// When: Resolving the fixtures path
|
||||||
|
const resolved = resolveFixturesPath(relativePath, mockAppPath);
|
||||||
|
|
||||||
|
// Then: Should resolve to monorepo root (4 levels up from apps/companion/dist/main)
|
||||||
|
// Level 0: apps/companion/dist/main (app.getAppPath())
|
||||||
|
// Level 1: apps/companion/dist (../)
|
||||||
|
// Level 2: apps/companion (../../)
|
||||||
|
// Level 3: apps (../../../)
|
||||||
|
// Level 4: gridpilot (monorepo root) (../../../../) ← CORRECT
|
||||||
|
const expectedPath = '/Users/test/Projects/gridpilot/resources/iracing-hosted-sessions';
|
||||||
|
expect(resolved).toBe(expectedPath);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return absolute paths unchanged', () => {
|
||||||
|
// Given: An absolute path
|
||||||
|
const absolutePath = '/some/absolute/path/to/fixtures';
|
||||||
|
const mockAppPath = '/Users/test/Projects/gridpilot/apps/companion/dist/main';
|
||||||
|
|
||||||
|
// When: Resolving an absolute path
|
||||||
|
const resolved = resolveFixturesPath(absolutePath, mockAppPath);
|
||||||
|
|
||||||
|
// Then: Should return the absolute path unchanged
|
||||||
|
expect(resolved).toBe(absolutePath);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should navigate exactly 4 levels up from app path', () => {
|
||||||
|
// Given: A path that demonstrates the 4-level navigation
|
||||||
|
const mockAppPath = '/level4/level3/level2/level1';
|
||||||
|
const relativePath = './target';
|
||||||
|
|
||||||
|
// When: Resolving the fixtures path
|
||||||
|
const resolved = resolveFixturesPath(relativePath, mockAppPath);
|
||||||
|
|
||||||
|
// Then: Should resolve to the path 4 levels up (root /)
|
||||||
|
// Level 0: /level4/level3/level2/level1 (appPath)
|
||||||
|
// Level 1: /level4/level3/level2 (../)
|
||||||
|
// Level 2: /level4/level3 (../../)
|
||||||
|
// Level 3: /level4 (../../../)
|
||||||
|
// Level 4: / (../../../../) ← monorepo root equivalent
|
||||||
|
expect(resolved).toBe('/target');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should work with different relative path formats', () => {
|
||||||
|
// Given: Various relative path formats
|
||||||
|
const mockAppPath = '/Users/test/Projects/gridpilot/apps/companion/dist/main';
|
||||||
|
|
||||||
|
// When/Then: Different relative formats should all work
|
||||||
|
expect(resolveFixturesPath('resources/fixtures', mockAppPath))
|
||||||
|
.toBe('/Users/test/Projects/gridpilot/resources/fixtures');
|
||||||
|
|
||||||
|
expect(resolveFixturesPath('./resources/fixtures', mockAppPath))
|
||||||
|
.toBe('/Users/test/Projects/gridpilot/resources/fixtures');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user