Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

refactor(open-knowledge): remove dead /api/local-op/open endpoint (#1740)

Andrew Mikofalvye30bcfa2bf04
diff --git a/packages/app/tests/integration/api-error-envelope/local-op-open.test.ts b/packages/app/tests/integration/api-error-envelope/local-op-open.test.ts
deleted file mode 100644
index a13125a85..000000000
--- a/packages/app/tests/integration/api-error-envelope/local-op-open.test.ts
+++ /dev/null
@@ -1,77 +0,0 @@
-import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
-import { ProblemDetailsSchema } from '@inkeep/open-knowledge-core';
-import { createTestServer, type TestServer } from '../test-harness';
-
-let server: TestServer;
-
-beforeAll(async () => {
- server = await createTestServer();
-});
-
-afterAll(async () => {
- await server.cleanup();
-});
-
-const UUID_RE = /^urn:uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
-
-async function postOpen(body: unknown): Promise<Response> {
- return fetch(`http://127.0.0.1:${server.port}/api/local-op/open`, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: typeof body === 'string' ? body : JSON.stringify(body),
- });
-}
-
-describe('local-op-open envelope (RFC 9457, US-012)', () => {
- test('malformed body emits problem+json 400 with urn:ok:error:invalid-request', async () => {
- const res = await postOpen('not-valid-json{');
- expect(res.status).toBe(400);
- expect(res.headers.get('content-type')).toBe('application/problem+json');
- const body = await res.json();
- const parsed = ProblemDetailsSchema.safeParse(body);
- expect(parsed.success).toBe(true);
- if (parsed.success) {
- expect(parsed.data.type).toBe('urn:ok:error:invalid-request');
- expect(parsed.data.status).toBe(400);
- expect(parsed.data.instance).toBeDefined();
- if (parsed.data.instance) expect(parsed.data.instance).toMatch(UUID_RE);
- }
- });
-
- test('missing dir field emits problem+json 400 (LocalOpOpenRequestSchema validation)', async () => {
- const res = await postOpen({});
- expect(res.status).toBe(400);
- const body = await res.json();
- const parsed = ProblemDetailsSchema.safeParse(body);
- expect(parsed.success).toBe(true);
- if (parsed.success) {
- expect(parsed.data.type).toBe('urn:ok:error:invalid-request');
- expect(parsed.data.detail ?? '').toMatch(/dir/i);
- }
- });
-
- test('dir outside home emits urn:ok:error:dir-outside-home', async () => {
- const res = await postOpen({ dir: '/etc/some-project' });
- expect(res.status).toBe(400);
- const body = await res.json();
- const parsed = ProblemDetailsSchema.safeParse(body);
- expect(parsed.success).toBe(true);
- if (parsed.success) {
- expect(parsed.data.type).toBe('urn:ok:error:dir-outside-home');
- }
- });
-
- test('method-not-allowed on GET emits problem+json 405 with Allow: POST', async () => {
- const res = await fetch(`http://127.0.0.1:${server.port}/api/local-op/open`, {
- method: 'GET',
- });
- expect(res.status).toBe(405);
- expect(res.headers.get('allow')).toBe('POST');
- const body = await res.json();
- const parsed = ProblemDetailsSchema.safeParse(body);
- expect(parsed.success).toBe(true);
- if (parsed.success) {
- expect(parsed.data.type).toBe('urn:ok:error:method-not-allowed');
- }
- });
-});
diff --git a/packages/app/tests/integration/attribution-sweep-coverage.test.ts b/packages/app/tests/integration/attribution-sweep-coverage.test.ts
index 2693d351c..ae69223d8 100644
--- a/packages/app/tests/integration/attribution-sweep-coverage.test.ts
+++ b/packages/app/tests/integration/attribution-sweep-coverage.test.ts
@@ -74,7 +74,6 @@ const EXEMPT_HANDLERS = new Set([
'handleSyncTrigger',
'handleSyncResolveConflict',
'handleLocalOpClone',
- 'handleLocalOpOpen',
'handleLocalOpOkInit',
'handleLocalOpAuthLogin',
'handleLocalOpAuthStatus',
diff --git a/packages/app/tests/integration/conflict-gate-coverage.test.ts b/packages/app/tests/integration/conflict-gate-coverage.test.ts
index 96558e786..b43876ae1 100644
--- a/packages/app/tests/integration/conflict-gate-coverage.test.ts
+++ b/packages/app/tests/integration/conflict-gate-coverage.test.ts
@@ -64,7 +64,6 @@ const EXEMPT_HANDLERS = new Set([
'handleAgentBurstDiff',
'handleTemplateGet',
'handleLocalOpClone',
- 'handleLocalOpOpen',
'handleLocalOpOkInit',
'handleLocalOpAuthLogin',
'handleLocalOpAuthStatus',
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 91c86756f..5285ac91b 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -599,10 +599,6 @@ export {
LocalOpOkInitRequestSchema,
type LocalOpOkInitResponse,
LocalOpOkInitResponseSchema,
- type LocalOpOpenRequest,
- LocalOpOpenRequestSchema,
- type LocalOpOpenSuccess,
- LocalOpOpenSuccessSchema,
type MetricsAgentPresenceSuccess,
MetricsAgentPresenceSuccessSchema,
type MetricsParseHealthSuccess,
diff --git a/packages/core/src/schemas/api/local-op.test.ts b/packages/core/src/schemas/api/local-op.test.ts
index d6047bed7..e5e8a35b8 100644
--- a/packages/core/src/schemas/api/local-op.test.ts
+++ b/packages/core/src/schemas/api/local-op.test.ts
@@ -4,8 +4,6 @@ import {
LocalOpAuthHostRequestSchema,
LocalOpAuthSetIdentityRequestSchema,
LocalOpAuthStatusSuccessSchema,
- LocalOpOpenRequestSchema,
- LocalOpOpenSuccessSchema,
ProblemTypeSchema,
} from './index.ts';
@@ -21,47 +19,6 @@ describe('Cluster G URN tokens (US-012)', () => {
});
});
-describe('LocalOpOpenRequestSchema', () => {
- test('parses a valid dir', () => {
- expect(LocalOpOpenRequestSchema.safeParse({ dir: '~/Projects/notes' }).success).toBe(true);
- });
- test('rejects empty dir', () => {
- expect(LocalOpOpenRequestSchema.safeParse({ dir: '' }).success).toBe(false);
- });
- test('rejects missing dir', () => {
- expect(LocalOpOpenRequestSchema.safeParse({}).success).toBe(false);
- });
- test('accepts an optional positive integer port (worktree-preview pane port)', () => {
- const parsed = LocalOpOpenRequestSchema.safeParse({ dir: '~/Projects/notes', port: 39848 });
- expect(parsed.success).toBe(true);
- if (parsed.success) expect(parsed.data.port).toBe(39848);
- });
- test('rejects a non-positive, non-integer, or out-of-range port', () => {
- expect(LocalOpOpenRequestSchema.safeParse({ dir: '~/p', port: 0 }).success).toBe(false);
- expect(LocalOpOpenRequestSchema.safeParse({ dir: '~/p', port: -1 }).success).toBe(false);
- expect(LocalOpOpenRequestSchema.safeParse({ dir: '~/p', port: 1.5 }).success).toBe(false);
- expect(LocalOpOpenRequestSchema.safeParse({ dir: '~/p', port: 99999 }).success).toBe(false);
- expect(LocalOpOpenRequestSchema.safeParse({ dir: '~/p', port: 65535 }).success).toBe(true);
- });
- test('omitting port still parses (clone-complete + legacy open paths)', () => {
- const parsed = LocalOpOpenRequestSchema.safeParse({ dir: '~/p' });
- expect(parsed.success).toBe(true);
- if (parsed.success) expect(parsed.data.port).toBeUndefined();
- });
-});
-
-describe('LocalOpOpenSuccessSchema', () => {
- test('parses a valid port', () => {
- expect(LocalOpOpenSuccessSchema.safeParse({ port: 5173 }).success).toBe(true);
- });
- test('rejects negative port', () => {
- expect(LocalOpOpenSuccessSchema.safeParse({ port: -1 }).success).toBe(false);
- });
- test('rejects zero port', () => {
- expect(LocalOpOpenSuccessSchema.safeParse({ port: 0 }).success).toBe(false);
- });
-});
-
describe('LocalOpAuthHostRequestSchema', () => {
test('parses with host', () => {
expect(LocalOpAuthHostRequestSchema.safeParse({ host: 'github.com' }).success).toBe(true);
diff --git a/packages/core/src/schemas/api/local-op.ts b/packages/core/src/schemas/api/local-op.ts
index 8d3c82573..498bca63d 100644
--- a/packages/core/src/schemas/api/local-op.ts
+++ b/packages/core/src/schemas/api/local-op.ts
@@ -1,21 +1,6 @@
import type { StandardSchemaV1 } from '@standard-schema/spec';
import { z } from 'zod';
-export const LocalOpOpenRequestSchema = z
- .object({
- dir: z.string().min(1),
- port: z.number().int().min(1).max(65535).optional(),
- })
- .loose() satisfies StandardSchemaV1;
-export type LocalOpOpenRequest = z.infer<typeof LocalOpOpenRequestSchema>;
-
-export const LocalOpOpenSuccessSchema = z
- .object({
- port: z.number().int().positive(),
- })
- .loose() satisfies StandardSchemaV1;
-export type LocalOpOpenSuccess = z.infer<typeof LocalOpOpenSuccessSchema>;
-
export const LocalOpOkInitRequestSchema = z
.object({
projectPath: z.string().min(1),
diff --git a/packages/server/src/api-extension.ts b/packages/server/src/api-extension.ts
index d07c7fe99..bb3afd32e 100644
--- a/packages/server/src/api-extension.ts
+++ b/packages/server/src/api-extension.ts
@@ -102,8 +102,6 @@ import {
LocalOpEmbeddingsSetKeyRequestSchema,
LocalOpOkInitRequestSchema,
LocalOpOkInitResponseSchema,
- LocalOpOpenRequestSchema,
- LocalOpOpenSuccessSchema,
MetricsAgentPresenceSuccessSchema,
MetricsParseHealthSuccessSchema,
MetricsReconciliationSuccessSchema,
@@ -7834,7 +7832,6 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {
}
const LOCAL_OP_CLONE_KEY = '/api/local-op/clone';
- const LOCAL_OP_OPEN_KEY = '/api/local-op/open';
const LOCAL_OP_OK_INIT_KEY = '/api/local-op/ok-init';
const LOCAL_OP_TIMEOUT_MS = 10 * 60 * 1000;
const LOCAL_OP_OPEN_TIMEOUT_MS = 45_000;
@@ -8013,7 +8010,7 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {
stderrChunks.push(chunk);
log.warn(
{ cwd: absDir, cliCmd, msg: chunk.toString('utf-8').trim() },
- '[local-op/open] child stderr',
+ '[local-op/clone] child stderr',
);
});
@@ -8029,7 +8026,7 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {
earlyExitCode = -1;
log.error(
{ cwd: absDir, cliCmd, err: err.message },
- '[local-op/open] failed to spawn child',
+ '[local-op/clone] failed to spawn child',
);
});
@@ -8079,64 +8076,6 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {
return { error: result.error };
}
- const HANDLE_LOCAL_OP_OPEN = 'local-op-open';
- const handleLocalOpOpen = withValidation(
- LocalOpOpenRequestSchema,
- async (_req, res, body) => {
- const { dir, port } = body;
-
- if (!isSafeLocalPath(dir)) {
- errorResponse(
- res,
- 400,
- 'urn:ok:error:dir-outside-home',
- 'dir must be within the user home directory.',
- { handler: HANDLE_LOCAL_OP_OPEN, cause: new Error(`dir=${dir}`) },
- );
- return;
- }
-
- if (!localOpGuard.tryAcquire(LOCAL_OP_OPEN_KEY)) {
- errorResponse(
- res,
- 429,
- 'urn:ok:error:concurrent-operation',
- 'A server-open operation is already in progress.',
- { handler: HANDLE_LOCAL_OP_OPEN, extraHeaders: { 'Retry-After': '5' } },
- );
- return;
- }
-
- try {
- const result = await startServerAtDirAndGetPort(dir, port);
- if ('port' in result) {
- successResponse(
- res,
- 200,
- LocalOpOpenSuccessSchema,
- { port: result.port },
- { handler: HANDLE_LOCAL_OP_OPEN },
- );
- } else {
- errorResponse(
- res,
- 504,
- 'urn:ok:error:server-open-failed',
- 'Failed to open project server.',
- { handler: HANDLE_LOCAL_OP_OPEN, cause: new Error(result.error) },
- );
- }
- } finally {
- localOpGuard.release(LOCAL_OP_OPEN_KEY);
- }
- },
- {
- handler: HANDLE_LOCAL_OP_OPEN,
- method: 'POST',
- preBodyGate: (req, res) => checkLocalOpSecurity(req, res, { handler: HANDLE_LOCAL_OP_OPEN }),
- },
- );
-
const HANDLE_LOCAL_OP_OK_INIT = 'local-op-ok-init';
const handleLocalOpOkInit = withValidation(
LocalOpOkInitRequestSchema,
@@ -11166,7 +11105,6 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {
'/api/sync/conflict-content': handleSyncConflictContent,
'/api/sync/resolve-conflict': handleSyncResolveConflict,
'/api/local-op/clone': handleLocalOpClone,
- '/api/local-op/open': handleLocalOpOpen,
'/api/local-op/ok-init': handleLocalOpOkInit,
'/api/local-op/auth/login': handleLocalOpAuthLogin,
'/api/local-op/auth/status': handleLocalOpAuthStatus,