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
@@ -72,7 +72,7 @@ export class ScenarioSchedulerService {
|
||||
): (order: number) => Promise<unknown> {
|
||||
return async (order: number) => {
|
||||
const targetOrder = order < 0 ? stepRun.order + order : order;
|
||||
if (targetOrder < 0) return null;
|
||||
if (targetOrder < 1) return null;
|
||||
const sr = await this.runStepRepo.findOne({
|
||||
where: { runId: stepRun.runId, order: targetOrder },
|
||||
});
|
||||
@@ -172,16 +172,16 @@ export class ScenarioSchedulerService {
|
||||
const creds = this.runCredentials.get(stepRun.runId);
|
||||
const snips = this.runSnippets.get(stepRun.runId);
|
||||
const env = this.runEnvironments.get(stepRun.runId);
|
||||
const { result: execOutput } = await this.codeExecutor.execute(
|
||||
const { result: execOutput } = await this.codeExecutor.execute({
|
||||
page,
|
||||
context,
|
||||
step.execCode,
|
||||
this.stepLogger(stepRun.id, stepRun.runId),
|
||||
browser: context,
|
||||
code: step.execCode,
|
||||
log: this.stepLogger(stepRun.id, stepRun.runId),
|
||||
getStepOutput,
|
||||
creds,
|
||||
env,
|
||||
snips,
|
||||
);
|
||||
credentials: creds,
|
||||
environment: env,
|
||||
snippets: snips,
|
||||
});
|
||||
|
||||
await this.passStepRun(stepRun, null, execOutput);
|
||||
} catch (err) {
|
||||
|
||||
@@ -104,8 +104,8 @@ export class ScenarioService {
|
||||
});
|
||||
for (let i = 0; i < ordered.length; i += 1) {
|
||||
const step = ordered[i];
|
||||
if (step.order !== i) {
|
||||
step.order = i;
|
||||
if (step.order !== i + 1) {
|
||||
step.order = i + 1;
|
||||
await this.stepRepo.save(step);
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ export class ScenarioService {
|
||||
const created = await this.stepRepo.save(
|
||||
this.stepRepo.create({
|
||||
...dto,
|
||||
order: currentCount,
|
||||
order: currentCount + 1,
|
||||
scenarioId,
|
||||
title: dto.title ?? null,
|
||||
execCode: dto.execCode ?? null,
|
||||
|
||||
Reference in new issue
Block a user