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

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

test("gateway client cancels local pending run even when remote cancel is unavailable", () => {
  assert.match(gatewaySource, /async cancelChatRun\(runId: string\)/)
  assert.match(gatewaySource, /remoteCancelled: false/)
  assert.match(gatewaySource, /this\.pendingChatRuns\.delete\(runId\)/)
})

test("gateway client only sends cancel RPC when gateway advertises chat cancel", () => {
  assert.match(gatewaySource, /availableMethods.*chat\.cancel/s)
  assert.match(gatewaySource, /this\.request\("chat\.cancel"/)
})
