test: 图片测试样例移到 src/__tests__/fixtures,Docker 构建内的单元测试可读取

- e2e/fixtures 下的真实 HEIC/PNG/JPEG 样例移到 src/__tests__/fixtures/images,单元测试与 E2E 共用;
  Docker 构建上下文按 .dockerignore 排除 e2e 用例目录,构建阶段的单元测试因此读不到样例(ENOENT)
- 同步更新 E2E 用例、E2E 本地模型说明与 Openclaw 测试脚本中的路径;样例内容与全部断言不变,最终镜像不含测试目录
This commit is contained in:
margrop
2026-11-03 16:00:24 +08:00
parent 15d954c029
commit eca2b19220
14 changed files with 9 additions and 9 deletions

View File

@@ -5,7 +5,7 @@ import type { Page, TestInfo } from '@playwright/test';
import { test } from './support/fixtures';
import type { Scenario } from './support/fixtures';
const fixture = (name: string) => resolve('e2e/fixtures', name);
const fixture = (name: string) => resolve('src/__tests__/fixtures/images', name);
/** 生成灰度 PNG(每行一种灰度),用于构造「文件很小但像素很多」的图片 */
function grayPng(width: number, height: number): Buffer {

View File

@@ -9,7 +9,7 @@ async function upload(page: Page, scenario: Scenario, path = '/') {
await scenario.control({ hold: true });
await scenario.login(page);
await page.goto(path);
await page.locator('input[type="file"]').first().setInputFiles(resolve('e2e/fixtures/math_test.png'));
await page.locator('input[type="file"]').first().setInputFiles(resolve('src/__tests__/fixtures/images/math_test.png'));
await expect(page.getByRole('heading', { name: /裁剪|Crop/ })).toBeVisible();
await page.getByRole('button', { name: /确认|Confirm/ }).click();
await expect.poll(async () => (await scenario.model()).calls.filter((call) => call.operation === 'analysis').length).toBe(1);
@@ -123,7 +123,7 @@ test('[E2E-T04] 框选 5 题先全部落库,模型排队时关闭页面后仍
await scenario.control({ hold: true });
await scenario.login(page);
await page.goto(`/notebooks/${scenario.book.id}/add`);
await page.locator('input[type="file"]').first().setInputFiles(resolve('e2e/fixtures/math_test.png'));
await page.locator('input[type="file"]').first().setInputFiles(resolve('src/__tests__/fixtures/images/math_test.png'));
await page.getByRole('button', { name: '手工框选' }).click();
const overlay = page.locator('.cursor-crosshair').first();
await expect(overlay).toBeVisible();

View File

@@ -3,7 +3,7 @@ import { expect, test } from './support/fixtures';
import { batchOf, calls, expectNoHorizontalOverflow, expectNotCovered, saveShot } from './support/batch-flows';
import { viewports } from './support/flows';
const PAGE_PHOTO = resolve('e2e/fixtures/multi-question-page.jpg');
const PAGE_PHOTO = resolve('src/__tests__/fixtures/images/multi-question-page.jpg');
for (const profile of viewports) {
test.describe(`照片 ${profile.name}`, () => {

View File

@@ -12,7 +12,7 @@ export async function importImage(page: Page, scenario: Scenario, confirm: boole
await scenario.control({ hold: true });
await scenario.login(page);
await page.goto(confirm ? '/' : `/?notebook=${scenario.book.id}`);
await page.locator('input[type="file"]').first().setInputFiles(resolve('e2e/fixtures/math_test.png'));
await page.locator('input[type="file"]').first().setInputFiles(resolve('src/__tests__/fixtures/images/math_test.png'));
await expect(page.getByRole('heading', { name: /裁剪|Crop/ })).toBeVisible();
await page.getByRole('button', { name: /确认|Confirm/ }).click();
await expect.poll(async () => (await scenario.model()).calls.filter((call) => call.operation === 'analysis').length).toBe(1);

View File

@@ -8,7 +8,7 @@ function json(response, status, value) {
response.end(JSON.stringify(value));
}
/** 多题照片样例(e2e/fixtures/multi-question-page.jpg)中各题的位置,按 0~1000 归一化 */
/** 多题照片样例(src/__tests__/fixtures/images/multi-question-page.jpg)中各题的位置,按 0~1000 归一化 */
export const PAGE_QUESTIONS = [
{ label: '1', text: '如图,长方形 ABCD 的长和宽如图中所示,求它的面积是多少平方厘米?', regions: [{ x: 48, y: 197, w: 905, h: 350 }], hasFigure: true },
{ label: '2', text: '下列分数中,与 3/4 相等的是(  )。A.6/8 B.4/6 C.9/16 D.5/7', regions: [{ x: 48, y: 590, w: 905, h: 105 }], hasFigure: false },

View File

@@ -107,7 +107,7 @@ echo "-----------------------------------------"
echo ""
# 准备测试图片 (base64)
TEST_IMAGE=$(base64 -i e2e/fixtures/math_test.png 2>/dev/null || echo "")
TEST_IMAGE=$(base64 -i src/__tests__/fixtures/images/math_test.png 2>/dev/null || echo "")
if [ -z "$TEST_IMAGE" ]; then
echo "使用内置测试图片..."
# 创建一个简单的1x1像素PNG图片的base64

View File

Before

Width:  |  Height:  |  Size: 562 KiB

After

Width:  |  Height:  |  Size: 562 KiB

View File

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@@ -6,7 +6,7 @@ import { resolve } from 'node:path';
import { describe, expect, it } from 'vitest';
import { computeOutputSize, DEFAULT_IMAGE_LIMITS, sniffImageFormat } from '@/lib/image-pipeline';
const fixture = (name: string) => new Uint8Array(readFileSync(resolve('e2e/fixtures', name)));
const fixture = (name: string) => new Uint8Array(readFileSync(resolve('src/__tests__/fixtures/images', name)));
const brandFile = (major: string, ...compatible: string[]) => {
const brands = [major, '\0\0\0\0', ...compatible].join('');
const size = 8 + brands.length;
@@ -142,7 +142,7 @@ describe('renderRegion', () => {
});
describe('prepareImage', () => {
const file = (name: string, type = '') => new File([readFileSync(resolve('e2e/fixtures', name))], name, { type });
const file = (name: string, type = '') => new File([readFileSync(resolve('src/__tests__/fixtures/images', name))], name, { type });
it('系统可以解码时不加载 HEIC 解码库(如 Safari 解码 HEIC)', async () => {
const createImageBitmap = vi.fn(async () => ({ width: 1024, height: 1024, close: vi.fn() }));