Skip to content

feat(tasks): add GET /api/tasks/by-key/:key endpoint#233

Merged
NovakPAai merged 1 commit into
mainfrom
claude/novak-task-by-key-endpoint
May 20, 2026
Merged

feat(tasks): add GET /api/tasks/by-key/:key endpoint#233
NovakPAai merged 1 commit into
mainfrom
claude/novak-task-by-key-endpoint

Conversation

@NovakPAai
Copy link
Copy Markdown
Owner

Что

Прямой lookup задачи по issueKey (DEV-42, PERS-7) — вместо обходного пути через /api/search?q=KEY + client-side фильтр.

Зачем

В companion-репо flow-tasks-agent LLM-тул get_task_by_key сейчас работает через workaround: search + JS-фильтр по точному совпадению issueKey. Это:

  • неточно (search ищет ещё и в title/description/comments)
  • ограничено лимитом search (max 10 результатов)
  • медленнее (двойной round-trip)

С этим endpoint'ом будет один прямой запрос. После мерджа закрою workaround отдельным PR в flow-tasks-agent.

Изменения

  • tasks.dto.ts: новый issueKeyParamDto (Zod path-param). Regex ^[A-Z][A-Z0-9]{1,9}-\d+$ — буквоведущий alphanumeric prefix (соответствует тому как генерируются board prefixes).
  • tasks.service.ts: getTaskByIssueKey(key, userId) — резолвит issueKey → id и делегирует в существующий getTask (уже проверяет workspace access, возвращает 404 cross-workspace без раскрытия существования).
  • tasks.router.ts: GET /api/tasks/by-key/:key. Зарегистрирован до router.use('/:id', taskMfaGuard) — иначе 'by-key' попадал бы в :id matcher.
  • tests/tasks-by-key.test.ts: 5 кейсов.

Тесты

  • Happy: existing key → 200, тот же payload что /api/tasks/:id
  • Unknown key → 404
  • Malformed key → 400 (lowercase, no dash, too-short prefix)
  • Cross-workspace → 404 (а не 403 — против leak)
  • Unauthenticated → 401

npx vitest run src/__tests__/tasks-by-key.test.ts → 5/5 ✓

Verify

  • npx tsc --noEmit ✓ для модуля tasks. Pre-existing TS errors в permissions-loader.ts и admin-permissions.test.ts этим PR не затронуты.
  • npx eslint src/modules/tasks src/__tests__/tasks-by-key.test.ts

Что НЕ в скоупе

  • OpenAPI spec обновление — flow-tasks repo пока не везде применяет OpenAPI registry (см. CLAUDE.md: "новый API эндпоинт → Zod DTO → OpenAPI регистрация"). Существующие task endpoints не зарегистрированы в OpenAPI; этот PR не вводит новой практики, следует existing pattern. Если есть стандарт куда регистрировать — поправлю в follow-up.
  • Frontend — этот endpoint вызывается через flow-tasks-agent, в UI не нужен.

🤖 Generated with Claude Code

Adds a direct lookup of a Task by its human-readable issueKey (e.g.
DEV-42, PERS-7) instead of having to round-trip through /api/search
and client-side filter the results.

Why now: flow-tasks-agent (companion repo) needs by-key lookups in its
`get_task_by_key` LLM tool. Without this endpoint, it has to call
/api/search?q=KEY and filter on issueKey === KEY in JS — works but
imprecise (search matches title/description/comments too, limit caps at
10) and slower. This endpoint resolves the workaround.

Changes:
- tasks.dto.ts: new `issueKeyParamDto` (Zod, path-param). Pattern is
  `^[A-Z][A-Z0-9]{1,9}-\d+$` — letter-led alphanumeric prefix to match
  how board.prefix is generated (alphanumeric, 2-10 chars).
- tasks.service.ts: new `getTaskByIssueKey(key, userId)`. Resolves
  issueKey → id, then delegates to the existing `getTask(id, userId)`
  which already enforces workspace access (returns 404 cross-workspace
  to avoid leaking existence).
- tasks.router.ts: `GET /api/tasks/by-key/:key`. Mounted BEFORE
  `router.use('/:id', taskMfaGuard)` so 'by-key' doesn't get caught
  as id='by-key'.
- tests/tasks-by-key.test.ts: 5 cases — happy path, unknown key (404),
  malformed key (400) × 3 sub-cases, cross-workspace (404 not 403 to
  avoid information leak), unauthenticated (401).

Verify:
- npx tsc --noEmit ✓ (scoped to tasks module; pre-existing unrelated TS
  errors in permissions-loader.ts and admin-permissions.test.ts are
  not touched by this PR)
- npx eslint src/modules/tasks src/__tests__/tasks-by-key.test.ts ✓
- npx vitest run src/__tests__/tasks-by-key.test.ts ✓ — 5/5 passing

Companion follow-up (in flow-tasks-agent repo):
- Replace search-based workaround in get_task_by_key tool with this
  new endpoint, remove client-side issueKey regex filter.
@NovakPAai NovakPAai merged commit 5318948 into main May 20, 2026
7 of 8 checks passed
@NovakPAai NovakPAai deleted the claude/novak-task-by-key-endpoint branch May 20, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant