PSA/scripts/guard-no-legacy-workflows-shims.mjs
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

150 lines
3.5 KiB
JavaScript

import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(__dirname, '..');
const legacyDirs = [
'packages/workflows/src/ee',
'packages/workflows/src/oss',
];
const legacyFiles = [
'packages/workflows/src/entry.ts',
'packages/workflows/src/entry.tsx',
];
const bannedNeedles = [
'packages/workflows/src/ee/',
'packages/workflows/src/oss/',
'packages/workflows/src/entry',
];
const scanRoots = [
'server',
'ee/server',
'packages',
].map((p) => path.join(repoRoot, p));
const ignoredDirNames = new Set([
'.git',
'.next',
'.turbo',
'coverage',
'dist',
'node_modules',
'tmp',
]);
const allowedExtensions = new Set([
'.ts',
'.tsx',
'.js',
'.jsx',
'.mjs',
'.cjs',
'.json',
'.yml',
'.yaml',
]);
async function pathExists(p) {
try {
await fs.access(p);
return true;
} catch {
return false;
}
}
async function directoryHasAnyFiles(dir) {
const entries = await fs.readdir(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isFile()) return true;
if (entry.isDirectory()) {
if (await directoryHasAnyFiles(fullPath)) return true;
}
}
return false;
}
async function walk(dir) {
const entries = await fs.readdir(dir, { withFileTypes: true });
const files = [];
for (const entry of entries) {
if (entry.isDirectory() && ignoredDirNames.has(entry.name)) continue;
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
files.push(...(await walk(fullPath)));
} else if (entry.isFile()) {
const ext = path.extname(entry.name);
if (allowedExtensions.has(ext)) files.push(fullPath);
}
}
return files;
}
async function main() {
for (const rel of legacyFiles) {
const abs = path.join(repoRoot, rel);
if (await pathExists(abs)) {
console.error('[workflows-shim-guard] Found legacy workflows shim artifact:', abs);
process.exit(1);
}
}
for (const rel of legacyDirs) {
const abs = path.join(repoRoot, rel);
if (await pathExists(abs)) {
try {
if (await directoryHasAnyFiles(abs)) {
console.error('[workflows-shim-guard] Found legacy workflows shim directory with files:', abs);
process.exit(1);
}
} catch {
// If we can't read it, be conservative.
console.error('[workflows-shim-guard] Unable to validate legacy workflows shim directory:', abs);
process.exit(1);
}
}
}
const hits = [];
for (const root of scanRoots) {
if (!(await pathExists(root))) continue;
const files = await walk(root);
for (const filePath of files) {
let contents;
try {
contents = await fs.readFile(filePath, 'utf8');
} catch {
continue;
}
for (const needle of bannedNeedles) {
if (contents.includes(needle)) {
hits.push({ filePath, needle });
}
}
}
}
if (hits.length > 0) {
console.error('[workflows-shim-guard] Found references to legacy workflows shims:');
for (const hit of hits.slice(0, 20)) {
console.error(`- ${hit.filePath} (needle: ${JSON.stringify(hit.needle)})`);
}
if (hits.length > 20) {
console.error(`...and ${hits.length - 20} more`);
}
process.exit(1);
}
console.log('[workflows-shim-guard] OK: no legacy workflows shims present or referenced.');
}
await main();