@ultimat3/testing 31.15.0 → 31.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +4 -0
- package/README.md +5 -1
- package/package.json +22 -22
- package/src/define-exercise.ts +28 -4
- package/src/errors.ts +7 -0
- package/src/exercise-crash.ts +9 -1
- package/src/exercise-report.ts +3 -0
- package/src/exercise-route-loads.ts +205 -0
- package/src/exercise-route-subjects.ts +162 -0
- package/src/exercise-statement-ceiling.ts +147 -0
- package/src/exercise-sweeps.ts +9 -6
- package/src/exercise.ts +48 -8
- package/src/fixture-jobs.ts +1 -1
- package/src/index.ts +19 -0
- package/src/scale-sweep-findings.ts +46 -0
- package/src/scale-sweep-run.ts +21 -13
- package/src/scale-sweep-seed.ts +140 -0
- package/src/scale-sweep.ts +19 -6
- package/src/seed-graph-values.ts +4 -1
- package/src/seed-graph.ts +5 -1
- package/src/sql-tables.ts +61 -0
package/src/scale-sweep.ts
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// sent more often when the tables hold more rows is a loop over rows — an N+1 no test named — and
|
|
3
3
|
// red, unless `expectedQueryLoop` scoped it, which is reported with its reason. Pure: tallies in.
|
|
4
4
|
|
|
5
|
+
import type { ScaleSeedFailure } from './scale-sweep-seed';
|
|
6
|
+
|
|
5
7
|
/** One statement shape in one call: every statement, and the ones no `expectedQueryLoop` covered. */
|
|
6
8
|
export interface StatementTally {
|
|
7
9
|
/** `statementFingerprint`: `posts.findById` when attributed, else the collapsed text. */
|
|
@@ -29,8 +31,11 @@ export type ScaleProof =
|
|
|
29
31
|
readonly shapes: readonly ScaleShape[];
|
|
30
32
|
readonly expected: readonly ScaleShape[];
|
|
31
33
|
}
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
+
/**
|
|
35
|
+
* A call at one size did not answer as at the other: the counts are not comparable. Never red
|
|
36
|
+
* itself; `seed` is the sized table it read and could not be written, `X_EXERCISE_SEED_FAILED`.
|
|
37
|
+
*/
|
|
38
|
+
| { readonly verdict: 'unproven'; readonly reason: string; readonly seed?: ScaleSeedFailure };
|
|
34
39
|
|
|
35
40
|
/** Rows a table per tenant at each size: a loop over them sends 2 statements, then 8. */
|
|
36
41
|
export const SCALE_SIZES = { small: 2, large: 8 } as const;
|
|
@@ -38,7 +43,10 @@ export const SCALE_SIZES = { small: 2, large: 8 } as const;
|
|
|
38
43
|
/**
|
|
39
44
|
* Per shape, the large run against the small one. Only unexpected statements are judged; a shape
|
|
40
45
|
* that grew only under an `expectedQueryLoop` is listed beside the verdict with its reason. A shape
|
|
41
|
-
* absent at the small size and
|
|
46
|
+
* absent at the small size and sent exactly ONCE at the large one is a different PATH, not a loop:
|
|
47
|
+
* the two calls branched on what they were handed. Only that is `unproven`. One sent more than once
|
|
48
|
+
* where it was absent is a loop over rows the small graph held none of (a filter on the third enum
|
|
49
|
+
* value, which two rows never reach) — red, as is a shape that grew from one or more.
|
|
42
50
|
*/
|
|
43
51
|
export function judgeScale(
|
|
44
52
|
small: readonly StatementTally[],
|
|
@@ -68,7 +76,12 @@ export function judgeScale(
|
|
|
68
76
|
a.fingerprint.localeCompare(b.fingerprint);
|
|
69
77
|
shapes.sort(byName);
|
|
70
78
|
expected.sort(byName);
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
79
|
+
if (shapes.length === 0) return { verdict: 'flat', expected };
|
|
80
|
+
const grown = shapes.filter((shape) => shape.small > 0 || shape.large > 1);
|
|
81
|
+
if (grown.length > 0) return { verdict: 'grows', shapes: grown, expected };
|
|
82
|
+
const appeared = shapes.map((shape) => `${shape.fingerprint} 0 → ${shape.large}`).join(', ');
|
|
83
|
+
return {
|
|
84
|
+
verdict: 'unproven',
|
|
85
|
+
reason: `the call took another path at ${SCALE_SIZES.large} rows than at ${SCALE_SIZES.small} (${appeared}): a branch on the row it was handed, so the counts are not comparable`,
|
|
86
|
+
};
|
|
74
87
|
}
|
package/src/seed-graph-values.ts
CHANGED
|
@@ -15,7 +15,10 @@ export interface SeedColumn {
|
|
|
15
15
|
|
|
16
16
|
/** What one row lends every column it generates: its place, its canary and its id stream. */
|
|
17
17
|
export interface ValueContext {
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* 1-based. For a unique column it continues past the graph written before (`beside`), so a value
|
|
20
|
+
* derived from it is unique per table; for any other column it restarts with each graph.
|
|
21
|
+
*/
|
|
19
22
|
readonly ordinal: number;
|
|
20
23
|
/** The row's canary: lower-case hex, so it survives a slug or a handle pattern. */
|
|
21
24
|
readonly canary: string;
|
package/src/seed-graph.ts
CHANGED
|
@@ -209,6 +209,10 @@ export function seedGraph(
|
|
|
209
209
|
// Positions continue past the graph written before this one: a reset factory rebuilt that
|
|
210
210
|
// graph's first values, and a unique column refused the second copy.
|
|
211
211
|
const start = besideNext[name] ?? 0;
|
|
212
|
+
// Only a unique column needs the continued position. Every other value is drawn from the row's
|
|
213
|
+
// place in THIS graph, so the scale sweep's 8-row graph opens on the 2-row graph's values and a
|
|
214
|
+
// branch on the handed row takes one path at both sizes (`scale-sweep-branch.test.ts`).
|
|
215
|
+
const uniqueColumns = new Set(allUniques.flat());
|
|
212
216
|
for (let skipped = 0; factory !== undefined && skipped < start; skipped += 1) factory.build();
|
|
213
217
|
let ordinal = start;
|
|
214
218
|
for (const [bucket, tenant] of buckets.entries()) {
|
|
@@ -245,7 +249,7 @@ export function seedGraph(
|
|
|
245
249
|
valuesInWindow(partitioned.kind, window, ordinal, position),
|
|
246
250
|
)
|
|
247
251
|
: candidatesFor(property, column, {
|
|
248
|
-
ordinal,
|
|
252
|
+
ordinal: uniqueColumns.has(property) ? ordinal : ordinal - start,
|
|
249
253
|
canary,
|
|
250
254
|
position,
|
|
251
255
|
patterns: patterns.get(property),
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// The tables one SQL statement reads or writes, read without a parser: each name after `from`,
|
|
2
|
+
// `join`, `update`, `into` or `using`, and each further name of a comma list there (`from orgs o,
|
|
3
|
+
// posts p`). Schema-qualified and double-quoted names answer their last part, lowercased.
|
|
4
|
+
|
|
5
|
+
// Whitespace, `as` and the comma are scanned by index, so no regex here can backtrack
|
|
6
|
+
// (CodeQL js/polynomial-redos).
|
|
7
|
+
|
|
8
|
+
const CLAUSE = /\b(?:from|join|update|into|using)\s+/gi;
|
|
9
|
+
const NAME = /(?:"([^"]+)"|(\w+))(?:\.(?:"([^"]+)"|(\w+)))?/y;
|
|
10
|
+
const WORD = /\w+/y;
|
|
11
|
+
const SPACE = /\s/;
|
|
12
|
+
/** The words that end a list: never read as an alias. */
|
|
13
|
+
const NOT_ALIAS = new Set(
|
|
14
|
+
'where on set join inner left right full cross natural group order limit offset returning values using union except intersect having window for select default lateral do when then'.split(
|
|
15
|
+
' ',
|
|
16
|
+
),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
function skipSpace(s: string, i: number): number {
|
|
20
|
+
let at = i;
|
|
21
|
+
while (at < s.length && SPACE.test(s.charAt(at))) at++;
|
|
22
|
+
return at;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The `\w+` at `at`, or null. */
|
|
26
|
+
function wordAt(s: string, at: number): string | null {
|
|
27
|
+
WORD.lastIndex = at;
|
|
28
|
+
return WORD.exec(s)?.[0] ?? null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Past an alias — `as p` or bare `p` — after whitespace at `at`; `at` itself when there is none. */
|
|
32
|
+
function skipAlias(s: string, at: number): number {
|
|
33
|
+
const start = skipSpace(s, at);
|
|
34
|
+
if (start === at) return at;
|
|
35
|
+
const word = wordAt(s, start);
|
|
36
|
+
if (word === null) return at;
|
|
37
|
+
if (word.toLowerCase() === 'as') {
|
|
38
|
+
const next = skipSpace(s, start + 2);
|
|
39
|
+
const alias = next > start + 2 ? wordAt(s, next) : null;
|
|
40
|
+
if (alias !== null && !NOT_ALIAS.has(alias.toLowerCase())) return next + alias.length;
|
|
41
|
+
}
|
|
42
|
+
return NOT_ALIAS.has(word.toLowerCase()) ? at : start + word.length;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Every table `statement` names in a table position, in order, repeats kept. */
|
|
46
|
+
export function statementTables(statement: string): readonly string[] {
|
|
47
|
+
const tables: string[] = [];
|
|
48
|
+
for (const clause of statement.matchAll(CLAUSE)) {
|
|
49
|
+
let at = clause.index + clause[0].length;
|
|
50
|
+
for (;;) {
|
|
51
|
+
NAME.lastIndex = at;
|
|
52
|
+
const name = NAME.exec(statement);
|
|
53
|
+
if (name === null) break;
|
|
54
|
+
tables.push((name[3] ?? name[4] ?? name[1] ?? name[2] ?? '').toLowerCase());
|
|
55
|
+
at = skipSpace(statement, skipAlias(statement, NAME.lastIndex));
|
|
56
|
+
if (statement.charAt(at) !== ',') break;
|
|
57
|
+
at = skipSpace(statement, at + 1);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return tables;
|
|
61
|
+
}
|