mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
fix(record): bug fix
This commit is contained in:
@@ -23,7 +23,7 @@ describe("RecordingTabCoordinator", () => {
|
||||
|
||||
expect(tabs.isLatest(second)).toBe(false);
|
||||
expect(tabs.isLatest(third)).toBe(true);
|
||||
expect(tabs.commit(6)).toBe(4);
|
||||
tabs.commit(6);
|
||||
expect(tabs.currentTabId).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,6 +48,15 @@ describe("trace reducer v3", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("does not export a tab transition without both observation endpoints", () => {
|
||||
const sourceOnly: RecordingDraftStep = { op: "switch_tab", preStateId: "s1" };
|
||||
const targetOnly: RecordingDraftStep = { op: "switch_tab", postStateId: "s2" };
|
||||
|
||||
expect(
|
||||
reduceTraceStepsV3([sourceOnly, targetOnly], { includeTabSwitches: true }).steps,
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("collapses redirect hops while retaining draft-to-step identity", () => {
|
||||
const drafts: RecordingDraftStep[] = [
|
||||
{ op: "navigate", url: "https://example.com/start", preStateId: "s1", postStateId: "s2" },
|
||||
|
||||
@@ -165,12 +165,8 @@ export class RecordingObservationRuntime {
|
||||
await context.settle.flush();
|
||||
}
|
||||
|
||||
async flushRedirects(tabId?: number): Promise<void> {
|
||||
if (tabId !== undefined) {
|
||||
await this.#contexts.get(tabId)?.settle.flushRedirects();
|
||||
return;
|
||||
}
|
||||
for (const context of this.#contexts.values()) await context.settle.flushRedirects();
|
||||
async flushRedirects(tabId: number): Promise<void> {
|
||||
await this.#contexts.get(tabId)?.settle.flushRedirects();
|
||||
}
|
||||
|
||||
async flush(): Promise<void> {
|
||||
|
||||
@@ -40,10 +40,8 @@ export class RecordingTabCoordinator {
|
||||
);
|
||||
}
|
||||
|
||||
commit(tabId: number): number {
|
||||
const previousTabId = this.#currentTabId;
|
||||
commit(tabId: number): void {
|
||||
this.#currentTabId = tabId;
|
||||
return previousTabId;
|
||||
}
|
||||
|
||||
navigation(tabId: number, fallbackUrl?: string): RecordingNavigationCursor {
|
||||
|
||||
@@ -69,6 +69,15 @@ function reduceDraft(
|
||||
options: ReduceDraftOptions,
|
||||
): StepV3 | null {
|
||||
if (!shouldIncludeDraft(draft)) return null;
|
||||
if (draft.op === "switch_tab") {
|
||||
if (!options.includeTabSwitches || !draft.preStateId || !draft.postStateId) return null;
|
||||
return {
|
||||
op: "switch_tab",
|
||||
id,
|
||||
state: draft.preStateId,
|
||||
result: { state: draft.postStateId },
|
||||
};
|
||||
}
|
||||
const state = draft.preStateId ?? draft.postStateId;
|
||||
const resultState = draft.postStateId ?? draft.preStateId;
|
||||
if (!state || !resultState) return null;
|
||||
@@ -77,8 +86,6 @@ function reduceDraft(
|
||||
switch (draft.op) {
|
||||
case "navigate":
|
||||
return { op: "navigate", ...common, to: draft.url, cause: navigationCause(draft) };
|
||||
case "switch_tab":
|
||||
return options.includeTabSwitches ? { op: "switch_tab", ...common } : null;
|
||||
case "click":
|
||||
return {
|
||||
op: "click",
|
||||
|
||||
Reference in New Issue
Block a user