-
Notifications
You must be signed in to change notification settings - Fork 0
Phase 1: Testing foundation (schemas, utils, turbo test:unit) #35
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 1 commit
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import type { ServerEvent } from "@cyrus/schemas/signaling"; | ||
| import { broadcastSignalingEvent, type SignalingWS } from "./signaling"; | ||
|
|
||
| function connection( | ||
| id: string, | ||
| eventId: string | null, | ||
| sent: unknown[] | ||
| ): SignalingWS { | ||
| return { | ||
| deserializeAttachment: <T = unknown>() => | ||
| (eventId ? { eventId, name: id, role: "worker" } : null) as T | null, | ||
| id, | ||
| send: (data) => sent.push(data), | ||
| serializeAttachment: () => undefined, | ||
| }; | ||
| } | ||
|
|
||
| describe("broadcastSignalingEvent", () => { | ||
| test("sends encoded hibernation events to peers with event iterators", () => { | ||
| const sent: unknown[] = []; | ||
| const event: ServerEvent = { | ||
| id: "worker-left", | ||
| type: "peer-left", | ||
| }; | ||
|
|
||
| broadcastSignalingEvent( | ||
| [ | ||
| connection("controller-1", "event-controller", sent), | ||
| connection("worker-1", "event-worker", sent), | ||
| ], | ||
| event | ||
| ); | ||
|
|
||
| expect(sent).toHaveLength(2); | ||
| expect(sent.every((payload) => typeof payload === "string")).toBe(true); | ||
| }); | ||
|
|
||
| test("skips excluded peers and peers without attachments", () => { | ||
| const sent: unknown[] = []; | ||
|
|
||
| broadcastSignalingEvent( | ||
| [ | ||
| connection("controller-1", "event-controller", sent), | ||
| connection("worker-1", "event-worker", sent), | ||
| connection("joining-peer", null, sent), | ||
| ], | ||
| { | ||
| peer: { | ||
| id: "worker-2", | ||
| name: "Worker 2", | ||
| role: "worker", | ||
| }, | ||
| type: "peer-joined", | ||
| }, | ||
| ["controller-1"] | ||
| ); | ||
|
|
||
| expect(sent).toHaveLength(1); | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,42 @@ | ||
| # Testing Strategy | ||
|
|
||
| Cyrus uses a layered test setup so each part of the system is tested with the | ||
| runtime closest to production. | ||
|
|
||
| ## Runners | ||
|
|
||
| | Scope | Runner | Location | | ||
| | --- | --- | --- | | ||
| | Pure TypeScript, schemas, CLI, database, process tests | Bun test | Colocated `*.test.ts` or package `__tests__/integration/` | | ||
| | React hooks, providers, Cloudflare Workers runtime | Vitest | Package-local `vitest.config.ts` | | ||
| | Browser user flows | Playwright | Root `tests/e2e/web/` | | ||
|
|
||
| Bun test is the default. Use Vitest when the package needs a browser-like React | ||
| test environment or the Cloudflare Workers test pool. | ||
|
|
||
| ## Layout | ||
|
|
||
| ```text | ||
| <package>/src/**/*.test.ts | ||
| <package>/__tests__/integration/ | ||
| tests/e2e/harness/ | ||
| tests/e2e/scenarios/ | ||
| tests/e2e/web/ | ||
| tooling/test/ | ||
| ``` | ||
|
|
||
| Unit tests stay close to the code they cover. Integration tests live under the | ||
| package boundary they exercise. Cross-app tests live at the repo root. | ||
|
|
||
| ## CI Levels | ||
|
|
||
| | Level | Trigger | Tests | | ||
| | --- | --- | --- | | ||
| | 0 | pre-commit | Ultracite only | | ||
| | 1 | pre-push | Typecheck now; unit tests once stable | | ||
| | 2 | pull request | Lint, typecheck, unit tests | | ||
| | 3 | main or nightly | Integration and E2E | | ||
| | 4 | deploy | Health and WebSocket smoke | | ||
|
|
||
| Phase 1 only adds the unit test foundation. Integration and E2E are introduced | ||
| in later phases. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { | ||
| AUTH_OPERATION_KEYS, | ||
| RTC_OPERATION_KEYS, | ||
| SIGNALING_OPERATION_KEYS, | ||
| } from "./operation-keys"; | ||
|
|
||
| describe("operation keys", () => { | ||
| test("builds stable signaling keys", () => { | ||
| expect(SIGNALING_OPERATION_KEYS.connection("user-1")).toEqual([ | ||
| "signaling", | ||
| "user-1", | ||
| ]); | ||
| expect(SIGNALING_OPERATION_KEYS.listPeers).toEqual([ | ||
| "signaling", | ||
| "list-peers", | ||
| ]); | ||
| }); | ||
|
|
||
| test("builds stable RTC keys", () => { | ||
| expect(RTC_OPERATION_KEYS.connection("worker-1")).toEqual([ | ||
| "controller", | ||
| "worker-1", | ||
| ]); | ||
| expect(RTC_OPERATION_KEYS.listThreads("project-1")).toEqual([ | ||
| "controller", | ||
| "list-threads", | ||
| "project-1", | ||
| ]); | ||
| expect(RTC_OPERATION_KEYS.listDir("/tmp/cyrus", 2)).toEqual([ | ||
| "controller", | ||
| "list-dir", | ||
| "/tmp/cyrus", | ||
| 2, | ||
| ]); | ||
| }); | ||
|
|
||
| test("keeps auth keys stable", () => { | ||
| expect(AUTH_OPERATION_KEYS.deviceDecide).toEqual([ | ||
| "auth", | ||
| "device", | ||
| "decide", | ||
| ]); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { | ||
| AgentEventSchema, | ||
| ChatChunkSchema, | ||
| ChatInputSchema, | ||
| ToolCallContentSchema, | ||
| } from "./chat"; | ||
|
|
||
| describe("chat schemas", () => { | ||
| test("parses a valid chat request", () => { | ||
| expect( | ||
| ChatInputSchema.parse({ | ||
| agentName: "claude", | ||
| message: "hello", | ||
| projectId: "project-1", | ||
| threadId: "00000000-0000-4000-8000-000000000001", | ||
| turnId: "00000000-0000-4000-8000-000000000002", | ||
| }) | ||
| ).toMatchObject({ | ||
| agentName: "claude", | ||
| message: "hello", | ||
| projectId: "project-1", | ||
| }); | ||
| }); | ||
|
|
||
| test("rejects non-uuid optional chat identifiers", () => { | ||
| expect(() => | ||
| ChatInputSchema.parse({ | ||
| agentName: "claude", | ||
| message: "hello", | ||
| projectId: "project-1", | ||
| threadId: "not-a-uuid", | ||
| }) | ||
| ).toThrow(); | ||
| }); | ||
|
|
||
| test("parses representative agent events", () => { | ||
| expect( | ||
| AgentEventSchema.parse({ | ||
| type: "tool_call", | ||
| toolCallId: "tool-1", | ||
| title: "Read file", | ||
| kind: "read", | ||
| status: "in_progress", | ||
| content: [ | ||
| { | ||
| type: "content", | ||
| content: { type: "text", text: "reading package.json" }, | ||
| }, | ||
| ], | ||
| }) | ||
| ).toMatchObject({ | ||
| type: "tool_call", | ||
| toolCallId: "tool-1", | ||
| kind: "read", | ||
| }); | ||
|
|
||
| expect( | ||
| AgentEventSchema.parse({ | ||
| type: "plan_update", | ||
| plan: { | ||
| type: "items", | ||
| id: "plan-1", | ||
| entries: [ | ||
| { | ||
| content: "Write schema tests", | ||
| priority: "high", | ||
| status: "completed", | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| ).toMatchObject({ type: "plan_update" }); | ||
| }); | ||
|
|
||
| test("parses chat chunks with nested events", () => { | ||
| expect( | ||
| ChatChunkSchema.parse({ | ||
| threadId: "thread-1", | ||
| turnId: "turn-1", | ||
| seq: 1, | ||
| event: { type: "token", text: "hello", messageId: "message-1" }, | ||
| }) | ||
| ).toEqual({ | ||
| threadId: "thread-1", | ||
| turnId: "turn-1", | ||
| seq: 1, | ||
| event: { type: "token", text: "hello", messageId: "message-1" }, | ||
| }); | ||
| }); | ||
|
|
||
| test("rejects unknown tool content types", () => { | ||
| expect(() => | ||
| ToolCallContentSchema.parse({ | ||
| type: "unknown", | ||
| content: { type: "text", text: "nope" }, | ||
| }) | ||
| ).toThrow(); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.