Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 15 additions & 3 deletions src/jsonFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@ export async function readText(uri: vscode.Uri): Promise<string | undefined> {
try { return decoder.decode(await wfs.readFile(uri)) } catch { return undefined }
}

/** Watches `<folder>/<rel>/*.json`: a file created or changed goes to `onFile`, a deleted one to `onDelete`. */
export function watchJsonFiles(folder: vscode.WorkspaceFolder, rel: string, onFile: (u: vscode.Uri) => unknown, onDelete: (u: vscode.Uri) => unknown): vscode.FileSystemWatcher {
/**
* Watches `<folder>/<rel>/*.json`: a file created or changed goes to `onFile`, a deleted one to `onDelete`. When `rel`
* (or a folder above it) is created, the files already in it go to `onFile` too: the file watcher starts watching a new
* folder only after it sees it, so files written right after the folder (`mkdir -p` then a write, a checkout) can come
* with no event of their own.
*/
export function watchJsonFiles(folder: vscode.WorkspaceFolder, rel: string, onFile: (u: vscode.Uri) => unknown, onDelete: (u: vscode.Uri) => unknown): vscode.Disposable {
const w = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(folder, `${rel}/*.json`))
w.onDidCreate(onFile)
w.onDidChange(onFile)
w.onDidDelete(onDelete)
return w
const parts = rel.split('/').filter(Boolean)
const dirs = parts.map((_, i) => parts.slice(0, i + 1).join('/'))
if (!dirs.length) return w
const made = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(folder, dirs.length > 1 ? `{${dirs.join(',')}}` : dirs[0]), false, true, true)
made.onDidCreate(async () => {
for (const u of (await jsonFilesIn(vscode.Uri.joinPath(folder.uri, rel)))?.files ?? []) await onFile(u)
})
return vscode.Disposable.from(w, made)
}

/** The `.json` files in `dir`, by name, and how many entries it has in all; undefined: it can't be read (not there yet). */
Expand Down
2 changes: 1 addition & 1 deletion test/integration/main/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const ctx = {
}

/** The main suite's wait (6 s by default): on a timeout it prints the tour's state (most waits are on it). */
export const until = waiter({ dump: () => { try { const t = ctx.api?.snapshot().tour; return t && { ...t, story: undefined } } catch { return undefined } } })
export const until = waiter({ dump: () => { try { const s = ctx.api?.snapshot(); return s && { journeys: s.journeys.map((j: { id: string }) => j.id), tour: s.tour && { ...s.tour, story: undefined } } } catch { return undefined } } })

/** Everything the extension shows, as data (notes, journeys, the tour, counts). */
export const snap = () => ctx.api.snapshot()
Expand Down
6 changes: 4 additions & 2 deletions test/integration/main/notesReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as vscode from 'vscode'
import * as fs from 'fs'
import assert from 'assert'
import { appendMessage, now, quiet, readJson, settle, test } from '../helpers'
import { appendMessage, now, quiet, readJson, settle, sleep, test } from '../helpers'
import { agentNote, writeNote } from '../fixtures'
import { at, bodyOf, tour, closeAllEditors, ctx, journeysTree, noteById, notePath, notesTree, snap, until, wsPath } from './context'
import { UNREAD_FINDING } from './shared'
Expand Down Expand Up @@ -189,7 +189,9 @@ export const notesReviewTests = [
editor.selection = new vscode.Selection(2, 0, 2, 0)
const notesBefore = snap().notes.length
await vscode.commands.executeCommand('codeNotes.add')
await settle(600, 'the comment box opening and taking the keyboard')
// Typed 600 ms later, as a person would, and not scaled with the other waits: in the test window the keyboard
// leaves the box after a second or two (to an open thread's Reply above it), and what is typed then is lost.
await sleep(600)
await vscode.commands.executeCommand('type', { text: 'Typed into the box' })
await vscode.commands.executeCommand('editor.action.submitComment')
await until('Add Note saved a note', () => snap().notes.length === notesBefore + 1 && snap().notes.some((x: any) => x.messages[0].body === 'Typed into the box'), 8000)
Expand Down
4 changes: 4 additions & 0 deletions test/integration/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { connectCdp } from './connectCdp'
import { writeSkillStandIn } from './fixtures'
import { writeSlowGit } from '../slowGit'

// The CI job's own variables (GITHUB_HEAD_REF, CI_COMMIT_REF_NAME, …) must not reach VS Code: the extension host
// passes its environment to the understanding CLI, which takes the branch from them. CI itself stays (helpers.ts: SCALE).
for (const k of Object.keys(process.env)) if (/^(GITHUB_|GITLAB_|CI_|RUNNER_)/.test(k)) delete process.env[k]

/** The extension's folder (out/test/integration/ is three below it). */
const ROOT = path.resolve(__dirname, '../../..')

Expand Down
5 changes: 3 additions & 2 deletions test/journey-list/shoot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ for (const theme of ['dark', 'light']) for (const w of [320, 600, 1000]) {
h = await home()
if (h.sel === top || h.focusKey !== h.sel) fail(`↓ did not move the focus and selection (${top} → ${h.sel}, focus ${h.focusKey})`)
await page.keyboard.press('End'); await settle()
const inView = await page.evaluate(() => { const r = document.activeElement.getBoundingClientRect(); return r.top >= 0 && r.bottom <= innerHeight })
if (!inView) fail('the focused row (End) is not scrolled into view')
// Within a pixel: the page scrolls by whole pixels, rows can end at fractions (font metrics differ per machine).
const inView = await page.evaluate(() => { const r = document.activeElement.getBoundingClientRect(); return { ok: r.top > -1 && r.bottom < innerHeight + 1, top: r.top, bottom: r.bottom, height: innerHeight } })
if (!inView.ok) fail(`the focused row (End) is not scrolled into view (${inView.top}–${inView.bottom} of ${inView.height})`)
if (OUT) await page.screenshot({ path: path.join(OUT, `home-keys-${w}-${theme}.png`) })
await page.keyboard.press('Home'); await settle(); await page.keyboard.press('ArrowUp'); await settle()
if ((await home()).focus !== 'hsearch') fail('↑ from the first row did not go back to the search')
Expand Down
Loading