Skip to content

Commit 726802a

Browse files
committed
chore: update cache test
1 parent 0165108 commit 726802a

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

packages/web-integration/playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dotenv.config({
1818
*/
1919
export default defineConfig({
2020
// testDir: './tests/ai/e2e',
21-
// testIgnore: 'generate-test-data.spec.ts',
21+
testIgnore: 'generate-test-data.spec.ts',
2222
timeout: 900 * 1000,
2323
/* Run tests in files in parallel */
2424
fullyParallel: true,

packages/web-integration/src/common/task-cache.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export type AiTaskCache = {
4545
};
4646

4747
export class TaskCache {
48-
cache: AiTaskCache | undefined;
48+
cache: AiTaskCache;
4949

5050
cacheId: string;
5151

@@ -56,7 +56,9 @@ export class TaskCache {
5656
constructor(opts?: { fileName?: string }) {
5757
this.midscenePkgInfo = getMidscenePkgInfo(__dirname);
5858
this.cacheId = generateCacheId(opts?.fileName);
59-
this.cache = this.readCacheFromFile();
59+
this.cache = this.readCacheFromFile() || {
60+
aiTasks: [],
61+
};
6062
this.newCache = {
6163
aiTasks: [],
6264
};

packages/web-integration/tests/ai/e2e/ai-online-order.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ test('ai online order', async ({ ai, page, aiQuery }) => {
3535
// productPrice: "商品价格",
3636
// productDescription: "商品描述(饮品的各种参数,吸管、冰沙等),在价格下面",
3737
// }));
38-
expect(cardDetail.productName).toContain('多肉葡萄');
39-
expect(cardDetail.productDescription).toContain('绿妍');
4038

4139
console.log('商品订单详情:', {
4240
productName: cardDetail.productName,
4341
productPrice: cardDetail.productPrice,
4442
productDescription: cardDetail.productDescription,
4543
});
44+
expect(cardDetail.productName).toContain('多肉葡萄');
45+
expect(cardDetail.productDescription).toContain('绿妍');
4646
});

packages/web-integration/tests/unit-test/task-cache.test.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,19 @@ describe('TaskCache', () => {
3333
});
3434

3535
it('should return false if the prompt does not match', async () => {
36-
if (taskCache.cache) {
37-
taskCache.cache.aiTasks = [
38-
{
39-
prompt: 'different prompt',
40-
tasks: [
41-
{
42-
type: 'plan',
43-
prompt: 'different prompt',
44-
pageContext,
45-
response: { plans: [] },
46-
},
47-
],
48-
},
49-
];
50-
}
36+
taskCache.cache.aiTasks = [
37+
{
38+
prompt: 'different prompt',
39+
tasks: [
40+
{
41+
type: 'plan',
42+
prompt: 'different prompt',
43+
pageContext,
44+
response: { plans: [] },
45+
},
46+
],
47+
},
48+
];
5149
const cacheGroup = taskCache.getCacheGroupByPrompt('test prompt');
5250
const result = cacheGroup.readCache(
5351
formalPageContext,

0 commit comments

Comments
 (0)