T-177: M2.1o — marimo check-gated static HTML snapshot exporter for research notebooks: exportNotebookSnapshot over an injected command-runner port in libs/research/src/notebook-snapshot.ts (check must pass before marimo export html, fail-closed, atomic output, no new deps, no real marimo in tests)
This commit is contained in:
parent
b23722f151
commit
be9ae5a7c9
2 changed files with 95 additions and 14 deletions
|
|
@ -255,14 +255,9 @@ function assertWithinRoot(
|
|||
}
|
||||
}
|
||||
|
||||
function splitDirAndBase(normalizedFilePath: string): {
|
||||
readonly dir: string;
|
||||
readonly base: string;
|
||||
} {
|
||||
function dirnamePosix(normalizedFilePath: string): string {
|
||||
const lastSlash = normalizedFilePath.lastIndexOf('/');
|
||||
const dir = lastSlash <= 0 ? '/' : normalizedFilePath.slice(0, lastSlash);
|
||||
const base = normalizedFilePath.slice(lastSlash + 1);
|
||||
return { dir, base };
|
||||
return lastSlash <= 0 ? '/' : normalizedFilePath.slice(0, lastSlash);
|
||||
}
|
||||
|
||||
function validatePortsAndOptions(options: ExportNotebookSnapshotOptions): {
|
||||
|
|
@ -530,11 +525,11 @@ function generateTempToken(): string {
|
|||
}
|
||||
|
||||
async function reserveSiblingTempHtml(fs: NotebookSnapshotFs, outputPath: string): Promise<string> {
|
||||
const { dir, base } = splitDirAndBase(outputPath);
|
||||
const dir = dirnamePosix(outputPath);
|
||||
const dirPrefix = dir === '/' ? '' : dir;
|
||||
|
||||
for (let attempt = 0; attempt < MAX_TEMP_RESERVATION_ATTEMPTS; attempt += 1) {
|
||||
const candidate = `${dirPrefix}/.${base}.${generateTempToken()}.tmp.html`;
|
||||
const candidate = `${dirPrefix}/.marimo-snapshot-${generateTempToken()}.tmp.html`;
|
||||
try {
|
||||
await fs.createExclusive(candidate);
|
||||
return candidate;
|
||||
|
|
@ -636,12 +631,12 @@ export async function exportNotebookSnapshot(
|
|||
'check'
|
||||
);
|
||||
|
||||
const trimmedCheckStdout = checkResult.stdout.trim();
|
||||
const hasCheckStdout = checkResult.stdout.length > 0;
|
||||
let parsedCheckJson: unknown = undefined;
|
||||
let checkJsonParseError: unknown = undefined;
|
||||
if (trimmedCheckStdout.length > 0) {
|
||||
if (hasCheckStdout) {
|
||||
try {
|
||||
parsedCheckJson = JSON.parse(trimmedCheckStdout);
|
||||
parsedCheckJson = JSON.parse(checkResult.stdout);
|
||||
} catch (err) {
|
||||
checkJsonParseError = err;
|
||||
}
|
||||
|
|
@ -665,7 +660,7 @@ export async function exportNotebookSnapshot(
|
|||
}
|
||||
|
||||
let checkDiagnostics: MarimoCheckReport | null = null;
|
||||
if (trimmedCheckStdout.length > 0) {
|
||||
if (hasCheckStdout) {
|
||||
if (checkJsonParseError !== undefined) {
|
||||
throw new NotebookSnapshotError(
|
||||
'CHECK_OUTPUT_INVALID',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue