Skip to content

Add branded core and Alliance ServerConfig types#179

Merged
wpak-ai merged 5 commits into
cppalliance:mainfrom
jonathanMLDev:feat/server-config-branding
Jun 25, 2026
Merged

Add branded core and Alliance ServerConfig types#179
wpak-ai merged 5 commits into
cppalliance:mainfrom
jonathanMLDev:feat/server-config-branding

Conversation

@jonathanMLDev

@jonathanMLDev jonathanMLDev commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Split the single ServerConfig type into ServerConfigBase plus branded CoreServerConfig and AllianceServerConfig using unique symbol brands
  • Narrow resolveConfig() / setupCoreServer() to core config and resolveAllianceConfig() / setupAllianceServer() to Alliance config so passing Alliance config into core setup is a compile-time error
  • Refactor setupAllianceServer to hand config to core setup via context only (setConfig / createServer), avoiding branded-type conflicts at the delegation boundary
  • Add src/__tests__/config-branding.compile-test.ts with @ts-expect-error guards; exclude dist/__tests__/ from npm via .npmignore
  • Update alliance examples to use resolveAllianceConfig

Motivation

resolveConfig() and resolveAllianceConfig() returned structurally identical configs with different defaults (suggest-flow gate, index, rerank). Passing an Alliance config to setupCoreServer() compiled cleanly but changed runtime behavior silently.

Test plan

  • npm run typecheck (includes compile-time branding misuse test)
  • npm run test (294 tests)
  • npm run ci

Related issue

Summary by CodeRabbit

  • New Features
    • Added branded configuration and context types to clearly separate core vs Alliance setup paths.
    • Improved server setup ergonomics with core tool registration on an existing context, plus clearer Alliance configuration typing.
  • Bug Fixes
    • Fixed package publishing to exclude bundled test directories.
    • Updated Alliance demos to use the Alliance configuration resolver.
  • Tests
    • Added compile-time checks to prevent mixing core/Alliance configs and contexts.
  • Documentation
    • Updated the unreleased migration guide with branded-type usage and examples.

@jonathanMLDev jonathanMLDev self-assigned this Jun 24, 2026
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds branded core and Alliance config types, threads them through server context and setup APIs, updates tests for type misuse, and switches Alliance examples and docs to the Alliance resolver entrypoint.

Changes

Config Type Branding and Enforcement

Layer / File(s) Summary
Branded config types
src/core/config.ts, src/core/index.ts, src/alliance/config.ts, src/alliance/index.ts
ServerConfigBase, branded core and Alliance config types, AnyServerConfig, and branding helpers are added; resolveConfig() and resolveAllianceConfig() now return branded config types.
Server context typing
src/core/server/server-context.ts, src/core/server/config-context.ts, src/core/server/tools/test-helpers.ts, src/core/server/server-context.legacy-facade.test.ts, src/core/setup-multi-instance.test.ts
ServerContext becomes generic over the shared base config, isolated context creation is added, config facade signatures use ServerConfigBase, and tests switch to isolated context setup where needed.
Setup API enforcement
src/core/setup.ts, src/alliance/setup.ts, src/index.ts
Core and Alliance setup signatures are narrowed to their branded config types, Alliance setup now routes through createServer and setupCoreServerOnContext, and the main entrypoint’s config return type changes to AllianceServerConfig.
Compile-time and runtime validation
src/__tests__/config-branding.compile-test.ts, src/core/setup-guards.test.ts
A new compile-time test asserts cross-config and cross-context misuse fails type checking, and runtime guard tests now match the branded error messages.
Examples and docs
examples/alliance/*, CHANGELOG.md, docs/MIGRATION.md, src/types.ts, .npmignore
Alliance examples now import and call resolveAllianceConfig(), the changelog and migration docs describe branded config behavior, the Pinecone client docs reference the shared base type, and dist/__tests__/ is added to .npmignore.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • AuraMindNest
  • wpak-ai
  • leostar0412

Poem

🐇 I hopped through types with a brand-new gleam,
Core and Alliance now stay in their stream.
No mix-up hops where the old configs went,
The compiler nods with a happy consent.
Tip-tap, type-skip, the bunny runs free —
safer configs for you and me.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The .npmignore update to exclude dist/__tests__/ is unrelated to the branding scope and appears to be a separate packaging tweak. Move the packaging ignore update to a separate PR unless it is required for this branding change.
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: branded ServerConfig types for core and Alliance.
Linked Issues check ✅ Passed The changes implement branded core/Alliance configs, narrow resolve/setup types, preserve a shared base type, and add cross-config compile-time tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.22222% with 7 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@7b8df0d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/alliance/setup.ts 85.18% 4 Missing ⚠️
src/core/setup.ts 92.85% 2 Missing ⚠️
src/core/server/config-context.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #179   +/-   ##
=======================================
  Coverage        ?   87.88%           
=======================================
  Files           ?       41           
  Lines           ?     1758           
  Branches        ?      559           
=======================================
  Hits            ?     1545           
  Misses          ?      213           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/alliance/setup.ts`:
- Around line 74-84: The setupAllianceServer path currently lets an incoming
context with no Alliance config fall back to core defaults when getConfig() is
later called. Update the setup logic in setupAllianceServer and its
ServerContext usage so it can distinguish “config already set” from “unset”
using a non-initializing check like hasConfig/getConfigIfSet, or reject
unconfigured contexts outright, and ensure Alliance always installs
resolveAllianceConfig({}) instead of materializing resolveConfig({}) from core
defaults.
- Around line 76-79: The context mutation in setupAllianceServer is bypassing
the injected-client validation in setupCoreServer, so restore the guard before
calling ServerContext.setConfig() and delegation. In setupAllianceServer, check
the combination of opts.config, resolvedCtx, and any injected client on the
context before mutating it, and throw the same conflict path that
setupCoreServer uses if both config and an injected client are present. Keep the
existing setupCoreServer call unchanged after the validation so
ServerContext.setConfig() does not silently clear the client.

In `@src/core/server/server-context.ts`:
- Around line 74-79: `setupCoreServer` is still accepting an unparameterized
`ServerContext`, which lets Alliance-specific config flow into the core path
through `createServer` and `ServerContext.setConfig`. Make
`SetupCoreServerOptions.context` use the core-specific generic/context type in
`server-context.ts`, or move the Alliance-to-core conversion behind an internal
helper so `setupCoreServer` stays core-only. Use the existing `setupCoreServer`,
`ServerContext`, and `setConfig` symbols to update the type boundary without
exposing `AnyServerConfig` to the core API.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6ec97d17-bec5-49e2-9cd3-1e56259c6a5d

📥 Commits

Reviewing files that changed from the base of the PR and between 7b8df0d and f1a4325.

📒 Files selected for processing (17)
  • .npmignore
  • examples/alliance/custom-url-generator.ts
  • examples/alliance/guided-query-demo.ts
  • examples/alliance/suggest-flow-demo.ts
  • src/__tests__/config-branding.compile-test.ts
  • src/alliance/config.ts
  • src/alliance/index.ts
  • src/alliance/setup.ts
  • src/core/config.ts
  • src/core/index.ts
  • src/core/server/config-context.ts
  • src/core/server/server-context.ts
  • src/core/server/tools/test-helpers.ts
  • src/core/setup-guards.test.ts
  • src/core/setup.ts
  • src/index.ts
  • src/types.ts

Comment thread src/alliance/setup.ts
Comment thread src/alliance/setup.ts Outdated
Comment thread src/core/server/server-context.ts Outdated
zho added 2 commits June 25, 2026 02:44
- In the context branch, when no opts.config and !ctx.hasConfig(), call resolveAllianceConfig({}) before tool registration
- Added test: unconfigured context + PINECONE_API_KEY env → Alliance gate defaults applied
- ServerContext<T> generic + CoreServerContext = ServerContext<CoreServerConfig>
- SetupCoreServerOptions.context is now CoreServerContext only
- createServer / createIsolatedContext overloaded by config brand
- Alliance uses internal setupCoreServerOnContext(ctx) (not exported from the public barrel) instead of setupCoreServer({ context })
…nd exported it from core/alliance barrels

- Narrowed SetupAllianceServerOptions.context to AllianceServerContext
- Extended config-branding.compile-test.ts with context-path @ts-expect-error cases (both directions)
@jonathanMLDev

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/server/server-context.ts`:
- Around line 145-150: The fallback in ServerContext.getConfig() is using
resolveConfig({}) for a lazily constructed Alliance context, which returns core
defaults instead of Alliance defaults. Update getConfig() so it does not
silently resolve the core config when the context is unconfigured: either make
the lazy fallback Alliance-aware by using the Alliance config path/type, or
explicitly reject direct ServerContext<AllianceServerConfig> construction
without prior seeding. Use the existing ServerContext and setupAllianceServer
flow as the reference points when adjusting the fallback behavior.

In `@src/core/setup.ts`:
- Around line 167-174: `setupCoreServer` still lets branded config objects slip
through the `SetupCoreServerOptions` branch because the options type is
structurally compatible with `AllianceServerConfig`, and
`normalizeSetupCoreServerArgs`/`isServerConfig` only key off `apiKey` and
`indexName`. Make the options path incompatible with config-shaped objects (for
example by adding a discriminant or required non-config field) or split
`setupCoreServer` into separate entry points so branded configs cannot be
accepted through the legacy/options overload.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bb050aba-629c-40b6-adca-8f4d053dbe4f

📥 Commits

Reviewing files that changed from the base of the PR and between 7b8df0d and 5bcfd09.

📒 Files selected for processing (21)
  • .npmignore
  • CHANGELOG.md
  • docs/MIGRATION.md
  • examples/alliance/custom-url-generator.ts
  • examples/alliance/guided-query-demo.ts
  • examples/alliance/suggest-flow-demo.ts
  • src/__tests__/config-branding.compile-test.ts
  • src/alliance/config.ts
  • src/alliance/index.ts
  • src/alliance/setup.ts
  • src/core/config.ts
  • src/core/index.ts
  • src/core/server/config-context.ts
  • src/core/server/server-context.legacy-facade.test.ts
  • src/core/server/server-context.ts
  • src/core/server/tools/test-helpers.ts
  • src/core/setup-guards.test.ts
  • src/core/setup-multi-instance.test.ts
  • src/core/setup.ts
  • src/index.ts
  • src/types.ts

Comment thread src/core/server/server-context.ts
Comment thread src/core/setup.ts
@AuraMindNest

Copy link
Copy Markdown
Collaborator

Please check the PR title again.
"Add branded CoreServerConfig / AllianceServerConfig to prevent cross-…"

@jonathanMLDev jonathanMLDev changed the title Add branded CoreServerConfig / AllianceServerConfig to prevent cross-… Add branded core and Alliance ServerConfig types Jun 24, 2026
Comment thread CHANGELOG.md Outdated
Comment thread src/core/setup.ts
Updated to #unreleased-branded-serverconfig-types (matches GitHub’s anchor for that heading, same pattern as other unreleased sections).

setup.ts — when opts.context is passed without opts.config, validate getConfigIfSet() via assertCoreServerConfig.
alliance/setup.ts — symmetric check with assertAllianceServerConfig when the context already has config.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/core/config.ts (1)

88-97: 🩺 Stability & Availability | 🔵 Trivial

Define the lineage marker as a non-enumerable property to avoid leaking through spreads.

brandCoreConfig and brandAllianceConfig attach SERVER_CONFIG_LINEAGE via direct assignment, creating an enumerable own symbol property. The JavaScript spread operator ({...obj}) and Object.assign copy enumerable symbol-keyed properties. Downstream code that clones a resolved config before passing it to setup guards could inadvertently retain the lineage marker, potentially skipping resolution logic or bypassing type distinctions at runtime. Defining the property as non-enumerable prevents propagation while maintaining runtime access.

♻️ Proposed change
 /** Attach the core brand after {`@link` resolveConfig} resolution. */
 export function brandCoreConfig(config: ServerConfigBase): CoreServerConfig {
-  (config as ServerConfigLineageHost)[SERVER_CONFIG_LINEAGE] = 'core';
+  Object.defineProperty(config, SERVER_CONFIG_LINEAGE, {
+    value: 'core',
+    enumerable: false,
+    configurable: true,
+    writable: true,
+  });
   return config as CoreServerConfig;
 }

 /** Attach the Alliance brand after {`@link` resolveAllianceConfig} resolution. */
 export function brandAllianceConfig(config: ServerConfigBase): AllianceServerConfig {
-  (config as ServerConfigLineageHost)[SERVER_CONFIG_LINEAGE] = 'alliance';
+  Object.defineProperty(config, SERVER_CONFIG_LINEAGE, {
+    value: 'alliance',
+    enumerable: false,
+    configurable: true,
+    writable: true,
+  });
   return config as AllianceServerConfig;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/config.ts` around lines 88 - 97, The lineage marker on the config
branding helpers is currently added as an enumerable symbol property, which can
leak through object spreads and Object.assign. Update brandCoreConfig and
brandAllianceConfig in config.ts to attach SERVER_CONFIG_LINEAGE via a
non-enumerable property definition while preserving the existing returned
CoreServerConfig and AllianceServerConfig types. Keep the change localized to
these branding helpers so downstream clones do not retain the marker
unexpectedly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/core/config.ts`:
- Around line 88-97: The lineage marker on the config branding helpers is
currently added as an enumerable symbol property, which can leak through object
spreads and Object.assign. Update brandCoreConfig and brandAllianceConfig in
config.ts to attach SERVER_CONFIG_LINEAGE via a non-enumerable property
definition while preserving the existing returned CoreServerConfig and
AllianceServerConfig types. Keep the change localized to these branding helpers
so downstream clones do not retain the marker unexpectedly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eecbb98e-0f98-49ec-8cb0-556dddb55052

📥 Commits

Reviewing files that changed from the base of the PR and between 5bcfd09 and 2a307c1.

📒 Files selected for processing (7)
  • CHANGELOG.md
  • src/alliance/setup.ts
  • src/core/config.ts
  • src/core/index.ts
  • src/core/server/server-context.ts
  • src/core/setup-guards.test.ts
  • src/core/setup.ts
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/alliance/setup.ts
  • src/core/setup.ts

@AuraMindNest AuraMindNest requested a review from wpak-ai June 25, 2026 03:24
@wpak-ai wpak-ai merged commit 35d0441 into cppalliance:main Jun 25, 2026
12 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.

ServerConfig type branding: distinguish core vs Alliance configs (3pt)

3 participants