import test from "node:test"
import assert from "node:assert/strict"
import { readFileSync } from "node:fs"

const sharedTypesSource = readFileSync(new URL("../src/index.ts", import.meta.url), "utf8")

test("shared desktop chat API exposes cancel stream contract", () => {
  assert.match(sharedTypesSource, /chatCancelStream:\s*"chat:cancel-stream"/)
  assert.match(sharedTypesSource, /export interface ChatCancelStreamRequest/)
  assert.match(sharedTypesSource, /export interface ChatCancelStreamResult/)
  assert.match(sharedTypesSource, /cancelStream\(requestId: string, runId\?: string, sessionId\?: string\): Promise<ChatCancelStreamResult>/)
})

test("shared stream events include cancelled payload", () => {
  assert.match(sharedTypesSource, /export interface ChatStreamCancelledEvent/)
  assert.match(sharedTypesSource, /type:\s*"cancelled"/)
  assert.match(sharedTypesSource, /ChatStreamEvent = .*ChatStreamCancelledEvent/s)
})
