55 lines
2.5 KiB
JavaScript
55 lines
2.5 KiB
JavaScript
/*
|
|
* Description: Static regression tests for resilient project save/reopen behavior.
|
|
* Inside functions: N/A - assertion-based test/module script.
|
|
* Developer : Qin Yue @ 2026
|
|
* Organization : OptiHK Limited
|
|
*/
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const backend = path.join(root, 'backend');
|
|
const layoutFilesPath = path.join(backend, 'layout_files.py');
|
|
const layoutFilesPy = fs.readFileSync(layoutFilesPath, 'utf8');
|
|
const serverPy = fs.readFileSync(path.join(backend, 'server.py'), 'utf8');
|
|
const gdsBuilderPy = fs.readFileSync(path.join(backend, 'gds_builder.py'), 'utf8');
|
|
const routedPreviewPy = fs.readFileSync(path.join(backend, 'routed_layout_preview.py'), 'utf8');
|
|
const canvasHtml = fs.readFileSync(path.join(root, 'frontend', 'canvas.html'), 'utf8');
|
|
|
|
assert(
|
|
fs.existsSync(layoutFilesPath),
|
|
'backend/layout_files.py should centralize saved layout YAML filtering and parsing'
|
|
);
|
|
assert(
|
|
layoutFilesPy.includes('ROUTE_SIDECAR_SUFFIXES') &&
|
|
layoutFilesPy.includes('def is_layout_cell_filename') &&
|
|
layoutFilesPy.includes('def parse_layout_cell_content') &&
|
|
layoutFilesPy.includes('def load_layout_cell_files'),
|
|
'layout file helpers should exclude route sidecars and validate saved layout cells'
|
|
);
|
|
assert(
|
|
serverPy.includes('is_layout_cell_filename') &&
|
|
serverPy.includes('load_layout_cell_files(root)') &&
|
|
serverPy.includes('parse_layout_cell_content(content') &&
|
|
serverPy.includes('except LayoutFileError as e'),
|
|
'project list/load/save endpoints should filter invalid YAML and reject malformed saves'
|
|
);
|
|
assert(
|
|
gdsBuilderPy.includes('TemporaryDirectory(prefix="mxpic_gds_project_"') &&
|
|
gdsBuilderPy.includes('write_layout_cells_to_directory(cells, staged_project_dir)'),
|
|
'Build GDS should call mxpic_router with a clean staged project directory'
|
|
);
|
|
assert(
|
|
routedPreviewPy.includes('staged_project_dir') &&
|
|
routedPreviewPy.includes('write_layout_cells_to_directory(staged_cells, staged_project_dir)') &&
|
|
routedPreviewPy.includes('project_dir=staged_project_dir'),
|
|
'Build Layout preview should stage valid cells before calling mxpic_router'
|
|
);
|
|
assert(
|
|
canvasHtml.includes('(data.warnings || []).forEach(warning => addLog(warning))') &&
|
|
canvasHtml.includes('const parsedCellPages = [];') &&
|
|
canvasHtml.includes('Skipped saved cell'),
|
|
'canvas project loading should report skipped files and keep loading remaining valid cells'
|
|
);
|