feat(usecase): add analyze adapter for pkg/prism#13
Merged
Conversation
First piece of the /v1/analyze endpoint. Thin adapter between HTTP
handlers and pkg/prism.Analyze, shaped so that handlers will depend
on a small interface defined in the handler package (accept
interfaces, return structs, per docs/development_rules.md §10); the
concrete implementation lives here in internal/usecase.
- AnalyzeInput carries the HTTP-layer-agnostic inputs that a handler
extracts from its validated AnalyzeRequest.
- Analyzer stores pkg/prism.Analyze in a function field rather than
wrapping it in an interface. That keeps the indirection minimal
and still lets tests inject a fake via field assignment without
maintaining an extra wrapper type.
- NewAnalyzer wires the real pkg/prism.Analyze as the function field.
- Analyze always sets Provider: "github" (Phase 2 is GitHub only per
the Phase 2 instruction §5) and keeps IncludePatches at the
pkg/prism default of false. Provider auto-detection is deliberately
bypassed so the provider is explicit in logs and debug traces.
- pkg/prism's sentinel errors flow through unchanged so the handler
layer can map them to response.Code via errors.Is.
Tests cover:
- Happy path with full AnalyzeOptions field inspection (Provider,
PRURL, GitHubToken, IncludePatches false, Mode/Language empty)
- Empty GitHubToken passthrough (Phase 2 supports public repos
without authentication)
- Error passthrough for all four pkg/prism sentinels (ErrInvalidInput,
ErrUnsupportedProvider, ErrAuthRequired, ErrUpstreamFailure)
- Context propagation to the underlying call
- NewAnalyzer constructor smoke check (non-nil Analyzer with
non-nil function field)
Adds github.com/hidetzu/prism v0.3.0 as the first direct pkg/prism
dependency. The adapter is not yet wired to an HTTP handler; PR 8
will add /v1/analyze and pull it in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR 7/9 of the Phase 2 series. First of the two PRs that together land `/v1/analyze`. This PR introduces the `internal/usecase` package with a thin adapter over `pkg/prism.Analyze` and adds `github.com/hidetzu/prism v0.3.0` as the first direct dependency. The handler and HTTP routing land in PR 8.
This code is not yet reachable from any HTTP route. It is intentionally dead until PR 8 lands — reviewability was preferred over temporary unused code. Dead-code cleanup is scheduled for v0.2.0 release time.
Design
Why a function field, not an interface
`pkg/prism.Analyze` is a package-level function, not a method on a struct. The conventional approach would be to wrap it in a `Prism` interface and inject that interface, but that adds a wrapper type plus an implementation that just forwards the call — indirection with no benefit. Instead:
Tests inject a fake by writing to the field directly. Production always uses `NewAnalyzer()`. This is an idiomatic Go pattern for adapting package-level functions.
Why `Provider: "github"` is hard-coded
`pkg/prism.AnalyzeOptions.Provider` supports auto-detection when empty, but the Phase 2 instruction §5 states Phase 2 is GitHub-only, and making the provider explicit improves log/debug clarity. If a future phase adds CodeCommit or similar, the adapter fans out per provider (or we flip to auto-detection) at that point.
Why `IncludePatches: false`
This is the `pkg/prism` default and keeps response payloads lightweight. A future API flag can opt in per request if users want diff patches in the response. Phase 2 ships without patches.
Error passthrough
`pkg/prism` exposes four sentinel errors (`ErrInvalidInput`, `ErrUnsupportedProvider`, `ErrAuthRequired`, `ErrUpstreamFailure`) that the HTTP handler in PR 8 will map to `response.Code` via `errors.Is`. The adapter does not rewrap or translate them — they flow through unchanged.
Test plan
7 test cases in `analyze_test.go`:
Local checks
Dependencies added
```
github.com/hidetzu/prism v0.3.0
```
Per `docs/development_rules.md` §3, this is the first pinned import of the `pkg/prism` library. The version matches the rules doc.
Phase 2 context
Intended to be squash-merged.