PSA/services/workflow-worker/scripts/validate-runtime-imports.test.ts
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

119 lines
3.8 KiB
TypeScript

import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
import { afterEach, describe, expect, it } from 'vitest';
async function createDistFixture(files: Record<string, string>): Promise<string> {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'workflow-worker-validate-'));
await Promise.all(
Object.entries(files).map(async ([relPath, source]) => {
const absPath = path.join(tempRoot, relPath);
await fs.mkdir(path.dirname(absPath), { recursive: true });
await fs.writeFile(absPath, source, 'utf8');
}),
);
return tempRoot;
}
async function removeDirIfExists(dirPath: string): Promise<void> {
await fs.rm(dirPath, { recursive: true, force: true });
}
describe('validate-runtime-imports', () => {
const tempDirs: string[] = [];
const scriptPath = path.resolve(process.cwd(), 'scripts/validate-runtime-imports.mjs');
afterEach(async () => {
while (tempDirs.length > 0) {
const dirPath = tempDirs.pop();
if (dirPath) {
await removeDirIfExists(dirPath);
}
}
});
it('passes when startup graph uses resolvable worker-safe imports only', async () => {
const distRoot = await createDistFixture({
'dist/src/index.js': "import './ok.js';\n",
'dist/src/ok.js': 'export const ok = true;\n',
});
tempDirs.push(distRoot);
const result = spawnSync(process.execPath, [scriptPath], {
cwd: process.cwd(),
env: {
...process.env,
WORKFLOW_WORKER_VALIDATE_DIST_ROOT: path.join(distRoot, 'dist'),
},
encoding: 'utf8',
});
expect(result.status).toBe(0);
expect(result.stdout).toContain('validation passed');
});
it('fails when unresolved @shared alias appears in runtime startup graph', async () => {
const distRoot = await createDistFixture({
'dist/src/index.js': "import '@shared/task-inbox';\n",
});
tempDirs.push(distRoot);
const result = spawnSync(process.execPath, [scriptPath], {
cwd: process.cwd(),
env: {
...process.env,
WORKFLOW_WORKER_VALIDATE_DIST_ROOT: path.join(distRoot, 'dist'),
},
encoding: 'utf8',
});
expect(result.status).not.toBe(0);
expect(result.stderr).toContain('unresolved @shared alias is not allowed');
});
it('fails when runtime startup graph contains repo-layout-relative source hops', async () => {
const distRoot = await createDistFixture({
'dist/src/index.js': "import '../../../../../../shared/workflow/runtime/init.js';\n",
});
tempDirs.push(distRoot);
const result = spawnSync(process.execPath, [scriptPath], {
cwd: process.cwd(),
env: {
...process.env,
WORKFLOW_WORKER_VALIDATE_DIST_ROOT: path.join(distRoot, 'dist'),
},
encoding: 'utf8',
});
expect(result.status).not.toBe(0);
expect(result.stderr).toContain('relative import does not resolve in dist output');
});
it('allows AI runtime wiring only through the dedicated runtime/worker entrypoint', async () => {
const distRoot = await createDistFixture({
'dist/src/index.js': "import '../../ee/packages/workflows/src/runtime/worker.js';\n",
'dist/ee/packages/workflows/src/runtime/worker.js': [
"import '../../../../../shared/workflow/runtime/actions/registerAiActions.js';",
"import '../../../../../packages/ee/src/services/workflowInferenceService.js';",
'export const ok = true;',
'',
].join('\n'),
});
tempDirs.push(distRoot);
const result = spawnSync(process.execPath, [scriptPath], {
cwd: process.cwd(),
env: {
...process.env,
WORKFLOW_WORKER_VALIDATE_DIST_ROOT: path.join(distRoot, 'dist'),
},
encoding: 'utf8',
});
expect(result.status).toBe(0);
expect(result.stdout).toContain('validation passed');
});
});