Tests never write the owner's real Strata profile: pytest gets scratch LOCALAPPDATA/XDG state and data folders; the host test runner and the native-control test files get a scratch settings file, components folder and app data

This commit is contained in:
Niko1221 committed 2026-10-24 18:43:52 +02:00
1 parent 67a6ee76f4
commit 535cacb052
10 files changed
+39 -1

No files matched your search

+7 -1
View File
@@ -5,6 +5,12 @@ import {spawn} from 'node:child_process';
import {resolve} from 'node:path';
const root=resolve(import.meta.dirname,'..');
const files=readdirSync(resolve(root,'tests')).filter(name=>name.endsWith('.test.mjs')).sort().map(name=>resolve(root,'tests',name));
const child=spawn(process.execPath,['--test',...files],{cwd:root,stdio:'inherit'});
/* Every test file runs against scratch copies of the per-user places the host writes to (the owner's real profile is never touched). */
import {mkdtempSync} from 'node:fs';
import {tmpdir} from 'node:os';
import {join} from 'node:path';
const scratch=mkdtempSync(join(tmpdir(),'strata-host-suite-profile-'));
const env={...process.env,STRATA_SETTINGS_FILE:join(scratch,'app-settings.json'),STRATA_COMPONENTS_DIR:join(scratch,'components'),LOCALAPPDATA:join(scratch,'Local'),APPDATA:join(scratch,'Roaming'),XDG_DATA_HOME:join(scratch,'xdg-data'),XDG_STATE_HOME:join(scratch,'xdg-state'),XDG_CONFIG_HOME:join(scratch,'xdg-config')};
const child=spawn(process.execPath,['--test',...files],{cwd:root,stdio:'inherit',env});
child.on('error',error=>{console.error(error.message);process.exitCode=1;});
child.on('exit',(code,signal)=>{process.exitCode=code??(signal?1:0);});
@@ -1,3 +1,4 @@
import './helpers/isolate-profile.mjs'; // a test run never writes the owner's real Strata profile
import test from 'node:test';
import assert from 'node:assert/strict';
import { EventEmitter } from 'node:events';
+1
View File
@@ -3,6 +3,7 @@
* Setup writes --mtp, --spec-min-p and --vision into the arguments every time it runs; the host applies the saved choices on every
* load. Nothing here starts an engine; Control is a fake that records what the host saved and asked it to start.
*/
import './helpers/isolate-profile.mjs'; // a test run never writes the owner's real Strata profile
import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
@@ -0,0 +1,19 @@
/**
* Import this FIRST in a test that builds the host's native control or starts the host: it points the per-user places the host writes to
* (the settings file Control reads, the components folder, the app's local data) at a scratch folder.
* On 2026-10-24 a host test run rewrote the owner's real %LOCALAPPDATA%\Strata\app-settings.json (its data_dir became a deleted test folder).
*/
import { mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
if (!process.env.STRATA_TEST_KEEP_PROFILE) {
const scratch = mkdtempSync(join(tmpdir(), 'strata-host-test-profile-'));
process.env.STRATA_SETTINGS_FILE = join(scratch, 'app-settings.json');
process.env.STRATA_COMPONENTS_DIR = join(scratch, 'components');
process.env.LOCALAPPDATA = join(scratch, 'Local');
process.env.APPDATA = join(scratch, 'Roaming');
process.env.XDG_DATA_HOME = join(scratch, 'xdg-data');
process.env.XDG_STATE_HOME = join(scratch, 'xdg-state');
process.env.XDG_CONFIG_HOME = join(scratch, 'xdg-config');
}
+1
View File
@@ -1,3 +1,4 @@
import './helpers/isolate-profile.mjs'; // a test run never writes the owner's real Strata profile
import test from 'node:test';
import assert from 'node:assert/strict';
import { EventEmitter } from 'node:events';
+1
View File
@@ -1,3 +1,4 @@
import './helpers/isolate-profile.mjs'; // a test run never writes the owner's real Strata profile
import test from 'node:test';
import assert from 'node:assert/strict';
import { spawn } from 'node:child_process';
@@ -1,3 +1,4 @@
import './helpers/isolate-profile.mjs'; // a test run never writes the owner's real Strata profile
import test from 'node:test';
import assert from 'node:assert/strict';
import { EventEmitter } from 'node:events';
@@ -3,6 +3,7 @@
* retry with one when a load with several slots fails. Nothing here starts an engine; Control is a fake that records what
* the host saved and asked it to start.
*/
import './helpers/isolate-profile.mjs'; // a test run never writes the owner's real Strata profile
import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+1
View File
@@ -3,6 +3,7 @@
* apps", and engine arguments the app does not know (the control vector options). Nothing here starts an engine; Control is a fake that
* records the run file the host saved and asked it to start.
*/
import './helpers/isolate-profile.mjs'; // a test run never writes the owner's real Strata profile
import test from 'node:test';
import assert from 'node:assert/strict';
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+6
View File
@@ -7,3 +7,9 @@ import tempfile
_home = tempfile.mkdtemp(prefix="strata-pytest-config-")
os.environ["APPDATA"] = _home
os.environ["XDG_CONFIG_HOME"] = _home
# The per-user STATE and DATA folders too (%LOCALAPPDATA%\Strata: tuning/recheck.json, the engine store, the update records; ~/.local/state, ~/.local/share).
# A test that installs a stub engine marks saved tuning presets for a re-check there: on 2026-10-24 one such run left an entry in the owner's real
# tuning\recheck.json. A test that wants a place of its own still names it (STRATA_COMPONENTS_DIR, state_base=...).
os.environ["LOCALAPPDATA"] = _home
os.environ["XDG_STATE_HOME"] = _home
os.environ["XDG_DATA_HOME"] = _home