refactor(code-executor): migrate user scripts to single context argument
- replace (page, context, helpers) signature with async (context) => {}
- add ScriptContext interface exposing page, browser, env, getEnv,
getCredential, getStepOutput, runSnippet, dumpDom, log/warn/error
- rename getEnvUrl to getEnv throughout service and docs
- fix step ordering: normalizeStepOrder and run step rows are now 1-based
- migrate existing DB rows (scenario_steps, scenario_run_steps) +1
- update all tests and stored snippet/step code in DB to new API
This commit is contained in:
1 parent
1a2e786ca8
commit
90be5a5490
10 files changed
+166
-91
No files matched your search
@@ -0,0 +1,59 @@
|
||||
import type { Page, BrowserContext } from "playwright";
|
||||
import type { ExecContext, ScriptLogger } from "./code-executor.service";
|
||||
import type { EnvironmentData } from "../environment/environment.entity";
|
||||
|
||||
export class ExecContextBuilder {
|
||||
private readonly ctx: Partial<ExecContext> = {};
|
||||
|
||||
page(page: Page): this {
|
||||
this.ctx.page = page;
|
||||
return this;
|
||||
}
|
||||
|
||||
browser(browser: BrowserContext): this {
|
||||
this.ctx.browser = browser;
|
||||
return this;
|
||||
}
|
||||
|
||||
code(code: string): this {
|
||||
this.ctx.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
log(log: ScriptLogger): this {
|
||||
this.ctx.log = log;
|
||||
return this;
|
||||
}
|
||||
|
||||
getStepOutput(fn: (order: number) => Promise<unknown>): this {
|
||||
this.ctx.getStepOutput = fn;
|
||||
return this;
|
||||
}
|
||||
|
||||
credentials(credentials: Record<string, unknown>): this {
|
||||
this.ctx.credentials = credentials;
|
||||
return this;
|
||||
}
|
||||
|
||||
environment(environment: EnvironmentData | null): this {
|
||||
this.ctx.environment = environment;
|
||||
return this;
|
||||
}
|
||||
|
||||
snippets(snippets: Record<string, string> | null): this {
|
||||
this.ctx.snippets = snippets;
|
||||
return this;
|
||||
}
|
||||
|
||||
result(result: unknown): this {
|
||||
this.ctx.result = result;
|
||||
return this;
|
||||
}
|
||||
|
||||
build(): ExecContext {
|
||||
if (!this.ctx.page) throw new Error("ExecContextBuilder: page is required");
|
||||
if (!this.ctx.browser) throw new Error("ExecContextBuilder: browser is required");
|
||||
if (this.ctx.code === undefined) throw new Error("ExecContextBuilder: code is required");
|
||||
return this.ctx as ExecContext;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user