Fix File > Open MSR dropping content through the preload bridge
preload.js readFile forwarded only null on success, so the renderer's openFile handler received undefined data and threw on data.toString() after the file dialog closed. Pass the content through (err, data). Add a bridge-contract regression test that settles on the renderer's load callback, plus a source-level guard that the readFile callback forwards data.
This commit is contained in:
1 parent
f740d53452
commit
37a54984bd
3 files changed
+67
-3
No files matched your search
@@ -3,6 +3,13 @@
|
||||
All notable changes to muSRFlow are recorded here. The project follows the
|
||||
release path documented in [`TODO.md`](TODO.md).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Bug fixes
|
||||
- File > Open MSR... now loads the selected file. The preload bridge's async
|
||||
`readFile` wrapper was forwarding only the error and dropping the content, so
|
||||
the renderer's `data.toString()` failed silently after the dialog closed.
|
||||
|
||||
## [0.9.0-beta.5] - 2026-09-07
|
||||
|
||||
### t0 / Background / Data range
|
||||
|
||||
+2
-2
@@ -121,9 +121,9 @@ const bridge = {
|
||||
if (typeof callback === "function") callback(err ? { message: err.message } : null);
|
||||
});
|
||||
},
|
||||
readFile: function (p, encoding, callback) {
|
||||
readFile: function (p, encoding, callback) {
|
||||
fs.readFile(p, encoding, function (err, data) {
|
||||
if (typeof callback === "function") callback(err, data);
|
||||
if (typeof callback === "function") callback(err ? { message: err.message } : null, data);
|
||||
});
|
||||
},
|
||||
constants: {
|
||||
|
||||
@@ -190,6 +190,55 @@ function testBridgeChildProcessSurface() {
|
||||
assert.strictEqual(syncRes.status, 0);
|
||||
}
|
||||
|
||||
// The preload readFile wrapper must forward the content and not just the error.
|
||||
// The renderer's Open MSR handler consumes (err, data); dropping data made the
|
||||
// File > Open MSR menu appear to do nothing while an uncaught data.toString()
|
||||
// TypeError fired on the renderer side.
|
||||
function testPreloadReadFileForwardsData() {
|
||||
const preloadContents = fs.readFileSync(path.join(repoRoot, "preload.js"), "utf8");
|
||||
assert.match(preloadContents, /callback\(err \? \{ message: err\.message \} : null, data\)/);
|
||||
const renderer = fs.readFileSync(path.join(repoRoot, "muSRFitelec.js"), "utf8");
|
||||
assert.match(renderer, /readFile\(filePath, "utf8", function read\(err, data\)/);
|
||||
assert.match(renderer, /loadMSRIntoEditor\(data\.toString\(\), filePath/);
|
||||
}
|
||||
|
||||
// Run file-menu payloads crossing the bridge contract with the real preload
|
||||
// readFile semantics: success forwards content to the renderer callback. The
|
||||
// read is asynchronous, so this test settles on the renderer's load callback.
|
||||
function testFileMenuOpenForwardsContentThroughBridge() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
const bridge = makeBridge();
|
||||
bridge.fs.readFile = function (p, encoding, callback) {
|
||||
fs.readFile(p, encoding, function (err, data) {
|
||||
if (typeof callback === "function") callback(err ? { message: err.message } : null, data);
|
||||
});
|
||||
};
|
||||
const { lib } = load(bridge);
|
||||
let loaded = false;
|
||||
lib.loadMSRIntoEditor = function (contents, filePath) {
|
||||
try {
|
||||
assert.strictEqual(contents, "TITLE Content forwarded\n");
|
||||
loaded = true;
|
||||
resolve();
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
};
|
||||
lib.openTab = function () {
|
||||
};
|
||||
lib.firstLoad();
|
||||
|
||||
const sourcePath = path.join(testRoot, "bridge-open-content.msr");
|
||||
fs.writeFileSync(sourcePath, "TITLE Content forwarded\n", "utf8");
|
||||
bridge.ipc.listeners.openFile[0]([sourcePath]);
|
||||
setTimeout(function() {
|
||||
if (!loaded) {
|
||||
reject(new Error("MSR open did not reach loadMSRIntoEditor"));
|
||||
}
|
||||
}, 200);
|
||||
});
|
||||
}
|
||||
|
||||
// A new working directory must exist before checkDir returns. Existing files
|
||||
// must be rejected immediately rather than failing later during MSR generation.
|
||||
function testSynchronousWorkDirectoryPreparation() {
|
||||
@@ -311,6 +360,8 @@ testBridgeChildProcessSurface();
|
||||
testSynchronousWorkDirectoryPreparation();
|
||||
testPreferenceBrowsePayloadsUseBridgeContract();
|
||||
testFileMenuPayloadsUseBridgeContract();
|
||||
const openForwards = testFileMenuOpenForwardsContentThroughBridge();
|
||||
testPreloadReadFileForwardsData();
|
||||
testRunLocalProcessOverBridge();
|
||||
testHardeningContract();
|
||||
testPreloadExposesBridgeObject();
|
||||
@@ -448,4 +499,10 @@ function testParameterPlotElecLoadsLocalPlotly() {
|
||||
testParameterPlotWindowUsesBridge();
|
||||
testParameterPlotElecAdapterUsesBridge();
|
||||
testParameterPlotElecLoadsLocalPlotly();
|
||||
console.log("Electron preload-bridge tests passed");
|
||||
|
||||
openForwards.then(function() {
|
||||
console.log("Electron preload-bridge tests passed");
|
||||
}).catch(function(error) {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in new issue
Block a user