Ver Fonte

test(python): restore concat through its spy

ZiyaZhang há 1 semana atrás
pai
commit
884485e7e6

+ 4 - 4
packages/experimental/code-runtime-python/tests/runtime.spec.ts

@@ -4784,15 +4784,15 @@ describe('PythonCodeRuntime — hostile peer', () => {
     // One-byte data events force the fragment-count limit independently of pipe
     // One-byte data events force the fragment-count limit independently of pipe
     // coalescing. The input-list bound rejects missing seals; copied bytes reject
     // coalescing. The input-list bound rejects missing seals; copied bytes reject
     // repeatedly merging the sealed prefix. Both regressions preserve log text.
     // repeatedly merging the sealed prefix. Both regressions preserve log text.
-    const realConcat = Buffer.concat
+    const realConcat = Buffer.concat.bind(Buffer)
     const previousSplitStdout = splitStdout.value
     const previousSplitStdout = splitStdout.value
     let copied = 0
     let copied = 0
     let maxParts = 0
     let maxParts = 0
-    Buffer.concat = (list: readonly Uint8Array[], total?: number): Buffer<ArrayBuffer> => {
+    const concatSpy = vi.spyOn(Buffer, 'concat').mockImplementation((list: readonly Uint8Array[], total?: number): Buffer<ArrayBuffer> => {
       for (const part of list) copied += part.length
       for (const part of list) copied += part.length
       maxParts = Math.max(maxParts, list.length)
       maxParts = Math.max(maxParts, list.length)
       return realConcat(list, total)
       return realConcat(list, total)
-    }
+    })
     let result: CodeRunResult
     let result: CodeRunResult
     try {
     try {
       splitStdout.value = true
       splitStdout.value = true
@@ -4806,7 +4806,7 @@ describe('PythonCodeRuntime — hostile peer', () => {
         bindings: [],
         bindings: [],
       })
       })
     } finally {
     } finally {
-      Buffer.concat = realConcat
+      concatSpy.mockRestore()
       splitStdout.value = previousSplitStdout
       splitStdout.value = previousSplitStdout
     }
     }
     expect(result.error).toBeUndefined()
     expect(result.error).toBeUndefined()