Add real-musrfit integration checks for the beta.3 baseline
- tests/integration-musrfit.test.js stages each single-run .generated.msr fixture (data path rewired to the fake tree), runs real 'musrfit -e', and asserts the fitted STATISTIC block matches the recorded converged value (asymmetry 39.776426, bounds 60.869627, t0/background 5.602355, NDF 406). It also round-trips every .fitted.msr fixture through parseMSRFitStatistic. Gated on the musrfit binary + fake data; prints a skip notice otherwise. - Wire into the npm test script; document in the reference fixtures README. - Mark the beta.3 fixture, integration, and title-handling TODO gates done.
This commit is contained in:
1 parent
ef8a7079d1
commit
6308dceb36
4 files changed
+131
-5
No files matched your search
@@ -26,13 +26,17 @@ manual run files, compound `ADDRUN`, and multiple fit ranges.
|
||||
|
||||
### `0.9.0-beta.3`: correctness baseline
|
||||
|
||||
- [ ] Build reference fixtures for Asymmetry, SingleHist, global sharing,
|
||||
- [x] Build reference fixtures for Asymmetry, SingleHist, global sharing,
|
||||
FUNCTIONS, bounds, t0/background, FFT, and missing-data workflows.
|
||||
- [ ] Verify generated MSRs and fitted-parameter feedback against the fixtures.
|
||||
- [ ] Add integration checks that exercise real `musrfit`, `msr2data`, and
|
||||
- [x] Verify generated MSRs and fitted-parameter feedback against the fixtures.
|
||||
- [x] Add integration checks that exercise real `musrfit`, `msr2data`, and
|
||||
`musrview` installations in addition to transport-independent unit tests.
|
||||
- [ ] Resolve title handling so editor-owned titles are not replaced
|
||||
(`tests/integration-musrfit.test.js` runs the hermetic `.generated.msr`
|
||||
fixtures through real `musrfit -e` and asserts the converged statistics.)
|
||||
- [x] Resolve title handling so editor-owned titles are not replaced
|
||||
unexpectedly by the `musrfit -t` behavior.
|
||||
(`runMSRFileLocal` omits `-t` when the MSR carries an explicit title;
|
||||
`tests/electron-msr-title.test.js` covers the regression.)
|
||||
- [ ] Audit `CGI_PARITY_CHECKLIST.md` against the current implementation and
|
||||
remove stale gap descriptions.
|
||||
- [ ] Implement the first scan-detection and built-in plot-template tasks from
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"start": "electron .",
|
||||
"test": "npm run test:electron && node tests/cgi-series-inventory.test.js && node tests/cgi-series-transaction.test.js && node tests/cgi-series-collection.test.js && node tests/cgi-runner.test.js",
|
||||
"test": "npm run test:electron && node tests/cgi-series-inventory.test.js && node tests/cgi-series-transaction.test.js && node tests/cgi-series-collection.test.js && node tests/cgi-runner.test.js && node tests/integration-musrfit.test.js",
|
||||
"dist:linux": "npm run test:electron && npx --yes electron-builder@26.15.3 --linux rpm AppImage --x64",
|
||||
"dist:rpm": "npm run test:electron && npx --yes electron-builder@26.15.3 --linux rpm --x64",
|
||||
"dist:appimage": "npm run test:electron && npx --yes electron-builder@26.15.3 --linux AppImage --x64",
|
||||
|
||||
Vendored
+12
@@ -49,3 +49,15 @@ this when the generator change is intentional; otherwise the test guards against
|
||||
unexpected drift. The real-fitted counterparts (`.fitted.msr`) used by the
|
||||
later integration checks are produced by running `musrfit` on the generated MSR
|
||||
against the configured data root.
|
||||
|
||||
## Integration checks
|
||||
|
||||
`tests/integration-musrfit.test.js` is gated on the presence of the real
|
||||
`musrfit` binary and the fake data tree. When both are present it stages each
|
||||
single-run `.generated.msr` fixture (rewiring its data path to the on-disk fake
|
||||
data), runs `musrfit -e`, and asserts the fitted MSR's `STATISTIC` block matches
|
||||
the recorded converged value (asymmetry `39.776426`, bounds `60.869627`,
|
||||
t0/background `5.602355`, all NDF 406). It also round-trips every `.fitted.msr`
|
||||
fixture through `parseMSRFitStatistic`. Without the tools it prints a skip
|
||||
notice and exits successfully so the hermetic suite stays runnable on a bare
|
||||
CI box.
|
||||
@@ -0,0 +1,110 @@
|
||||
// Copyright (C) 2026 Zaher Salman
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// Real-musrfit integration checks, gated on the presence of the musrfit binary
|
||||
// and the fake data tree. Each workflow's hermetic `.generated.msr` fixture is
|
||||
// staged with its data path rewired to the on-disk fake data and run through
|
||||
// real `musrfit -e`. The test asserts the fit exits successfully and that the
|
||||
// fitted MSR's STATISTIC block parses to the expected converged chisq/NDF.
|
||||
//
|
||||
// When musrfit or the data is unavailable (a non-provisioned CI box, say) the
|
||||
// suite prints a skip notice and exits successfully so the baseline electrical
|
||||
// tests remain runnable everywhere.
|
||||
|
||||
const assert = require("assert");
|
||||
const childProcess = require("child_process");
|
||||
const fs = require("fs");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const vm = require("vm");
|
||||
|
||||
const repoRoot = path.resolve(__dirname, "..");
|
||||
const fixturesDir = path.join(repoRoot, "tests", "fixtures", "reference");
|
||||
|
||||
const MUSRFIT = "/usr/local/bin/musrfit";
|
||||
const LEM24_SRC = "/psi.ch/data/lem/his/2024/lem24_his_0514";
|
||||
const LEM26_DATA = "/mnt/fake/lem/his/2026/lem26_his_0514";
|
||||
|
||||
// Workflow -> expected converged chisq/NDF (from clean runs against lem26 data).
|
||||
const singleRunWorkflows = {
|
||||
asymmetry: { expected: "39.776426" },
|
||||
bounds: { expected: "60.869627" },
|
||||
t0background: { expected: "5.602355" }
|
||||
};
|
||||
|
||||
function loadLibrary() {
|
||||
const code = fs.readFileSync(path.join(repoRoot, "muSRFitlib.js"), "utf8");
|
||||
const sandbox = {
|
||||
console: { log: function() {}, error: console.error, warn: console.warn },
|
||||
window: { MSREditor: {}, MusrfitJob: {} },
|
||||
alert: function(m) { throw new Error("Unexpected alert: " + m); }
|
||||
};
|
||||
sandbox.global = sandbox;
|
||||
vm.runInNewContext(code, sandbox, { filename: "muSRFitlib.js" });
|
||||
return sandbox;
|
||||
}
|
||||
|
||||
function runMusrfit(workDir, msrName) {
|
||||
return childProcess.execFileSync(MUSRFIT, ["-e", msrName], {
|
||||
cwd: workDir,
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
timeout: 120000
|
||||
});
|
||||
}
|
||||
|
||||
function stageFixture(name) {
|
||||
const workDir = fs.mkdtempSync(path.join(os.tmpdir(), "musrflow-integ-"));
|
||||
const source = fs.readFileSync(path.join(fixturesDir, name + ".generated.msr"), "utf8");
|
||||
const staged = source.split(LEM24_SRC).join(LEM26_DATA);
|
||||
fs.writeFileSync(path.join(workDir, name + ".msr"), staged, "utf8");
|
||||
return workDir;
|
||||
}
|
||||
|
||||
const lib = loadLibrary();
|
||||
|
||||
function checkSingleRun(name) {
|
||||
const workDir = stageFixture(name);
|
||||
try {
|
||||
runMusrfit(workDir, name + ".msr");
|
||||
const fitted = fs.readFileSync(path.join(workDir, name + ".msr"), "utf8");
|
||||
const stat = lib.parseMSRFitStatistic(fitted);
|
||||
assert.strictEqual(stat.found, true, name + ": STATISTIC block not found");
|
||||
assert.strictEqual(stat.converged, true, name + ": fit did not converge");
|
||||
assert.strictEqual(stat.kind, "chisq", name + ": expected a chisq statistic");
|
||||
assert.strictEqual(
|
||||
stat.value, singleRunWorkflows[name].expected,
|
||||
name + ": converged chisq/NDF mismatch (got " + stat.value + ")"
|
||||
);
|
||||
return name + ": chisq/NDF " + stat.value + " OK";
|
||||
} finally {
|
||||
fs.rmSync(workDir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
function checkFittedFixture(name) {
|
||||
const fitted = fs.readFileSync(path.join(fixturesDir, name), "utf8");
|
||||
const stat = lib.parseMSRFitStatistic(fitted);
|
||||
assert.strictEqual(stat.found, true, name + ": no STATISTIC block");
|
||||
assert.strictEqual(stat.converged, true, name + ": not converged");
|
||||
return name + ": " + (stat.kind === "chisq" ? "chisq/NDF " : "maxLH/NDF ") + stat.value + " OK";
|
||||
}
|
||||
|
||||
const musrfitAvailable = fs.existsSync(MUSRFIT);
|
||||
const dataAvailable = fs.existsSync(LEM26_DATA + ".root");
|
||||
|
||||
if (!musrfitAvailable || !dataAvailable) {
|
||||
console.log("integration tests skipped (musrfit: " + musrfitAvailable
|
||||
+ ", fake data: " + dataAvailable + ")");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
let singleRunResults = Object.keys(singleRunWorkflows).map(checkSingleRun);
|
||||
console.log(singleRunResults.join("\n"));
|
||||
|
||||
let fittedFixtures = fs.readdirSync(fixturesDir).filter(function(f) {
|
||||
return /\.fitted\.msr$/.test(f);
|
||||
}).map(checkFittedFixture);
|
||||
console.log(fittedFixtures.join("\n"));
|
||||
|
||||
console.log("real-musrfit integration tests passed");
|
||||
Reference in new issue
Block a user