diff --git a/docs/pr-cccc-branch.md b/docs/pr-cccc-branch.md new file mode 100644 index 0000000..a25e000 --- /dev/null +++ b/docs/pr-cccc-branch.md @@ -0,0 +1,56 @@ +# cccc 分支 PR 描述(合并时请复制到 GitHub PR 正文) + +--- + +在 GitHub 创建 PR 时,将下方「PR 正文」整段复制到描述框。PR 合并后,正文中的 6 个 `Closes #N` 会使对应 Issue 自动关闭。 + +--- + +## PR 正文(复制以下内容) + +### 概述 + +本 PR 包含 Web 端错误态与 emoji 替换、Python SDK 最小可用实现、Registry Context 类型修复等改动。 + +Closes #4 +Closes #5 +Closes #6 +Closes #7 +Closes #8 +Closes #9 + +### 关联的 Issues([GeneHub Issues](https://github.com/NoDeskAI/genehub/issues),合并后将自动关闭) + +| Issue | 标题 | +|-------|------| +| #9 | [sdk] Python SDK 初始化实现 | +| #8 | [web] 版本历史加载失败静默吞错 + 违规使用 emoji | +| #7 | [cli] 实现 genehub info 命令,查看单个基因详情 | +| #6 | [cli] search 命令未接入联邦搜索,无法搜到外部基因源 | +| #5 | [sdk] Nanobot Adapter 缺少测试覆盖,config.nanobot 配置注入未实现 | +| #4 | [registry] 删除基因/基因组/模板时 Gitea 仓库清理失败不抛错,导致数据不一致 | + +### 主要变更 + +**Web(packages/web)** +- 列表/版本历史加载失败时展示错误提示;列表失败时重置 totalPages / federatedSources +- 详情页 slug 变化时清空 error 与数据,避免一直显示错误页 +- 剩余 emoji 替换为 Lucide 图标(Home 分类、GenomeBrowse 空态、CategoryNav 等) + +**Python SDK(packages/sdk/python)** +- 新增 GeneHubClient、GeneAdapter、GenericAdapter、LearningEngine(最小可用) +- 按 Copilot 评论修正:URL 编码、JSON 异常处理、GeneManifest 类型、safe_dump、时间戳、非 JSON 响应测试 + +**Registry(packages/registry)** +- 为 Hono Context 声明 AuthVariables 类型,消除 genes API 等处的 TypeScript 报错 + +**文档** +- architecture.md、README、AGENTS.md 等补充/更新 Python SDK 与目录结构 +- docs/pr-registry-context-types.md、docs/pr-cccc-branch.md(本 PR 说明) + +### Test plan + +- `pnpm build`、`pnpm test` 全量通过 +- Web:本地 `pnpm dev` 验证列表/详情错误态与分类图标 +- Python SDK:`cd packages/sdk/python && uv run pytest tests/ -v` +- Registry:本地启动后调用需鉴权接口验证行为不变 diff --git a/docs/pr-registry-context-types.md b/docs/pr-registry-context-types.md new file mode 100644 index 0000000..e6ada30 --- /dev/null +++ b/docs/pr-registry-context-types.md @@ -0,0 +1,25 @@ +# fix(registry): 为 Hono Context 声明 Auth 变量类型,消除 genes 等 API 的 TypeScript 报错 + +## Summary + +- 修复 Registry 中 `packages/registry/src/api/genes.ts` 等文件因 Hono Context 未声明 `authRole` / `publisherId` / `githubLogin` 导致的 TypeScript 报错(`c.get('authRole')` 等被判定为非法)。 +- 在 auth 中间件中导出 `AuthVariables` 类型,并在主 App 与 genes 路由上使用 `Hono<{ Variables: AuthVariables }>`,使类型与运行时行为一致。 + +## Changes + +| 文件 | 变更 | +|------|------| +| `packages/registry/src/middleware/auth.ts` | 新增并导出 `AuthVariables` 类型(authRole、publisherId、githubLogin) | +| `packages/registry/src/app.ts` | 使用 `new Hono<{ Variables: AuthVariables }>()` 创建 App | +| `packages/registry/src/api/genes.ts` | 使用 `new Hono<{ Variables: AuthVariables }>()` 创建 genesRouter | + +## Impact + +- **运行时**:无行为变化,auth 中间件原本就会注入上述变量。 +- **构建 / CI**:带类型检查的构建与 `tsc` 可通过。 +- **开发体验**:IDE 中相关类型错误与红色波浪线消失。 + +## Test plan + +- 在 `packages/registry` 下执行 `pnpm build` 与 `pnpm test`,确认通过。 +- 本地 `pnpm dev` 启动 Registry,调用需鉴权或 optionalAuth 的接口(如 `GET /api/v1/genes?review_status=...`),确认行为与修改前一致。 diff --git a/packages/registry/src/api/genes.ts b/packages/registry/src/api/genes.ts index 36341fd..599506b 100644 --- a/packages/registry/src/api/genes.ts +++ b/packages/registry/src/api/genes.ts @@ -1,10 +1,11 @@ import { Hono } from 'hono'; +import type { AuthVariables } from '../middleware/auth.js'; import { optionalAuth, requireAuth } from '../middleware/auth.js'; import { paginated, success } from '../middleware/response.js'; import { federatedSearch } from '../services/federated-search.js'; import * as geneService from '../services/gene-service.js'; -export const genesRouter = new Hono(); +export const genesRouter = new Hono<{ Variables: AuthVariables }>(); genesRouter.get('/search', async (c) => { const q = c.req.query('q') ?? ''; diff --git a/packages/registry/src/app.ts b/packages/registry/src/app.ts index 1364335..90c7388 100644 --- a/packages/registry/src/app.ts +++ b/packages/registry/src/app.ts @@ -15,9 +15,10 @@ import { syncRouter } from './api/sync.js'; import { templatesRouter } from './api/templates.js'; import { webhooksRouter } from './api/webhooks.js'; import { handleMcpRequest } from './mcp/http.js'; +import type { AuthVariables } from './middleware/auth.js'; import { errorHandler } from './middleware/error-handler.js'; -export const app = new Hono(); +export const app = new Hono<{ Variables: AuthVariables }>(); let healthOkCount = 0; app.use('*', async (c, next) => { diff --git a/packages/registry/src/middleware/auth.ts b/packages/registry/src/middleware/auth.ts index cb57025..1d1bee0 100644 --- a/packages/registry/src/middleware/auth.ts +++ b/packages/registry/src/middleware/auth.ts @@ -10,6 +10,13 @@ const { apiKeys, publishers } = schema; export type AuthRole = 'public' | 'publisher' | 'admin'; +/** Hono Context 上由 auth 中间件注入的变量,需在 App/Router 的 Variables 中声明。 */ +export type AuthVariables = { + authRole?: AuthRole; + publisherId?: string; + githubLogin?: string; +}; + const ADMIN_TOKEN = process.env.GENEHUB_ADMIN_TOKEN ?? 'admin-dev-token'; const JWT_SECRET = process.env.GENEHUB_JWT_SECRET ?? 'genehub-dev-jwt-secret'; const COOKIE_NAME = 'ghb_session';