Skip to content

pkg restructure: pkg/charon, internal/server, cmd/proxy#71

Merged
elevran merged 4 commits into
mainfrom
pkg-restructure
Jul 8, 2026
Merged

pkg restructure: pkg/charon, internal/server, cmd/proxy#71
elevran merged 4 commits into
mainfrom
pkg-restructure

Conversation

@elevran

@elevran elevran commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • internal/charonpkg/charon: public client package (importable outside repo)
  • internal/apiinternal/server: Charon HTTP server, renamed package from api to server
  • internal/proxy + test/compliance + test/disruptivecmd/proxy: proxy binary as package main; all test files co-located with the code they test
  • cmd/charon/main.go: stripped proxy startup — now starts only the Charon server
  • cmd/proxy/main.go (new): starts the demo proxy server
  • cmd/proxy/testhelpers_test.go (new): unified test helpers with newTestStack + stackOption pattern, replacing five duplicate setup functions

Notes

  • All renames done with git mv to preserve history
  • Compliance and disruptive tests now live in cmd/proxy/ as package main (no import needed for types)
  • withCharonMiddleware, withInferenceURL, withRealListeners, withTimeout options cover all test stack variants

Test plan

  • make presubmit passes (all packages, vet, fmt)
  • go test ./cmd/proxy/ -v shows all compliance, disruptive, handler, SSE, WS, parity tests passing
  • go test ./internal/server/ passes (e2e proxy test)
  • go test ./test/integration/ passes

elevran added 2 commits July 8, 2026 11:00
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>
Comment thread cmd/proxy/disruptive_test.go Outdated
Comment thread cmd/proxy/testhelpers_test.go Outdated
Comment thread cmd/proxy/testhelpers_test.go Outdated
Comment thread cmd/proxy/main.go
elevran added 2 commits July 8, 2026 14:05
- 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>
@elevran elevran merged commit 08dc6df into main Jul 8, 2026
6 checks passed
@elevran elevran deleted the pkg-restructure branch July 8, 2026 11:21
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>
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