Now working as a vm.Script passing in all the Globals the proxy script needs
This commit is contained in:
@@ -1,15 +1,20 @@
|
||||
/**
|
||||
* Unit Tests for General Utilities
|
||||
*
|
||||
* NOTE: Per constitution requirement, proxy.js has ZERO exports.
|
||||
* Internal functions (generateRequestId, validateDocumentId, etc.) cannot be unit tested directly.
|
||||
* These functions are tested indirectly through integration tests of the main handleRequest function.
|
||||
* NOTE: Per constitution requirement, proxy.js has ZERO exports and NO globalThis usage.
|
||||
* The file is a pure function expression loaded via Function constructor.
|
||||
*
|
||||
* This test file verifies constitution compliance only.
|
||||
*/
|
||||
|
||||
import { test, describe } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
// Set up globals that server.js would provide
|
||||
// Note: crypto is already available on globalThis (Web Crypto API)
|
||||
@@ -17,11 +22,23 @@ globalThis.config = { google: {}, server: {}, sitemap: {} };
|
||||
|
||||
describe('Unit: Constitution Compliance', () => {
|
||||
|
||||
test('T046: proxy.js has ZERO exports and exposes handleRequest via globalThis', async () => {
|
||||
// Verify proxy.js can be loaded and exposes handleRequest via globalThis
|
||||
await import('../../src/proxy.js');
|
||||
assert.ok(globalThis.handleRequest, 'handleRequest should be available on globalThis');
|
||||
assert.strictEqual(typeof globalThis.handleRequest, 'function', 'handleRequest should be a function');
|
||||
test('T046: proxy.js has ZERO exports/imports and loads as pure function', () => {
|
||||
const proxyPath = join(__dirname, '..', '..', 'src', 'proxy.js');
|
||||
const proxyCode = readFileSync(proxyPath, 'utf-8');
|
||||
|
||||
// Verify no exports
|
||||
assert.ok(!proxyCode.match(/^export /m), 'Should have no export statements');
|
||||
|
||||
// Verify no imports
|
||||
assert.ok(!proxyCode.match(/^import /m), 'Should have no import statements');
|
||||
|
||||
// Verify no globalThis usage (except for accessing provided globals)
|
||||
const globalThisAssignments = proxyCode.match(/globalThis\.[a-zA-Z_]+ =/g);
|
||||
assert.ok(!globalThisAssignments, 'Should not assign to globalThis');
|
||||
|
||||
// Verify it's a function expression that can be executed
|
||||
assert.ok(proxyCode.includes('(function()'), 'Should contain function expression');
|
||||
assert.ok(proxyCode.includes('return handleRequest'), 'Should return handleRequest');
|
||||
});
|
||||
|
||||
test('T046: crypto is available on globalThis (Web Crypto API)', () => {
|
||||
|
||||
Reference in New Issue
Block a user