test(opencode): remove redundant global event casts (#28564)
This commit is contained in:
@@ -171,7 +171,7 @@ function globalSse(stream: GlobalEventStream) {
|
|||||||
function wrapGlobalStream(stream: EventStream): GlobalEventStream {
|
function wrapGlobalStream(stream: EventStream): GlobalEventStream {
|
||||||
return (async function* (): GlobalEventStream {
|
return (async function* (): GlobalEventStream {
|
||||||
for await (const event of stream) {
|
for await (const event of stream) {
|
||||||
yield globalEvent(event as GlobalEvent["payload"])
|
yield globalEvent(event)
|
||||||
}
|
}
|
||||||
return StreamClosed
|
return StreamClosed
|
||||||
})()
|
})()
|
||||||
@@ -339,11 +339,11 @@ function child(id: string): SessionChild {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function globalEvent(payload: SdkEvent | GlobalEvent["payload"]): GlobalEvent {
|
function globalEvent(payload: GlobalEvent["payload"]): GlobalEvent {
|
||||||
return {
|
return {
|
||||||
directory: "/tmp",
|
directory: "/tmp",
|
||||||
project: "project-1",
|
project: "project-1",
|
||||||
payload: payload as GlobalEvent["payload"],
|
payload,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/** @jsxImportSource @opentui/solid */
|
/** @jsxImportSource @opentui/solid */
|
||||||
import { describe, expect, test } from "bun:test"
|
import { describe, expect, test } from "bun:test"
|
||||||
import { testRender } from "@opentui/solid"
|
import { testRender } from "@opentui/solid"
|
||||||
import type { GlobalEvent } from "@opencode-ai/sdk/v2"
|
import type { Event, GlobalEvent } from "@opencode-ai/sdk/v2"
|
||||||
import { onMount } from "solid-js"
|
import { onMount } from "solid-js"
|
||||||
import { ProjectProvider, useProject } from "../../../src/cli/cmd/tui/context/project"
|
import { ProjectProvider, useProject } from "../../../src/cli/cmd/tui/context/project"
|
||||||
import { SDKProvider } from "../../../src/cli/cmd/tui/context/sdk"
|
import { SDKProvider } from "../../../src/cli/cmd/tui/context/sdk"
|
||||||
@@ -17,10 +17,7 @@ async function wait(fn: () => boolean, timeout = 2000) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function event(
|
function event(payload: Event, input: { directory: string; project?: string; workspace?: string }): GlobalEvent {
|
||||||
payload: GlobalEvent["payload"],
|
|
||||||
input: { directory: string; project?: string; workspace?: string },
|
|
||||||
): GlobalEvent {
|
|
||||||
return {
|
return {
|
||||||
directory: input.directory,
|
directory: input.directory,
|
||||||
project: input.project,
|
project: input.project,
|
||||||
@@ -29,7 +26,7 @@ function event(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function vcs(branch: string): GlobalEvent["payload"] {
|
function vcs(branch: string): Event {
|
||||||
return {
|
return {
|
||||||
id: `evt_vcs_${branch}`,
|
id: `evt_vcs_${branch}`,
|
||||||
type: "vcs.branch.updated",
|
type: "vcs.branch.updated",
|
||||||
@@ -39,7 +36,7 @@ function vcs(branch: string): GlobalEvent["payload"] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function update(version: string): GlobalEvent["payload"] {
|
function update(version: string): Event {
|
||||||
return {
|
return {
|
||||||
id: `evt_update_${version}`,
|
id: `evt_update_${version}`,
|
||||||
type: "installation.update-available",
|
type: "installation.update-available",
|
||||||
@@ -70,7 +67,7 @@ function createSource() {
|
|||||||
|
|
||||||
async function mount() {
|
async function mount() {
|
||||||
const source = createSource()
|
const source = createSource()
|
||||||
const seen: GlobalEvent["payload"][] = []
|
const seen: Event[] = []
|
||||||
const workspaces: Array<string | undefined> = []
|
const workspaces: Array<string | undefined> = []
|
||||||
const fetch = (async (input: RequestInfo | URL) => {
|
const fetch = (async (input: RequestInfo | URL) => {
|
||||||
const url = new URL(input instanceof Request ? input.url : String(input))
|
const url = new URL(input instanceof Request ? input.url : String(input))
|
||||||
@@ -105,7 +102,7 @@ async function mount() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Probe(props: {
|
function Probe(props: {
|
||||||
seen: GlobalEvent["payload"][]
|
seen: Event[]
|
||||||
workspaces: Array<string | undefined>
|
workspaces: Array<string | undefined>
|
||||||
onReady: (ctx: { project: ReturnType<typeof useProject> }) => void
|
onReady: (ctx: { project: ReturnType<typeof useProject> }) => void
|
||||||
}) {
|
}) {
|
||||||
@@ -114,7 +111,7 @@ function Probe(props: {
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
event.subscribe((evt, { workspace }) => {
|
event.subscribe((evt, { workspace }) => {
|
||||||
props.seen.push(evt as GlobalEvent["payload"])
|
props.seen.push(evt)
|
||||||
props.workspaces.push(workspace)
|
props.workspaces.push(workspace)
|
||||||
})
|
})
|
||||||
props.onReady({ project })
|
props.onReady({ project })
|
||||||
|
|||||||
Reference in New Issue
Block a user