diff --git a/src/backend/electron/engineAndVvppController.ts b/src/backend/electron/engineAndVvppController.ts index 634d612885..2dedf1649d 100644 --- a/src/backend/electron/engineAndVvppController.ts +++ b/src/backend/electron/engineAndVvppController.ts @@ -15,9 +15,9 @@ import { EngineSettingType, } from "@/type/preload"; import { - EnginePackage, + EngineVariant, fetchLatestDefaultEngineInfo, - getSuitablePackage, + getSuitableVariant, } from "@/domain/defaultEngine/latetDefaultEngine"; import { EnvEngineInfoType, @@ -148,7 +148,7 @@ export class EngineAndVvppController { async fetchEngineAndPackageInfosToInstall(): Promise< { envEngineInfo: EnvEngineInfoType; - packageInfo: EnginePackage; + packageInfo: EngineVariant; }[] > { // .envのデフォルトエンジン情報のうち、downloadVvppなものを集める @@ -168,7 +168,7 @@ export class EngineAndVvppController { continue; } - const packageInfo = getSuitablePackage(latestInfo); + const packageInfo = getSuitableVariant(latestInfo); log.info(`Latest default engine version: ${packageInfo.version}`); // インストール済みだった場合はスキップ @@ -190,7 +190,7 @@ export class EngineAndVvppController { /** VVPPパッケージをダウンロードし、インストールする */ async downloadAndInstallVvppEngine( downloadDir: string, - packageInfo: EnginePackage, + packageInfo: EngineVariant, ) { // ダウンロード const downloadedPaths = new Array(packageInfo.packages.length); diff --git a/src/domain/defaultEngine/latetDefaultEngine.ts b/src/domain/defaultEngine/latetDefaultEngine.ts index a87c04dee3..7315d8f913 100644 --- a/src/domain/defaultEngine/latetDefaultEngine.ts +++ b/src/domain/defaultEngine/latetDefaultEngine.ts @@ -5,7 +5,7 @@ import { z } from "zod"; /** パッケージ情報のスキーマ */ -const enginePackageSchema = z.object({ +const engineVariantSchema = z.object({ version: z.string(), packages: z .object({ @@ -16,34 +16,34 @@ const enginePackageSchema = z.object({ }) .array(), }); -export type EnginePackage = z.infer; +export type EngineVariant = z.infer; -/** デフォルトエンジンの更新情報のスキーマ */ +/** デフォルトエンジンの最新情報のスキーマ */ const latestDefaultEngineInfoSchema = z.object({ formatVersion: z.number(), windows: z.object({ x64: z.object({ - CPU: enginePackageSchema, - "GPU/CPU": enginePackageSchema, + CPU: engineVariantSchema, + "GPU/CPU": engineVariantSchema, }), }), macos: z.object({ x64: z.object({ - CPU: enginePackageSchema, + CPU: engineVariantSchema, }), arm64: z.object({ - CPU: enginePackageSchema, + CPU: engineVariantSchema, }), }), linux: z.object({ x64: z.object({ - CPU: enginePackageSchema, - "GPU/CPU": enginePackageSchema, + CPU: engineVariantSchema, + "GPU/CPU": engineVariantSchema, }), }), }); -/** デフォルトエンジンの更新情報を取得する */ +/** デフォルトエンジンの最新情報を取得する */ export const fetchLatestDefaultEngineInfo = async (url: string) => { const response = await fetch(url); return latestDefaultEngineInfoSchema.parse(await response.json()); @@ -53,9 +53,9 @@ export const fetchLatestDefaultEngineInfo = async (url: string) => { * 実行環境に合うパッケージを取得する。GPU版があればGPU版を返す。 * FIXME: どのデバイス版にするかはユーザーが選べるようにするべき。 */ -export const getSuitablePackage = ( +export const getSuitableVariant = ( updateInfo: z.infer, -): EnginePackage => { +): EngineVariant => { const platform = process.platform; const arch = process.arch; diff --git a/tests/unit/domain/defaultEngine/defaultEngine.node.spec.ts b/tests/unit/domain/defaultEngine/latetDefaultEngine.spec.ts similarity index 57% rename from tests/unit/domain/defaultEngine/defaultEngine.node.spec.ts rename to tests/unit/domain/defaultEngine/latetDefaultEngine.spec.ts index a6b76c168d..d3b09e4d1b 100644 --- a/tests/unit/domain/defaultEngine/defaultEngine.node.spec.ts +++ b/tests/unit/domain/defaultEngine/latetDefaultEngine.spec.ts @@ -1,17 +1,12 @@ -// テスト用のファイルを読み込むのでNode環境で実行する - -import path from "path"; -import fs from "fs"; +import latestDefaultEngineInfos from "./latestDefaultEngineInfos.json"; import { fetchLatestDefaultEngineInfo } from "@/domain/defaultEngine/latetDefaultEngine"; -const currentDir = "tests/unit/domain/defaultEngine"; - test("fetchLatestDefaultEngineInfo", async () => { // テスト用のjsonファイルでfetchをモックする // 元ファイルは https://raw.githubusercontent.com/VOICEVOX/voicevox_blog/master/src/generateLatestDefaultEngineInfos.ts - const p = path.resolve(currentDir, "latestDefaultEngineInfos.json"); - const json = fs.readFileSync(p, "utf-8"); - const spy = vi.spyOn(global, "fetch").mockResolvedValue(new Response(json)); + const spy = vi + .spyOn(global, "fetch") + .mockResolvedValue(new Response(JSON.stringify(latestDefaultEngineInfos))); // 読み込めることを確認 const infos = await fetchLatestDefaultEngineInfo("https://example.com/");