pkg restructure: pkg/charon, internal/server, cmd/proxy#71
Merged
Conversation
Move internal/charon → pkg/charon Client and Backend interface are the public API consumed by any proxy implementation; pkg/ signals they are importable outside this repo. Rename internal/api → internal/server The package name 'api' was ambiguous alongside the OpenAI Responses API. 'server' better describes what it provides: HTTP server setup, middleware, and the Charon API handlers. Move internal/proxy → cmd/proxy (package main) The demo proxy is not a library — it is a standalone binary for testing and demonstrating Charon integration. Moving it to cmd/proxy makes its demo-only nature explicit and prevents accidental import from other code. All proxy source files become package main. Tests that previously imported internal/proxy (test/compliance, test/disruptive, proxy unit tests) move into cmd/proxy alongside the source, eliminating the need for an importable proxy package. Duplicate test helpers (startStack, dialWS) arising from merging three test packages into one are resolved: handler_test uses startHandlerStack, ws_test uses dialWSConn; compliance_test owns the primary WS test suite and duplicate ws_test cases are removed. cmd/charon/main.go stripped of proxy startup; proxy runs as its own binary (cmd/proxy/main.go) with its own telemetry initialisation. Signed-off-by: Etai Lev Ran <elevran@gmail.com>
Replace five separate stack-setup functions (startStack, startHandlerStack, startNormalStack, startFailingStoreStack, startRealStack, startParityStack) with a single newTestStack(t, ...stackOption) backed by testhelpers_test.go. Options: withCharonMiddleware(mw) — inject middleware (e.g. failing store) withInferenceURL(u) — use a pre-started inference server withRealListeners() — bind to OS-assigned TCP ports (bun runner) withTimeout(d) — set client timeout (default 5s) Also consolidates all SSE, WebSocket, and HTTP helpers into testhelpers_test.go, removing ~250 lines of duplicated setup code across 6 test files. Signed-off-by: Etai Lev Ran <elevran@gmail.com>
elevran
commented
Jul 8, 2026
- disruptive_test.go: use partialSrv.URL directly (embedded field selector) - testhelpers_test.go: drop mustMarshal helper, inline json.Marshal at call site; restructure newTestStack to build proxy handler once (via buildProxy closure) after Charon URL is known, removing the throw-away placeholder build - main.go: add TODO to split config.ServerOptions into Charon + Proxy parts Signed-off-by: Etai Lev Ran <elevran@gmail.com>
test/compliance/ and test/disruptive/ moved into cmd/proxy/ as package main. Update test-compliance, test-disruptive, and test-compliance-bun targets to point at ./cmd/proxy/... instead of the now-deleted test/ subdirectories. Signed-off-by: Etai Lev Ran <elevran@gmail.com>
2 tasks
elevran
added a commit
that referenced
this pull request
Jul 8, 2026
* refactor: restructure packages — pkg/charon, internal/server, cmd/proxy Move internal/charon → pkg/charon Client and Backend interface are the public API consumed by any proxy implementation; pkg/ signals they are importable outside this repo. Rename internal/api → internal/server The package name 'api' was ambiguous alongside the OpenAI Responses API. 'server' better describes what it provides: HTTP server setup, middleware, and the Charon API handlers. Move internal/proxy → cmd/proxy (package main) The demo proxy is not a library — it is a standalone binary for testing and demonstrating Charon integration. Moving it to cmd/proxy makes its demo-only nature explicit and prevents accidental import from other code. All proxy source files become package main. Tests that previously imported internal/proxy (test/compliance, test/disruptive, proxy unit tests) move into cmd/proxy alongside the source, eliminating the need for an importable proxy package. Duplicate test helpers (startStack, dialWS) arising from merging three test packages into one are resolved: handler_test uses startHandlerStack, ws_test uses dialWSConn; compliance_test owns the primary WS test suite and duplicate ws_test cases are removed. cmd/charon/main.go stripped of proxy startup; proxy runs as its own binary (cmd/proxy/main.go) with its own telemetry initialisation. Signed-off-by: Etai Lev Ran <elevran@gmail.com> * cmd/proxy: unify test helpers with stackOption pattern Replace five separate stack-setup functions (startStack, startHandlerStack, startNormalStack, startFailingStoreStack, startRealStack, startParityStack) with a single newTestStack(t, ...stackOption) backed by testhelpers_test.go. Options: withCharonMiddleware(mw) — inject middleware (e.g. failing store) withInferenceURL(u) — use a pre-started inference server withRealListeners() — bind to OS-assigned TCP ports (bun runner) withTimeout(d) — set client timeout (default 5s) Also consolidates all SSE, WebSocket, and HTTP helpers into testhelpers_test.go, removing ~250 lines of duplicated setup code across 6 test files. Signed-off-by: Etai Lev Ran <elevran@gmail.com> * cmd/proxy: address review comments - disruptive_test.go: use partialSrv.URL directly (embedded field selector) - testhelpers_test.go: drop mustMarshal helper, inline json.Marshal at call site; restructure newTestStack to build proxy handler once (via buildProxy closure) after Charon URL is known, removing the throw-away placeholder build - main.go: add TODO to split config.ServerOptions into Charon + Proxy parts Signed-off-by: Etai Lev Ran <elevran@gmail.com> * Makefile: update compliance/disruptive targets after test migration test/compliance/ and test/disruptive/ moved into cmd/proxy/ as package main. Update test-compliance, test-disruptive, and test-compliance-bun targets to point at ./cmd/proxy/... instead of the now-deleted test/ subdirectories. Signed-off-by: Etai Lev Ran <elevran@gmail.com> --------- Signed-off-by: Etai Lev Ran <elevran@gmail.com>
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
internal/charon→pkg/charon: public client package (importable outside repo)internal/api→internal/server: Charon HTTP server, renamed package fromapitoserverinternal/proxy+test/compliance+test/disruptive→cmd/proxy: proxy binary aspackage main; all test files co-located with the code they testcmd/charon/main.go: stripped proxy startup — now starts only the Charon servercmd/proxy/main.go(new): starts the demo proxy servercmd/proxy/testhelpers_test.go(new): unified test helpers withnewTestStack+stackOptionpattern, replacing five duplicate setup functionsNotes
git mvto preserve historycmd/proxy/aspackage main(no import needed for types)withCharonMiddleware,withInferenceURL,withRealListeners,withTimeoutoptions cover all test stack variantsTest plan
make presubmitpasses (all packages, vet, fmt)go test ./cmd/proxy/ -vshows all compliance, disruptive, handler, SSE, WS, parity tests passinggo test ./internal/server/passes (e2e proxy test)go test ./test/integration/passes