|
1 | 1 | import assert from "node:assert/strict"; |
2 | 2 | import { readFileSync } from "node:fs"; |
| 3 | +import { performance } from "node:perf_hooks"; |
3 | 4 | import test from "node:test"; |
4 | 5 |
|
5 | 6 | import { |
@@ -444,6 +445,41 @@ test("SQLite schema detector finds production table changes and ignores non-sche |
444 | 445 | }); |
445 | 446 | }); |
446 | 447 |
|
| 448 | +test("production path classification preserves test segment and basename boundaries", () => { |
| 449 | + const cases = [ |
| 450 | + ["test/schema.sql", false], |
| 451 | + ["src/__TESTS__/schema.sql", false], |
| 452 | + ["examples/schema.sql", false], |
| 453 | + ["src/cache/store.spec.ts", false], |
| 454 | + ["src/cache/store.TEST.TS", false], |
| 455 | + ["src/spec/schema.sql", true], |
| 456 | + ["src/test-fixtures/schema.sql", true], |
| 457 | + ["src/cache/store.spec.", true], |
| 458 | + ["src/cache/store.spec.unit.spec.", false], |
| 459 | + ] as const; |
| 460 | + |
| 461 | + for (const [filename, expectedChange] of cases) { |
| 462 | + const detection = sqliteSchemaChangeFromPullFilesForTest({ |
| 463 | + pullFiles: [{ filename, patch: "@@\n+CREATE TABLE example (id TEXT);" }], |
| 464 | + }); |
| 465 | + |
| 466 | + assert.equal(detection.change, expectedChange, filename); |
| 467 | + } |
| 468 | +}); |
| 469 | + |
| 470 | +test("production path classification is bounded for repeated test markers", () => { |
| 471 | + const filename = `${".spec.".repeat(20_000)}/schema.sql`; |
| 472 | + const startedAt = performance.now(); |
| 473 | + const detection = sqliteSchemaChangeFromPullFilesForTest({ |
| 474 | + pullFiles: [{ filename, patch: "@@\n+CREATE TABLE example (id TEXT);" }], |
| 475 | + }); |
| 476 | + const elapsedMs = performance.now() - startedAt; |
| 477 | + |
| 478 | + assert.equal(detection.change, true); |
| 479 | + assert.equal(detection.files.length, 1); |
| 480 | + assert.ok(elapsedMs < 250, `classification took ${elapsedMs.toFixed(1)}ms`); |
| 481 | +}); |
| 482 | + |
447 | 483 | test("SQLite schema warning is visible for table changes and absent otherwise", () => { |
448 | 484 | const reportBody = ` |
449 | 485 |
|
|
0 commit comments