Skip to content

Commit

Permalink
ハミング/ソングスタイルを使用して作成されてしまったデフォルトプリセットを削除するマイグレーション処理に対してのテストを追加する (#2064)
Browse files Browse the repository at this point in the history
* add unit test

* update

* add individual test for 0.19.1 to configManager.spec.ts

* マイグレーション前の設定に、消されているべきものが入っているかを確認

---------

Co-authored-by: Hiroshiba <hihokaruta@gmail.com>
  • Loading branch information
madosuki and Hiroshiba authored May 16, 2024
1 parent 4c9550b commit 3f41639
Show file tree
Hide file tree
Showing 2 changed files with 2,134 additions and 1 deletion.
62 changes: 61 additions & 1 deletion tests/unit/backend/common/configManager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pastConfigs from "./pastConfigs";
import configBugDefaultPreset1996 from "./pastConfigs/0.19.1-bug_default_preset.json";
import { BaseConfigManager } from "@/backend/common/ConfigManager";
import { configSchema } from "@/type/preload";
import { Preset, PresetKey, VoiceId, configSchema } from "@/type/preload";

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / lint

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-test

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-test

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-test

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-directml-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-directml-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-directml-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-directml-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-directml-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-directml-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-cpu-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-cpu-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-cpu-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-cpu-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-cpu-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-cpu-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-cpu-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-cpu-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-cpu-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-cpu-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-cpu-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-cpu-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (macos-cpu-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (macos-cpu-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (macos-cpu-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (macos-cpu-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (macos-cpu-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (macos-cpu-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-nvidia-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-nvidia-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-nvidia-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-nvidia-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-nvidia-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (linux-nvidia-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-nvidia-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-nvidia-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-nvidia-prepackage)

'VoiceId' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-nvidia-prepackage)

'Preset' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-nvidia-prepackage)

'PresetKey' is defined but never used

Check warning on line 4 in tests/unit/backend/common/configManager.spec.ts

View workflow job for this annotation

GitHub Actions / build-and-upload (windows-nvidia-prepackage)

'VoiceId' is defined but never used

const configBase = {
...configSchema.parse({}),
Expand Down Expand Up @@ -83,6 +84,65 @@ for (const [version, data] of pastConfigs) {
});
}

it("0.19.1からのマイグレーション時にハミング・ソングスタイル由来のデフォルトプリセットを削除できている", async () => {
const data = configBugDefaultPreset1996;
vi.spyOn(TestConfigManager.prototype, "exists").mockImplementation(
async () => true,
);
vi.spyOn(TestConfigManager.prototype, "save").mockImplementation(
async () => undefined,
);
vi.spyOn(TestConfigManager.prototype, "load").mockImplementation(
async () => data,
);

// VoiceIdからスタイルIDを取得する。VoiceIdの3番目がスタイルID。
function getStyleIdFromVoiceId(voiceId: string): number {
const splited = voiceId.split(":");
const styleId = parseInt(splited[2]);
return styleId;
}

// ソング・ハミングスタイルかどうかを判定する
function isSingerLikeStyle(styleId: number): boolean {
// スタイルIDが3000以上3085以下または6000のものをソング・ハミングスタイルとみなす
return (styleId >= 3000 && styleId <= 3085) || styleId === 6000;
}

// マイグレーション前のデフォルトプリセットのスタイルID
const beforeDefaultPresetStyleIds = Object.keys(
configBugDefaultPreset1996.defaultPresetKeys,
).map((key) => getStyleIdFromVoiceId(key));

// マイグレーション
const configManager = new TestConfigManager();
await configManager.initialize();
const presets = configManager.get("presets");
const defaultPresetKeys = configManager.get("defaultPresetKeys");

// ソング・ハミングスタイルのデフォルトプリセットが削除されていることを確認
const afterDefaultPresetStyleIds = Object.keys(defaultPresetKeys).map((key) =>
getStyleIdFromVoiceId(key),
);
const deletedStyleIds = beforeDefaultPresetStyleIds.filter(
(styleId) => !afterDefaultPresetStyleIds.includes(styleId),
);
expect(deletedStyleIds.length).toBe(86 - 5 + 1);
expect(deletedStyleIds.every(isSingerLikeStyle)).toBeTruthy();

// 残っているデフォルトプリセットはトークスタイルなことを確認
const remainingStyleIds = afterDefaultPresetStyleIds.filter(
(styleId) => !deletedStyleIds.includes(styleId),
);
expect(
remainingStyleIds.every((styleId) => !isSingerLikeStyle(styleId)),
).toBeTruthy();

// プリセットが削除されていることを確認
expect(remainingStyleIds.length).toBe(presets.keys.length);
expect(remainingStyleIds.length).toBe(Object.keys(presets.items).length);
});

it("getできる", async () => {
vi.spyOn(TestConfigManager.prototype, "exists").mockImplementation(
async () => true,
Expand Down
Loading

0 comments on commit 3f41639

Please sign in to comment.