11import { describe , it , expect , beforeEach , vi } from "vitest" ;
2- import { createOPFSTools , sanitizePath } from "./opfs_tools" ;
2+ import { createOPFSTools , sanitizePath , setCreateBlobUrlFn } from "./opfs_tools" ;
33
44// ---- In-memory OPFS mock ----
55
@@ -139,6 +139,8 @@ describe("opfs_tools", () => {
139139 getDirectory : vi . fn ( ) . mockResolvedValue ( mockFS . rootHandle ) ,
140140 } ,
141141 } ) ;
142+ // opfs_read 总是返回 blobUrl,需要初始化 createBlobUrlFn
143+ setCreateBlobUrlFn ( async ( ) => "blob:mock-url" ) ;
142144 } ) ;
143145
144146 function getTool ( name : string ) {
@@ -165,7 +167,7 @@ describe("opfs_tools", () => {
165167
166168 const readResult = JSON . parse ( ( await read . executor . execute ( { path : "hello.txt" } ) ) as string ) ;
167169 expect ( readResult . path ) . toBe ( "hello.txt" ) ;
168- expect ( readResult . content ) . toBe ( "Hello! " ) ;
170+ expect ( readResult . blobUrl ) . toBe ( "blob:mock-url " ) ;
169171 expect ( readResult . size ) . toBe ( 6 ) ;
170172 } ) ;
171173
@@ -175,7 +177,7 @@ describe("opfs_tools", () => {
175177
176178 await write . executor . execute ( { path : "a/b/c.txt" , content : "deep" } ) ;
177179 const result = JSON . parse ( ( await read . executor . execute ( { path : "a/b/c.txt" } ) ) as string ) ;
178- expect ( result . content ) . toBe ( "deep " ) ;
180+ expect ( result . blobUrl ) . toBe ( "blob:mock-url " ) ;
179181 } ) ;
180182
181183 it ( "should overwrite existing file" , async ( ) => {
@@ -185,7 +187,7 @@ describe("opfs_tools", () => {
185187 await write . executor . execute ( { path : "f.txt" , content : "v1" } ) ;
186188 await write . executor . execute ( { path : "f.txt" , content : "v2" } ) ;
187189 const result = JSON . parse ( ( await read . executor . execute ( { path : "f.txt" } ) ) as string ) ;
188- expect ( result . content ) . toBe ( "v2 " ) ;
190+ expect ( result . blobUrl ) . toBe ( "blob:mock-url " ) ;
189191 } ) ;
190192
191193 it ( "should strip leading slashes from path" , async ( ) => {
@@ -194,7 +196,7 @@ describe("opfs_tools", () => {
194196
195197 await write . executor . execute ( { path : "/leading.txt" , content : "ok" } ) ;
196198 const result = JSON . parse ( ( await read . executor . execute ( { path : "leading.txt" } ) ) as string ) ;
197- expect ( result . content ) . toBe ( "ok " ) ;
199+ expect ( result . blobUrl ) . toBe ( "blob:mock-url " ) ;
198200 } ) ;
199201
200202 it ( "should reject .. in path" , async ( ) => {
0 commit comments