GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — opencode/packages/plugin/test/gui-scope.test.ts at dev · erickwill/opencode

Expand file tree

/

gui-scope.test.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
107 lines (92 loc) · 3.71 KB
/

gui-scope.test.ts

Copy path

File metadata and controls

107 lines (92 loc) · 3.71 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { afterEach, beforeEach, expect, jest, test } from "bun:test"
import { Scope } from "../src/gui/scope"
const TIMEOUT = 1_000
beforeEach(() => jest.useFakeTimers())
afterEach(() => jest.useRealTimers())
// Fake timers leave setImmediate real: one turn drains every pending microtask.
const flush = () => new Promise<void>((resolve) => setImmediate(resolve))
const fixture = () => {
const events: string[] = []
const logs: { message: string; data: object }[] = []
const scope = Scope.make("test", { timeout: TIMEOUT, log: (message, data) => logs.push({ message, data }) })
const record = (name: string) => () => {
events.push(name)
}
return { events, logs, scope, record }
}
const settled = (promise: Promise<unknown>) => {
const state = { settled: false }
void promise.then(() => (state.settled = true))
return state
}
test("close aborts the signal at once and runs finalizers in reverse, past one that fails", async () => {
const world = fixture()
world.scope.addFinalizer(world.record("first"))
world.scope.addFinalizer(() => {
world.events.push("failing")
throw new Error("boom")
})
world.scope.addFinalizer(world.record("last"))
const closing = world.scope.close()
expect(world.scope.signal.aborted).toBe(true)
// Finalizers start only once the closing code yields.
expect(world.events).toEqual([])
await closing
expect(world.events).toEqual(["last", "failing", "first"])
expect(world.logs.map((entry) => entry.message)).toEqual(["scope finalizer failed"])
})
test("a finalizer added after close runs at once, and closing again waits for it", async () => {
const world = fixture()
await world.scope.close()
const release = { resolve: () => {} }
world.scope.addFinalizer(async () => {
world.events.push("late")
await new Promise<void>((resolve) => (release.resolve = resolve))
world.events.push("late done")
})
await flush()
expect(world.events).toEqual(["late"])
const again = settled(world.scope.close())
await flush()
expect(again.settled).toBe(false)
release.resolve()
await flush()
expect(again.settled).toBe(true)
expect(world.events).toEqual(["late", "late done"])
})
test("a fork closes with its parent in reverse order like a finalizer, or earlier on its own", async () => {
const world = fixture()
world.scope.addFinalizer(world.record("parent before fork"))
const fork = world.scope.fork("child")
fork.addFinalizer(world.record("child"))
const alone = world.scope.fork("alone")
alone.addFinalizer(world.record("alone"))
world.scope.addFinalizer(world.record("parent after fork"))
await alone.close()
expect(world.events).toEqual(["alone"])
await world.scope.close()
expect(fork.signal.aborted).toBe(true)
// The fork that closed on its own left the parent: it does not run again.
expect(world.events).toEqual(["alone", "parent after fork", "child", "parent before fork"])
expect(world.scope.fork("after close").signal.aborted).toBe(true)
})
test("the deadline gives up on a hung finalizer, logs it, and runs the rest", async () => {
const world = fixture()
world.scope.addFinalizer(world.record("first"))
world.scope.addFinalizer(function hung() {
world.events.push("hung")
return new Promise<void>(() => {})
})
world.scope.addFinalizer(world.record("last"))
const closing = settled(world.scope.close())
await flush()
jest.advanceTimersByTime(TIMEOUT - 1)
await flush()
expect(world.events).toEqual(["last", "hung"])
expect(closing.settled).toBe(false)
jest.advanceTimersByTime(1)
await flush()
expect(world.events).toEqual(["last", "hung", "first"])
expect(closing.settled).toBe(true)
expect(world.logs).toEqual([{ message: "scope finalizer timed out", data: { scope: "test", finalizer: "hung" } }])
})
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.