Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
289 changes: 229 additions & 60 deletions config/patches/@xterm__addon-image@0.10.0-beta.301.patch

Large diffs are not rendered by default.

269 changes: 219 additions & 50 deletions config/patches/xterm-src/@xterm__addon-image@0.10.0-beta.301.src.patch

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('Kitty virtual placement ownership and rendering', () => {
}
})

it('invalidates virtual placement bookkeeping when the pixel budget evicts it', async () => {
it('retains virtual placement metadata when the pixel budget evicts its bitmap', async () => {
const h = createPlaceholderTerminal()
try {
await writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG)
Expand All @@ -109,7 +109,7 @@ describe('Kitty virtual placement ownership and rendering', () => {
await writeKitty(h.terminal, 'a=T,f=100,i=8,U=1,c=2,r=2', PNG)
expect(render(h)).toHaveLength(0)
expect(h.bitmaps[0].close).toHaveBeenCalledOnce()
expect(h.kitty._virtualPlacements.has(7)).toBe(false)
expect(h.kitty._virtualPlacements.has(7)).toBe(true)
} finally {
h.terminal.dispose()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
afterEach(() => vi.unstubAllGlobals())

describe('Kitty virtual placement lifecycle', () => {
it('keeps alternate-buffer prototypes across ordinary image placement and releases them on exit', async () => {
it('keeps alternate-buffer prototypes across ordinary image placement and releases their pixels on exit', async () => {
const h = createPlaceholderTerminal()
try {
await write(h.terminal, '\x1b[?1049h')
Expand All @@ -23,7 +23,7 @@ describe('Kitty virtual placement lifecycle', () => {
expect(render(h).filter((call) => call[0] === virtual)).toHaveLength(2)
await write(h.terminal, '\x1b[?1049l')
expect(h.storage._images.size).toBe(0)
expect(h.kitty._virtualPlacements.size).toBe(0)
expect(h.kitty._virtualPlacements.size).toBe(1)
expect(virtual.close).toHaveBeenCalledOnce()
} finally {
h.terminal.dispose()
Expand Down
264 changes: 264 additions & 0 deletions config/scripts/xterm-image-kitty-recovery.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
import { afterEach, expect, it, vi } from 'vitest'
import {
createPlaceholderTerminal,
placeholderCells,
PNG,
render,
TrackedBitmap,
write,
writeKitty
} from './xterm-kitty-placeholder-test-terminal.mjs'
afterEach(() => vi.unstubAllGlobals())

it('lazily decodes a pixel-evicted prototype without a new transmission', async () => {
const h = createPlaceholderTerminal()
try {
await writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG)
await write(h.terminal, placeholderCells(7))
h.storage._pixelLimit = 200
await writeKitty(h.terminal, 'a=T,f=100,i=8,U=1,c=2,r=2', PNG)
expect(h.bitmaps[0].close).toHaveBeenCalledOnce()
render(h)
await vi.waitFor(() => expect(h.bitmaps).toHaveLength(3))
await vi.waitFor(() => expect(render(h)).toHaveLength(2))
expect(h.storage.getUsage()).toBeLessThanOrEqual(0.0008)
} finally {
h.terminal.dispose()
}
})

it('recovers after an alternate-buffer round trip empties the entire pixel store', async () => {
const h = createPlaceholderTerminal()
try {
await write(h.terminal, '\x1b[?1049h')
await writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG)
await write(h.terminal, `\x1b[?1049l\x1b[?1049h${placeholderCells(7)}`)
expect(h.storage._images.size).toBe(0)
render(h)
await vi.waitFor(() => expect(h.storage._images.size).toBe(1))
h.renderer._layers.set('top', {
drawImage: h.drawImage,
clearRect() {},
canvas: { remove() {} }
})
expect(render(h)).toHaveLength(2)
} finally {
h.terminal.dispose()
}
})

it('does not resurrect a deleted prototype while its recovery decode is in flight', async () => {
const h = createPlaceholderTerminal()
try {
await writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG)
await write(h.terminal, placeholderCells(7))
h.storage._evictOldest(32_000_000)
let complete
h.decode.mockImplementationOnce(
() =>
new Promise((resolve) => {
complete = resolve
})
)
render(h)
await vi.waitFor(() => expect(complete).toBeTypeOf('function'))
await writeKitty(h.terminal, 'a=d,d=I,i=7,q=2')
const bitmap = new TrackedBitmap()
complete(bitmap)
await vi.waitFor(() => expect(bitmap.close).toHaveBeenCalledOnce())
expect(h.storage._images.size).toBe(0)
expect(h.kitty._virtualPlacements.size).toBe(0)
} finally {
h.terminal.dispose()
}
})

it('restores only referenced images after a new renderer replays placeholder text', async () => {
const saved = new Map()
const first = createPlaceholderTerminal({
onKittyImageChanged: (id, image) => {
if (image) {
saved.set(id, image)
} else {
saved.delete(id)
}
}
})
await writeKitty(first.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG)
first.terminal.dispose()
const read = vi.fn(async (id) => saved.get(id))
const second = createPlaceholderTerminal({ readKittyImage: read })
try {
expect(second.decode).not.toHaveBeenCalled()
await write(second.terminal, placeholderCells(7))
render(second)
await vi.waitFor(() => expect(second.kitty.getImage(7)).toBeDefined())
render(second)
await vi.waitFor(() => expect(second.storage._images.size).toBe(1))
second.renderer._layers.set('top', {
drawImage: second.drawImage,
clearRect() {},
canvas: { remove() {} }
})
expect(render(second)).toHaveLength(2)
expect(read).toHaveBeenCalledTimes(1)
} finally {
second.terminal.dispose()
}
})

it('lets new uploads win over an old asynchronous replay lookup', async () => {
let finish
const h = createPlaceholderTerminal({
readKittyImage: () =>
new Promise((resolve) => {
finish = resolve
})
})
try {
await write(h.terminal, placeholderCells(7))
render(h)
await writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,c=3,r=1', PNG)
const current = h.kitty.getImage(7)
finish({
image: current,
placements: [{ placementId: 0, cols: 99, rows: 99, command: { unicodePlaceholder: 1 } }]
})
await Promise.resolve()
await Promise.resolve()
expect(h.kitty.getImage(7)).toBe(current)
expect(h.kitty._virtualPlacementFor(7, 0).cols).toBe(3)
} finally {
h.terminal.dispose()
}
})

it('recovers again after a restored encoded payload is evicted by the byte budget', async () => {
let snapshot
const first = createPlaceholderTerminal({
onKittyImageChanged: (_id, image) => {
if (image) {
snapshot = image
}
}
})
await writeKitty(first.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG)
first.terminal.dispose()
const read = vi.fn(async () => snapshot)
const second = createPlaceholderTerminal({ readKittyImage: read })
try {
vi.spyOn(second.storage, 'getLimit').mockReturnValue(snapshot.image.data.size / 1000000)
await write(second.terminal, placeholderCells(7))
for (let attempt = 0; attempt < 3; attempt++) {
render(second)
await vi.waitFor(() => expect(second.kitty.getImage(7)).toBeDefined())
expect(read).toHaveBeenCalledTimes(attempt + 1)
await writeKitty(second.terminal, `a=T,f=100,i=${8 + attempt},U=1,c=2,r=2`, PNG)
expect(second.kitty.getImage(7)).toBeUndefined()
}
} finally {
second.terminal.dispose()
}
})

it.each(['absent', 'rejected', 'wrong id', 'oversized'])(
'retries a %s replay lookup after a viewport change without polling the same viewport',
async (failure) => {
let snapshot
const first = createPlaceholderTerminal({
onKittyImageChanged: (_id, image) => {
if (image) {
snapshot = image
}
}
})
await writeKitty(first.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG)
first.terminal.dispose()
const read = vi
.fn(async () => snapshot)
.mockImplementationOnce(async () => {
if (failure === 'rejected') {
throw new Error('temporary cache failure')
}
if (failure === 'absent') {
return undefined
}
return {
...snapshot,
image: {
...snapshot.image,
...(failure === 'wrong id'
? { id: 8 }
: { data: new Blob([new Uint8Array(9 * 1024 * 1024)]) })
}
}
})
const h = createPlaceholderTerminal({ readKittyImage: read })
try {
await write(h.terminal, placeholderCells(7))
for (let frame = 0; frame < 5; frame++) {
render(h)
await new Promise((resolve) => setTimeout(resolve, 0))
}
expect(read).toHaveBeenCalledTimes(1)
expect(h.kitty.getImage(7)).toBeUndefined()
await write(h.terminal, '\r')
render(h)
await vi.waitFor(() => expect(h.kitty.getImage(7)).toBeDefined())
expect(read).toHaveBeenCalledTimes(2)
} finally {
h.terminal.dispose()
}
}
)

it('bounds recovery when visible prototypes exceed the decoded-pixel budget', async () => {
const h = createPlaceholderTerminal()
try {
h.storage._pixelLimit = 200
for (const id of [7, 8, 9]) {
await writeKitty(h.terminal, `a=T,f=100,i=${id},U=1,c=2,r=2`, PNG)
}
await write(
h.terminal,
`${placeholderCells(7)}\r\n${placeholderCells(8)}\r\n${placeholderCells(9)}`
)
for (let frame = 0; frame < 20; frame++) {
render(h)
await new Promise((resolve) => setTimeout(resolve, 0))
}
expect(h.bitmaps.length).toBeLessThanOrEqual(6)
expect(h.storage.getUsage()).toBeLessThanOrEqual(0.0008)
} finally {
h.terminal.dispose()
}
})

it('bounds replay reads when visible payloads exceed the encoded-byte budget', async () => {
const saved = new Map()
const first = createPlaceholderTerminal({
onKittyImageChanged: (id, image) => {
if (image) {
saved.set(id, image)
}
}
})
for (const id of [7, 8]) {
await writeKitty(first.terminal, `a=T,f=100,i=${id},U=1,c=2,r=2`, PNG)
}
first.terminal.dispose()
const read = vi.fn(async (id) => saved.get(id))
const second = createPlaceholderTerminal({ readKittyImage: read })
try {
vi.spyOn(second.storage, 'getLimit').mockReturnValue(saved.get(7).image.data.size / 1000000)
await write(second.terminal, `${placeholderCells(7)}\r\n${placeholderCells(8)}`)
for (let frame = 0; frame < 20; frame++) {
render(second)
await new Promise((resolve) => setTimeout(resolve, 0))
}
expect(read).toHaveBeenCalledTimes(2)
expect(second.kitty.images.size).toBeLessThanOrEqual(1)
} finally {
second.terminal.dispose()
}
})
5 changes: 3 additions & 2 deletions config/scripts/xterm-kitty-placeholder-test-terminal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class TrackedBitmap {
}
}

export function createPlaceholderTerminal() {
export function createPlaceholderTerminal(options = {}) {
const bitmaps = []
const decode = vi.fn(async () => {
const bitmap = new TrackedBitmap()
Expand All @@ -36,7 +36,8 @@ export function createPlaceholderTerminal() {
const addon = new ImageAddon({
enableSizeReports: false,
storageLimit: 32,
kittySizeLimit: 8 * 1024 * 1024
kittySizeLimit: 8 * 1024 * 1024,
...options
})
terminal.loadAddon(addon)
const renderer = addon._renderer
Expand Down
53 changes: 39 additions & 14 deletions config/scripts/zcode-credential-workflow.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,46 @@ function executeScope(directory, overrides = {}) {
}

// The workflow owns Bash execution on Windows; this contract executes the same source on Unix.
it.skipIf(process.platform === 'win32')(
'selects the original path groups, including deletions and renames',
() => {
it.skipIf(process.platform === 'win32').each([
['default caller', {}],
[
'caller identity',
{
GIT_AUTHOR_NAME: 'Caller',
GIT_AUTHOR_EMAIL: 'caller@example.test',
GIT_COMMITTER_NAME: 'Caller',
GIT_COMMITTER_EMAIL: 'caller@example.test'
}
]
])(
'selects the original path groups, including deletions and renames (%s)',
(_label, inheritedIdentity) => {
const directory = mkdtempSync(join(tmpdir(), 'orca-zcode-workflow-'))
const git = (args) => execFileSync('git', args, { cwd: directory, stdio: 'pipe' })
const git = (args) =>
execFileSync('git', args, {
cwd: directory,
stdio: 'pipe',
env: {
...process.env,
...inheritedIdentity,
GIT_AUTHOR_NAME: 'Fixture',
GIT_AUTHOR_EMAIL: 'fixture@example.test',
GIT_COMMITTER_NAME: 'Fixture',
GIT_COMMITTER_EMAIL: 'fixture@example.test'
}
})
const write = (file, value) => {
mkdirSync(dirname(join(directory, file)), { recursive: true })
writeFileSync(join(directory, file), value)
}
let parent
const commit = () => {
git(['add', '-A'])
git([
'-c',
'user.name=Fixture',
'-c',
'user.email=fixture@example.test',
'commit',
'--allow-empty',
'-qm',
'fixture'
])
const tree = git(['write-tree']).toString().trim()
parent = git(['commit-tree', tree, ...(parent ? ['-p', parent] : []), '-m', 'fixture'])
.toString()
.trim()
git(['update-ref', 'HEAD', parent])
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
const cases = [
['src/main/zcode/credentials.ts', true, true],
Expand All @@ -160,6 +179,12 @@ it.skipIf(process.platform === 'win32')(
git(['init', '-q'])
write('README.md', 'fixture')
commit()
expect(git(['reflog', 'show', '--format=%gn <%ge>', '-1', 'HEAD']).toString().trim()).toBe(
'Fixture <fixture@example.test>'
)
expect(git(['show', '-s', '--format=%an <%ae>', 'HEAD']).toString().trim()).toBe(
'Fixture <fixture@example.test>'
)
expect(executeScope(directory)).toEqual({ account: 'true', credentials: 'true' })
for (const [file, runsAccount, runsCredentials] of cases) {
write(file, 'first')
Expand Down
Loading