feat(versioning): version scenarios and snippets, bump to 1.16.0

- snapshot scenario and snippet content into version tables on every
  content change; live tables keep holding the latest version
- record the scenario version on each run and copy its steps into the
  run steps, so runs execute and show the version they were created with
- keep run step history when a step is deleted (FK set null)
- pin a snippet version with runSnippet('alias@N')
- add version picker to the run modal and version info across the UI
- add version list/get endpoints and MCP tools
- include version in exports and require it on import, restoring the
  exact version by id + version
This commit is contained in:
ars9 committed 2026-09-30 15:24:44 +03:00
1 parent a328ef5ea7
commit ff83b6c7da
40 files changed
+1457 -137

No files matched your search

@@ -27,7 +27,6 @@ import { SnippetService } from "../snippet/snippet.service";
import { ScenarioRunLogEntity } from "./scenario-run-log.entity";
import { ScenarioRunStepEntity } from "./scenario-run-step.entity";
import { ScenarioRunEntity } from "./scenario-run.entity";
import { ScenarioStepEntity } from "./scenario-step.entity";
import { ScenarioService } from "./scenario.service";
interface BrowserHandle {
@@ -215,10 +214,19 @@ export class ScenarioSchedulerService implements OnModuleInit {
.then((env) => env?.data ?? {})
.catch(() => ({}) as EnvironmentData);
this.runEnvironments.set(run.id, environmentData);
const scenario = await this.scenarioService
.findOne(run.scenarioId)
.catch(() => null);
this.runScenarioTimeouts.set(run.id, scenario?.timeoutSeconds ?? null);
// Legacy runs (no scenarioVersion) fall back to the live scenario
const versioned =
run.scenarioVersion != null
? await this.scenarioService
.findVersion(run.scenarioId, run.scenarioVersion)
.catch(() => null)
: await this.scenarioService
.findOne(run.scenarioId)
.catch(() => null);
this.runScenarioTimeouts.set(
run.id,
versioned?.timeoutSeconds ?? null,
);
this.runScenarioIds.set(run.id, run.scenarioId);
this.runTraceModes.set(
run.id,
@@ -263,7 +271,6 @@ export class ScenarioSchedulerService implements OnModuleInit {
try {
let stepRun = await this.runStepRepo.findOne({
where: { runId, status: "pending" },
relations: ["scenarioStep"],
order: { order: "ASC" },
});
while (stepRun) {
@@ -280,7 +287,6 @@ export class ScenarioSchedulerService implements OnModuleInit {
await this.executeStepRun(stepRun);
stepRun = await this.runStepRepo.findOne({
where: { runId, status: "pending" },
relations: ["scenarioStep"],
order: { order: "ASC" },
});
}
@@ -365,12 +371,13 @@ export class ScenarioSchedulerService implements OnModuleInit {
}
private async executeStepRun(stepRun: ScenarioRunStepEntity): Promise<void> {
const step = stepRun.scenarioStep as ScenarioStepEntity;
// Run steps carry a copy of the step from the run's scenario version
const step = stepRun;
stepRun.status = "in_progress";
await this.runStepRepo.save(stepRun);
this.logger.log(
`StepRun #${stepRun.id} (run #${stepRun.runId}, step #${step.id} order=${step.order}) → in_progress`,
`StepRun #${stepRun.id} (run #${stepRun.runId}, step #${step.scenarioStepId ?? "deleted"} order=${step.order}) → in_progress`,
);
this.persistLog(
stepRun.runId,
@@ -549,7 +556,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
stepRun.runId,
stepRun.id,
"log",
`Step ${(stepRun.scenarioStep as ScenarioStepEntity | undefined)?.order ?? "?"} passed`,
`Step ${stepRun.order} passed`,
);
// Find the next waiting step in this run (next by order)
@@ -591,7 +598,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
stepRun.runId,
stepRun.id,
"error",
`Step ${(stepRun.scenarioStep as ScenarioStepEntity | undefined)?.order ?? "?"} failed: ${description}`,
`Step ${stepRun.order} failed: ${description}`,
);
await this.dumpPageOnFailure(stepRun);
@@ -624,8 +631,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
const handle = this.runBrowsers.get(stepRun.runId);
if (!handle) return; // no browser was ever opened for this run (e.g. setup error)
const step = stepRun.scenarioStep as ScenarioStepEntity | undefined;
const namePrefix = `step-${step?.order ?? stepRun.id}-failure`;
const namePrefix = `step-${stepRun.order}-failure`;
try {
const screenshot = await handle.page.screenshot({ fullPage: true });
@@ -659,7 +665,7 @@ export class ScenarioSchedulerService implements OnModuleInit {
stepRun.runId,
stepRun.id,
"log",
`Step ${step?.order ?? "?"} failed: page dump uploaded to run files`,
`Step ${stepRun.order} failed: page dump uploaded to run files`,
);
}
}