Skip to content

feat: support short task links like /PRJ-1 - #778

Merged
pikann merged 2 commits into
Paca-AI:masterfrom
megazoll:short-links
Nov 17, 2026
Merged

pikann merged 2 commits into
Paca-AI:masterfrom
megazoll:short-links

Conversation

@megazoll

@megazoll megazoll commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds support for short task links such as paca.example.com/PRJ-1.

  • The API gains GET /api/v1/tasks/by-key/{taskKey}. It looks a task up by project prefix and number, case-insensitively, and checks tasks:read on the task it resolves to.
  • The web app gains a /$taskKey route that resolves the key and redirects to /projects/:projectId/tasks/:taskId. Anything that isn't shaped like a key shows a 404.
  • The task header's share button and the context menu's "Copy link" now copy the short link. A project with no prefix still gets the long URL.
  • I added tests for the key parser, the handler, the permission resolver and the route-coverage check.
  • Project prefixes aren't unique. If two projects share a prefix, a key resolves to the older project.

Type of Change

  • Documentation
  • Repository structure
  • Architecture clarification
  • Scaffolding
  • Other (feature: short task links)

Checklist

  • The change is focused and scoped.
  • Related documentation is updated.
  • New structure or direction is explained clearly.
  • I avoided unnecessary detail or premature abstraction.

Add GET /tasks/by-key/{taskKey} (authorized on the resolved task), a
/$taskKey web route that redirects to the task page, and use the short
link for the share/copy-link actions.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

The API's integration-test package no longer compiles, and the tracked TanStack route tree was not regenerated, so the web app fails tsc -b on a clean checkout. One design gap also needs a decision: a short link can open a different project's task.

Reviewed changes

  • Short-link API — GET /api/v1/tasks/by-key/{taskKey} parses PREFIX-N, resolves it with a new FindTaskByKey query (oldest project wins on a shared prefix), and gates on tasks:read against the resolved task.
  • Short-link route — /$taskKey rejects paths that aren't key-shaped, resolves the key, and replaces the URL with the canonical task page.
  • Share links — the task header and context menu now copy /PREFIX-N via taskShareUrl, falling back to the canonical URL when the project has no prefix.
  • Tests — key parser, handler, gate resolver, and route-coverage additions.

🚨 services/api/test/integration no longer compiles

TaskRepository gained FindTaskByKey, but the package's fakeTaskRepo was not updated, so every tasksvc.New / sprintsvc.New / NewViewService / NewTaskOwnerChecker call in the package fails to typecheck. The API PR workflow runs this package, so the suite is red before any test executes.

Technical details
# Integration test fake is missing `FindTaskByKey`

## Affected sites
- `services/api/test/integration/task_test.go:418` — `fakeTaskRepo` implements `FindTaskByID`/`FindTaskByNumber` but not `FindTaskByKey`, so it no longer satisfies `taskdom.Repository` and `taskdom.TaskRepository`.
- `services/api/test/integration/agent_apikey_test.go:65-67`, `attachment_test.go:281-285` (and `313`, `340`), plus the other `tasksvc.New` / `sprintsvc.New` / `NewViewService` / `NewTaskOwnerChecker` call sites in the package.

## Required outcome
- `go test ./test/integration/` compiles again; the fake answers `FindTaskByKey` consistently with its `FindTaskByNumber` (returning `taskdom.ErrTaskNotFound` is fine).

## Evidence
- `cd services/api && go test -run TestNothingMatches ./test/integration/` → `cannot use taskRepo (variable of type *fakeTaskRepo) as taskdom.Repository value ... (missing method FindTaskByKey)`.
- `.github/workflows/api-pr-ci.yml:110` runs `go test ... $(go list ./... | grep -v '/test/e2e')`, which includes this package.

⚠️ A shared link can open a different project's task

task_id_prefix has no uniqueness constraint and suggestPrefix derives it from the project name, so two projects routinely end up with the same prefix. The new query then picks the oldest project, which means Share/Copy link on the newer project's task #N emits a URL that opens the older project's task #N — silently, for anyone with access to both. The PR body notes the ambiguity, but the consequence for the feature being added (and for anyone who receives the link) is worth an explicit decision rather than a caveat.

Technical details
# Short URLs are not unique across projects

## Affected sites
- `services/api/migrations/000001_init.sql:57` — `task_id_prefix TEXT NOT NULL DEFAULT ''`, no unique index.
- `services/api/internal/service/project/project_service.go:44` (`suggestPrefix`) and `:298` (`validatePrefix`) — the prefix is derived from the name and validated only for shape.
- `services/api/internal/repository/postgres/task_repository.go:1602-1612` — `ORDER BY p.created_at ASC LIMIT 1` decides the collision.
- `apps/web/src/lib/interaction-api.ts:865-867` — `taskShareUrl` emits the short form unconditionally when a prefix exists.

## Required outcome
- Choose one: enforce a case-insensitive unique prefix on project create/update (with a migration or suffixing for existing duplicates), or fall back to the canonical `/projects/.../tasks/...` URL whenever a prefix is shared.
- Whichever way it goes, pin the tie-break with a repository test; the PG tests are `PACA_TEST_PG_DSN`-gated and nothing currently covers `FindTaskByKey` itself.

## Open questions for the human
- Is the short link intended to be the primary share link, or a convenience that may fall back to the canonical URL when ambiguous?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

}
t, err := lookup.FindTaskByKey(r.Context(), prefix, number)
if errors.Is(err, taskdom.ErrTaskNotFound) {
return "task-key/" + raw, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A not-found (and a malformed) key resolves to task-key/<raw>, which no policy names, so ordinary callers get 403 before the handler runs — GetTaskByKey's 400/404 branches and the new NotFoundReturns404 / InvalidKeyReturns400 handler tests never exercise the production path. Avoiding an existence oracle is a good reason to keep it, but the endpoint's real contract is then "403 for anything you cannot resolve", so say that here explicitly.

Technical details
# Unknown keys are denied at the gate, not answered by the handler

## Affected sites
- `services/api/internal/transport/http/middleware/resource_lookup.go:187,194` — malformed and not-found keys both return `task-key/<raw>`.
- `services/api/internal/transport/http/handler/task_handler.go:1122` — the 400/404 branches are only reachable for a wildcard-grant holder, or in a router built without the gate (as in `task_handler_test.go:536`).

## Required outcome
- Document the 403 contract on the resolver (or handler), and add a router-level test with a real authorizer asserting a project member gets 403 for a mistyped key, so the intended behaviour is pinned.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found in the new commits.

Reviewed changes

The two commits since the prior review fix the integration-test compile failure, regenerate the tracked route tree, and document the short-link endpoint's authorization contract.

  • Route tree regenerated — apps/web/src/routeTree.gen.ts now registers /$taskKey in every generated section; bun run build (tsc + vite) passes and the generator leaves the committed file unchanged.
  • Integration fake completed — fakeTaskRepo.FindTaskByKey returns taskdom.ErrTaskNotFound, matching its FindTaskByNumber; services/api/test/integration compiles again and go vet is clean across the API packages.
  • 403 contract documented — TaskByKeyResource now explains that unresolvable keys are refused at the gate and why the handler's 400/404 answers are wildcard-only.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit 4a5e5da into Paca-AI:master Nov 17, 2026
7 checks passed
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.

2 participants