Skip to content

Commit b357be3

Browse files
committed
chore(test): implement POC for ai.json-based tests
Signed-off-by: Tibor Dancs <[email protected]>
1 parent 12b59b0 commit b357be3

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

tests/playwright/src/ai-lab-extension.spec.ts

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,58 @@ import * as fs from 'node:fs';
5656
import * as path from 'node:path';
5757
import { fileURLToPath } from 'node:url';
5858
import type { AILabTryInstructLabPage } from './model/ai-lab-try-instructlab-page';
59+
import type { ApplicationCatalog } from '../../../packages/shared/src/models/IApplicationCatalog';
60+
61+
const __filename = fileURLToPath(import.meta.url);
62+
const __dirname = path.dirname(__filename);
63+
const TEST_AUDIO_FILE_PATH: string = path.resolve(
64+
__dirname,
65+
'..',
66+
'..',
67+
'playwright',
68+
'resources',
69+
`test-audio-to-text.wav`,
70+
);
71+
const AI_JSON_FILE_PATH: string = path.resolve(
72+
__dirname,
73+
'..',
74+
'..',
75+
'..',
76+
'packages',
77+
'backend',
78+
'src',
79+
'assets',
80+
'ai.json',
81+
);
82+
83+
const aiJSONFile = fs.readFileSync(AI_JSON_FILE_PATH, 'utf8');
84+
const AI_JSON: ApplicationCatalog = JSON.parse(aiJSONFile) as ApplicationCatalog;
85+
const AI_APP_MODELS: Set<string> = new Set();
86+
AI_JSON.recipes.forEach(recipe => {
87+
recipe.recommended?.forEach(model => {
88+
AI_APP_MODELS.add(model);
89+
});
90+
});
91+
// Create a set of AI models that are not the first recommended model for any app
92+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
93+
const _AI_APP_UNUSED_MODELS: string[] = [
94+
...AI_APP_MODELS.values().filter(model => {
95+
// Check if the model is not the first recommended model for any app
96+
return !Array.from(AI_JSON.recipes).some(recipe => {
97+
return recipe.recommended?.at(0) === model;
98+
});
99+
}),
100+
];
101+
const AI_APP_MODEL_AND_NAMES: Map<string, string[]> = new Map();
102+
AI_JSON.recipes.forEach(recipe => {
103+
const recommendedModel = recipe.recommended?.at(0);
104+
if (recommendedModel) {
105+
if (!AI_APP_MODEL_AND_NAMES.has(recommendedModel)) {
106+
AI_APP_MODEL_AND_NAMES.set(recommendedModel, []);
107+
}
108+
AI_APP_MODEL_AND_NAMES.get(recommendedModel)?.push(recipe.name);
109+
}
110+
});
59111

60112
const AI_LAB_EXTENSION_OCI_IMAGE =
61113
process.env.EXTENSION_OCI_IMAGE ?? 'ghcr.io/containers/podman-desktop-extension-ai-lab:nightly';
@@ -83,17 +135,6 @@ const AI_APPS: AiApp[] = [
83135
{ appName: 'Object Detection', appModel: 'facebook/detr-resnet-101' },
84136
];
85137

86-
const __filename = fileURLToPath(import.meta.url);
87-
const __dirname = path.dirname(__filename);
88-
const TEST_AUDIO_FILE_PATH: string = path.resolve(
89-
__dirname,
90-
'..',
91-
'..',
92-
'playwright',
93-
'resources',
94-
`test-audio-to-text.wav`,
95-
);
96-
97138
test.use({
98139
runnerOptions: new RunnerOptions(runnerOptions),
99140
});

tests/playwright/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"compilerOptions": {
33
"target": "esnext",
44
"module": "esnext",
5-
"moduleResolution":"node",
5+
"moduleResolution": "node",
66
"strict": true,
77
"preserveValueImports": false,
88
"skipLibCheck": false,
99
"baseUrl": ".",
10+
"resolveJsonModule": true
1011
},
1112
"include": ["src/**/*.ts", "playwright.config.ts"],
1213
"exclude": ["node_modules/**"]

0 commit comments

Comments
 (0)