feat: integrate learning module
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
inman
2026-08-16 20:52:16 +08:00
parent 26b52d76e3
commit 01bee3188b
107 changed files with 6318 additions and 12063 deletions

View File

@@ -1366,6 +1366,70 @@ describe('works square host api routes', () => {
expect(JSON.stringify(response.json())).not.toContain('private-source.zip');
});
it('uploads the submitted cover before creating the project with complete metadata', async () => {
tempDir = await mkdtemp(join(tmpdir(), 'makelore-source-cover-publish-'));
await writePublishableProject(tempDir);
const project = { id: 'project-1', path: tempDir, name: 'space-cleaner' };
const projectMetadata = {
app_id: 'space-cleaner',
title: '太空清洁队',
summary: '收集漂浮垃圾的小游戏。',
description: '清理轨道上的垃圾并完成关卡。',
cover_url: null,
creator_name: '小明',
creator_age: 12,
category: 'game',
age_band: '6-12岁',
difficulty: '入门',
};
const cover = {
fileName: 'cover.png',
mimeType: 'image/png',
dataBase64: Buffer.from('cover bytes').toString('base64'),
};
const fetchMock = vi.fn()
.mockResolvedValueOnce(new Response(JSON.stringify({
cover_url: 'coverimage/00000000-0000-0000-0000-000000000001.jpg',
}), { status: 201 }))
.mockResolvedValueOnce(new Response(JSON.stringify(projectMetadata), { status: 201 }))
.mockResolvedValueOnce(new Response(JSON.stringify({
version_id: 'version-1',
review_status: 'building',
build_job_id: 'job-1',
build_status: 'queued',
}), { status: 201 }));
vi.stubGlobal('fetch', fetchMock);
const response = createResponse();
prepareProjectReleaseMock.mockResolvedValueOnce(preparedRelease(tempDir));
await handleWorksRoutes(
createRendererRequest('POST', { projectId: project.id, project: projectMetadata, cover }),
response.res,
new URL('http://127.0.0.1/api/works/projects/publish-source'),
{
opencodeProjectStore: { listProjects: vi.fn(async () => [project]) },
agentBrowser: { preflightStaticArtifact: vi.fn(async () => ({ ok: true })) },
} as never,
);
expect(response.statusCode).toBe(201);
expect(fetchMock).toHaveBeenCalledTimes(3);
const [coverUrl, coverInit] = fetchMock.mock.calls[0] as [string, RequestInit];
expect(coverUrl).toBe('https://square.nianxx.cn/api/projects/covers');
expect(coverInit.headers).toEqual({ Authorization: 'Bearer main-owned-access-token' });
const coverForm = coverInit.body as FormData;
const coverFile = coverForm.get('file');
expect(coverFile).toBeInstanceOf(File);
expect((coverFile as File).name).toBe('cover.png');
expect(await (coverFile as File).text()).toBe('cover bytes');
const [, createInit] = fetchMock.mock.calls[1] as [string, RequestInit];
expect(JSON.parse(String(createInit.body))).toEqual({
...projectMetadata,
cover_url: 'coverimage/00000000-0000-0000-0000-000000000001.jpg',
});
});
it('stops before creating or uploading when the local browser preflight fails', async () => {
tempDir = await mkdtemp(join(tmpdir(), 'makelore-source-preflight-failure-'));
await writePublishableProject(tempDir);