Skip to content

Commit 2929dde

Browse files
committed
fix: recheck workshop scan access after refresh
1 parent a919f22 commit 2929dde

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎ui/src/pages/skill-workshop/history-scan.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,31 @@ describe("Skill Workshop history scan controller", () => {
142142
});
143143
});
144144

145+
it("does not scan through a read-only replacement client after a status retry", async () => {
146+
const status = deferred<SkillWorkshopHistoryScanResult>();
147+
const oldRequest = vi.fn(() => status.promise);
148+
const newRequest = vi.fn();
149+
const state = createSkillWorkshopHistoryScanState();
150+
state.loaded = true;
151+
const appGateway = gateway(oldRequest);
152+
153+
const scan = runSkillWorkshopHistoryScan({ agentId: "main", gateway: appGateway, state });
154+
await vi.waitFor(() => expect(oldRequest).toHaveBeenCalledTimes(1));
155+
(appGateway.snapshot as unknown as { client: { request: typeof newRequest } }).client = {
156+
request: newRequest,
157+
};
158+
(appGateway.snapshot as ApplicationGateway["snapshot"]).hello = {
159+
type: "hello-ok",
160+
protocol: 4,
161+
auth: { role: "operator", scopes: ["operator.read"] },
162+
features: { methods: ["skills.proposals.historyScan"] },
163+
} as ApplicationGateway["snapshot"]["hello"];
164+
status.resolve(result());
165+
166+
await expect(scan).resolves.toBe(false);
167+
expect(newRequest).not.toHaveBeenCalled();
168+
});
169+
145170
it("does not race a scan against status loading", async () => {
146171
let resolveStatus: ((value: SkillWorkshopHistoryScanResult) => void) | undefined;
147172
const request = vi.fn(

‎ui/src/pages/skill-workshop/history-scan.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,16 @@ export async function runSkillWorkshopHistoryScan(params: {
114114
if (!params.state.result) {
115115
return false;
116116
}
117-
client = params.gateway.snapshot.client;
118-
if (!client || params.gateway.snapshot.phase !== "connected") {
117+
if (
118+
!canCallGatewayMethod(
119+
params.gateway.snapshot,
120+
"skills.proposals.historyScan",
121+
"operator.admin",
122+
)
123+
) {
119124
return false;
120125
}
126+
client = params.gateway.snapshot.client;
121127
}
122128
const direction = params.state.result.hasScanned
123129
? params.state.result.hasMore

0 commit comments

Comments
 (0)