The cluster never ran Theia or the IDE gateway, so every workspace stayed "未配置" forever. The feature is gone instead of half-present: - API: workspace, launch and lifecycle endpoints, the gateway identity and its internal routes, the dispatcher's workspace provisioning and the lifecycle worker. Migration 003 deletes stored workspaces and settles their pending outbox items. - Provisioner: workspace provisioning and lifecycle for both backends. - Web: the 云 IDE panel, the launch route, the start-branch picker that listed IDE branches, and the workspace count on usage. - apps/ide, infra/oct, dev:ide and the CI job; IDE parts of local k3s, network policies, RBAC, docs and the architecture diagram. A wish can still start from a pushed branch through the API (sourceBranch). Plan files and stored entitlements may still carry maxWorkspaces; it is accepted and ignored. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
106 lines
4.6 KiB
JavaScript
106 lines
4.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import test from 'node:test';
|
|
import { platformPorts, selectServices, startServices, webListener } from './local-services.mjs';
|
|
|
|
const alive = pid => {
|
|
try {
|
|
process.kill(pid, 0);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|
|
async function gone(pid) {
|
|
for (let attempt = 0; attempt < 40 && alive(pid); attempt++) await new Promise(resolve => setTimeout(resolve, 50));
|
|
return !alive(pid);
|
|
}
|
|
|
|
test('stopping takes down each service with everything it spawned, even a service ignoring SIGTERM', async t => {
|
|
const directory = await mkdtemp(path.join(os.tmpdir(), 'wishforge-services-'));
|
|
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
const pids = path.join(directory, 'pids.json');
|
|
// A service that ignores SIGTERM and leaves a child of its own running, like a dev server's workers.
|
|
const service = `
|
|
const { spawn } = require('node:child_process');
|
|
process.on('SIGTERM', () => {});
|
|
const child = spawn(process.execPath, ['-e', 'setInterval(() => {}, 1000)'], { stdio: 'ignore' });
|
|
require('node:fs').writeFileSync(${JSON.stringify(pids)}, JSON.stringify([process.pid, child.pid]));
|
|
setInterval(() => {}, 1000);
|
|
`;
|
|
const services = await startServices(
|
|
[{ name: 'stubborn', cwd: directory, args: ['-e', service], env: process.env }],
|
|
'',
|
|
{
|
|
graceMs: 300,
|
|
},
|
|
);
|
|
const [leader, grandchild] = JSON.parse(await readFile(pids, 'utf8'));
|
|
assert.ok(alive(leader) && alive(grandchild));
|
|
await services.stop();
|
|
assert.ok(await gone(leader), 'the service itself stopped');
|
|
assert.ok(await gone(grandchild), 'the process it spawned stopped too');
|
|
process.exitCode = undefined;
|
|
});
|
|
|
|
test('under the supervisor, a service already answering is refused instead of adopted', async t => {
|
|
const original = globalThis.fetch;
|
|
t.after(() => {
|
|
globalThis.fetch = original;
|
|
process.exitCode = undefined;
|
|
});
|
|
globalThis.fetch = async () => Response.json({ service: 'wishforge-control-plane' });
|
|
const api = { name: 'api', url: 'http://127.0.0.1:4000/health', identity: 'wishforge-control-plane', args: [] };
|
|
await assert.rejects(startServices([api], '', { reuse: false }), /already answers; stop that process/);
|
|
// A developer's own start may still reuse it.
|
|
await startServices([api], '');
|
|
});
|
|
|
|
test('only the production web build listens beyond loopback, and readiness is checked where it listens', () => {
|
|
assert.deepEqual(webListener({}), { host: '127.0.0.1', port: 3000, probe: '127.0.0.1' });
|
|
const lan = { WF_LOCAL_ACCESS: 'true', WF_WEB_SERVE_MODE: 'production' };
|
|
assert.deepEqual(webListener({ ...lan, WF_WEB_HOST: '0.0.0.0', WF_WEB_PORT: '3100' }), {
|
|
host: '0.0.0.0',
|
|
port: 3100,
|
|
probe: '127.0.0.1',
|
|
});
|
|
// A listener bound to one address answers only there.
|
|
assert.equal(webListener({ ...lan, WF_WEB_HOST: '192.168.1.20' }).probe, '192.168.1.20');
|
|
assert.throws(() => webListener({ WF_WEB_HOST: '0.0.0.0', WF_WEB_SERVE_MODE: 'production' }), /local sign-in/);
|
|
// The development server hands visitors its sources and hot-reload channel.
|
|
assert.throws(() => webListener({ WF_WEB_HOST: '0.0.0.0', WF_LOCAL_ACCESS: 'true' }), /production web build/);
|
|
assert.equal(webListener({ WF_WEB_HOST: 'localhost', WF_WEB_SERVE_MODE: 'development' }).host, 'localhost');
|
|
assert.throws(() => webListener({ WF_WEB_PORT: '70000' }), /TCP port/);
|
|
});
|
|
|
|
test("the platform's own ports come from its configured addresses", () => {
|
|
assert.deepEqual(
|
|
platformPorts({
|
|
WF_API_URL: 'http://127.0.0.1:4000',
|
|
DATABASE_URL: 'postgresql://user:password@127.0.0.1:55432/wishforge',
|
|
TEMPORAL_ADDRESS: '127.0.0.1:7233',
|
|
S3_ENDPOINT: 'http://127.0.0.1:49000',
|
|
WF_PROVISIONER_URL: 'http://127.0.0.1:4450',
|
|
WF_HOST_CHECK_BLOCKED_PORTS: '6379',
|
|
WF_GIT_SERVICE_URL: 'not an address',
|
|
}),
|
|
[3000, 4000, 4450, 4504, 6379, 7233, 8233, 49000, 55432],
|
|
);
|
|
});
|
|
|
|
test('starts every service, or only those a container is given, in their order', () => {
|
|
const services = ['git', 'api', 'provisioner', 'coordinator', 'deployer', 'web'].map(name => ({ name }));
|
|
assert.equal(selectServices(services, {}), services);
|
|
assert.deepEqual(
|
|
selectServices(services, { WF_LOCAL_SERVICES: 'web, api ,git' }).map(service => service.name),
|
|
['git', 'api', 'web'],
|
|
);
|
|
assert.deepEqual(
|
|
selectServices(services, { WF_LOCAL_SERVICES: 'provisioner' }).map(service => service.name),
|
|
['provisioner'],
|
|
);
|
|
assert.throws(() => selectServices(services, { WF_LOCAL_SERVICES: 'api,database' }), /unknown services: database/);
|
|
});
|