Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

refactor(open-knowledge): remove dead GET /api/rescue/:docName route (#1738)

Andrew Mikofalvye55fc371391e
diff --git a/packages/app/tests/integration/api-error-envelope/rescue-get.test.ts b/packages/app/tests/integration/api-error-envelope/rescue-get.test.ts
deleted file mode 100644
index 00fe5981c..000000000
--- a/packages/app/tests/integration/api-error-envelope/rescue-get.test.ts
+++ /dev/null
@@ -1,42 +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();
-});
-
-describe('rescue-get envelope (RFC 9457)', () => {
- test('missing docName returns 404 problem+json not-found', async () => {
- const res = await fetch(`http://127.0.0.1:${server.port}/api/rescue/this-doc-does-not-exist`);
- expect(res.status).toBe(404);
- 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:not-found');
- }
- });
-
- test('method-not-allowed on POST emits problem+json with Allow: GET', async () => {
- const res = await fetch(`http://127.0.0.1:${server.port}/api/rescue/anything`, {
- method: 'POST',
- });
- expect(res.status).toBe(405);
- expect(res.headers.get('content-type')).toBe('application/problem+json');
- expect(res.headers.get('allow')).toBe('GET');
- 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 c183b6c92..56b07c63a 100644
--- a/packages/app/tests/integration/attribution-sweep-coverage.test.ts
+++ b/packages/app/tests/integration/attribution-sweep-coverage.test.ts
@@ -68,7 +68,6 @@ const EXEMPT_HANDLERS = new Set([
'handleClientLogs',
'handleWorkspace',
'handleRescueList',
- 'handleRescueGet',
'handleSyncStatus',
'handleSyncConflicts',
'handleSyncConflictContent',
diff --git a/packages/app/tests/integration/conflict-gate-coverage.test.ts b/packages/app/tests/integration/conflict-gate-coverage.test.ts
index c53e6c56c..331790dd4 100644
--- a/packages/app/tests/integration/conflict-gate-coverage.test.ts
+++ b/packages/app/tests/integration/conflict-gate-coverage.test.ts
@@ -52,7 +52,6 @@ const EXEMPT_HANDLERS = new Set([
'handleWorkspace',
'handleApiConfig',
'handleRescueList',
- 'handleRescueGet',
'handleSyncStatus',
'handleSyncConflicts',
'handleSyncConflictContent',
diff --git a/packages/server/src/api-extension.ts b/packages/server/src/api-extension.ts
index b4fdee7ca..437ddf03a 100644
--- a/packages/server/src/api-extension.ts
+++ b/packages/server/src/api-extension.ts
@@ -6240,79 +6240,6 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {
{ handler: 'rescue-list', method: 'GET', skipBodyParse: true },
);
- async function handleRescueGet(
- req: IncomingMessage,
- res: ServerResponse,
- docName: string,
- ): Promise<void> {
- if (req.method !== 'GET') {
- errorResponse(res, 405, 'urn:ok:error:method-not-allowed', 'Method not allowed.', {
- handler: 'rescue-get',
- extraHeaders: { Allow: 'GET' },
- });
- return;
- }
- if (!shadowRef?.current) {
- errorResponse(res, 503, 'urn:ok:error:shadow-not-configured', 'Shadow repo not configured.', {
- handler: 'rescue-get',
- });
- return;
- }
-
- const rescueBase = resolve(shadowRef.current.gitDir, 'rescue');
- const filePath = resolve(rescueBase, `${docName}${getDocExtension(docName)}`);
- if (!filePath.startsWith(`${rescueBase}/`)) {
- errorResponse(res, 400, 'urn:ok:error:invalid-request', 'Invalid document name.', {
- handler: 'rescue-get',
- });
- return;
- }
- if (existsSync(filePath)) {
- const stat = statSync(filePath);
- if (Date.now() - stat.mtimeMs > RESCUE_MAX_AGE_MS) {
- try {
- unlinkSync(filePath);
- } catch {}
- } else {
- const content = readFileSync(filePath, 'utf-8');
- res.writeHead(200, {
- 'Content-Type': 'text/markdown',
- 'X-Content-Type-Options': 'nosniff',
- });
- res.end(content);
- return;
- }
- }
-
- try {
- const branch = getCurrentBranch?.() ?? 'main';
- const timelineEntries = await listRescueCheckpoints(shadowRef.current, branch);
- const match = timelineEntries
- .filter((e) => e.docName === docName)
- .sort((a, b) => b.timestamp.localeCompare(a.timestamp))[0];
- if (match) {
- const sg = shadowGit(shadowRef.current);
- const tree = (await sg.raw('ls-tree', '-r', match.sha)).trim();
- const firstLine = tree.split('\n')[0] ?? '';
- const parts = firstLine.split(/\s+/);
- const blobSha = parts[2];
- if (blobSha) {
- const content = await sg.raw('cat-file', '-p', blobSha);
- res.writeHead(200, {
- 'Content-Type': 'text/markdown',
- 'X-Content-Type-Options': 'nosniff',
- });
- res.end(content);
- return;
- }
- }
- } catch (e) {
- console.warn('[rescue] timeline-ref fallback failed:', e);
- }
-
- errorResponse(res, 404, 'urn:ok:error:not-found', 'Not found.', { handler: 'rescue-get' });
- }
-
const handleCreatePage = withValidation(
CreatePageRequestSchema,
async (_req, res, body) => {
@@ -11436,8 +11363,7 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {
const extractedCtx = propagation.extract(context.active(), request.headers);
const method = request.method ?? 'GET';
let routeTemplate = url;
- if (url.startsWith('/api/rescue/')) routeTemplate = '/api/rescue/:docName';
- else if (url.startsWith('/api/history/')) routeTemplate = '/api/history/:sha';
+ if (url.startsWith('/api/history/')) routeTemplate = '/api/history/:sha';
else if (url.startsWith('/api/tags/')) routeTemplate = '/api/tags/:name';
else if (!routes[url]) routeTemplate = '/api/*';
@@ -11463,12 +11389,6 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {
if (handler) {
dispatched = true;
await handler(request, response);
- } else if (url.startsWith('/api/rescue/')) {
- const docName = decodeURIComponent(url.slice('/api/rescue/'.length));
- if (docName) {
- dispatched = true;
- await handleRescueGet(request, response, docName);
- }
} else if (url.startsWith('/api/history/')) {
const sha = decodeURIComponent(url.slice('/api/history/'.length));
if (sha) {