Files
crank/apps/ui/scripts/playwright-ui-server.js
bsodfather 54ce770682
CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
feat(epic3): deliver the accepted Epic 3 scope through Story 3.17
Recovery delivery of the accumulated, TL-accepted Epic 3 work that had never been
committed to Git (stories 3.6-3.17, see the crank board). Story 3.18 is not accepted
yet and is deliberately excluded: its logging surface, its capability registration,
its oracle projections and its tests are not part of this tree.

Accepted scope
- 3.6 typed static Resource Drafts; 3.7 publication and exact binding of static
  Resource Versions; 3.8 MCP discovery/read and revocation of static Resources;
- 3.9 Resource import/export in API and UI plus TLS dependency maintenance;
  3.10 REST-backed Resource templates; 3.11 shared REST read runtime and the MCP
  revision/capability foundation;
- 3.12 parameterised Prompt Drafts with preview; 3.13 Prompt publication and exact
  version binding to Agents; 3.14 MCP prompts; 3.15 Prompt import/export;
- 3.16 composite Prompts with published Resources (dependency content scan plus
  dynamic read through the accepted 3.11 runtime, admin preview and MCP prompts/get);
- 3.17 bounded MCP completion suggestions from typed published schemas and the
  resources/list admission fix for bound template publications.

Accepted evidence being reused (unchanged code paths)
- 3.16 candidate: core 7, admin-api 22, registry 4, mcp-server 4, UI 6; one final
  `just verify` run 1651 passed / 0 failed / 2 ignored.
- 3.17 candidate: full run 1672 passed / 0 failed / 2 ignored, QA targeted reruns and
  a real MCP Inspector 2.12.0 client smoke.

Delivery engineering in this commit
- CI: one event per change (feature branches are gated by their pull request, push
  runs only on main), story events run the changed packages, the full workspace suite
  stays the feature/release gate; no cache/sharding without a measured runner check.
- Release: the packaged archives, checksums and SBOM are now uploaded to the Gitea
  release entry of the tag instead of dying with the runner workspace.

Not included on purpose: Story 3.18 work, build caches, runtime databases, local
credentials and scratch evidence.

Refs: crank kanban t_e39d7263; baseline 1b6db09bd1.
2026-10-25 09:08:22 +00:00

254 lines
6.9 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const http = require('http');
const { pipeline } = require('stream');
const { URL } = require('url');
const ROOT_DIR = path.resolve(__dirname, '..', 'dist');
const UI_PORT = Number(process.env.CRANK_E2E_UI_PORT || 3300);
const ADMIN_PORT = Number(process.env.CRANK_E2E_ADMIN_PORT || 3301);
const MCP_PORT = Number(process.env.CRANK_E2E_MCP_PORT || 3302);
const ADMIN_BASE = new URL(`http://127.0.0.1:${ADMIN_PORT}`);
const MCP_BASE = new URL(`http://127.0.0.1:${MCP_PORT}`);
const MIME_TYPES = {
'.css': 'text/css; charset=utf-8',
'.html': 'text/html; charset=utf-8',
'.js': 'application/javascript; charset=utf-8',
'.json': 'application/json; charset=utf-8',
'.png': 'image/png',
'.svg': 'image/svg+xml',
'.ico': 'image/x-icon',
'.woff2': 'font/woff2',
'.txt': 'text/plain; charset=utf-8',
};
function sendNotFound(response) {
response.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
response.end('Not Found');
}
function redirect(response, location) {
response.writeHead(302, { Location: location });
response.end();
}
function mapRoute(urlPath) {
if (urlPath === '/' || urlPath === '/index.html') {
return path.join(ROOT_DIR, 'index.html');
}
if (urlPath === '/login' || urlPath === '/login.html') {
return path.join(ROOT_DIR, 'html', 'login.html');
}
if (urlPath === '/agents') {
return path.join(ROOT_DIR, 'html', 'agents.html');
}
if (urlPath === '/api-keys') {
return path.join(ROOT_DIR, 'html', 'api-keys.html');
}
if (urlPath === '/secrets') {
return path.join(ROOT_DIR, 'html', 'secrets.html');
}
if (urlPath === '/resources') {
return path.join(ROOT_DIR, 'html', 'resources.html');
}
if (urlPath === '/prompts') {
return path.join(ROOT_DIR, 'html', 'prompts.html');
}
if (urlPath === '/logs') {
return path.join(ROOT_DIR, 'html', 'logs.html');
}
if (urlPath === '/usage') {
return path.join(ROOT_DIR, 'html', 'usage.html');
}
if (urlPath === '/settings') {
return path.join(ROOT_DIR, 'html', 'settings.html');
}
if (urlPath === '/workspace-setup') {
return path.join(ROOT_DIR, 'html', 'workspace-setup.html');
}
if (urlPath === '/wizard/') {
return path.join(ROOT_DIR, 'html', 'wizard', 'index.html');
}
if (urlPath.startsWith('/wizard/')) {
return path.join(ROOT_DIR, 'html', 'wizard', urlPath.slice('/wizard/'.length));
}
if (urlPath.startsWith('/css/')) {
return path.join(ROOT_DIR, urlPath.slice(1));
}
if (urlPath.startsWith('/js/')) {
return path.join(ROOT_DIR, urlPath.slice(1));
}
if (urlPath.startsWith('/icons/')) {
return path.join(ROOT_DIR, urlPath.slice(1));
}
if (urlPath.startsWith('/data/')) {
return path.join(ROOT_DIR, urlPath.slice(1));
}
if (urlPath === '/Crank.png') {
return path.resolve(ROOT_DIR, '..', '..', 'crank-community.png');
}
return null;
}
function serveFile(filePath, response) {
const normalized = path.normalize(filePath);
if (!normalized.startsWith(ROOT_DIR) && !normalized.endsWith(path.sep + 'crank-community.png')) {
sendNotFound(response);
return;
}
fs.stat(normalized, (error, stats) => {
if (response.destroyed || response.writableEnded) {
return;
}
if (error || !stats.isFile()) {
sendNotFound(response);
return;
}
const extension = path.extname(normalized).toLowerCase();
response.writeHead(200, {
'Content-Length': stats.size,
'Content-Type': MIME_TYPES[extension] || 'application/octet-stream',
'Cache-Control': 'no-store',
});
if (response.destroyed || response.writableEnded) {
return;
}
var fileStream = fs.createReadStream(normalized);
fileStream.on('error', function() {
if (!response.destroyed && !response.writableEnded) response.destroy();
});
response.on('close', function() {
if (!fileStream.destroyed) fileStream.destroy();
});
try {
fileStream.pipe(response);
} catch (_error) {
fileStream.destroy();
}
});
}
function proxyRequest(request, response, base, targetPath) {
const target = new URL(targetPath || request.url, base);
const proxy = http.request(
target,
{
method: request.method,
headers: {
...request.headers,
},
},
(proxyResponse) => {
if (response.destroyed || response.writableEnded) {
proxyResponse.resume();
return;
}
response.writeHead(proxyResponse.statusCode || 502, proxyResponse.headers);
proxyResponse.on('error', function() {
if (!response.destroyed) response.destroy();
});
response.on('close', function() {
if (!proxyResponse.destroyed) proxyResponse.destroy();
});
try {
proxyResponse.pipe(response);
} catch (_error) {
proxyResponse.destroy();
}
},
);
proxy.on('error', () => {
if (response.destroyed || response.writableEnded) return;
response.writeHead(502, { 'Content-Type': 'text/plain; charset=utf-8' });
response.end('Bad Gateway');
});
try {
pipeline(request, proxy, () => {});
} catch (_error) {
proxy.destroy();
}
}
const server = http.createServer((request, response) => {
const requestUrl = new URL(request.url, `http://127.0.0.1:${UI_PORT}`);
const urlPath = requestUrl.pathname;
if (urlPath === '/wizard') {
redirect(response, '/wizard/');
return;
}
if (urlPath === '/html/login.html') {
redirect(response, '/login');
return;
}
if (urlPath === '/html/agents.html') {
redirect(response, '/agents');
return;
}
if (urlPath === '/html/api-keys.html') {
redirect(response, '/api-keys');
return;
}
if (urlPath === '/html/secrets.html') {
redirect(response, '/secrets');
return;
}
if (urlPath === '/html/resources.html') {
redirect(response, '/resources');
return;
}
if (urlPath === '/html/prompts.html') {
redirect(response, '/prompts');
return;
}
if (urlPath === '/html/logs.html') {
redirect(response, '/logs');
return;
}
if (urlPath === '/html/usage.html') {
redirect(response, '/usage');
return;
}
if (urlPath === '/html/settings.html') {
redirect(response, '/settings');
return;
}
if (urlPath === '/html/workspace-setup.html') {
redirect(response, '/workspace-setup');
return;
}
if (urlPath === '/html/wizard' || urlPath === '/html/wizard/') {
redirect(response, '/wizard/');
return;
}
if (urlPath.startsWith('/api/auth/') || urlPath.startsWith('/api/admin/')) {
proxyRequest(request, response, ADMIN_BASE);
return;
}
if (urlPath.startsWith('/mcp/')) {
proxyRequest(request, response, MCP_BASE, request.url.slice('/mcp'.length));
return;
}
const filePath = mapRoute(urlPath);
if (!filePath) {
sendNotFound(response);
return;
}
serveFile(filePath, response);
});
server.listen(UI_PORT, '127.0.0.1', () => {
console.log(`Playwright UI server listening on http://127.0.0.1:${UI_PORT}`);
});