Add authenticated LAN access, native Claude execution, checkpoint and budget recovery, and signed POC build/deploy/rollback contracts. Include local service management, regression coverage, and evidence from the completed POC delivery.
148 lines
6.4 KiB
TypeScript
148 lines
6.4 KiB
TypeScript
import { afterEach, describe, expect, it } from 'vitest';
|
|
import http from 'node:http';
|
|
import { mkdtemp, writeFile, rm } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import path from 'node:path';
|
|
import { PocRunnerDeploymentAdapter, KubernetesDeploymentAdapter, ComposeDeploymentAdapter } from '@wishforge/runtime';
|
|
import { createRunnerTransport, runnerTransportPolicy } from '../src/transport.js';
|
|
import { createRunnerAdapters } from '../src/adapters.js';
|
|
|
|
const local = {
|
|
WF_DEPLOYMENT_MODE: 'development',
|
|
WF_RUNNER_ALLOW_LOCAL_HTTP: 'true',
|
|
WF_CONTROL_PLANE_URL: 'http://127.0.0.1:4000',
|
|
};
|
|
const dirs: string[] = [];
|
|
afterEach(async () => {
|
|
await Promise.all(dirs.splice(0).map(directory => rm(directory, { recursive: true, force: true })));
|
|
});
|
|
|
|
describe('local runner transport boundary', () => {
|
|
it('requires explicit development and a literal loopback HTTP origin', () => {
|
|
expect(runnerTransportPolicy(local).localHttp).toBe(true);
|
|
expect(runnerTransportPolicy({ ...local, WF_CONTROL_PLANE_URL: 'http://localhost:4000/' }).localHttp).toBe(true);
|
|
for (const value of [
|
|
'http://192.168.1.2:4000',
|
|
'http://example.test',
|
|
'http://127.1:4000',
|
|
'http://2130706433:4000',
|
|
'http://[::1]:4000',
|
|
'http://localhost.evil.test',
|
|
'https://user:pass@example.test',
|
|
'http://localhost:4000/?x=1',
|
|
'http://localhost:4000/api',
|
|
])
|
|
expect(() => runnerTransportPolicy({ ...local, WF_CONTROL_PLANE_URL: value })).toThrow();
|
|
expect(() => runnerTransportPolicy({ ...local, WF_RUNNER_ALLOW_LOCAL_HTTP: undefined })).toThrow('HTTPS');
|
|
expect(() => runnerTransportPolicy({ ...local, WF_DEPLOYMENT_MODE: 'production' })).toThrow('HTTPS');
|
|
expect(() => runnerTransportPolicy({ ...local, WF_DEPLOYMENT_MODE: undefined })).toThrow('Set WF_DEPLOYMENT_MODE');
|
|
});
|
|
it('retains mandatory mTLS for every HTTPS connection and never inherits global insecure-HTTP opt-in', () => {
|
|
expect(() => runnerTransportPolicy({ ...local, WF_CONTROL_PLANE_URL: 'https://localhost:4000' })).toThrow(
|
|
'WF_RUNNER_CA',
|
|
);
|
|
expect(() =>
|
|
runnerTransportPolicy({ ...local, WF_RUNNER_ALLOW_LOCAL_HTTP: undefined, WF_ALLOW_INSECURE_HTTP: 'true' }),
|
|
).toThrow('HTTPS');
|
|
expect(
|
|
runnerTransportPolicy({
|
|
...local,
|
|
WF_DEPLOYMENT_MODE: 'production',
|
|
WF_CONTROL_PLANE_URL: 'https://control.example.test',
|
|
WF_RUNNER_CA: '/ca',
|
|
WF_RUNNER_CERT: '/cert',
|
|
WF_RUNNER_KEY: '/key',
|
|
}).localHttp,
|
|
).toBe(false);
|
|
});
|
|
it('keeps registered bearer and tenant headers on local requests, rejects redirects and origin escapes', async () => {
|
|
const seen: Array<{ method?: string; url?: string; token?: string; tenant?: string; body: string }> = [];
|
|
const server = http.createServer((req, res) => {
|
|
let body = '';
|
|
req.on('data', chunk => {
|
|
body += String(chunk);
|
|
});
|
|
req.on('end', () => {
|
|
seen.push({
|
|
method: req.method,
|
|
url: req.url,
|
|
token: req.headers.authorization,
|
|
tenant: String(req.headers['x-wishforge-tenant']),
|
|
body,
|
|
});
|
|
if (req.url === '/redirect') {
|
|
res.writeHead(302, { location: 'http://example.test/leak' });
|
|
res.end();
|
|
} else {
|
|
res.setHeader('Content-Type', 'application/json');
|
|
res.end(JSON.stringify({ accepted: true }));
|
|
}
|
|
});
|
|
});
|
|
await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));
|
|
const address = server.address();
|
|
if (!address || typeof address === 'string') throw new Error('Expected TCP test server');
|
|
const transport = await createRunnerTransport({
|
|
...local,
|
|
WF_CONTROL_PLANE_URL: `http://127.0.0.1:${address.port}`,
|
|
WF_RUNNER_TOKEN: 'test-only-registered-runner-token',
|
|
WF_TENANT_ID: 'tenant-poc',
|
|
});
|
|
try {
|
|
expect(await transport.request('/internal/runner/tasks?environmentId=env-poc')).toEqual({ accepted: true });
|
|
await transport.request('/internal/runner/tasks/task-1/result', { result: { status: 'verified' } });
|
|
expect(seen[0]).toMatchObject({
|
|
method: 'GET',
|
|
token: 'Bearer test-only-registered-runner-token',
|
|
tenant: 'tenant-poc',
|
|
});
|
|
expect(JSON.parse(seen[1].body)).toEqual({ result: { status: 'verified' } });
|
|
await expect(transport.request('http://example.test/leak')).rejects.toThrow('origin mismatch');
|
|
await expect(transport.request('/redirect')).rejects.toThrow('302');
|
|
expect(seen).toHaveLength(3);
|
|
} finally {
|
|
transport.close();
|
|
await new Promise<void>((resolve, reject) => server.close(error => (error ? reject(error) : resolve())));
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('operator POC runner adapter wiring', () => {
|
|
it('loads the fixed operator profile and enables only the POC Kubernetes adapter', async () => {
|
|
const directory = await mkdtemp(path.join(tmpdir(), 'wishforge-runner-entry-'));
|
|
dirs.push(directory);
|
|
const file = path.join(directory, 'profile.json');
|
|
const uid = '11111111-1111-4111-8111-111111111111';
|
|
await writeFile(
|
|
file,
|
|
JSON.stringify({
|
|
schemaVersion: 1,
|
|
id: 'droboticflow-poc',
|
|
repository: 'https://gitea.d-robotics.cc/longtao.wu/droboticflow.git',
|
|
branch: 'poc',
|
|
kubeconfig: '/operator/poc.kubeconfig',
|
|
clusterServer: 'https://120.48.181.105:6443',
|
|
namespace: 'droboticflow',
|
|
namespaceUid: uid,
|
|
deployments: { api: uid, worker: uid, coordinator: uid },
|
|
registry: 'ccr-29eug8s3-pub.cnc.bj.baidubce.com/dataflow-poc',
|
|
registrySecret: 'droboticflow-registry',
|
|
applicationUrl: 'http://120.48.164.19',
|
|
kanikoImage: `registry.test/kaniko@sha256:${'a'.repeat(64)}`,
|
|
}),
|
|
{ mode: 0o600 },
|
|
);
|
|
const adapters = await createRunnerAdapters({ WF_POC_PROFILE_FILE: file, WF_RUNNER_STATE_DIR: directory });
|
|
expect(Object.keys(adapters)).toEqual(['kubernetes']);
|
|
expect(adapters.kubernetes).toBeInstanceOf(PocRunnerDeploymentAdapter);
|
|
await expect(
|
|
createRunnerAdapters({ WF_POC_PROFILE_FILE: 'relative.json', WF_RUNNER_STATE_DIR: directory }),
|
|
).rejects.toThrow('absolute path');
|
|
});
|
|
it('preserves generic adapters only when an adopted POC profile is absent', async () => {
|
|
const adapters = await createRunnerAdapters({});
|
|
expect(adapters.compose).toBeInstanceOf(ComposeDeploymentAdapter);
|
|
expect(adapters.kubernetes).toBeInstanceOf(KubernetesDeploymentAdapter);
|
|
});
|
|
});
|