Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
refactor(open-knowledge): remove dead /api/local-op/auth/pat endpoint (#1737)
Andrew Mikofalvy400a0850225d
diff --git a/packages/app/tests/integration/api-error-envelope/local-op-auth-pat.test.ts b/packages/app/tests/integration/api-error-envelope/local-op-auth-pat.test.tsdeleted file mode 100644index eb0e33317..000000000--- a/packages/app/tests/integration/api-error-envelope/local-op-auth-pat.test.ts+++ /dev/null@@ -1,86 +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({- localOpCliArgs: ['/nonexistent-test-binary-do-not-create-this-file'],- });-});--afterAll(async () => {- await server.cleanup();-});--async function postPat(body: unknown): Promise<Response> {- return fetch(`http://127.0.0.1:${server.port}/api/local-op/auth/pat`, {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: typeof body === 'string' ? body : JSON.stringify(body),- });-}--describe('local-op-auth-pat envelope (RFC 9457, US-012)', () => {- test('missing pat field emits urn:ok:error:invalid-request', async () => {- const res = await postPat({});- 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(/pat/i);- }- });-- test('empty pat string fails schema with urn:ok:error:invalid-request', async () => {- const res = await postPat({ pat: '' });- 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');- }- });-- test('malformed JSON body emits problem+json 400', async () => {- const res = await postPat('not-valid-json{');- 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');- }- });-- test('spawn failure emits urn:ok:error:auth-failed problem+json 500', async () => {- const res = await postPat({ pat: 'ghp_abc123' });- expect(res.status).toBe(500);- 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:auth-failed');- expect(parsed.data.status).toBe(500);- }- });-- test('method-not-allowed on GET emits problem+json with Allow: POST', async () => {- const res = await fetch(`http://127.0.0.1:${server.port}/api/local-op/auth/pat`, {- 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.tsindex 50225705b..c183b6c92 100644--- a/packages/app/tests/integration/attribution-sweep-coverage.test.ts+++ b/packages/app/tests/integration/attribution-sweep-coverage.test.ts@@ -81,7 +81,6 @@ const EXEMPT_HANDLERS = new Set(['handleLocalOpAuthStatus','handleLocalOpAuthRepos','handleLocalOpAuthSignout',- 'handleLocalOpAuthPat','handleLocalOpAuthIdentity','handleLocalOpAuthSetIdentity','handleLocalOpEmbeddingsSetKey',diff --git a/packages/app/tests/integration/conflict-gate-coverage.test.ts b/packages/app/tests/integration/conflict-gate-coverage.test.tsindex 14cdfd89e..c53e6c56c 100644--- a/packages/app/tests/integration/conflict-gate-coverage.test.ts+++ b/packages/app/tests/integration/conflict-gate-coverage.test.ts@@ -71,7 +71,6 @@ const EXEMPT_HANDLERS = new Set(['handleLocalOpAuthStatus','handleLocalOpAuthRepos','handleLocalOpAuthSignout',- 'handleLocalOpAuthPat','handleLocalOpAuthIdentity','handleLocalOpAuthSetIdentity','handleLocalOpEmbeddingsSetKey',diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex d5a99ac81..b04c604f4 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -586,10 +586,6 @@ export {LocalOpAuthIdentitySchema,type LocalOpAuthIdentitySuccess,LocalOpAuthIdentitySuccessSchema,- type LocalOpAuthPatRequest,- LocalOpAuthPatRequestSchema,- type LocalOpAuthPatSuccess,- LocalOpAuthPatSuccessSchema,type LocalOpAuthSetIdentityRequest,LocalOpAuthSetIdentityRequestSchema,type LocalOpAuthStatusSuccess,diff --git a/packages/core/src/schemas/api/local-op.test.ts b/packages/core/src/schemas/api/local-op.test.tsindex 35ca808f2..34dfabfff 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,LocalOpAuthIdentitySchema,LocalOpAuthIdentitySuccessSchema,- LocalOpAuthPatRequestSchema,- LocalOpAuthPatSuccessSchema,LocalOpAuthSetIdentityRequestSchema,LocalOpAuthStatusSuccessSchema,LocalOpOpenRequestSchema,@@ -78,23 +76,6 @@ describe('LocalOpAuthHostRequestSchema', () => {});});-describe('LocalOpAuthPatRequestSchema', () => {- test('parses pat-only', () => {- expect(LocalOpAuthPatRequestSchema.safeParse({ pat: 'ghp_abc123' }).success).toBe(true);- });- test('parses pat with host', () => {- expect(- LocalOpAuthPatRequestSchema.safeParse({ pat: 'ghp_abc123', host: 'github.com' }).success,- ).toBe(true);- });- test('rejects missing pat', () => {- expect(LocalOpAuthPatRequestSchema.safeParse({ host: 'github.com' }).success).toBe(false);- });- test('rejects empty pat', () => {- expect(LocalOpAuthPatRequestSchema.safeParse({ pat: '' }).success).toBe(false);- });-});-describe('LocalOpAuthSetIdentityRequestSchema', () => {test('parses valid name + email', () => {expect(@@ -176,21 +157,6 @@ describe('LocalOpAuthStatusSuccessSchema', () => {});});-describe('LocalOpAuthPatSuccessSchema', () => {- test('parses CLI complete event with login', () => {- expect(- LocalOpAuthPatSuccessSchema.safeParse({- type: 'complete',- login: 'alice',- name: 'Alice',- }).success,- ).toBe(true);- });- test('parses bare empty object (fallback shape)', () => {- expect(LocalOpAuthPatSuccessSchema.safeParse({}).success).toBe(true);- });-});-describe('LocalOpAuthEmptySuccessSchema', () => {test('parses empty body', () => {expect(LocalOpAuthEmptySuccessSchema.safeParse({}).success).toBe(true);diff --git a/packages/core/src/schemas/api/local-op.ts b/packages/core/src/schemas/api/local-op.tsindex d2abc8761..841792b08 100644--- a/packages/core/src/schemas/api/local-op.ts+++ b/packages/core/src/schemas/api/local-op.ts@@ -53,14 +53,6 @@ export const LocalOpAuthHostRequestSchema = z.loose() satisfies StandardSchemaV1;export type LocalOpAuthHostRequest = z.infer<typeof LocalOpAuthHostRequestSchema>;-export const LocalOpAuthPatRequestSchema = z- .object({- pat: z.string().min(1),- host: z.string().min(1).optional(),- })- .loose() satisfies StandardSchemaV1;-export type LocalOpAuthPatRequest = z.infer<typeof LocalOpAuthPatRequestSchema>;-export const LocalOpEmbeddingsSetKeyRequestSchema = z.object({key: z.string().min(1),@@ -108,13 +100,5 @@ export const LocalOpAuthStatusSuccessSchema = z.loose() satisfies StandardSchemaV1;export type LocalOpAuthStatusSuccess = z.infer<typeof LocalOpAuthStatusSuccessSchema>;-export const LocalOpAuthPatSuccessSchema = z- .object({- type: z.literal('complete').optional(),- login: z.string().min(1).optional(),- })- .loose() satisfies StandardSchemaV1;-export type LocalOpAuthPatSuccess = z.infer<typeof LocalOpAuthPatSuccessSchema>;-export const LocalOpAuthEmptySuccessSchema = z.object({}).loose() satisfies StandardSchemaV1;export type LocalOpAuthEmptySuccess = z.infer<typeof LocalOpAuthEmptySuccessSchema>;diff --git a/packages/server/src/api-extension.ts b/packages/server/src/api-extension.tsindex a279adc94..b4fdee7ca 100644--- a/packages/server/src/api-extension.ts+++ b/packages/server/src/api-extension.ts@@ -95,8 +95,6 @@ import {type LocalOpAuthHostRequest,LocalOpAuthHostRequestSchema,LocalOpAuthIdentitySuccessSchema,- LocalOpAuthPatRequestSchema,- LocalOpAuthPatSuccessSchema,LocalOpAuthSetIdentityRequestSchema,LocalOpAuthStatusSuccessSchema,type LocalOpCloneRequest,@@ -8349,7 +8347,6 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {const LOCAL_OP_AUTH_STATUS_KEY = '/api/local-op/auth/status';const LOCAL_OP_AUTH_REPOS_KEY = '/api/local-op/auth/repos';const LOCAL_OP_AUTH_SIGNOUT_KEY = '/api/local-op/auth/signout';- const LOCAL_OP_AUTH_PAT_KEY = '/api/local-op/auth/pat';let authLoginInFlight: ReturnType<typeof runDeviceFlowSubprocess> | null = null;@@ -8733,98 +8730,6 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {},);- const HANDLE_LOCAL_OP_AUTH_PAT = 'local-op-auth-pat';- const handleLocalOpAuthPat = withValidation(- LocalOpAuthPatRequestSchema,- async (_req, res, body) => {- const { pat, host: hostInput } = body;- const host = hostInput ?? 'github.com';-- if (!localOpGuard.tryAcquire(LOCAL_OP_AUTH_PAT_KEY)) {- errorResponse(- res,- 429,- 'urn:ok:error:concurrent-operation',- 'An auth pat operation is already in progress.',- { handler: HANDLE_LOCAL_OP_AUTH_PAT, extraHeaders: { 'Retry-After': '5' } },- );- return;- }-- try {- const [cmd, ...baseArgs] = localOpCliArgs;- const spawnArgs = [...baseArgs, 'auth', 'pat', '--json', '--host', host];-- const output = await new Promise<string>((resolve, reject) => {- const child = spawn(cmd, spawnArgs, {- stdio: ['pipe', 'pipe', 'pipe'],- env: { ...process.env },- });- const killTimer = setTimeout(() => {- child.kill('SIGTERM');- }, 30_000);- child.stdin.write(`${pat}\n`);- child.stdin.end();-- const chunks: Buffer[] = [];- child.stdout.on('data', (chunk: Buffer) => chunks.push(chunk));- child.on('close', (code) => {- clearTimeout(killTimer);- if (code !== 0) {- reject(new Error(`auth pat exited with code ${code}`));- } else {- resolve(Buffer.concat(chunks).toString('utf-8'));- }- });- child.on('error', (err) => {- clearTimeout(killTimer);- reject(err);- });- });-- const lines = output- .split('\n')- .map((l) => l.trim())- .filter(Boolean);- let parsed: unknown = null;- for (let i = lines.length - 1; i >= 0; i--) {- try {- parsed = JSON.parse(lines[i] as string);- break;- } catch {}- }- if (parsed !== null) {- successResponse(res, 200, LocalOpAuthPatSuccessSchema, parsed, {- handler: HANDLE_LOCAL_OP_AUTH_PAT,- });- } else {- successResponse(- res,- 200,- LocalOpAuthPatSuccessSchema,- {},- {- handler: HANDLE_LOCAL_OP_AUTH_PAT,- },- );- }- } catch (err) {- errorResponse(res, 500, 'urn:ok:error:auth-failed', 'Auth pat failed.', {- handler: HANDLE_LOCAL_OP_AUTH_PAT,- cause: err,- });- } finally {- localOpGuard.release(LOCAL_OP_AUTH_PAT_KEY);- }- },- {- handler: HANDLE_LOCAL_OP_AUTH_PAT,- method: 'POST',- preBodyGate: (req, res) =>- checkLocalOpSecurity(req, res, { handler: HANDLE_LOCAL_OP_AUTH_PAT }),- },- );-const HANDLE_LOCAL_OP_AUTH_IDENTITY = 'local-op-auth-identity';async function handleLocalOpAuthIdentity(req: IncomingMessage,@@ -11379,7 +11284,6 @@ export function createApiExtension(options: ApiExtensionOptions): Extension {'/api/local-op/auth/status': handleLocalOpAuthStatus,'/api/local-op/auth/repos': handleLocalOpAuthRepos,'/api/local-op/auth/signout': handleLocalOpAuthSignout,- '/api/local-op/auth/pat': handleLocalOpAuthPat,'/api/local-op/auth/identity': handleLocalOpAuthIdentity,'/api/local-op/auth/set-identity': handleLocalOpAuthSetIdentity,'/api/local-op/embeddings/set-key': handleLocalOpEmbeddingsSetKey,