Local development had no provisioner, so every wish stopped at "sandbox not ready", and dev:all started neither the coordinator nor the deployer. - The provisioner moves from apps/ide to apps/provisioner and gains a backend switch: `local` starts an executor and a verifier process per run generation on this host (WF_SANDBOX_MODE=host, own directories and run-scoped tokens, development mode only) and points workspaces at the local Theia; `kubernetes` keeps the Kata Jobs, now started with the image entrypoint instead of the npm dev script and allowed to reach the platform Git service. - In development the resource grant needs no runtime image digest. - setup:local is one idempotent script that creates or completes .env.local, including the deployment mode, provisioner and grant settings. - dev:all starts Git, API, provisioner, coordinator, deployer and web; dev:ide starts Theia and the IDE gateway; ide:install and ide:build wrap the separate Theia package. npm test also runs the provisioner tests. - Project settings accept the target branch and dependency install commands. - Web development conveniences require WF_DEPLOYMENT_MODE=development. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
5.2 KiB
JavaScript
127 lines
5.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { renderWorkspaceResources } from '../workspaces.mjs';
|
|
import { observeWorkspaceLifecycle, reconcileWorkspaceLifecycle } from '../workspace-lifecycle.mjs';
|
|
const config = {
|
|
tenantId: 'alpha',
|
|
namespace: 'wf-alpha',
|
|
context: 'fixture',
|
|
controlNamespace: 'wf-control',
|
|
runtimeClass: 'kata',
|
|
storageClass: 'fixture',
|
|
storageSize: '10Gi',
|
|
};
|
|
const input = { tenantId: 'alpha', projectId: 'project', workspaceId: 'workspace' };
|
|
function fixture() {
|
|
const rendered = renderWorkspaceResources(config, input, `registry.example/theia@sha256:${'a'.repeat(64)}`);
|
|
const d = rendered.resources.find(r => r.kind === 'Deployment');
|
|
d.metadata.uid = 'immutable-uid';
|
|
d.metadata.resourceVersion = '1';
|
|
d.metadata.generation = 1;
|
|
d.status = { observedGeneration: 1, availableReplicas: 1, updatedReplicas: 1, replicas: 1 };
|
|
let pods = [];
|
|
let lose = false;
|
|
const calls = [];
|
|
const execute = async (_config, args) => {
|
|
calls.push(args);
|
|
if (args[0] === 'get' && args[1] === 'pods') return { items: pods };
|
|
if (args[0] === 'get') return structuredClone(d);
|
|
assert.equal(args[0], 'patch');
|
|
assert.equal(args[1], 'deployment');
|
|
assert.equal(args[2], rendered.name);
|
|
const patch = JSON.parse(args[args.indexOf('-p') + 1]);
|
|
assert.equal(patch[0].value, d.metadata.resourceVersion);
|
|
assert.equal(patch[1].value, d.metadata.uid);
|
|
d.metadata.annotations = patch[2].value;
|
|
d.spec.replicas = patch[3].value;
|
|
d.metadata.resourceVersion = String(Number(d.metadata.resourceVersion) + 1);
|
|
d.metadata.generation++;
|
|
if (lose) throw new Error('KUBERNETES_LIFECYCLE_UNKNOWN');
|
|
return structuredClone(d);
|
|
};
|
|
return {
|
|
d,
|
|
calls,
|
|
execute,
|
|
setPods: value => {
|
|
pods = value;
|
|
},
|
|
lose: () => {
|
|
lose = true;
|
|
},
|
|
converge: () => {
|
|
d.status = {
|
|
observedGeneration: d.metadata.generation,
|
|
replicas: d.spec.replicas,
|
|
availableReplicas: d.spec.replicas,
|
|
updatedReplicas: d.spec.replicas,
|
|
};
|
|
},
|
|
};
|
|
}
|
|
test('pause only patches the owned IDE deployment, retains all PVCs, and waits for observed termination', async () => {
|
|
const f = fixture();
|
|
const request = { ...input, revision: 1, desired: 'paused' };
|
|
assert.equal((await reconcileWorkspaceLifecycle(config, request, { execute: f.execute })).status, 'pending');
|
|
f.converge();
|
|
f.setPods([{ status: { phase: 'Running' }, metadata: { deletionTimestamp: new Date().toISOString() } }]);
|
|
assert.equal((await observeWorkspaceLifecycle(config, input, { execute: f.execute })).status, 'pending');
|
|
f.setPods([]);
|
|
assert.equal((await observeWorkspaceLifecycle(config, input, { execute: f.execute })).status, 'paused');
|
|
assert.ok(f.calls.every(args => !args.includes('pvc') && !args.includes('delete') && !args.includes('service')));
|
|
});
|
|
test('resume does not claim ready until updated and available replica is observed', async () => {
|
|
const f = fixture();
|
|
await reconcileWorkspaceLifecycle(config, { ...input, revision: 1, desired: 'paused' }, { execute: f.execute });
|
|
f.converge();
|
|
assert.equal(
|
|
(await reconcileWorkspaceLifecycle(config, { ...input, revision: 2, desired: 'running' }, { execute: f.execute }))
|
|
.status,
|
|
'pending',
|
|
);
|
|
f.converge();
|
|
assert.equal((await observeWorkspaceLifecycle(config, input, { execute: f.execute })).status, 'ready');
|
|
});
|
|
test('lost mutation response reconciles by observation and does not send a duplicate patch', async () => {
|
|
const f = fixture();
|
|
f.lose();
|
|
const request = { ...input, revision: 1, desired: 'paused' };
|
|
await assert.rejects(reconcileWorkspaceLifecycle(config, request, { execute: f.execute }), /UNKNOWN/);
|
|
f.converge();
|
|
assert.equal((await reconcileWorkspaceLifecycle(config, request, { execute: f.execute })).status, 'paused');
|
|
assert.equal(f.calls.filter(a => a[0] === 'patch').length, 1);
|
|
});
|
|
test('tenant, namespace, managed labels and revision fencing reject without mutations', async () => {
|
|
const f = fixture();
|
|
await assert.rejects(
|
|
reconcileWorkspaceLifecycle(
|
|
config,
|
|
{ ...input, tenantId: 'other', revision: 1, desired: 'paused' },
|
|
{ execute: f.execute },
|
|
),
|
|
/SCOPE/,
|
|
);
|
|
f.d.metadata.labels['wishforge.io/component'] = 'production-app';
|
|
await assert.rejects(
|
|
reconcileWorkspaceLifecycle(config, { ...input, revision: 1, desired: 'paused' }, { execute: f.execute }),
|
|
/OWNERSHIP/,
|
|
);
|
|
f.d.metadata.labels['wishforge.io/component'] = 'ide';
|
|
f.d.metadata.namespace = 'production';
|
|
await assert.rejects(
|
|
reconcileWorkspaceLifecycle(config, { ...input, revision: 1, desired: 'paused' }, { execute: f.execute }),
|
|
/OWNERSHIP/,
|
|
);
|
|
f.d.metadata.namespace = config.namespace;
|
|
f.d.metadata.annotations = { 'wishforge.io/lifecycle-revision': '3', 'wishforge.io/lifecycle-desired': 'running' };
|
|
await assert.rejects(
|
|
reconcileWorkspaceLifecycle(config, { ...input, revision: 2, desired: 'paused' }, { execute: f.execute }),
|
|
/STALE/,
|
|
);
|
|
await assert.rejects(
|
|
reconcileWorkspaceLifecycle(config, { ...input, revision: 3, desired: 'paused' }, { execute: f.execute }),
|
|
/CONFLICT/,
|
|
);
|
|
assert.equal(f.calls.filter(a => a[0] === 'patch').length, 0);
|
|
});
|