Skip to content

Commit f4e3f76

Browse files
test(dependency): add boundary and contract tests for dependency refactoring
Add comprehensive tests to verify the dependency boundary refactoring and ensure IPC contracts are properly maintained. Changes: - add version-management-dependency-boundary.test.ts for main process boundary tests - add version-bridge.contract.test.ts for preload bridge contract tests - update versionManagement.installProgress.render.test.ts with UI removal assertions Co-Authored-By: Hagicode <noreply@hagicode.com> Signed-off-by: newbe36524 <newbe36524@qq.com>
1 parent c931b7d commit f4e3f76

3 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import assert from 'node:assert/strict';
2+
import fs from 'node:fs/promises';
3+
import path from 'node:path';
4+
import { describe, it } from 'node:test';
5+
6+
const versionHandlersPath = path.resolve(process.cwd(), 'src/main/ipc/handlers/versionHandlers.ts');
7+
const dependencyHandlersPath = path.resolve(process.cwd(), 'src/main/ipc/handlers/dependencyHandlers.ts');
8+
const mainPath = path.resolve(process.cwd(), 'src/main/main.ts');
9+
const versionManagerPath = path.resolve(process.cwd(), 'src/main/version-manager.ts');
10+
const dependencyManagerPath = path.resolve(process.cwd(), 'src/main/dependency-manager.ts');
11+
12+
describe('version management dependency boundary', () => {
13+
it('removes the retired version dependency IPC channel while keeping lifecycle handlers', async () => {
14+
const [versionHandlersSource, mainSource] = await Promise.all([
15+
fs.readFile(versionHandlersPath, 'utf8'),
16+
fs.readFile(mainPath, 'utf8'),
17+
]);
18+
19+
assert.equal(versionHandlersSource.includes('version:checkDependencies'), false);
20+
assert.equal(mainSource.includes('version:checkDependencies'), false);
21+
assert.match(versionHandlersSource, /ipcMain\.handle\('version:list'/);
22+
assert.match(versionHandlersSource, /ipcMain\.handle\('version:getInstalled'/);
23+
assert.match(versionHandlersSource, /ipcMain\.handle\('version:getActive'/);
24+
assert.match(versionHandlersSource, /ipcMain\.handle\('version:install'/);
25+
assert.match(versionHandlersSource, /ipcMain\.handle\('version:uninstall'/);
26+
assert.match(versionHandlersSource, /ipcMain\.handle\('version:reinstall'/);
27+
assert.match(versionHandlersSource, /ipcMain\.handle\('version:switch'/);
28+
assert.match(versionHandlersSource, /ipcMain\.handle\('version:openLogs'/);
29+
});
30+
31+
it('moves manifest dependency list loading onto the dependency manager boundary', async () => {
32+
const [dependencyHandlersSource, versionManagerSource, dependencyManagerSource, mainSource] = await Promise.all([
33+
fs.readFile(dependencyHandlersPath, 'utf8'),
34+
fs.readFile(versionManagerPath, 'utf8'),
35+
fs.readFile(dependencyManagerPath, 'utf8'),
36+
fs.readFile(mainPath, 'utf8'),
37+
]);
38+
39+
assert.match(versionManagerSource, /async resolveVersionInstallPath\(versionId: string\): Promise<string \| null>/);
40+
assert.equal(versionManagerSource.includes('async getDependencyListFromManifest('), false);
41+
assert.match(dependencyManagerSource, /async getDependencyListFromManifest\(installPath: string\): Promise<DependencyCheckResult\[]>/);
42+
assert.match(dependencyHandlersSource, /resolveVersionInstallPath\(versionId\)/);
43+
assert.match(dependencyHandlersSource, /getDependencyListFromManifest\(installPath\)/);
44+
assert.match(mainSource, /resolveVersionInstallPath\(versionId\)/);
45+
assert.match(mainSource, /getDependencyListFromManifest\(installPath\)/);
46+
});
47+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import assert from 'node:assert/strict';
2+
import fs from 'node:fs/promises';
3+
import path from 'node:path';
4+
import { describe, it } from 'node:test';
5+
6+
const preloadPath = path.resolve(process.cwd(), 'src/preload/index.ts');
7+
8+
describe('version preload bridge contract', () => {
9+
it('removes the retired dependency inspection bridge while keeping lifecycle bridges', async () => {
10+
const source = await fs.readFile(preloadPath, 'utf8');
11+
12+
assert.equal(source.includes('versionCheckDependencies'), false);
13+
assert.equal(source.includes('version:checkDependencies'), false);
14+
assert.match(source, /versionList: \(\) => ipcRenderer\.invoke\('version:list'\)/);
15+
assert.match(source, /versionGetInstalled: \(\) => ipcRenderer\.invoke\('version:getInstalled'\)/);
16+
assert.match(source, /versionGetActive: \(\) => ipcRenderer\.invoke\('version:getActive'\)/);
17+
assert.match(source, /versionInstall: \(versionId\) => ipcRenderer\.invoke\('version:install', versionId\)/);
18+
assert.match(source, /versionReinstall: \(versionId\) => ipcRenderer\.invoke\('version:reinstall', versionId\)/);
19+
assert.match(source, /versionSwitch: \(versionId\) => ipcRenderer\.invoke\('version:switch', versionId\)/);
20+
assert.match(source, /versionOpenLogs: \(versionId\) => ipcRenderer\.invoke\('version:openLogs', versionId\)/);
21+
});
22+
});

src/renderer/store/slices/__tests__/versionManagement.installProgress.render.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,16 @@ describe('version management install progress rendering', () => {
1212
assert.match(source, /installingVersionId === version\.id/);
1313
assert.match(source, /renderInstallTelemetry\(version\.id\)/);
1414
});
15+
16+
it('removes dependency affordances from installed version cards', async () => {
17+
const source = await fs.readFile(pagePath, 'utf8');
18+
19+
assert.equal(source.includes('VersionDependencyGuidance'), false);
20+
assert.equal(source.includes('handleToggleDependencies'), false);
21+
assert.equal(source.includes('getDependencyList('), false);
22+
assert.equal(source.includes('viewDependencies'), false);
23+
assert.equal(source.includes('collapseDependencies'), false);
24+
assert.equal(source.includes('dependencyInfo'), false);
25+
assert.equal(source.includes('aiGuidance'), false);
26+
});
1527
});

0 commit comments

Comments
 (0)