-
Notifications
You must be signed in to change notification settings - Fork 3k
feat(serve): advertise typed_event_schema + pin SDK public surface (#4175 PR 4 follow-up) #4226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
103 changes: 103 additions & 0 deletions
103
packages/sdk-typescript/test/unit/daemon-public-surface.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Qwen Team | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, it, expect, expectTypeOf } from 'vitest'; | ||
| import * as Public from '../../src/index.js'; | ||
| // Type-only imports also exercise the public entry: any name missing | ||
| // from `src/index.ts` is a tsc compile error and the suite refuses to | ||
| // build, which is the regression fence for the kind of "exists in | ||
| // `src/daemon/index.ts` but not re-exported by the published entry" | ||
| // gap that two-layer SDK re-exports are easy to drift on. | ||
| import type { | ||
| DaemonClientEvictedData, | ||
| DaemonClientEvictedEvent, | ||
| DaemonControlEvent, | ||
| DaemonEvent, | ||
| DaemonEventEnvelope, | ||
| DaemonKnownEventType, | ||
| DaemonModelSwitchedData, | ||
| DaemonModelSwitchedEvent, | ||
| DaemonModelSwitchFailedData, | ||
| DaemonModelSwitchFailedEvent, | ||
| DaemonPermissionOption, | ||
| DaemonPermissionRequestData, | ||
| DaemonPermissionRequestEvent, | ||
| DaemonPermissionResolvedData, | ||
| DaemonPermissionResolvedEvent, | ||
| DaemonSessionDiedData, | ||
| DaemonSessionDiedEvent, | ||
| DaemonSessionEvent, | ||
| DaemonSessionUpdateData, | ||
| DaemonSessionUpdateEvent, | ||
| DaemonSessionViewState, | ||
| DaemonStreamErrorData, | ||
| DaemonStreamErrorEvent, | ||
| DaemonStreamLifecycleEvent, | ||
| KnownDaemonEvent, | ||
| } from '../../src/index.js'; | ||
|
|
||
| describe('public SDK entry — typed daemon event surface (#4217)', () => { | ||
| it('exports the runtime narrow + reducer surface', () => { | ||
| expect(typeof Public.asKnownDaemonEvent).toBe('function'); | ||
| expect(typeof Public.isKnownDaemonEvent).toBe('function'); | ||
| expect(typeof Public.isDaemonEventType).toBe('function'); | ||
| expect(typeof Public.reduceDaemonSessionEvent).toBe('function'); | ||
| expect(typeof Public.reduceDaemonSessionEvents).toBe('function'); | ||
| expect(typeof Public.createDaemonSessionViewState).toBe('function'); | ||
| }); | ||
|
|
||
| it('round-trips a raw DaemonEvent through the public narrow helper', () => { | ||
| // Pin the user-facing contract: `import { asKnownDaemonEvent } | ||
| // from '@qwen-code/sdk'` must work end-to-end via the published | ||
| // entry, not just exist as a re-export inside src/daemon/index.ts. | ||
| const evt: DaemonEvent = { | ||
| id: 1, | ||
| v: 1, | ||
| type: 'model_switched', | ||
| data: { sessionId: 'sess-1', modelId: 'qwen-plus' }, | ||
| }; | ||
| const narrowed = Public.asKnownDaemonEvent(evt); | ||
| if (narrowed?.type === 'model_switched') { | ||
| expect(narrowed.data.modelId).toBe('qwen-plus'); | ||
| } else { | ||
| expect.fail('expected typed model_switched'); | ||
| } | ||
| }); | ||
|
|
||
| it('exposes the typed event schema types at the public entry (compile-time)', () => { | ||
| // The type-only imports at the top of this file would fail to | ||
| // compile if any of these names were absent from src/index.ts. | ||
| // The runtime expectations below document the surface set the | ||
| // SDK promises to ship and give tooling that ignores type-only | ||
| // imports a runtime assertion trail. | ||
| expectTypeOf<KnownDaemonEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonSessionEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonControlEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonStreamLifecycleEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonSessionViewState>().not.toBeNever(); | ||
| expectTypeOf<DaemonKnownEventType>().not.toBeNever(); | ||
| expectTypeOf<DaemonEventEnvelope<'foo', { x: 1 }>>().not.toBeNever(); | ||
|
|
||
| expectTypeOf<DaemonSessionUpdateEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonPermissionRequestEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonPermissionResolvedEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonModelSwitchedEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonModelSwitchFailedEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonSessionDiedEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonClientEvictedEvent>().not.toBeNever(); | ||
| expectTypeOf<DaemonStreamErrorEvent>().not.toBeNever(); | ||
|
|
||
| expectTypeOf<DaemonSessionUpdateData>().not.toBeNever(); | ||
| expectTypeOf<DaemonPermissionRequestData>().not.toBeNever(); | ||
| expectTypeOf<DaemonPermissionResolvedData>().not.toBeNever(); | ||
| expectTypeOf<DaemonModelSwitchedData>().not.toBeNever(); | ||
| expectTypeOf<DaemonModelSwitchFailedData>().not.toBeNever(); | ||
| expectTypeOf<DaemonSessionDiedData>().not.toBeNever(); | ||
| expectTypeOf<DaemonClientEvictedData>().not.toBeNever(); | ||
| expectTypeOf<DaemonStreamErrorData>().not.toBeNever(); | ||
| expectTypeOf<DaemonPermissionOption>().not.toBeNever(); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] Comment references
narrowDaemonEventfalling back tokind: 'unknown', but the actual API isasKnownDaemonEventwhich returnsundefinedfor unknown/unrecognized events.— DeepSeek/deepseek-v4-pro via Qwen Code /review