-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
デフォルトエンジン更新情報jsonの仕様を書き、スキーマを定義 (#2257)
* デフォルトエンジン更新情報jsonの仕様を書き、スキーマを定義 * mockRestoreする * 不要なTextが入ってた * 説明追加
- Loading branch information
Showing
5 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* デフォルトエンジン関連のモジュール | ||
*/ | ||
|
||
import { z } from "zod"; | ||
|
||
/** パッケージ(vvppやvvppp1ファイル)ごとのスキーマ */ | ||
const defaultEnginePackageSchema = z.object({ | ||
url: z.string(), | ||
name: z.string(), | ||
size: z.number(), | ||
hash: z.string().optional(), | ||
}); | ||
|
||
/** デバイスごとのスキーマ */ | ||
const defaultEngineDeviceSchema = z.object({ | ||
version: z.string(), | ||
packages: z.array(defaultEnginePackageSchema), | ||
}); | ||
|
||
/** デフォルトエンジンの更新情報のスキーマ */ | ||
const defaultEngineInfosSchema = z.object({ | ||
formatVersion: z.number(), | ||
windows: z.object({ | ||
x64: z.object({ | ||
CPU: defaultEngineDeviceSchema, | ||
"GPU/CPU": defaultEngineDeviceSchema, | ||
}), | ||
}), | ||
macos: z.object({ | ||
x64: z.object({ | ||
CPU: defaultEngineDeviceSchema, | ||
}), | ||
arm64: z.object({ | ||
CPU: defaultEngineDeviceSchema, | ||
}), | ||
}), | ||
linux: z.object({ | ||
x64: z.object({ | ||
CPU: defaultEngineDeviceSchema, | ||
"GPU/CPU": defaultEngineDeviceSchema, | ||
}), | ||
}), | ||
}); | ||
|
||
/** デフォルトエンジンの更新情報を取得する */ | ||
export const fetchDefaultEngineInfos = async (url: string) => { | ||
const response = await fetch(url); | ||
return defaultEngineInfosSchema.parse(await response.json()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// テスト用のファイルを読み込むのでNode環境で実行する | ||
// @vitest-environment node | ||
|
||
import path from "path"; | ||
import fs from "fs"; | ||
import { fetchDefaultEngineInfos } from "@/domain/defaultEngine"; | ||
|
||
const currentDir = "tests/unit/domain/defaultEngine"; | ||
|
||
test("fetchDefaultEngineInfos", 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 infos = await fetchDefaultEngineInfos("https://example.com/"); | ||
expect(infos.formatVersion).toBe(1); | ||
|
||
spy.mockRestore(); | ||
}); |
82 changes: 82 additions & 0 deletions
82
tests/unit/domain/defaultEngine/latestDefaultEngineInfos.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
"formatVersion": 1, | ||
"windows": { | ||
"x64": { | ||
"CPU": { | ||
"version": "0.20.0", | ||
"packages": [ | ||
{ | ||
"url": "https://github.com/VOICEVOX/voicevox_engine/releases/download/0.20.0/voicevox_engine-windows-cpu-0.20.0.vvpp", | ||
"name": "voicevox_engine-windows-cpu-0.20.0.vvpp", | ||
"size": 1374659234 | ||
} | ||
] | ||
}, | ||
"GPU/CPU": { | ||
"version": "0.20.0", | ||
"packages": [ | ||
{ | ||
"url": "https://github.com/VOICEVOX/voicevox_engine/releases/download/0.20.0/voicevox_engine-windows-directml-0.20.0.vvpp", | ||
"name": "voicevox_engine-windows-directml-0.20.0.vvpp", | ||
"size": 1382829369 | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"macos": { | ||
"x64": { | ||
"CPU": { | ||
"version": "0.20.0", | ||
"packages": [ | ||
{ | ||
"url": "https://github.com/VOICEVOX/voicevox_engine/releases/download/0.20.0/voicevox_engine-macos-x64-0.20.0.001.vvppp", | ||
"name": "voicevox_engine-macos-x64-0.20.0.001.vvppp", | ||
"size": 1382766014 | ||
} | ||
] | ||
} | ||
}, | ||
"arm64": { | ||
"CPU": { | ||
"version": "0.20.0", | ||
"packages": [ | ||
{ | ||
"url": "https://github.com/VOICEVOX/voicevox_engine/releases/download/0.20.0/voicevox_engine-macos-arm64-0.20.0.001.vvppp", | ||
"name": "voicevox_engine-macos-arm64-0.20.0.001.vvppp", | ||
"size": 1375008115 | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"linux": { | ||
"x64": { | ||
"CPU": { | ||
"version": "0.20.0", | ||
"packages": [ | ||
{ | ||
"url": "https://github.com/VOICEVOX/voicevox_engine/releases/download/0.20.0/voicevox_engine-linux-cpu-0.20.0.vvpp", | ||
"name": "voicevox_engine-linux-cpu-0.20.0.vvpp", | ||
"size": 1399437028 | ||
} | ||
] | ||
}, | ||
"GPU/CPU": { | ||
"version": "0.20.0", | ||
"packages": [ | ||
{ | ||
"url": "https://github.com/VOICEVOX/voicevox_engine/releases/download/0.20.0/voicevox_engine-linux-nvidia-0.20.0.001.vvppp", | ||
"name": "voicevox_engine-linux-nvidia-0.20.0.001.vvppp", | ||
"size": 1992294400 | ||
}, | ||
{ | ||
"url": "https://github.com/VOICEVOX/voicevox_engine/releases/download/0.20.0/voicevox_engine-linux-nvidia-0.20.0.002.vvppp", | ||
"name": "voicevox_engine-linux-nvidia-0.20.0.002.vvppp", | ||
"size": 645130316 | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |