fix: fix links in scenario service

This commit is contained in:
2026-04-14 21:11:35 +03:00
parent 5ec9fd0bc3
commit a71be39076
6 changed files with 50 additions and 45 deletions
+4 -4
View File
@@ -8,10 +8,10 @@ import {
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";
import { ScenarioRunStepEntity } from "./scenario-run-step.entity";
import { ScenarioEntity } from "./scenario.entity";
import { EnvironmentEntity } from "../environment/environment.entity";
import { SessionEntity } from "../session/session.entity";
import { ScenarioRunStepEntity } from "./scenario-run-step.entity";
import { ScenarioEntity } from "./scenario.entity";
export type RunStatus = "pending" | "in_progress" | "pass" | "fail";
@@ -23,8 +23,8 @@ export class ScenarioRunEntity {
@Column("text")
scenarioId: string;
@Column("text", { default: "" })
environmentId: string;
@Column("text", { nullable: true, default: null })
environmentId: string | null;
@ManyToOne(() => ScenarioEntity, { onDelete: "CASCADE" })
@JoinColumn({ name: "scenarioId" })
@@ -7,6 +7,7 @@ import { chromium } from "playwright";
import { Repository } from "typeorm";
import type { ScriptLogger } from "../code-executor/code-executor.service";
import { CodeExecutorService } from "../code-executor/code-executor.service";
import { ExecContextBuilder } from "../code-executor/exec-context.builder";
import { traceStorage } from "../common/trace-context";
import { TraceLogger } from "../common/trace-logger";
import { EnvironmentData, EnvironmentEntity } from "../environment/environment.entity";
@@ -170,7 +171,9 @@ export class ScenarioSchedulerService {
}
const handle = this.runBrowsers.get(runId);
if (!handle) return;
if (!handle) {
return;
}
const sessionName = `run-${runId}`;
try {
@@ -184,7 +187,8 @@ export class ScenarioSchedulerService {
cookies.find((c) => c.name === "token")?.value ??
"";
await this.sessionService.upsert(sessionName, token, cookies, localStorage);
const session = await this.sessionService.upsert(sessionName, token, cookies, localStorage);
await this.runRepo.update(runId, { sessionId: session.id });
this.sessionContextService.register(
sessionName,
handle.browser,
@@ -194,7 +198,7 @@ export class ScenarioSchedulerService {
// Remove from runBrowsers so closeBrowserHandle won't close it
this.runBrowsers.delete(runId);
this.logger.log(
`Run #${runId}: browser preserved as session "${sessionName}"`,
`Run #${runId}: browser preserved as session "${sessionName}" (${session.id})`,
);
} catch (err) {
this.logger.warn(
@@ -223,16 +227,17 @@ 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({
page,
browser: context,
code: step.execCode,
log: this.stepLogger(stepRun.id, stepRun.runId),
getStepOutput,
credentials: creds,
environment: env,
snippets: snips,
});
const execCtx = new ExecContextBuilder()
.page(page)
.browser(context)
.code(step.execCode)
.log(this.stepLogger(stepRun.id, stepRun.runId))
.getStepOutput(getStepOutput)
.credentials(creds)
.environment(env)
.snippets(snips)
.build();
const { result: execOutput } = await this.codeExecutor.execute(execCtx);
await this.passStepRun(stepRun, null, execOutput);
} catch (err) {
@@ -310,7 +315,8 @@ export class ScenarioSchedulerService {
],
});
if (remaining === 0) {
await this.closeBrowserHandle(stepRun.runId);
// Don't close the browser here — maybePreserveSession will handle it
// (either preserving it if saveSession=true, or closing if false)
await this.runRepo.update(stepRun.runId, { status: "pass" });
this.logger.log(`Run #${stepRun.runId} → pass (all steps passed)`);
}
+2 -2
View File
@@ -322,7 +322,7 @@ export class ScenarioService {
await this.findOne(scenarioId); // 404 guard
const run = await this.runRepo.findOne({
where: { id: runId, scenarioId },
relations: ["stepRuns", "stepRuns.scenarioStep"],
relations: ["stepRuns", "stepRuns.scenarioStep", "environment", "session"],
order: { stepRuns: { order: "ASC" } },
});
if (!run)
@@ -387,7 +387,7 @@ export class ScenarioService {
return this.runRepo.findOne({
where: { id: run.id },
relations: ["stepRuns"],
relations: ["stepRuns", "environment", "session"],
order: { stepRuns: { order: "ASC" } },
}) as Promise<ScenarioRunEntity>;
}