diff --git a/.github/workflows/builtin-fx-preset-native.yml b/.github/workflows/builtin-fx-preset-native.yml new file mode 100644 index 000000000..44f981fa5 --- /dev/null +++ b/.github/workflows/builtin-fx-preset-native.yml @@ -0,0 +1,74 @@ +name: Native Built-in FX User Presets (targeted Windows CTest) +on: + pull_request: + types: [opened, reopened, synchronize, ready_for_review] + paths: + - 'src/BuiltInFxUserPresetStore.h' + - 'tests/builtin_fx_user_preset_store_test.cpp' + - '.github/workflows/builtin-fx-preset-native.yml' + - 'CMakeLists.txt' + +permissions: + contents: read + +concurrency: + group: preset-store-ctest-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + native-preset: + name: Windows MSVC single-target actual disk CTest (Release) + runs-on: windows-2022 + timeout-minutes: 22 + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Verify exact candidate source + shell: pwsh + env: + EXPECTED_SHA: ${{ github.event.pull_request.head.sha }} + run: | + $actual = (& git rev-parse HEAD).Trim() + if ($LASTEXITCODE -ne 0 -or $actual -ne $env:EXPECTED_SHA) { + throw "PRESET_SOURCE_SHA_MISMATCH expected=$env:EXPECTED_SHA actual=$actual" + } + Write-Host "PRESET_CTEST_SOURCE_SHA=$actual" + - name: Checkout pinned JUCE 8 + uses: actions/checkout@v4 + with: + repository: juce-framework/JUCE + ref: 8.0.15 + path: third_party/JUCE + - name: Install WebView2 SDK needed by common CMake app configure + shell: pwsh + run: | + nuget install Microsoft.Web.WebView2 -Version 1.0.3485.44 -OutputDirectory .deps -NonInteractive + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + - name: Configure and validate CTest catalog + shell: pwsh + run: | + cmake -S . -B build -G "Visual Studio 17 2022" -A x64 ` + -DJUCE_ROOT="${{ github.workspace }}/third_party/JUCE" ` + -DBUILD_TESTING=ON ` + -DJUCE_WEBVIEW2_PACKAGE_LOCATION="${{ github.workspace }}/.deps" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + $catalogText = & ctest --test-dir build -C Release --show-only=json-v1 + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + $catalog = ($catalogText | Out-String | ConvertFrom-Json) + if ('BuiltInFxUserPresetNativePortableSaveAndRecovery' -notin + @($catalog.tests | ForEach-Object { $_.name })) { + throw 'PRESET_CTEST_MISSING_EXACT_SOURCE' + } + - name: Compile only native preset store test (not the whole mixer) + shell: pwsh + run: | + cmake --build build --config Release --parallel 2 --target ARMixBuiltInFxPresetStoreTests + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + - name: Run immutable-source Release CTest (assertions always enabled) + shell: pwsh + run: | + ctest --test-dir build -C Release --output-on-failure ` + -R '^BuiltInFxUserPresetNativePortableSaveAndRecovery$' + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + Write-Host 'PRESET_NATIVE_MSVC_TARGET_AND_DISK_ROUNDTRIP=PASS' diff --git a/CMakeLists.txt b/CMakeLists.txt index a6440f98d..124e56c6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,15 @@ if(BUILD_TESTING) target_link_libraries(ARMixFactoryFxRegistryTests PRIVATE juce::juce_core juce::juce_cryptography juce::juce_recommended_config_flags) target_compile_features(ARMixFactoryFxRegistryTests PRIVATE cxx_std_20) add_test(NAME FactoryFxVerifiedManifestAndNegativePathGate COMMAND ARMixFactoryFxRegistryTests) + # One user-owned, effect-scoped library; not .smix or FX-chain .armix. + # File IO is forbidden in the realtime PCM callback. + juce_add_console_app(ARMixBuiltInFxPresetStoreTests PRODUCT_NAME "ArSonMix Native Built-in FX User Preset Store") + target_sources(ARMixBuiltInFxPresetStoreTests PRIVATE + tests/builtin_fx_user_preset_store_test.cpp src/BuiltInFxUserPresetStore.h) + target_link_libraries(ARMixBuiltInFxPresetStoreTests PRIVATE + juce::juce_core juce::juce_cryptography juce::juce_recommended_config_flags) + target_compile_features(ARMixBuiltInFxPresetStoreTests PRIVATE cxx_std_20) + add_test(NAME BuiltInFxUserPresetNativePortableSaveAndRecovery COMMAND ARMixBuiltInFxPresetStoreTests) add_executable(ARMixFxStructuralHandoffTests tests/live_fx_structural_handoff_test.cpp) target_compile_features(ARMixFxStructuralHandoffTests PRIVATE cxx_std_20) add_test(NAME R0BStructuralFxAckAndControlThreadRetirement COMMAND ARMixFxStructuralHandoffTests) diff --git a/src/BuiltInFxUserPresetStore.h b/src/BuiltInFxUserPresetStore.h new file mode 100644 index 000000000..9fca0415f --- /dev/null +++ b/src/BuiltInFxUserPresetStore.h @@ -0,0 +1,277 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#pragma once +#include "PortableWorkspace.h" +#include +#include +#include +#include +#include +#include + +// CONTROL / IO THREAD ONLY. A per-built-in FX sound is deliberately NOT a +// .smix session or a historical .armix multi-insert My Sounds archive. +// This data service never touches a published JUCE AudioProcessor. The host +// must capture the exact accepted DSP readback before save and must apply a +// recalled preset through the existing audio-owner SPSC / ACK transaction. +namespace armix::storage { +struct BuiltInFxUserPreset { + juce::String id,catalogId,name,category; + juce::var settings; +}; +class BuiltInFxUserPresetStore final { +public: + explicit BuiltInFxUserPresetStore(juce::File workspace=PortableWorkspace::dataRoot()) + : root_(workspace.getChildFile("BuiltInFxPresets")) {} + + static constexpr juce::int64 maxBytes=16*1024; + static constexpr int maxFilesPerEffect=512; + static constexpr int schemaVersion=1; + + static juce::String effectFolder(const juce::String& catalog) { + if(catalog=="armix.builtin.channel-eq.v1")return "eq"; + if(catalog=="armix.builtin.channel-compressor.v1")return "compressor"; + if(catalog=="armix.builtin.arson-harmony.v1")return "harmonice"; + if(catalog=="armix.builtin.vocal-throw.v1")return "vocal-throw"; + return {}; + } + static bool safeText(const juce::String& value,int maxLen) { + if(value.isEmpty()||value.length()>maxLen||value.trim()!=value) + return false; + for(const auto ch:value) + if(ch<32||ch==127||ch=='/'||ch=='\\')return false; + return true; + } + static bool safeId(const juce::String& id) { + if(id.length()!=36)return false; + for(int i=0;i<36;++i) { + const auto ch=id[i]; + if(i==8||i==13||i==18||i==23){if(ch!='-')return false;} + else if(!((ch>='0'&&ch<='9')|| + (ch>='a'&&ch<='f')|| + (ch>='A'&&ch<='F')))return false; + } + return true; + } + static bool number(const juce::var& obj,const char* key,double a,double b) { + const auto v=obj.getProperty(key,{}); + if(!(v.isInt()||v.isDouble()))return false; + const double x=static_cast(v); + return std::isfinite(x)&&x>=a&&x<=b; + } + static bool integer(const juce::var& obj,const char* key,int a,int b) { + const auto v=obj.getProperty(key,{}); + return v.isInt()&&static_cast(v)>=a&&static_cast(v)<=b; + } + static bool boolean(const juce::var& obj,const char* key) { + return obj.getProperty(key,{}).isBool(); + } + static bool containsOnly(const juce::var& obj,const juce::StringArray& names) { + if(!obj.isObject())return false; + const auto& properties=obj.getDynamicObject()->getProperties(); + for(int i=0;i(mode)>=0&& + static_cast(mode)<=1))&& + boolean(settings,"correction")&&number(settings,"wet",0,1)&& + number(settings,"space",0,1)&&number(settings,"color",0,1)&& + number(settings,"gainDb",-24,12); + } + if(catalog=="armix.builtin.vocal-throw.v1"){ + if(!containsOnly(settings,{"mode","bpm","division","repeats","captureMs", + "silenceMs","thresholdDb","wet","decay","ducking"}))return false; + return integer(settings,"mode",0,2)&&number(settings,"bpm",60,200)&& + integer(settings,"division",0,3)&&integer(settings,"repeats",1,6)&& + number(settings,"captureMs",80,1500)&&number(settings,"silenceMs",80,900)&& + number(settings,"thresholdDb",-65,-15)&&number(settings,"wet",0,1)&& + number(settings,"decay",.15,.9)&&number(settings,"ducking",0,1); + } + if(catalog=="armix.builtin.channel-eq.v1"){ + if(!containsOnly(settings,{"bands"}))return false; + const auto bands=settings.getProperty("bands",{}); + if(!bands.isArray()||bands.getArray()->size()!=8)return false; + for(const auto& band:*bands.getArray()){ + if(!containsOnly(band,{"enabled","frequencyHz","gainDb","q","slope"})|| + !boolean(band,"enabled")||!number(band,"frequencyHz",20,20000)|| + !number(band,"gainDb",-18,18)||!number(band,"q",.2,12)|| + !(integer(band,"slope",12,12)||integer(band,"slope",24,24))) + return false; + } + return true; + } + return false; + } + + juce::String saveNew(BuiltInFxUserPreset& item) const { + if(!safeText(item.name,80)||!safeText(item.category,40)|| + !validateSettings(item.catalogId,item.settings)) + return "Preset name/category/parameters invalid"; + // Count physical files, not only valid parsed items. A corrupted + // 513-file library must not look empty and silently bypass quota. + // Fail closed on corrupt entries before creating a new user file. + juce::Array files; + folder(item.catalogId).findChildFiles( + files,juce::File::findFiles,false,"*.armixfx"); + if(files.size()>=maxFilesPerEffect) + return "Per-effect user preset quota reached"; + for(const auto& file:files) { + BuiltInFxUserPreset existing; + if(read(item.catalogId,file.getFileNameWithoutExtension(), + existing).isNotEmpty()) + return "Preset library contains an invalid/corrupt entry"; + } + auto list=enumerate(item.catalogId); + for(const auto& existing:list) + if(existing.name.equalsIgnoreCase(item.name)&& + existing.category.equalsIgnoreCase(item.category)) + return "Preset name already exists in this effect/category"; + const auto uuid=juce::Uuid().toDashedString().toLowerCase(); + if(!safeId(uuid))return "Unable to allocate preset ID"; + item.id=uuid; + return persist(item,false); + } + + juce::String overwrite(const BuiltInFxUserPreset& item) const { + BuiltInFxUserPreset old; + const auto error=read(item.catalogId,item.id,old); + if(error.isNotEmpty())return error; + if(!safeText(item.name,80)||!safeText(item.category,40)|| + !validateSettings(item.catalogId,item.settings)) + return "Invalid user preset edit"; + for(const auto& other:enumerate(item.catalogId)) + if(other.id!=item.id&&other.name.equalsIgnoreCase(item.name)&& + other.category.equalsIgnoreCase(item.category)) + return "Name collision with another user preset"; + return persist(item,true); + } + + juce::String rename(const juce::String& catalog,const juce::String& id, + const juce::String& newName) const { + BuiltInFxUserPreset old; + if(const auto error=read(catalog,id,old);error.isNotEmpty())return error; + old.name=newName; + return overwrite(old); + } + + juce::String remove(const juce::String& catalog,const juce::String& id) const { + BuiltInFxUserPreset existing; + if(const auto error=read(catalog,id,existing);error.isNotEmpty())return error; + const auto file=filename(catalog,id); + return file.deleteFile()?juce::String{}:"Unable to delete user preset"; + } + + juce::String read(const juce::String& catalog,const juce::String& id, + BuiltInFxUserPreset& result) const { + if(effectFolder(catalog).isEmpty()||!safeId(id)) + return "Invalid effect or preset ID"; + const auto file=filename(catalog,id); + if(!file.existsAsFile()||file.getSize()<1||file.getSize()>maxBytes) + return "Preset missing or exceeds size budget"; + const auto json=file.loadFileAsString(); + if(json.getNumBytesAsUTF8()>maxBytes)return "Preset size budget exceeded"; + auto record=juce::JSON::parse(json); + if(!record.isObject()|| + !containsOnly(record,{"schemaVersion","presetId","catalogId", + "name","category","settings","sha256"})) + return "Preset JSON schema invalid"; + if(!integer(record,"schemaVersion",schemaVersion,schemaVersion)|| + !record.getProperty("presetId","").toString().equalsIgnoreCase(id)|| + record.getProperty("catalogId","").toString()!=catalog) + return "Preset version/identity mismatch"; + BuiltInFxUserPreset entry{id,catalog,record.getProperty("name","").toString(), + record.getProperty("category","").toString(), + record.getProperty("settings",{})}; + if(!safeText(entry.name,80)||!safeText(entry.category,40)|| + !validateSettings(catalog,entry.settings))return "Preset parameters invalid"; + const auto payload=juce::JSON::toString(entry.settings,false); + const auto hash=juce::SHA256(payload.toRawUTF8(), + static_cast(payload.getNumBytesAsUTF8())).toHexString(); + if(record.getProperty("sha256","").toString()!=hash) + return "Preset settings checksum mismatch"; + result=std::move(entry); + return {}; + } + + std::vector enumerate(const juce::String& catalog) const { + std::vector items; + if(effectFolder(catalog).isEmpty())return items; + juce::Array files; + folder(catalog).findChildFiles(files,juce::File::findFiles,false,"*.armixfx"); + if(files.size()>maxFilesPerEffect)return items; // fail-closed; no unbounded scan + for(const auto& file:files){ + BuiltInFxUserPreset entry; + if(read(catalog,file.getFileNameWithoutExtension(),entry).isEmpty()) + items.push_back(std::move(entry)); + } + std::sort(items.begin(),items.end(),[](const auto& a,const auto& b){ + const auto order=a.category.compareIgnoreCase(b.category); + return order?order<0:a.name.compareIgnoreCase(b.name)<0; + }); + return items; + } +private: + juce::File folder(const juce::String& catalog) const { + return root_.getChildFile(effectFolder(catalog)); + } + juce::File filename(const juce::String& catalog,const juce::String& id) const { + if(effectFolder(catalog).isEmpty()||!safeId(id))return {}; + return folder(catalog).getChildFile(id.toLowerCase()+".armixfx"); + } + juce::String persist(const BuiltInFxUserPreset& entry,bool replacing) const { + if(!safeId(entry.id)||effectFolder(entry.catalogId).isEmpty()|| + !validateSettings(entry.catalogId,entry.settings)) + return "Preset identity/parameters invalid"; + const auto dir=folder(entry.catalogId); + if(!dir.isDirectory()&&dir.createDirectory().failed()) + return "Cannot create user preset directory"; + const auto file=filename(entry.catalogId,entry.id); + if(file.existsAsFile()!=replacing) + return "Preset write conflict; old data preserved"; + const auto payload=juce::JSON::toString(entry.settings,false); + const auto hash=juce::SHA256(payload.toRawUTF8(), + static_cast(payload.getNumBytesAsUTF8())).toHexString(); + auto obj=juce::var(new juce::DynamicObject()); + auto* fields=obj.getDynamicObject(); + fields->setProperty("schemaVersion",schemaVersion); + fields->setProperty("presetId",entry.id); + fields->setProperty("catalogId",entry.catalogId); + fields->setProperty("name",entry.name); + fields->setProperty("category",entry.category); + fields->setProperty("settings",entry.settings); + fields->setProperty("sha256",hash); + const auto json=juce::JSON::toString(obj,false); + if(json.getNumBytesAsUTF8()>maxBytes)return "Preset exceeds size budget"; + juce::TemporaryFile stage(file); + if(!stage.getFile().replaceWithText(json))return "Could not stage user preset"; + // Verify stage content without publishing a partial file. + const auto candidate=juce::JSON::parse(stage.getFile().loadFileAsString()); + if(!candidate.isObject()|| + candidate.getProperty("sha256","").toString()!=hash) + return "Staged preset verification failed"; + return stage.overwriteTargetFileWithTemporary()?juce::String{}: + juce::String("Could not commit user preset atomically"); + } + juce::File root_; +}; +} // namespace armix::storage diff --git a/tests/builtin_fx_user_preset_store_test.cpp b/tests/builtin_fx_user_preset_store_test.cpp new file mode 100644 index 000000000..1d2240e37 --- /dev/null +++ b/tests/builtin_fx_user_preset_store_test.cpp @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: AGPL-3.0-only +#include "../src/BuiltInFxUserPresetStore.h" +#include +#include +#include +#include +using armix::storage::BuiltInFxUserPreset; +using armix::storage::BuiltInFxUserPresetStore; + +// Do not use : Release/NDEBUG omits both assertions AND their +// mutating operations, producing a false-green Windows CTest. +#define REQUIRE(expr) do { if (!(expr)) throw std::runtime_error(\ + std::string("PRESET_TEST_FAILED: ") + #expr + " at line " +\ + std::to_string(__LINE__)); } while (false) + + +static juce::var object(std::initializer_list> fields) { + juce::var out(new juce::DynamicObject()); + for(const auto& item:fields) + out.getDynamicObject()->setProperty(item.first,item.second); + return out; +} +static BuiltInFxUserPreset comp() { + return {{}, "armix.builtin.channel-compressor.v1", "Live Vocal", "Voice", + object({{"thresholdDb",-18.0},{"ratio",3.0},{"attackMs",10.0}, + {"releaseMs",120.0},{"kneeDb",6.0},{"makeupDb",2.0},{"mix",1.0}})}; +} +static BuiltInFxUserPreset harmony() { + return {{}, "armix.builtin.arson-harmony.v1","My Trio","Harmony", + object({{"key",0},{"scale",0},{"voices",3},{"voiceMode",0}, + {"correction",false},{"wet",0.45},{"space",0.6}, + {"color",0.5},{"gainDb",0.0}})}; +} +static BuiltInFxUserPreset throwSettings() { + return {{}, "armix.builtin.vocal-throw.v1","Last Word","Vocal", + object({{"mode",2},{"bpm",120.0},{"division",0},{"repeats",3}, + {"captureMs",460.0},{"silenceMs",220.0},{"thresholdDb",-35.0}, + {"wet",0.42},{"decay",0.55},{"ducking",0.7}})}; +} +static BuiltInFxUserPreset eq() { + auto bands=juce::var(juce::Array{}); + for(int i=0;i<8;++i) + bands.append(object({{"enabled",i==2},{"frequencyHz",i==2?2300.0:1000.0}, + {"gainDb",i==2?2.5:0.0},{"q",1.0},{"slope",12}})); + return {{}, "armix.builtin.channel-eq.v1","Vocal Presence","Voice", + object({{"bands",bands}})}; +} +int main() { + try { + const auto testRoot=juce::File::getSpecialLocation( + juce::File::tempDirectory).getChildFile( + "ArSonMix-Preset-CTest-"+juce::Uuid().toDashedString()); + REQUIRE(!testRoot.exists()); + struct Cleanup { juce::File folder;~Cleanup(){folder.deleteRecursively();} } cleanup{testRoot}; + BuiltInFxUserPresetStore store(testRoot); + auto items=std::array{comp(),harmony(),throwSettings(),eq()}; + for(auto& item:items) { + REQUIRE(BuiltInFxUserPresetStore::validateSettings(item.catalogId,item.settings)); + REQUIRE(store.saveNew(item).isEmpty()); + REQUIRE(BuiltInFxUserPresetStore::safeId(item.id)); + BuiltInFxUserPreset readback; + REQUIRE(store.read(item.catalogId,item.id,readback).isEmpty()); + REQUIRE(readback.name==item.name); + REQUIRE(juce::JSON::toString(readback.settings,false)== + juce::JSON::toString(item.settings,false)); + const BuiltInFxUserPresetStore reopened(testRoot); + BuiltInFxUserPreset cold; + REQUIRE(reopened.read(item.catalogId,item.id,cold).isEmpty()); + REQUIRE(cold.id==item.id); + REQUIRE(reopened.enumerate(item.catalogId).size()==1); + // Presets are effect-scoped rather than channel, slot or device-scoped. + for(const auto& other:items) + if(other.catalogId!=item.catalogId) { + BuiltInFxUserPreset wrong; + REQUIRE(reopened.read(other.catalogId,item.id,wrong).isNotEmpty()); + } + } + // Factory and user data must remain conceptually distinct; disk-only + // user presets cannot silently be replaced by same category/name. + auto duplicate=comp(); + REQUIRE(store.saveNew(duplicate).isNotEmpty()); + auto renamed=items[0]; + renamed.name="Natural Vocal"; + REQUIRE(store.overwrite(renamed).isEmpty()); + BuiltInFxUserPreset readback; + REQUIRE(store.read(renamed.catalogId,renamed.id,readback).isEmpty()); + REQUIRE(readback.name=="Natural Vocal"); + REQUIRE(store.rename(renamed.catalogId,renamed.id,"Warm Vocal").isEmpty()); + REQUIRE(store.read(renamed.catalogId,renamed.id,readback).isEmpty()); + REQUIRE(readback.name=="Warm Vocal"); + REQUIRE(store.remove(renamed.catalogId,renamed.id).isEmpty()); + REQUIRE(store.read(renamed.catalogId,renamed.id,readback).isNotEmpty()); + // Exercise an actual overwrite of accepted settings; it must survive a + // cold store re-open, independent of any mixer channel or session. + auto tuned=items[2]; + tuned.settings.getDynamicObject()->setProperty("wet",0.83); + REQUIRE(store.overwrite(tuned).isEmpty()); + BuiltInFxUserPreset coldTuned; + REQUIRE(BuiltInFxUserPresetStore(testRoot).read( + tuned.catalogId,tuned.id,coldTuned).isEmpty()); + REQUIRE(static_cast( + coldTuned.settings.getProperty("wet",{}))==0.83); + // A new preset may not fake a factory or malformed unique identity. + auto preassigned=comp(); + preassigned.id="../../unsafe"; + REQUIRE(store.saveNew(preassigned).isEmpty()); + REQUIRE(BuiltInFxUserPresetStore::safeId(preassigned.id)); + REQUIRE(store.remove(preassigned.catalogId,preassigned.id).isEmpty()); + // Nonportable channel routing, malformed/hostile values, unknown version + // and cross-catalog data must all fail without damaging another preset. + auto bad=harmony(); + bad.settings.getDynamicObject()->setProperty("guideChannelId","123456"); + REQUIRE(!BuiltInFxUserPresetStore::validateSettings(bad.catalogId,bad.settings)); + REQUIRE(store.saveNew(bad).isNotEmpty()); + bad=harmony();bad.settings.getDynamicObject()->setProperty("voices",7); + REQUIRE(store.saveNew(bad).isNotEmpty()); + bad=throwSettings();bad.settings.getDynamicObject()->setProperty("bpm",-1); + REQUIRE(store.saveNew(bad).isNotEmpty()); + bad=eq();bad.settings.getDynamicObject()->setProperty("liveInput",2); + REQUIRE(store.saveNew(bad).isNotEmpty()); + REQUIRE(BuiltInFxUserPresetStore::safeId( + "12345678-1234-AbCd-ABCD-0123456789Ab")); + REQUIRE(!BuiltInFxUserPresetStore::safeId( + "12345678-1234-AbCd-GBCD-0123456789Ab")); + REQUIRE(!BuiltInFxUserPresetStore::safeId( + "12345678-1234-AbCd-ABCD-0123456789A/")); + REQUIRE(!BuiltInFxUserPresetStore::safeId("../outside")); + REQUIRE(!BuiltInFxUserPresetStore::safeText("../outside",80)); + REQUIRE(!BuiltInFxUserPresetStore::safeText("bad/name",80)); + REQUIRE(!BuiltInFxUserPresetStore::safeText("hi\nthere",80)); + REQUIRE(!BuiltInFxUserPresetStore::validateSettings( + "vendor.external.plugin",comp().settings)); + // Checksum or schema corruption must not be advertised as a valid sound. + const auto& saved=items[1]; + const auto path=testRoot.getChildFile("BuiltInFxPresets") + .getChildFile("harmonice").getChildFile(saved.id+".armixfx"); + REQUIRE(path.existsAsFile()); + auto tampered=juce::JSON::parse(path.loadFileAsString()); + REQUIRE(tampered.isObject()); + tampered.getDynamicObject()->setProperty("sha256","deadbeef"); + REQUIRE(path.replaceWithText(juce::JSON::toString(tampered,false))); + REQUIRE(store.read(saved.catalogId,saved.id,readback).isNotEmpty()); + REQUIRE(store.enumerate(saved.catalogId).empty()); + // Corruption must not bypass either quota or name collision checks. + // This exercise is required in Release; no side-effecting assert(). + const auto compDir=testRoot.getChildFile("BuiltInFxPresets") + .getChildFile("compressor"); + const auto corrupt=compDir.getChildFile( + "22222222-2222-2222-2222-222222222222.armixfx"); + REQUIRE(corrupt.replaceWithText("{bad json")); + auto otherwiseValid=comp(); + otherwiseValid.name="Safe New"; + REQUIRE(store.saveNew(otherwiseValid).isNotEmpty()); + REQUIRE(otherwiseValid.id.isEmpty()); + REQUIRE(corrupt.deleteFile()); + // Empty/stale data from another catalogue must not become a mixer preset. + REQUIRE(store.enumerate(comp().catalogId).empty()); + std::cout<<"Shared per-built-in FX preset store: EQ/Comp/Harmony/Throw " + <<"native typed disk roundtrip, corruption and rollback PASS\n"; + return 0; + } catch (const std::exception& e) { + std::cerr<<"PRESET_CTEST_REJECTED: "<