chore(vscode): format notebook tool changes

This commit is contained in:
Mark IJbema
2026-06-25 11:32:46 +02:00
parent 75d13ef701
commit b0747d2595
3 changed files with 24 additions and 10 deletions
@@ -230,7 +230,10 @@ export class NotebookAdapter {
})
}
const expected = revisions.get(revisionKey(loaded.target, request.expectedRevision))
if (state.revision !== request.expectedRevision && !sameCell(expected?.cells[request.index], state.cells[request.index])) {
if (
state.revision !== request.expectedRevision &&
!sameCell(expected?.cells[request.index], state.cells[request.index])
) {
throw this.stale(loaded.path, request.index, state.revision, "The targeted notebook cell changed")
}
const cell = loaded.document.cellAt(request.index)
@@ -347,7 +350,9 @@ export class NotebookAdapter {
document.cellAt(request.index) !== cell ||
!sameCell(fingerprint, current.cells[request.index])
) {
reject(this.stale(path, request.index, current.revision, "The targeted notebook cell changed during execution"))
reject(
this.stale(path, request.index, current.revision, "The targeted notebook cell changed during execution"),
)
stop()
return
}
@@ -90,7 +90,13 @@ function harness(context: NotebookBridgeContext, dirs = ["/repo"]) {
function context(overrides: Partial<NotebookBridgeContext["adapter"]> = {}) {
const dispose = mock(() => undefined)
const adapter = {
read: mock(async () => ({ operation: "read" as const, path: "book.ipynb", requestPath: "book.ipynb", revision: "content:2", cells: [] })),
read: mock(async () => ({
operation: "read" as const,
path: "book.ipynb",
requestPath: "book.ipynb",
revision: "content:2",
cells: [],
})),
edit: mock(async () => ({
operation: "edit" as const,
path: "book.ipynb",
@@ -69,8 +69,9 @@ function harness(document: vscode.NotebookDocument, cells: vscode.NotebookCell[]
},
apply: async (edit) => {
calls.apply++
const item = (edit as unknown as { edits: Array<{ type: string; index: number; cells?: vscode.NotebookCellData[] }> })
.edits[0]!
const item = (
edit as unknown as { edits: Array<{ type: string; index: number; cells?: vscode.NotebookCellData[] }> }
).edits[0]!
if (item.type === "delete") cells.splice(item.index, 1)
if (item.type !== "delete") {
const input = (item.cells?.[0] as unknown as { input: NotebookCellInput }).input
@@ -148,9 +149,9 @@ describe("notebook path security", () => {
relative: "nested/book.ipynb",
})
const ctx = adapter([cell()], "/repo/nested/book.ipynb")
expect((await ctx.adapter.read({ directory: "/repo", path: "/repo/nested/book.ipynb", includeOutputs: false })).path).toBe(
"nested/book.ipynb",
)
expect(
(await ctx.adapter.read({ directory: "/repo", path: "/repo/nested/book.ipynb", includeOutputs: false })).path,
).toBe("nested/book.ipynb")
})
it("rejects outside absolute paths and relative or absolute symlink escapes", async () => {
@@ -352,7 +353,8 @@ describe("notebook adapter", () => {
{ items: [{ mime: "text/plain", data: new TextEncoder().encode("done") }] } as vscode.NotebookCellOutput,
]
target.state.execution = { success: true, executionOrder: 2, timing: { startTime: 10, endTime: 20 } }
for (const listener of ctx.changes) listener(event(ctx.document, target.value, { executionSummary: target.state.execution }))
for (const listener of ctx.changes)
listener(event(ctx.document, target.value, { executionSummary: target.state.execution }))
}
const result = await ctx.adapter.execute({
directory: "/repo",
@@ -430,7 +432,8 @@ describe("notebook adapter", () => {
ctx.calls.commandArgs = args
if (args[0] !== "notebook.cell.execute") return
target.state.source = "after"
for (const listener of ctx.changes) listener(event(ctx.document, target.value, { document: target.value.document }))
for (const listener of ctx.changes)
listener(event(ctx.document, target.value, { document: target.value.document }))
}
await expect(
ctx.adapter.execute({ directory: "/repo", path: "book.ipynb", index: 0, expectedRevision }),