- scenario_run_logs gains a context column (step:N, snippet:alias, assertion:pass/fail, run), tracked through a call stack in CodeExecutorService so nested runSnippet calls tag their own and inner log lines - automatic step started/passed/failed entries and the Playwright trace upload notice are tagged accordingly - run log export (CSV/Markdown) and the logs search match context as well as message - add a LogOutput UI component: a terminal-style log viewer with level color coding, elapsed-time-since-start timestamps and a context tag, replacing the generic Table on the run detail page - show the full log list instead of paginating it, capped to a scrollable block - fix migrations.spec.ts's revert test, which only undid the last migration instead of all of them
68 lines
2.5 KiB
TypeScript
68 lines
2.5 KiB
TypeScript
/**
|
|
* The schema is managed by migrations. These tests fail when an entity
|
|
* changes without a matching migration, and cover adopting databases that
|
|
* were created by `synchronize` before migrations existed.
|
|
*/
|
|
|
|
import { DataSource } from "typeorm";
|
|
import { dataSourceOptions } from "../src/database/data-source";
|
|
import { MIGRATIONS } from "../src/database/migrations";
|
|
|
|
async function pendingSchemaChanges(dataSource: DataSource): Promise<string[]> {
|
|
const sql = await dataSource.driver.createSchemaBuilder().log();
|
|
return sql.upQueries.map((q) => q.query);
|
|
}
|
|
|
|
describe("Database migrations", () => {
|
|
it("migrations produce exactly the schema the entities describe", async () => {
|
|
const dataSource = new DataSource(dataSourceOptions(":memory:"));
|
|
await dataSource.initialize();
|
|
try {
|
|
await dataSource.runMigrations();
|
|
expect(await dataSource.showMigrations()).toBe(false);
|
|
// If this fails, generate a migration: see "Database migrations" in docs/development.md
|
|
expect(await pendingSchemaChanges(dataSource)).toEqual([]);
|
|
} finally {
|
|
await dataSource.destroy();
|
|
}
|
|
});
|
|
|
|
it("adopts a database created by synchronize", async () => {
|
|
const dataSource = new DataSource({
|
|
...dataSourceOptions(":memory:"),
|
|
synchronize: true,
|
|
});
|
|
await dataSource.initialize();
|
|
try {
|
|
await dataSource.query(
|
|
`INSERT INTO scenarios (id, name, version) VALUES ('11111111-1111-4111-8111-111111111111', 'kept', 1)`,
|
|
);
|
|
const applied = await dataSource.runMigrations();
|
|
expect(applied.map((m) => m.name)).toEqual(MIGRATIONS.map((m) => m.name));
|
|
expect(await dataSource.showMigrations()).toBe(false);
|
|
expect(await pendingSchemaChanges(dataSource)).toEqual([]);
|
|
const [row] = await dataSource.query(`SELECT name FROM scenarios`);
|
|
expect(row.name).toBe("kept");
|
|
} finally {
|
|
await dataSource.destroy();
|
|
}
|
|
});
|
|
|
|
it("can revert all migrations", async () => {
|
|
const dataSource = new DataSource(dataSourceOptions(":memory:"));
|
|
await dataSource.initialize();
|
|
try {
|
|
await dataSource.runMigrations();
|
|
for (let i = 0; i < MIGRATIONS.length; i++) {
|
|
await dataSource.undoLastMigration();
|
|
}
|
|
const tables = await dataSource.query(
|
|
`SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT IN ('migrations', 'sqlite_sequence')`,
|
|
);
|
|
expect(tables).toEqual([]);
|
|
} finally {
|
|
await dataSource.destroy();
|
|
}
|
|
});
|
|
});
|