Sandbox Jobs never received WF_DEPLOYMENT_MODE, which every worker requires before anything else, so each Kubernetes sandbox exited at start. The provisioner now passes its own mode. A local development cluster (k3s) has no Kata, no bubblewrap inside runc and no TLS between services. For it, and only with WF_DEPLOYMENT_MODE=development: - WF_ALLOW_INSECURE_HTTP=true lets services reach each other over plain HTTP (Git, the model proxy, the provisioner and IDE gateway targets, the worker's control-plane client); production refuses the setting outright. - The provisioner accepts WF_RUN_SANDBOX_MODE=host and WF_KATA_RUNTIME_CLASS=none and passes the HTTP settings to its sandboxes. - The development seed is built into the image (dist/api/seed.mjs). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1.9 KiB
TypeScript
30 lines
1.9 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { deploymentMode, isProduction, plainHttpAllowed, requireDeploymentMode } from '@wishforge/contracts';
|
|
|
|
describe('explicit deployment mode', () => {
|
|
it('prefers WF_DEPLOYMENT_MODE and rejects misspelled or conflicting values', () => {
|
|
expect(deploymentMode({ WF_DEPLOYMENT_MODE: 'production', NODE_ENV: 'development' })).toBe('production');
|
|
expect(deploymentMode({ WF_DEPLOYMENT_MODE: 'development' })).toBe('development');
|
|
expect(() => deploymentMode({ WF_DEPLOYMENT_MODE: 'prod' })).toThrow('must be');
|
|
expect(() => deploymentMode({ WF_DEPLOYMENT_MODE: 'development', NODE_ENV: 'production' })).toThrow('conflicts');
|
|
});
|
|
it('falls back to NODE_ENV only for libraries and tests', () => {
|
|
expect(isProduction({ NODE_ENV: 'production' })).toBe(true);
|
|
expect(isProduction({})).toBe(false);
|
|
});
|
|
it('allows plain HTTP to loopback in development, and to cluster services only when opted in', () => {
|
|
const service = new URL('http://api.wishforge-control.svc:4000');
|
|
expect(plainHttpAllowed({ WF_DEPLOYMENT_MODE: 'development' }, new URL('http://127.0.0.1:4000'))).toBe(true);
|
|
expect(plainHttpAllowed({ WF_DEPLOYMENT_MODE: 'development' }, service)).toBe(false);
|
|
expect(plainHttpAllowed({ WF_DEPLOYMENT_MODE: 'development', WF_ALLOW_INSECURE_HTTP: 'true' }, service)).toBe(true);
|
|
expect(plainHttpAllowed({ WF_DEPLOYMENT_MODE: 'production' }, new URL('http://127.0.0.1:4000'))).toBe(false);
|
|
expect(() => isProduction({ WF_DEPLOYMENT_MODE: 'production', WF_ALLOW_INSECURE_HTTP: 'true' })).toThrow(
|
|
'local development clusters only',
|
|
);
|
|
});
|
|
it('makes service entry points refuse to start without an explicit choice', () => {
|
|
expect(() => requireDeploymentMode({ NODE_ENV: 'production' })).toThrow('Set WF_DEPLOYMENT_MODE');
|
|
expect(requireDeploymentMode({ WF_DEPLOYMENT_MODE: 'production' })).toBe('production');
|
|
});
|
|
});
|