11import {
2+ AssetWorkspaceAssetNotFoundError ,
23 AuthFilesystemReadScope ,
34 EnvironmentAuthorizationError ,
45 EnvironmentId ,
56 ThreadId ,
67 type AuthSessionState ,
78} from "@t3tools/contracts" ;
89import * as Cause from "effect/Cause" ;
9- import { AsyncResult } from "effect/reactivity" ;
10+ import { Atom , AsyncResult } from "effect/reactivity" ;
1011import { beforeEach , expect , it , vi } from "vite-plus/test" ;
1112
1213const state = vi . hoisted ( ( ) => ( {
@@ -15,6 +16,8 @@ const state = vi.hoisted(() => ({
1516 assetAtom : { } ,
1617 mint : vi . fn ( ) ,
1718 assetQuery : vi . fn ( ) ,
19+ executeQuery : vi . fn ( ) ,
20+ preparedConnectionAtom : null as unknown ,
1821} ) ) ;
1922
2023vi . mock ( "react" , ( ) => ( { useCallback : < A > ( callback : A ) => callback } ) ) ;
@@ -27,7 +30,10 @@ vi.mock("@effect/atom-react", () => ({
2730 : AsyncResult . initial ( false ) ,
2831} ) ) ;
2932vi . mock ( "./session" , ( ) => ( {
30- environmentSession : { sessionStateAtom : ( ) => ( { } ) } ,
33+ environmentSession : {
34+ sessionStateAtom : ( ) => ( { } ) ,
35+ preparedConnectionValueAtom : ( ) => state . preparedConnectionAtom ,
36+ } ,
3137 usePreparedConnection : ( ) => ( { _tag : "Some" , value : { httpBaseUrl : "https://host.test" } } ) ,
3238} ) ) ;
3339vi . mock ( "./presentation" , ( ) => ( {
@@ -48,9 +54,13 @@ vi.mock("@t3tools/client-runtime/state/assets", async (importOriginal) => ({
4854 ...( await importOriginal < typeof import ( "@t3tools/client-runtime/state/assets" ) > ( ) ) ,
4955 createAssetEnvironmentAtoms : ( ) => ( { createUrl : state . assetQuery } ) ,
5056} ) ) ;
57+ vi . mock ( "@t3tools/client-runtime/state/runtime" , async ( importOriginal ) => ( {
58+ ...( await importOriginal < typeof import ( "@t3tools/client-runtime/state/runtime" ) > ( ) ) ,
59+ executeAtomQuery : state . executeQuery ,
60+ } ) ) ;
5161vi . mock ( "./use-atom-query-runner" , ( ) => ( { useAtomQueryRunner : ( ) => state . mint } ) ) ;
5262
53- import { useRefreshAssetUrl , useAssetUrlState } from "./assets" ;
63+ import { refreshAssetUrl , useRefreshAssetUrl , useAssetUrlState } from "./assets" ;
5464
5565const environmentId = EnvironmentId . make ( "asset-environment" ) ;
5666const threadId = ThreadId . make ( "asset-thread" ) ;
@@ -107,3 +117,19 @@ it("lets the server authorize an explicit refresh before the client grant loads"
107117 state . mint . mockResolvedValue ( AsyncResult . failure ( Cause . fail ( denied ) ) ) ;
108118 await expect ( useRefreshAssetUrl ( environmentId , resource ) ( ) ) . resolves . toBeNull ( ) ;
109119} ) ;
120+
121+ it ( "rejects with the server's error and resolves null only without a connection" , async ( ) => {
122+ const missing = new AssetWorkspaceAssetNotFoundError ( {
123+ resource,
124+ checkedPath : "/repo/missing.png" ,
125+ } ) ;
126+ state . executeQuery . mockResolvedValue ( AsyncResult . failure ( Cause . fail ( missing ) ) ) ;
127+ state . preparedConnectionAtom = Atom . make ( {
128+ _tag : "Some" ,
129+ value : { httpBaseUrl : "https://host.test" } ,
130+ } ) ;
131+ await expect ( refreshAssetUrl ( environmentId , resource ) ) . rejects . toBe ( missing ) ;
132+
133+ state . preparedConnectionAtom = Atom . make ( { _tag : "None" } ) ;
134+ await expect ( refreshAssetUrl ( environmentId , resource ) ) . resolves . toBeNull ( ) ;
135+ } ) ;
0 commit comments