@hublo/sentinel 1.7.0-alpha.3 → 1.7.0-alpha.31

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.
Files changed (70) hide show
  1. package/README.md +4 -0
  2. package/dist/bin/sentinel.js +95 -82
  3. package/dist/chunk-2DUG6GVU.js +19301 -0
  4. package/dist/chunk-F5WISUN3.js +17 -0
  5. package/dist/chunk-F5WISUN3.js.map +1 -0
  6. package/dist/{chunk-P6KTBQ2Q.js → chunk-FZLUCPST.js} +24 -15
  7. package/dist/{chunk-ZNANJEMK.js → chunk-KKHKRY7P.js} +40 -16
  8. package/dist/chunk-KKHKRY7P.js.map +1 -0
  9. package/dist/chunk-NE3IEJBN.js +59 -0
  10. package/dist/chunk-NE3IEJBN.js.map +1 -0
  11. package/dist/chunk-NGLEGAEN.js +190 -0
  12. package/dist/chunk-NGLEGAEN.js.map +1 -0
  13. package/dist/chunk-PXTU5MPW.js +9 -0
  14. package/dist/chunk-PXTU5MPW.js.map +1 -0
  15. package/dist/{chunk-4YQXLPJ5.js → chunk-QMIJ4ZGJ.js} +2 -2
  16. package/dist/chunk-TMVKYXZ3.js +18 -0
  17. package/dist/chunk-TMVKYXZ3.js.map +1 -0
  18. package/dist/chunk-U7G2Y6YC.js +15 -0
  19. package/dist/chunk-U7G2Y6YC.js.map +1 -0
  20. package/dist/chunk-VWASE6NN.js +34 -0
  21. package/dist/chunk-VWASE6NN.js.map +1 -0
  22. package/dist/{chunk-THTXP2QU.js → chunk-XMAXE2Q2.js} +10 -7
  23. package/dist/chunk-XMAXE2Q2.js.map +1 -0
  24. package/dist/chunk-XYOIXC6A.js +126 -0
  25. package/dist/chunk-XYOIXC6A.js.map +1 -0
  26. package/dist/chunk-ZZMYV576.js +297 -0
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +14 -5
  29. package/dist/{migrate-NWQ3LYER.js → migrate-X7PB2X7R.js} +237 -228
  30. package/dist/roles/arch/config.d.ts +25 -0
  31. package/dist/roles/arch/config.js +8 -0
  32. package/dist/roles/arch/config.js.map +1 -0
  33. package/dist/roles/build/nest/toolchain.js +3 -3
  34. package/dist/roles/code-churn/config.d.ts +92 -0
  35. package/dist/roles/code-churn/config.js +10 -0
  36. package/dist/roles/code-churn/config.js.map +1 -0
  37. package/dist/roles/runtime-analysis/config.d.ts +97 -0
  38. package/dist/roles/runtime-analysis/config.js +10 -0
  39. package/dist/roles/runtime-analysis/config.js.map +1 -0
  40. package/dist/roles/runtime-analysis/gateway.d.ts +2 -0
  41. package/dist/roles/runtime-analysis/gateway.js +89 -0
  42. package/dist/roles/runtime-analysis/gateway.js.map +1 -0
  43. package/dist/roles/runtime-analysis/mock-api.d.ts +2 -0
  44. package/dist/roles/runtime-analysis/mock-api.js +43 -0
  45. package/dist/roles/runtime-analysis/mock-api.js.map +1 -0
  46. package/dist/roles/sql/config.d.ts +68 -0
  47. package/dist/roles/sql/config.js +8 -0
  48. package/dist/roles/sql/config.js.map +1 -0
  49. package/dist/roles/static-analysis/config.js +2 -1
  50. package/dist/roles/test/setup/file-boundary.js +3 -3
  51. package/dist/roles/test/setup/jest-parity.js +4 -4
  52. package/dist/roles/test/setup/workspace-entry.js +2 -2
  53. package/dist/{validate-4V3EGTXN.js → validate-GTBRD2M4.js} +2 -2
  54. package/docs/arch-adoption.md +201 -0
  55. package/docs/code-churn-adoption.md +237 -0
  56. package/docs/runtime-analysis-adoption.md +198 -0
  57. package/docs/sql-adoption.md +598 -0
  58. package/docs/static-analysis-adoption.md +1 -1
  59. package/docs/static-analysis-study.md +49 -10
  60. package/docs/typescript-adoption.md +47 -6
  61. package/docs/typescript-traces.md +512 -8
  62. package/docs/using-sentinel.md +4 -2
  63. package/package.json +25 -2
  64. package/runtime-analysis-deps/load.mjs +6 -0
  65. package/runtime-analysis-deps/package-lock.json +1766 -0
  66. package/runtime-analysis-deps/package.json +11 -0
  67. package/dist/chunk-F6ART7RH.js +0 -9555
  68. package/dist/chunk-THTXP2QU.js.map +0 -1
  69. package/dist/chunk-ZNANJEMK.js.map +0 -1
  70. /package/dist/{chunk-4YQXLPJ5.js.map → chunk-QMIJ4ZGJ.js.map} +0 -0
@@ -0,0 +1,92 @@
1
+ interface CodeChurnDefaults {
2
+ /** The two durations the figure is made of, in days. */
3
+ window: {
4
+ /**
5
+ * How long after a line is written a change to it counts as rework. 21 days, the window
6
+ * Sourcegraph uses ("code rewritten or deleted within three weeks of being written"); DevStats
7
+ * gives 14 to 21. A change after it is maintenance, not rework, and is not counted.
8
+ */
9
+ reworkDays: number;
10
+ /**
11
+ * How far back the lines that are measured were written, in days, ending `reworkDays` before
12
+ * the newest commit read. The period stops there so every line it holds has had its full
13
+ * window: a line written yesterday cannot have been rewritten yet, and counting it would lower
14
+ * the figure for a reason that has nothing to do with the code.
15
+ */
16
+ periodDays: number;
17
+ };
18
+ /**
19
+ * A commit that touches more files than this IN THE MODULE is a sweep, a formatter run or a
20
+ * rename sweep, and its lines are not counted. Counted in the module and not in the repository,
21
+ * which was measured: see `churn.ts`, "What is not counted".
22
+ */
23
+ maxFilesPerCommit: number;
24
+ /**
25
+ * Where a module's figure stands, in percent, and below how many added lines it has none.
26
+ *
27
+ * Calibrated on hublo/monorepo `main` f12da701121 (2026-07-28 to 2026-10-26): of the 113 sentinel
28
+ * modules, 33 added no line and 44 fewer than 500 (26 in the median), where one rewrite moves the
29
+ * figure by points; over the 36 others, the 25th, 75th and 90th percentiles are 3.1, 11.4 and
30
+ * 15.9%, rounded DOWN to 3, 11 and 16. They say where a module stands among those modules, never
31
+ * whether its code is good, and are recalibrated by a sweep at each stable release.
32
+ */
33
+ levels: {
34
+ /** Below this many lines added in the period, the module is `quiet`: no percentage stated. */
35
+ minimumAdded: number;
36
+ /** Under this, `low`. */
37
+ low: number;
38
+ /** Over this, `above`. Between `low` and it, `usual`. */
39
+ above: number;
40
+ /** Over this, `watch`. */
41
+ watch: number;
42
+ };
43
+ /** The files whose lines are measured, as globs relative to the module. */
44
+ include: string[];
45
+ /**
46
+ * Measure the tests too. OFF by default: the figure is about the product code, and a test
47
+ * rewritten with the code it checks is the expected case, not rework. A module that decides
48
+ * otherwise sets it to true, and the report says so.
49
+ */
50
+ includeTests: boolean;
51
+ /** What counts as a test, by path. The list the sql role measured, extended to JavaScript. */
52
+ tests: string[];
53
+ /**
54
+ * Files never measured, whatever `include` says: generated and built output. `*.gen.*` is
55
+ * TanStack Router's `routeTree.gen.ts`, regenerated on every route change (career, console and
56
+ * host-admin on hublo/monorepo): measured, it was one of host-admin's most changed files.
57
+ */
58
+ ignore: string[];
59
+ /** How many files the report lists, highest churn first. */
60
+ listed: number;
61
+ }
62
+
63
+ type DeepPartial<T> = {
64
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
65
+ };
66
+ /** What a module's config file passes. Everything is optional, including the file itself. */
67
+ interface CodeChurnInput {
68
+ /** The module's own directory, normally `import.meta.dirname`. */
69
+ root?: string;
70
+ /** The seam. Replaces whatever it names, and every path it sets lands in `moved`. */
71
+ overrides?: DeepPartial<CodeChurnDefaults>;
72
+ }
73
+ interface ResolvedCodeChurnConfig extends CodeChurnDefaults {
74
+ /** The module's directory, or null when its config file did not say. */
75
+ root: string | null;
76
+ /** Dotted paths the module set through `overrides`, sorted so two runs print the same report. */
77
+ moved: string[];
78
+ }
79
+ /** Resolve a module's declaration against this role's defaults. */
80
+ declare function defineCodeChurn(input?: CodeChurnInput): ResolvedCodeChurnConfig;
81
+ /**
82
+ * The settings of a resolved config that cannot be measured with, one sentence each naming the
83
+ * setting and the value. Empty when the config is usable.
84
+ *
85
+ * ⛔ Checked rather than trusted: a negative window runs the period into the future, a `listed` of
86
+ * -1 drops the last file through `slice(0, -1)`, a cap of 0 makes every commit a sweep, an empty
87
+ * `include` measures nothing, levels that do not rise put every module in two bands at once, and
88
+ * none of them says so. Each one is a figure that looks right.
89
+ */
90
+ declare function invalidSettings(config: CodeChurnDefaults): string[];
91
+
92
+ export { type CodeChurnInput, type ResolvedCodeChurnConfig, defineCodeChurn, invalidSettings };
@@ -0,0 +1,10 @@
1
+ import {
2
+ defineCodeChurn,
3
+ invalidSettings
4
+ } from "../../chunk-XYOIXC6A.js";
5
+ import "../../chunk-PXTU5MPW.js";
6
+ export {
7
+ defineCodeChurn,
8
+ invalidSettings
9
+ };
10
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,97 @@
1
+ declare const METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE"];
2
+ type Method = (typeof METHODS)[number];
3
+ /** One entry of a front's `api` list, as written. */
4
+ interface ApiEntry {
5
+ method?: Method;
6
+ path: string;
7
+ status?: number;
8
+ /** The JSON answered, relative to the module. */
9
+ file: string;
10
+ }
11
+
12
+ /** The one interaction a screen's flow performs, timed for INP. */
13
+ type Interaction = {
14
+ click: string;
15
+ } | {
16
+ clickText: string;
17
+ } | {
18
+ type: {
19
+ selector: string;
20
+ text: string;
21
+ };
22
+ };
23
+ /** A screen measured: the route that renders it, the path opened, and what proves it opened. */
24
+ interface Screen {
25
+ id: string;
26
+ /** The route file, relative to `router.routes`: a change to what it loads measures it. */
27
+ route: string;
28
+ /** The path opened, starting with `/`. */
29
+ path: string;
30
+ /** Texts the screen shows once opened: each must be visible before the figures count. */
31
+ expectText: string[];
32
+ interact: Interaction;
33
+ /** Rows the screen must list once opened, by count or at least a minimum. */
34
+ rows?: {
35
+ selector: string;
36
+ count?: number;
37
+ min?: number;
38
+ };
39
+ /** An element that must be there once opened. */
40
+ expectSelector?: string;
41
+ /**
42
+ * This screen's own ready call, when it does not make the front's: console's institution screens
43
+ * and its client page share no BFF call. Checked like the front's, answered by the mocks with 200.
44
+ */
45
+ ready?: string;
46
+ }
47
+ /** What a front's config file passes to `defineRuntimeAnalysis`. */
48
+ interface RuntimeAnalysisInput {
49
+ /** The front's own directory, normally `import.meta.dirname`. */
50
+ root?: string;
51
+ /** The path the app is served under: the rest goes to the mocks. Or `mockPrefixes`, not both. */
52
+ basePath?: string;
53
+ /** The paths sent to the mocks, for an app served at the root. Or `basePath`, not both. */
54
+ mockPrefixes?: string[];
55
+ /** The app's health path, answered once it is up. */
56
+ health: string;
57
+ /** The call that tells the app is ready (a session): answered by the mocks, with 200. */
58
+ ready: string;
59
+ build: {
60
+ /** The build output, relative to the front. */
61
+ output: string;
62
+ /** The server the output starts with (`node <server>`, `HOST` and `PORT` set). */
63
+ server: string;
64
+ /** The build variables; `{origin}` is the gateway the build is served behind. */
65
+ env: Record<string, string>;
66
+ };
67
+ /** The answers of the calls the screens make. */
68
+ api: ApiEntry[];
69
+ router: {
70
+ /** The tsconfig the route imports are resolved with. */
71
+ tsconfig: string;
72
+ /** The app shell files every screen loads. */
73
+ shell: string[];
74
+ /** The file routes directory (TanStack Router), holding `__root.tsx`. */
75
+ routes: string;
76
+ };
77
+ screens: Screen[];
78
+ /**
79
+ * The translations folder, relative to the front, holding `<lang>/<namespace>.json`: a change
80
+ * to one measures the screens whose code names its namespace, not every screen.
81
+ */
82
+ translations?: string;
83
+ /**
84
+ * The browser's language, as the screens' expected texts are written (`fr-FR`): a front that
85
+ * picks its language from the browser otherwise renders the runner's. `en-US` when left out.
86
+ */
87
+ locale?: string;
88
+ }
89
+ /** The browser language when a config names none. */
90
+ declare const DEFAULT_LOCALE: string;
91
+ /** The config as sentinel reads it: what the module passed, marked as defined here. */
92
+ type RuntimeAnalysisConfig = RuntimeAnalysisInput & {
93
+ readonly defined: true;
94
+ };
95
+ declare function defineRuntimeAnalysis(input: RuntimeAnalysisInput): RuntimeAnalysisConfig;
96
+
97
+ export { DEFAULT_LOCALE, type Interaction, type RuntimeAnalysisConfig, type RuntimeAnalysisInput, type Screen, defineRuntimeAnalysis };
@@ -0,0 +1,10 @@
1
+ import {
2
+ DEFAULT_LOCALE,
3
+ defineRuntimeAnalysis
4
+ } from "../../chunk-U7G2Y6YC.js";
5
+ import "../../chunk-F5WISUN3.js";
6
+ export {
7
+ DEFAULT_LOCALE,
8
+ defineRuntimeAnalysis
9
+ };
10
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,89 @@
1
+ import {
2
+ loadRuntimeConfig
3
+ } from "../../chunk-VWASE6NN.js";
4
+ import "../../chunk-F5WISUN3.js";
5
+
6
+ // src/roles/runtime-analysis/serve/gateway-main.ts
7
+ import { resolve } from "node:path";
8
+ import { parseArgs } from "node:util";
9
+
10
+ // src/roles/runtime-analysis/serve/gateway.ts
11
+ import { appendFileSync, writeFileSync } from "node:fs";
12
+ import http from "node:http";
13
+ var under = (pathname, prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`);
14
+ function isAppPath(pathname, options) {
15
+ const base = (options.basePath ?? "").replace(/\/$/, "");
16
+ return options.mockPrefixes ? !options.mockPrefixes.some((prefix) => under(pathname, prefix)) : under(pathname, base);
17
+ }
18
+ function createGateway(options) {
19
+ writeFileSync(options.log, "");
20
+ const agent = new http.Agent({ keepAlive: true });
21
+ return http.createServer((request, response) => {
22
+ const startedAt = Date.now();
23
+ const { pathname } = new URL(request.url ?? "/", "http://gateway");
24
+ const toApp = isAppPath(pathname, options);
25
+ const port = toApp ? options.appPort : options.mockPort;
26
+ const log = (status, mock, error) => appendFileSync(
27
+ options.log,
28
+ `${JSON.stringify({ at: new Date(startedAt).toISOString(), method: request.method, path: request.url, to: toApp ? "app" : "mock", status, mock, ms: Date.now() - startedAt, ...error ? { error } : {} })}
29
+ `
30
+ );
31
+ const upstream = http.request(
32
+ {
33
+ hostname: "127.0.0.1",
34
+ port,
35
+ path: request.url,
36
+ method: request.method,
37
+ // What an ingress does: the upstream gets its own host, and the host the browser used in
38
+ // `x-forwarded-host`. A server that trusts only its public origin reads it there: console
39
+ // answered 500 ("Untrusted Console request origin") when it saw only the app's port.
40
+ headers: {
41
+ ...request.headers,
42
+ host: `127.0.0.1:${port}`,
43
+ "x-forwarded-host": request.headers["x-forwarded-host"] ?? request.headers.host ?? ""
44
+ },
45
+ agent
46
+ },
47
+ (answer) => {
48
+ response.writeHead(answer.statusCode ?? 502, answer.headers);
49
+ answer.pipe(response);
50
+ answer.on("end", () => log(answer.statusCode, answer.headers["x-cwv-mock"] ?? null));
51
+ }
52
+ );
53
+ upstream.on("error", (error) => {
54
+ log(502, null, error.code ?? String(error));
55
+ response.writeHead(502, { "content-type": "text/plain" });
56
+ response.end("upstream unreachable");
57
+ });
58
+ request.pipe(upstream);
59
+ });
60
+ }
61
+
62
+ // src/roles/runtime-analysis/serve/gateway-main.ts
63
+ var { values: args } = parseArgs({
64
+ options: Object.fromEntries(
65
+ ["module", "port", "app-port", "mock-port", "log"].map((key) => [
66
+ key,
67
+ { type: "string" }
68
+ ])
69
+ )
70
+ });
71
+ var loaded = await loadRuntimeConfig(resolve(String(args.module)));
72
+ if (!("config" in loaded)) {
73
+ console.error(`no runtime-analysis config in ${args.module}`);
74
+ process.exit(2);
75
+ }
76
+ createGateway({
77
+ ...loaded.config.basePath === void 0 ? {} : { basePath: loaded.config.basePath },
78
+ ...loaded.config.mockPrefixes === void 0 ? {} : { mockPrefixes: loaded.config.mockPrefixes },
79
+ appPort: Number(args["app-port"]),
80
+ mockPort: Number(args["mock-port"]),
81
+ log: resolve(String(args.log))
82
+ }).listen(
83
+ Number(args.port),
84
+ "127.0.0.1",
85
+ () => console.log(
86
+ `gateway on http://127.0.0.1:${args.port}, app ${args["app-port"]}, mocks ${args["mock-port"]}`
87
+ )
88
+ );
89
+ //# sourceMappingURL=gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/roles/runtime-analysis/serve/gateway-main.ts","../../../src/roles/runtime-analysis/serve/gateway.ts"],"sourcesContent":["/**\n * The gateway as its own process: `node gateway.js --module <dir> --port 4101 --app-port 4111\n * --mock-port 4199 --log requests-base.jsonl`. The front's routing is read from its config.\n */\nimport { resolve } from 'node:path'\nimport { parseArgs } from 'node:util'\n\nimport { loadRuntimeConfig } from '../config/resolve.js'\n\nimport { createGateway } from './gateway.js'\n\nconst { values: args } = parseArgs({\n options: Object.fromEntries(\n ['module', 'port', 'app-port', 'mock-port', 'log'].map((key) => [\n key,\n { type: 'string' as const },\n ]),\n ),\n})\nconst loaded = await loadRuntimeConfig(resolve(String(args.module)))\nif (!('config' in loaded)) {\n console.error(`no runtime-analysis config in ${args.module}`)\n process.exit(2)\n}\ncreateGateway({\n ...(loaded.config.basePath === undefined ? {} : { basePath: loaded.config.basePath }),\n ...(loaded.config.mockPrefixes === undefined ? {} : { mockPrefixes: loaded.config.mockPrefixes }),\n appPort: Number(args['app-port']),\n mockPort: Number(args['mock-port']),\n log: resolve(String(args.log)),\n}).listen(Number(args.port), '127.0.0.1', () =>\n console.log(\n `gateway on http://127.0.0.1:${args.port}, app ${args['app-port']}, mocks ${args['mock-port']}`,\n ),\n)\n","/**\n * The gateway, one per build, like an environment's: the front's own paths go to that build's\n * server, every other path to the mock API. A plain proxy, no interception. Every request is logged\n * as one JSON line with its status and whether the mock API handled it, which is how a flow later\n * proves its screen was fed by the mocks and nothing else.\n *\n * Moved from the monorepo's harness (`engine/serve/gateway.mjs`, hublo/monorepo#23672), unchanged\n * in behaviour. It runs in its OWN process (`gateway-main.ts`): proxying from the process that runs\n * Lighthouse would delay the very responses being measured.\n */\nimport { appendFileSync, writeFileSync } from 'node:fs'\nimport http from 'node:http'\n\nexport interface GatewayOptions {\n /** The path the app is served under; the rest is mocked. Or `mockPrefixes`. */\n basePath?: string\n /** The paths mocked, for an app at the root; the rest goes to the app. */\n mockPrefixes?: string[]\n appPort: number\n mockPort: number\n /** The request log, one JSON line per request, emptied at start. */\n log: string\n}\n\nconst under = (pathname: string, prefix: string): boolean =>\n pathname === prefix || pathname.startsWith(`${prefix}/`)\n\n/** Whether a request's path is the app's, by the front's base path or its mocked prefixes. */\nexport function isAppPath(\n pathname: string,\n options: Pick<GatewayOptions, 'basePath' | 'mockPrefixes'>,\n): boolean {\n const base = (options.basePath ?? '').replace(/\\/$/, '')\n return options.mockPrefixes\n ? !options.mockPrefixes.some((prefix) => under(pathname, prefix))\n : under(pathname, base)\n}\n\nexport function createGateway(options: GatewayOptions): http.Server {\n writeFileSync(options.log, '')\n const agent = new http.Agent({ keepAlive: true })\n return http.createServer((request, response) => {\n const startedAt = Date.now()\n const { pathname } = new URL(request.url ?? '/', 'http://gateway')\n const toApp = isAppPath(pathname, options)\n const port = toApp ? options.appPort : options.mockPort\n const log = (\n status: number | undefined,\n mock: string | string[] | null,\n error?: string,\n ): void =>\n appendFileSync(\n options.log,\n `${JSON.stringify({ at: new Date(startedAt).toISOString(), method: request.method, path: request.url, to: toApp ? 'app' : 'mock', status, mock, ms: Date.now() - startedAt, ...(error ? { error } : {}) })}\\n`,\n )\n const upstream = http.request(\n {\n hostname: '127.0.0.1',\n port,\n path: request.url,\n method: request.method,\n // What an ingress does: the upstream gets its own host, and the host the browser used in\n // `x-forwarded-host`. A server that trusts only its public origin reads it there: console\n // answered 500 (\"Untrusted Console request origin\") when it saw only the app's port.\n headers: {\n ...request.headers,\n host: `127.0.0.1:${port}`,\n 'x-forwarded-host': request.headers['x-forwarded-host'] ?? request.headers.host ?? '',\n },\n agent,\n },\n (answer) => {\n response.writeHead(answer.statusCode ?? 502, answer.headers)\n answer.pipe(response)\n answer.on('end', () => log(answer.statusCode, answer.headers['x-cwv-mock'] ?? null))\n },\n )\n upstream.on('error', (error: NodeJS.ErrnoException) => {\n log(502, null, error.code ?? String(error))\n response.writeHead(502, { 'content-type': 'text/plain' })\n response.end('upstream unreachable')\n })\n request.pipe(upstream)\n })\n}\n"],"mappings":";;;;;;AAIA,SAAS,eAAe;AACxB,SAAS,iBAAiB;;;ACK1B,SAAS,gBAAgB,qBAAqB;AAC9C,OAAO,UAAU;AAajB,IAAM,QAAQ,CAAC,UAAkB,WAC/B,aAAa,UAAU,SAAS,WAAW,GAAG,MAAM,GAAG;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,KAAK,UAAU,CAAC,WAAW,KAAK,WAAW,CAAC;AAAA,EAC/F;AACF;","names":[]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,43 @@
1
+ import {
2
+ answer,
3
+ loadApi
4
+ } from "../../chunk-NE3IEJBN.js";
5
+ import {
6
+ loadRuntimeConfig
7
+ } from "../../chunk-VWASE6NN.js";
8
+ import "../../chunk-F5WISUN3.js";
9
+
10
+ // src/roles/runtime-analysis/serve/mock-api-main.ts
11
+ import { resolve } from "node:path";
12
+ import { parseArgs } from "node:util";
13
+
14
+ // src/roles/runtime-analysis/serve/mock-api.ts
15
+ import http from "node:http";
16
+ function createMockApi(api) {
17
+ return http.createServer((request, response) => {
18
+ request.resume();
19
+ const { status, body, mock } = answer(api, request.method ?? "GET", request.url ?? "/");
20
+ response.writeHead(status, {
21
+ "content-type": mock === "handled" ? "application/json" : "text/plain",
22
+ "x-cwv-mock": mock
23
+ });
24
+ response.end(body);
25
+ });
26
+ }
27
+
28
+ // src/roles/runtime-analysis/serve/mock-api-main.ts
29
+ var { values: args } = parseArgs({
30
+ options: { module: { type: "string" }, port: { type: "string" } }
31
+ });
32
+ var moduleDir = resolve(String(args.module));
33
+ var loaded = await loadRuntimeConfig(moduleDir);
34
+ if (!("config" in loaded)) {
35
+ console.error(`no runtime-analysis config in ${args.module}`);
36
+ process.exit(2);
37
+ }
38
+ createMockApi(loadApi(loaded.config.api, moduleDir)).listen(
39
+ Number(args.port),
40
+ "127.0.0.1",
41
+ () => console.log(`mock API on http://127.0.0.1:${args.port}`)
42
+ );
43
+ //# sourceMappingURL=mock-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/roles/runtime-analysis/serve/mock-api-main.ts","../../../src/roles/runtime-analysis/serve/mock-api.ts"],"sourcesContent":["/** The mock API as its own process: `node mock-api.js --module <dir> --port 4199`. */\nimport { resolve } from 'node:path'\nimport { parseArgs } from 'node:util'\n\nimport { loadApi } from '../config/api.js'\nimport { loadRuntimeConfig } from '../config/resolve.js'\n\nimport { createMockApi } from './mock-api.js'\n\nconst { values: args } = parseArgs({\n options: { module: { type: 'string' }, port: { type: 'string' } },\n})\nconst moduleDir = resolve(String(args.module))\nconst loaded = await loadRuntimeConfig(moduleDir)\nif (!('config' in loaded)) {\n console.error(`no runtime-analysis config in ${args.module}`)\n process.exit(2)\n}\ncreateMockApi(loadApi(loaded.config.api, moduleDir)).listen(Number(args.port), '127.0.0.1', () =>\n console.log(`mock API on http://127.0.0.1:${args.port}`),\n)\n","/**\n * The mock API: answers a front's API calls from the `api` list of its config, nothing else. A\n * request no entry matches is answered 501, which fails the flow's \"no unhandled request\" proof.\n * Moved from the monorepo's harness (`engine/serve/mock-api.mjs`), unchanged in behaviour; its own\n * process (`mock-api-main.ts`), like the gateway.\n */\nimport http from 'node:http'\n\nimport { answer, type LoadedAnswer } from '../config/api.js'\n\nexport function createMockApi(api: readonly LoadedAnswer[]): http.Server {\n return http.createServer((request, response) => {\n // The body is not read: an entry answers by method and path only.\n request.resume()\n const { status, body, mock } = answer(api, request.method ?? 'GET', request.url ?? '/')\n response.writeHead(status, {\n 'content-type': mock === 'handled' ? 'application/json' : 'text/plain',\n 'x-cwv-mock': mock,\n })\n response.end(body)\n })\n}\n"],"mappings":";;;;;;;;;;AACA,SAAS,eAAe;AACxB,SAAS,iBAAiB;;;ACI1B,OAAO,UAAU;AAIV,SAAS,cAAc,KAA2C;AACvE,SAAO,KAAK,aAAa,CAAC,SAAS,aAAa;AAE9C,YAAQ,OAAO;AACf,UAAM,EAAE,QAAQ,MAAM,KAAK,IAAI,OAAO,KAAK,QAAQ,UAAU,OAAO,QAAQ,OAAO,GAAG;AACtF,aAAS,UAAU,QAAQ;AAAA,MACzB,gBAAgB,SAAS,YAAY,qBAAqB;AAAA,MAC1D,cAAc;AAAA,IAChB,CAAC;AACD,aAAS,IAAI,IAAI;AAAA,EACnB,CAAC;AACH;;;ADZA,IAAM,EAAE,QAAQ,KAAK,IAAI,UAAU;AAAA,EACjC,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,GAAG,MAAM,EAAE,MAAM,SAAS,EAAE;AAClE,CAAC;AACD,IAAM,YAAY,QAAQ,OAAO,KAAK,MAAM,CAAC;AAC7C,IAAM,SAAS,MAAM,kBAAkB,SAAS;AAChD,IAAI,EAAE,YAAY,SAAS;AACzB,UAAQ,MAAM,iCAAiC,KAAK,MAAM,EAAE;AAC5D,UAAQ,KAAK,CAAC;AAChB;AACA,cAAc,QAAQ,OAAO,OAAO,KAAK,SAAS,CAAC,EAAE;AAAA,EAAO,OAAO,KAAK,IAAI;AAAA,EAAG;AAAA,EAAa,MAC1F,QAAQ,IAAI,gCAAgC,KAAK,IAAI,EAAE;AACzD;","names":[]}
@@ -0,0 +1,68 @@
1
+ /** A rule's level. `off` is a module's decision, and the report prints it as one. */
2
+ type Severity = 'off' | 'warn' | 'error';
3
+ interface SqlDefaults {
4
+ /** The migration files squawk reads, as globs relative to the module. */
5
+ migrations: {
6
+ /**
7
+ * ⛔ `migration.sql` BY NAME, and that is what keeps the rollback scripts out. Beside the 871
8
+ * migrations sit 385 `down.sql`, 2 `drop.sql` and one `donw.sql`: scripts a human runs by hand,
9
+ * which Prisma never applies. Reading them would report every `DROP` they are made of, for a
10
+ * file that never reaches production through a deploy. Naming the file Prisma applies, rather
11
+ * than excluding the others, also keeps out the misspelling nobody would think to exclude.
12
+ */
13
+ include: string[];
14
+ /** Migrations a module chooses not to read. Empty by default. */
15
+ exclude: string[];
16
+ };
17
+ /** What the `Unsafe` rule reads. */
18
+ unsafe: {
19
+ /**
20
+ * Read the tests too. ON by default: 203 of the 226 `Unsafe` calls are in tests, and a call
21
+ * that is safe today is not safe by construction tomorrow. A module that decides otherwise sets
22
+ * it to false, and the report says so; the decision is the team's.
23
+ */
24
+ includeTests: boolean;
25
+ /**
26
+ * What counts as a test, by PATH. Measured on the monorepo before it was written: the filter
27
+ * `*.spec.*` alone let 149 test calls through as production, because `*.integration-spec.ts`,
28
+ * `*.steps.ts`, `tests/database/` and `*.test-util.ts` are all test code and none of them
29
+ * matches it.
30
+ */
31
+ tests: string[];
32
+ };
33
+ /** Directories never read, whatever the includes say. */
34
+ ignore: string[];
35
+ /**
36
+ * The PostgreSQL version squawk checks against, since some rules depend on it.
37
+ *
38
+ * 16.8 is the version the monorepo pins (`postgres:16.8`, in its integration tests and its
39
+ * database tooling). The role reads what the repository declares and never asks production.
40
+ */
41
+ pgVersion: string;
42
+ /**
43
+ * Each rule's level, by name. Empty means every rule at its default, `warn` in this version: the
44
+ * role refuses nothing while its adoption runs.
45
+ */
46
+ rules: Record<string, Severity>;
47
+ }
48
+
49
+ type DeepPartial<T> = {
50
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
51
+ };
52
+ /** What a module's config file passes. Everything is optional, including the file itself. */
53
+ interface SqlInput {
54
+ /** The module's own directory, normally `import.meta.dirname`. */
55
+ root?: string;
56
+ /** The seam. Replaces whatever it names, and every path it sets lands in `moved`. */
57
+ overrides?: DeepPartial<SqlDefaults>;
58
+ }
59
+ interface ResolvedSqlConfig extends SqlDefaults {
60
+ /** The module's directory, or null when its config file did not say. */
61
+ root: string | null;
62
+ /** Dotted paths the module set through `overrides`, sorted so two runs print the same report. */
63
+ moved: string[];
64
+ }
65
+ /** Resolve a module's declaration against this role's defaults. */
66
+ declare function defineSql(input?: SqlInput): ResolvedSqlConfig;
67
+
68
+ export { type ResolvedSqlConfig, type SqlInput, defineSql };
@@ -0,0 +1,8 @@
1
+ import {
2
+ defineSql
3
+ } from "../../chunk-NGLEGAEN.js";
4
+ import "../../chunk-PXTU5MPW.js";
5
+ export {
6
+ defineSql
7
+ };
8
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  defineStaticAnalysis
3
- } from "../../chunk-THTXP2QU.js";
3
+ } from "../../chunk-XMAXE2Q2.js";
4
+ import "../../chunk-PXTU5MPW.js";
4
5
  export {
5
6
  defineStaticAnalysis
6
7
  };
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  alreadyInstalled
3
3
  } from "../../../chunk-NUOQXAYR.js";
4
+ import {
5
+ fromModule
6
+ } from "../../../chunk-ELZHIN6E.js";
4
7
  import {
5
8
  CURRENT_FILE_MOCKS,
6
9
  PHASE,
7
10
  SHARED_WORKER
8
11
  } from "../../../chunk-H3GSGAX2.js";
9
- import {
10
- fromModule
11
- } from "../../../chunk-ELZHIN6E.js";
12
12
 
13
13
  // src/roles/test/setup/file-boundary.ts
14
14
  import { afterAll, afterEach, vi } from "vitest";
@@ -1,3 +1,6 @@
1
+ import {
2
+ installWorkspaceSetup
3
+ } from "../../../chunk-QMIJ4ZGJ.js";
1
4
  import {
2
5
  clearDeepMocks,
3
6
  resetDeepMocks
@@ -5,11 +8,8 @@ import {
5
8
  import {
6
9
  alreadyInstalled
7
10
  } from "../../../chunk-NUOQXAYR.js";
8
- import {
9
- installWorkspaceSetup
10
- } from "../../../chunk-4YQXLPJ5.js";
11
11
  import "../../../chunk-ELZHIN6E.js";
12
- import "../../../chunk-ZNANJEMK.js";
12
+ import "../../../chunk-KKHKRY7P.js";
13
13
 
14
14
  // src/roles/test/setup/jest-parity.ts
15
15
  import { expect, vi } from "vitest";
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  pinWorkspaceTimezone
3
- } from "../../../chunk-4YQXLPJ5.js";
3
+ } from "../../../chunk-QMIJ4ZGJ.js";
4
4
  import "../../../chunk-ELZHIN6E.js";
5
- import "../../../chunk-ZNANJEMK.js";
5
+ import "../../../chunk-KKHKRY7P.js";
6
6
 
7
7
  // src/roles/test/setup/workspace-entry.ts
8
8
  await pinWorkspaceTimezone();
@@ -7,12 +7,12 @@ import {
7
7
  readTestAdoption,
8
8
  resolveVitest,
9
9
  suiteOf
10
- } from "./chunk-P6KTBQ2Q.js";
10
+ } from "./chunk-FZLUCPST.js";
11
11
  import "./chunk-ZFG6P27V.js";
12
- import "./chunk-ZNANJEMK.js";
13
12
  import "./chunk-O7REVMOC.js";
14
13
  import "./chunk-H4HAFJFZ.js";
15
14
  import "./chunk-QXFCZON7.js";
15
+ import "./chunk-KKHKRY7P.js";
16
16
 
17
17
  // src/roles/test/validate.ts
18
18
  import { execFileSync } from "node:child_process";