Skip to content

Commit a56741f

Browse files
authored
fix for task history (#1765)
1 parent 878b382 commit a56741f

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

src/core/__tests__/contextProxy.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ describe("ContextProxy", () => {
102102
const result = proxy.getGlobalState("apiProvider", "default-value")
103103
expect(result).toBe("default-value")
104104
})
105+
106+
it("should bypass cache for pass-through state keys", async () => {
107+
// Setup mock return value
108+
mockGlobalState.get.mockReturnValue("pass-through-value")
109+
110+
// Use a pass-through key (taskHistory)
111+
const result = proxy.getGlobalState("taskHistory" as GlobalStateKey)
112+
113+
// Should get value directly from original context
114+
expect(result).toBe("pass-through-value")
115+
expect(mockGlobalState.get).toHaveBeenCalledWith("taskHistory")
116+
})
117+
118+
it("should respect default values for pass-through state keys", async () => {
119+
// Setup mock to return undefined
120+
mockGlobalState.get.mockReturnValue(undefined)
121+
122+
// Use a pass-through key with default value
123+
const result = proxy.getGlobalState("taskHistory" as GlobalStateKey, "default-value")
124+
125+
// Should return default value when original context returns undefined
126+
expect(result).toBe("default-value")
127+
})
105128
})
106129

107130
describe("updateGlobalState", () => {
@@ -115,6 +138,21 @@ describe("ContextProxy", () => {
115138
const storedValue = await proxy.getGlobalState("apiProvider")
116139
expect(storedValue).toBe("new-value")
117140
})
141+
142+
it("should bypass cache for pass-through state keys", async () => {
143+
await proxy.updateGlobalState("taskHistory" as GlobalStateKey, "new-value")
144+
145+
// Should update original context
146+
expect(mockGlobalState.update).toHaveBeenCalledWith("taskHistory", "new-value")
147+
148+
// Setup mock for subsequent get
149+
mockGlobalState.get.mockReturnValue("new-value")
150+
151+
// Should get fresh value from original context
152+
const storedValue = proxy.getGlobalState("taskHistory" as GlobalStateKey)
153+
expect(storedValue).toBe("new-value")
154+
expect(mockGlobalState.get).toHaveBeenCalledWith("taskHistory")
155+
})
118156
})
119157

120158
describe("getSecret", () => {

src/core/contextProxy.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ConfigurationValues,
1111
isSecretKey,
1212
isGlobalStateKey,
13+
isPassThroughStateKey,
1314
} from "../shared/globalState"
1415
import { API_CONFIG_KEYS, ApiConfiguration } from "../shared/api"
1516

@@ -80,11 +81,18 @@ export class ContextProxy {
8081
getGlobalState<T>(key: GlobalStateKey): T | undefined
8182
getGlobalState<T>(key: GlobalStateKey, defaultValue: T): T
8283
getGlobalState<T>(key: GlobalStateKey, defaultValue?: T): T | undefined {
84+
if (isPassThroughStateKey(key)) {
85+
const value = this.originalContext.globalState.get(key)
86+
return value === undefined || value === null ? defaultValue : (value as T)
87+
}
8388
const value = this.stateCache.get(key) as T | undefined
8489
return value !== undefined ? value : (defaultValue as T | undefined)
8590
}
8691

8792
updateGlobalState<T>(key: GlobalStateKey, value: T) {
93+
if (isPassThroughStateKey(key)) {
94+
return this.originalContext.globalState.update(key, value)
95+
}
8896
this.stateCache.set(key, value)
8997
return this.originalContext.globalState.update(key, value)
9098
}
@@ -114,12 +122,14 @@ export class ContextProxy {
114122
setValue(key: ConfigurationKey, value: any) {
115123
if (isSecretKey(key)) {
116124
return this.storeSecret(key, value)
117-
} else if (isGlobalStateKey(key)) {
118-
return this.updateGlobalState(key, value)
119-
} else {
120-
logger.warn(`Unknown key: ${key}. Storing as global state.`)
125+
}
126+
127+
if (isGlobalStateKey(key)) {
121128
return this.updateGlobalState(key, value)
122129
}
130+
131+
logger.warn(`Unknown key: ${key}. Storing as global state.`)
132+
return this.updateGlobalState(key, value)
123133
}
124134

125135
/**

src/shared/globalState.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ export const GLOBAL_STATE_KEYS = [
124124
"maxWorkspaceFiles",
125125
] as const
126126

127+
export const PASS_THROUGH_STATE_KEYS = ["taskHistory"] as const
128+
127129
type CheckGlobalStateKeysExhaustiveness =
128130
Exclude<GlobalStateKey, (typeof GLOBAL_STATE_KEYS)[number]> extends never ? true : false
129131

@@ -133,3 +135,6 @@ export const isSecretKey = (key: string): key is SecretKey => SECRET_KEYS.includ
133135

134136
export const isGlobalStateKey = (key: string): key is GlobalStateKey =>
135137
GLOBAL_STATE_KEYS.includes(key as GlobalStateKey)
138+
139+
export const isPassThroughStateKey = (key: string): key is (typeof PASS_THROUGH_STATE_KEYS)[number] =>
140+
PASS_THROUGH_STATE_KEYS.includes(key as (typeof PASS_THROUGH_STATE_KEYS)[number])

0 commit comments

Comments
 (0)