mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 16:29:04 +00:00
scripts/test.mjs gave every test file scratch copies of APPDATA, LOCALAPPDATA, the
XDG folders and the settings and components files, but kept the person's HOME and
USERPROFILE: the Harness finds personal skills through the home folder and the
host's data root (STRATA_HOME) defaults to it, so a test run could read the
developer's own skills and state. The runner now gives the children a scratch home
and STRATA_HOME as well.
Test (contributor's): test-runner-home.test.mjs (a personal skill and state beside
the run are not seen; the child writes only in scratch): fails on e06e5d871, passes.
24 lines
2.3 KiB
JavaScript
24 lines
2.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/** Enumerate test files explicitly so npm test works without shell glob expansion. */
|
|
import {readdirSync} from 'node:fs';
|
|
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));
|
|
/* 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 {mkdirSync,mkdtempSync} from 'node:fs';
|
|
import {tmpdir} from 'node:os';
|
|
import {join} from 'node:path';
|
|
const scratch=mkdtempSync(join(tmpdir(),'strata-host-suite-profile-'));
|
|
// Harness discovers personal skills through the home directory, independently of APPDATA/XDG.
|
|
const home=join(scratch,'home');mkdirSync(home);
|
|
const env={...process.env,HOME:home,USERPROFILE:home,STRATA_HOME:home,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')};
|
|
/* Run from PowerShell 7 (GitHub's Windows runners), PSModulePath names PowerShell 7's module folders first and a Windows PowerShell 5.1 child
|
|
that a test starts cannot load Get-Acl / Get-FileHash from them: keep only the folders that are not PowerShell 7's. */
|
|
if(process.platform==='win32'&&env.PSModulePath){const ps7=p=>{const l=p.toLowerCase().replace(/\//g,'\\');return l.includes('\\powershell\\')&&!l.includes('\\windowspowershell\\');};env.PSModulePath=env.PSModulePath.split(';').filter(p=>p&&!ps7(p)).join(';');}
|
|
/* A test that never finishes fails after STRATA_TEST_TIMEOUT_MS (default 10 minutes) instead of holding the whole run for ever; extra arguments (a reporter, --test-name-pattern) go to node --test. */
|
|
const timeout=Number(process.env.STRATA_TEST_TIMEOUT_MS)||600000;
|
|
const child=spawn(process.execPath,['--test',`--test-timeout=${timeout}`,...process.argv.slice(2),...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);});
|