结论:真实 Node/native DB_PROGRAM transcript 与 flat-file 已接入 Tool DB OPFS store 证据链,浏览器执行仍保持锁定等待 Python/WASM Worker。
79 lines
2.5 KiB
JavaScript
79 lines
2.5 KiB
JavaScript
import {
|
|
loadToolDbFile,
|
|
loadToolDbTranscript,
|
|
saveToolDbFile,
|
|
saveToolDbTranscript,
|
|
} from "../../opfs/tool-db-store.js";
|
|
import {
|
|
createToolDbProcessDiagnostics,
|
|
createToolDbTransactionPlan,
|
|
validateToolDbTranscript,
|
|
} from "./tool-db-process-port.js";
|
|
|
|
function requireString(value, label) {
|
|
if (typeof value !== "string" || value.length === 0) {
|
|
throw new Error(`${label} must be a non-empty string.`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
export async function runToolDbProcessPortPersistenceSession({
|
|
port,
|
|
machineId,
|
|
runId = "run-1",
|
|
dbProgramPath = "./db_nonran.py",
|
|
dbFileText,
|
|
storage,
|
|
plan = createToolDbTransactionPlan(),
|
|
startupToolCount = 10,
|
|
mutationCount = 3,
|
|
readDbFileText = null,
|
|
} = {}) {
|
|
if (!port?.start || !port?.runTransactionPlan || !port?.exportTranscript || !port?.close) {
|
|
throw new Error("port must be a ToolDbProcessPort-like object.");
|
|
}
|
|
requireString(machineId, "machineId");
|
|
requireString(runId, "runId");
|
|
requireString(dbProgramPath, "dbProgramPath");
|
|
|
|
const startResult = await port.start();
|
|
const planResult = await port.runTransactionPlan(plan);
|
|
const transcript = port.exportTranscript();
|
|
const validation = validateToolDbTranscript(transcript);
|
|
const resolvedDbFileText = readDbFileText ? await readDbFileText() : (dbFileText ?? "");
|
|
await port.close();
|
|
|
|
const savedDb = await saveToolDbFile(machineId, resolvedDbFileText, { storage });
|
|
const savedTranscript = await saveToolDbTranscript(machineId, runId, transcript, { storage });
|
|
const loadedDb = await loadToolDbFile(machineId, { storage });
|
|
const loadedTranscript = await loadToolDbTranscript(machineId, runId, { storage });
|
|
const diagnostics = createToolDbProcessDiagnostics({
|
|
dbProgramPath,
|
|
opfsDbPath: savedDb.displayPath,
|
|
transcript,
|
|
dbFileText: loadedDb.text,
|
|
startupToolCount,
|
|
mutationCount,
|
|
runtimeMode: startResult.runtimeMode,
|
|
runtimeExecutionReady: startResult.runtimeExecutionReady === true && planResult.runtimeExecutionReady === true,
|
|
});
|
|
|
|
return {
|
|
apiName: "linuxcnc-tool-db-process-runtime-persistence-session",
|
|
ready: validation.ready &&
|
|
diagnostics.runtimeExecutionReady === true &&
|
|
diagnostics.opfsPersistenceReady === true &&
|
|
diagnostics.protocolTranscriptReady === true,
|
|
startResult,
|
|
planResult,
|
|
validation,
|
|
savedDb,
|
|
savedTranscript,
|
|
loadedDb,
|
|
loadedTranscript,
|
|
diagnostics,
|
|
executionEnabled: false,
|
|
promotionAllowed: false,
|
|
};
|
|
}
|