wishforge-ide/tests/integration-lease.test.ts
eust-w da1cfcea13 🔥 Remove the cloud IDE
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>
2026-11-04 12:43:02 +08:00

73 lines
3.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { Actor, Run } from '@wishforge/contracts';
import { MemoryStore } from './helpers/memory-store.js';
import { ControlPlane } from '../apps/api/src/domain/control-plane.js';
import { Connections } from '../apps/api/src/domain/connections.js';
const owner: Actor = { tenantId: 'alpha', userId: 'owner', role: 'owner', kind: 'human' };
async function fixture() {
const db = new MemoryStore();
db.seed('alpha');
const control = new ControlPlane(db, { NODE_ENV: 'test', WF_VAULT_KEY: 'a'.repeat(64) });
const project = await control.createProject(owner, {
name: 'Integration queue',
repositoryUrl: 'https://example.test/repo.git',
verificationCommands: [['node', '--test']],
});
await new Connections(db, control.env).create(owner, {
provider: 'codex',
label: 'fixture',
apiKey: 'fixture-only-key',
});
/** Submits a run and leases it to a run-scoped verifier of a fixed generation. */
async function verifierFor(key: string) {
const { run_id: id } = await control.submit(
owner,
project.id,
{ goal: `Change ${key}`, acceptanceCriteria: ['It works'] },
`integration-${key}`,
);
const generation = `generation-${key}`;
await db.transaction('alpha', async tx => {
const run = (await tx.get<Run>('run', id))!;
// As the dispatcher starts the pending generation (reserveExecutionGrant).
run.executionGeneration = run.pendingStartId = generation;
await tx.put('run', run);
});
const actor: Actor = { ...owner, kind: 'verifier', userId: `verifier-${key}`, runId: id, credentialId: generation };
const leased = await control.lease(actor, id, `worker-${key}`, generation);
return { id, actor, token: leased.lease!.token };
}
return { db, control, project, verifierFor };
}
describe('project integration lease', () => {
it('admits one integrating run per project and fences stale owners', async () => {
const f = await fixture();
const first = await f.verifierFor('one');
const second = await f.verifierFor('two');
const lease = await f.control.integration.acquire(first.actor, first.id, first.token);
expect(lease).toMatchObject({ runId: first.id, fence: 1 });
expect(await f.control.integration.acquire(first.actor, first.id, first.token)).toMatchObject({ fence: 1 });
await expect(f.control.integration.acquire(second.actor, second.id, second.token)).rejects.toMatchObject({
code: 'INTEGRATION_BUSY',
});
await expect(f.control.integration.renew(first.actor, first.id, first.token, 99)).rejects.toMatchObject({
code: 'STALE_INTEGRATION_FENCE',
});
expect(await f.control.integration.release(first.actor, first.id, first.token, 1)).toEqual({ released: true });
expect(await f.control.integration.acquire(second.actor, second.id, second.token)).toMatchObject({ fence: 2 });
});
it('requires the live lease of this execution before integrating or building', async () => {
const f = await fixture();
const run = await f.verifierFor('gate');
await expect(f.control.integration.enforce(run.actor, run.id, run.token)).rejects.toMatchObject({
code: 'INTEGRATION_LEASE_REQUIRED',
});
await f.control.integration.acquire(run.actor, run.id, run.token);
await expect(f.control.integration.enforce(run.actor, run.id, run.token)).resolves.toBeUndefined();
});
});