Files
mxpic_EDA/tests/database-root-static.test.js
T
2026-06-08 14:48:14 +08:00

65 lines
2.4 KiB
JavaScript

/*
* Description: Static regression tests for keeping mxPIC EDA runtime data outside the repository.
* 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 storagePathsPath = path.join(backend, 'storage_paths.py');
const storagePathsPy = fs.existsSync(storagePathsPath)
? fs.readFileSync(storagePathsPath, 'utf8')
: '';
const databasePy = fs.readFileSync(path.join(backend, 'database.py'), 'utf8');
const serverPy = fs.readFileSync(path.join(backend, 'server.py'), 'utf8');
const gitignore = fs.readFileSync(path.join(root, '.gitignore'), 'utf8');
assert(
fs.existsSync(storagePathsPath),
'backend/storage_paths.py should be the single source of truth for runtime storage paths'
);
assert(
storagePathsPy.includes('MXPIC_DATABASE_ROOT'),
'storage path layer should support MXPIC_DATABASE_ROOT override'
);
assert(
storagePathsPy.includes('mxpic_EDA_database'),
'default runtime database folder should be sibling mxpic_EDA_database'
);
assert(
storagePathsPy.includes('DB_FILE') && storagePathsPy.includes('EXPORT_ROOT'),
'storage path layer should export DB_FILE and EXPORT_ROOT'
);
assert(
storagePathsPy.includes('raise RuntimeError'),
'storage path layer should fail fast when the external database root is invalid'
);
assert(
!serverPy.includes("DATABASE_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'database'))"),
'server.py should not hardcode in-repo database/ as DATABASE_ROOT'
);
assert(
serverPy.includes('from storage_paths import DATABASE_ROOT, EXPORT_ROOT'),
'server.py should import runtime storage roots from storage_paths'
);
assert(
!databasePy.includes('"..", "database", "mxpic_data.db"') &&
!databasePy.includes("'..', 'database', 'mxpic_data.db'"),
'database.py should not hardcode database/mxpic_data.db inside the repository'
);
assert(
databasePy.includes('from storage_paths import DB_FILE'),
'database.py should import DB_FILE from storage_paths'
);
assert(
gitignore.includes('/database/') &&
gitignore.includes('/backend/*.db') &&
gitignore.includes('*.db-wal') &&
gitignore.includes('/mxpic_EDA_database/'),
'.gitignore should ignore old and accidental in-repo runtime database artifacts'
);