@hublo/sentinel 1.7.0-alpha.21 → 1.7.0-alpha.23

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 (48) hide show
  1. package/README.md +0 -1
  2. package/dist/bin/sentinel.js +15 -16
  3. package/dist/{chunk-RI7R3S3T.js → chunk-426EFSK7.js} +7068 -6911
  4. package/dist/{chunk-J2RMARWP.js → chunk-4YQXLPJ5.js} +2 -2
  5. package/dist/{chunk-UVXXEAHU.js → chunk-7JTCUK77.js} +3 -3
  6. package/dist/{chunk-BBNABWZ6.js → chunk-CSZW7OMC.js} +8 -6
  7. package/dist/chunk-CSZW7OMC.js.map +1 -0
  8. package/dist/chunk-F5WISUN3.js +17 -0
  9. package/dist/chunk-F5WISUN3.js.map +1 -0
  10. package/dist/chunk-FY3P5QPH.js +15 -0
  11. package/dist/chunk-FY3P5QPH.js.map +1 -0
  12. package/dist/chunk-NE3IEJBN.js +59 -0
  13. package/dist/chunk-NE3IEJBN.js.map +1 -0
  14. package/dist/chunk-VWASE6NN.js +34 -0
  15. package/dist/chunk-VWASE6NN.js.map +1 -0
  16. package/dist/{chunk-XTBHIKFG.js → chunk-ZNANJEMK.js} +16 -30
  17. package/dist/chunk-ZNANJEMK.js.map +1 -0
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +8 -6
  20. package/dist/roles/runtime-analysis/config.d.ts +92 -0
  21. package/dist/roles/runtime-analysis/config.js +10 -0
  22. package/dist/roles/runtime-analysis/gateway.d.ts +2 -0
  23. package/dist/roles/runtime-analysis/gateway.js +82 -0
  24. package/dist/roles/runtime-analysis/gateway.js.map +1 -0
  25. package/dist/roles/runtime-analysis/mock-api.d.ts +2 -0
  26. package/dist/roles/runtime-analysis/mock-api.js +43 -0
  27. package/dist/roles/runtime-analysis/mock-api.js.map +1 -0
  28. package/dist/roles/static-analysis/config.js +1 -2
  29. package/dist/roles/test/setup/jest-parity.js +2 -2
  30. package/dist/roles/test/setup/workspace-entry.js +2 -2
  31. package/dist/{validate-YCTNTNFT.js → validate-GD63SP6M.js} +2 -2
  32. package/docs/static-analysis-study.md +10 -49
  33. package/docs/typescript-traces.md +2 -216
  34. package/package.json +9 -5
  35. package/runtime-analysis-deps/load.mjs +6 -0
  36. package/runtime-analysis-deps/package-lock.json +1766 -0
  37. package/runtime-analysis-deps/package.json +11 -0
  38. package/dist/chunk-BBNABWZ6.js.map +0 -1
  39. package/dist/chunk-PXTU5MPW.js +0 -9
  40. package/dist/chunk-PXTU5MPW.js.map +0 -1
  41. package/dist/chunk-XTBHIKFG.js.map +0 -1
  42. package/dist/chunk-XYOIXC6A.js +0 -126
  43. package/dist/chunk-XYOIXC6A.js.map +0 -1
  44. package/dist/roles/code-churn/config.d.ts +0 -92
  45. package/dist/roles/code-churn/config.js +0 -10
  46. package/docs/code-churn-adoption.md +0 -237
  47. /package/dist/{chunk-J2RMARWP.js.map → chunk-4YQXLPJ5.js.map} +0 -0
  48. /package/dist/roles/{code-churn → runtime-analysis}/config.js.map +0 -0
@@ -0,0 +1,92 @@
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
+ /** What a front's config file passes to `defineRuntimeAnalysis`. */
43
+ interface RuntimeAnalysisInput {
44
+ /** The front's own directory, normally `import.meta.dirname`. */
45
+ root?: string;
46
+ /** The path the app is served under: the rest goes to the mocks. Or `mockPrefixes`, not both. */
47
+ basePath?: string;
48
+ /** The paths sent to the mocks, for an app served at the root. Or `basePath`, not both. */
49
+ mockPrefixes?: string[];
50
+ /** The app's health path, answered once it is up. */
51
+ health: string;
52
+ /** The call that tells the app is ready (a session): answered by the mocks, with 200. */
53
+ ready: string;
54
+ build: {
55
+ /** The build output, relative to the front. */
56
+ output: string;
57
+ /** The server the output starts with (`node <server>`, `HOST` and `PORT` set). */
58
+ server: string;
59
+ /** The build variables; `{origin}` is the gateway the build is served behind. */
60
+ env: Record<string, string>;
61
+ };
62
+ /** The answers of the calls the screens make. */
63
+ api: ApiEntry[];
64
+ router: {
65
+ /** The tsconfig the route imports are resolved with. */
66
+ tsconfig: string;
67
+ /** The app shell files every screen loads. */
68
+ shell: string[];
69
+ /** The file routes directory (TanStack Router), holding `__root.tsx`. */
70
+ routes: string;
71
+ };
72
+ screens: Screen[];
73
+ /**
74
+ * The translations folder, relative to the front, holding `<lang>/<namespace>.json`: a change
75
+ * to one measures the screens whose code names its namespace, not every screen.
76
+ */
77
+ translations?: string;
78
+ /**
79
+ * The browser's language, as the screens' expected texts are written (`fr-FR`): a front that
80
+ * picks its language from the browser otherwise renders the runner's. `en-US` when left out.
81
+ */
82
+ locale?: string;
83
+ }
84
+ /** The browser language when a config names none. */
85
+ declare const DEFAULT_LOCALE: string;
86
+ /** The config as sentinel reads it: what the module passed, marked as defined here. */
87
+ type RuntimeAnalysisConfig = RuntimeAnalysisInput & {
88
+ readonly defined: true;
89
+ };
90
+ declare function defineRuntimeAnalysis(input: RuntimeAnalysisInput): RuntimeAnalysisConfig;
91
+
92
+ 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-FY3P5QPH.js";
5
+ import "../../chunk-F5WISUN3.js";
6
+ export {
7
+ DEFAULT_LOCALE,
8
+ defineRuntimeAnalysis
9
+ };
10
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,82 @@
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
+ headers: { ...request.headers, host: `127.0.0.1:${port}` },
38
+ agent
39
+ },
40
+ (answer) => {
41
+ response.writeHead(answer.statusCode ?? 502, answer.headers);
42
+ answer.pipe(response);
43
+ answer.on("end", () => log(answer.statusCode, answer.headers["x-cwv-mock"] ?? null));
44
+ }
45
+ );
46
+ upstream.on("error", (error) => {
47
+ log(502, null, error.code ?? String(error));
48
+ response.writeHead(502, { "content-type": "text/plain" });
49
+ response.end("upstream unreachable");
50
+ });
51
+ request.pipe(upstream);
52
+ });
53
+ }
54
+
55
+ // src/roles/runtime-analysis/serve/gateway-main.ts
56
+ var { values: args } = parseArgs({
57
+ options: Object.fromEntries(
58
+ ["module", "port", "app-port", "mock-port", "log"].map((key) => [
59
+ key,
60
+ { type: "string" }
61
+ ])
62
+ )
63
+ });
64
+ var loaded = await loadRuntimeConfig(resolve(String(args.module)));
65
+ if (!("config" in loaded)) {
66
+ console.error(`no runtime-analysis config in ${args.module}`);
67
+ process.exit(2);
68
+ }
69
+ createGateway({
70
+ ...loaded.config.basePath === void 0 ? {} : { basePath: loaded.config.basePath },
71
+ ...loaded.config.mockPrefixes === void 0 ? {} : { mockPrefixes: loaded.config.mockPrefixes },
72
+ appPort: Number(args["app-port"]),
73
+ mockPort: Number(args["mock-port"]),
74
+ log: resolve(String(args.log))
75
+ }).listen(
76
+ Number(args.port),
77
+ "127.0.0.1",
78
+ () => console.log(
79
+ `gateway on http://127.0.0.1:${args.port}, app ${args["app-port"]}, mocks ${args["mock-port"]}`
80
+ )
81
+ );
82
+ //# 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 headers: { ...request.headers, host: `127.0.0.1:${port}` },\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;AAGlD,SAAS,UACd,UACA,SACS;AACT,QAAM,QAAQ,QAAQ,YAAY,IAAI,QAAQ,OAAO,EAAE;AACvD,SAAO,QAAQ,eACX,CAAC,QAAQ,aAAa,KAAK,CAAC,WAAW,MAAM,UAAU,MAAM,CAA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+ // 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":[]}
@@ -1,7 +1,6 @@
1
1
  import {
2
2
  defineStaticAnalysis
3
- } from "../../chunk-BBNABWZ6.js";
4
- import "../../chunk-PXTU5MPW.js";
3
+ } from "../../chunk-CSZW7OMC.js";
5
4
  export {
6
5
  defineStaticAnalysis
7
6
  };
@@ -7,9 +7,9 @@ import {
7
7
  } from "../../../chunk-NUOQXAYR.js";
8
8
  import {
9
9
  installWorkspaceSetup
10
- } from "../../../chunk-J2RMARWP.js";
10
+ } from "../../../chunk-4YQXLPJ5.js";
11
11
  import "../../../chunk-ELZHIN6E.js";
12
- import "../../../chunk-XTBHIKFG.js";
12
+ import "../../../chunk-ZNANJEMK.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-J2RMARWP.js";
3
+ } from "../../../chunk-4YQXLPJ5.js";
4
4
  import "../../../chunk-ELZHIN6E.js";
5
- import "../../../chunk-XTBHIKFG.js";
5
+ import "../../../chunk-ZNANJEMK.js";
6
6
 
7
7
  // src/roles/test/setup/workspace-entry.ts
8
8
  await pinWorkspaceTimezone();
@@ -7,8 +7,8 @@ import {
7
7
  readTestAdoption,
8
8
  resolveVitest,
9
9
  suiteOf
10
- } from "./chunk-UVXXEAHU.js";
11
- import "./chunk-XTBHIKFG.js";
10
+ } from "./chunk-7JTCUK77.js";
11
+ import "./chunk-ZNANJEMK.js";
12
12
  import "./chunk-O7REVMOC.js";
13
13
  import "./chunk-QXFCZON7.js";
14
14
 
@@ -44,9 +44,7 @@ the same idea sometimes carries two names.
44
44
  ⚠️ Not every symbol above is produced in the first version. `A`, `D`, `H` and `LCOM4` are not:
45
45
  `A` is not graph-derivable (section 8), and `LCOM4` was dropped because the front end is functional,
46
46
  which leaves it a nest-only metric to be re-examined. The Lakos family, visibility, churn and
47
- entropy were planned as the second version; measured, they became something else, and section 11
48
- says what and why: churn is a role of its own (`code-churn`), coupling and visibility were already
49
- here, Lakos and entropy were not added. What the first version produces is listed in section 7.
47
+ entropy are the second version. What the first one produces is listed in section 7.
50
48
 
51
49
  Two conventions worth stating because they bite. A **percentile** is written `p95` and means the
52
50
  value below which 95% of the measured population sits. A **rank correlation** is Spearman's: 1
@@ -255,15 +253,15 @@ that validates the categories now. Two of its cells are already filled, and both
255
253
  **A category is sound when its metrics lead to the same action.** Otherwise it is a filing
256
254
  cabinet, not a tool.
257
255
 
258
- | category | the question | contains | the action |
259
- | ---------------- | ------------------------------- | ------------------------------------------------------------------------------------------------ | ------------------- |
260
- | **Impact** | what does it break | Ca, Ce, DC, I, later A and D | none. It **orders** |
261
- | **Activity** | how much does it move | churn, entropy, authors, co-change (section 11: churn is the `code-churn` role, entropy dropped) | none. It **orders** |
262
- | **Cycles** | what bites its own tail | SCCs, System Cyclicality | move one import |
263
- | **Modularity** | is the split right | Q, density per module | re-cut, move a file |
264
- | **Complexity** | is it readable | CX per file and per folder, Halstead, MI | read it, then split |
265
- | **Duplication** | does it already exist elsewhere | clones, duplicated lines, share per language | extract, or accept |
266
- | **Reachability** | is any of it still run | dead code, with a confidence per finding | delete, or declare |
256
+ | category | the question | contains | the action |
257
+ | ---------------- | ------------------------------- | -------------------------------------------- | ------------------- |
258
+ | **Impact** | what does it break | Ca, Ce, DC, I, later A and D | none. It **orders** |
259
+ | **Activity** | how much does it move | churn, entropy, authors, co-change | none. It **orders** |
260
+ | **Cycles** | what bites its own tail | SCCs, System Cyclicality | move one import |
261
+ | **Modularity** | is the split right | Q, density per module | re-cut, move a file |
262
+ | **Complexity** | is it readable | CX per file and per folder, Halstead, MI | read it, then split |
263
+ | **Duplication** | does it already exist elsewhere | clones, duplicated lines, share per language | extract, or accept |
264
+ | **Reachability** | is any of it still run | dead code, with a confidence per finding | delete, or declare |
267
265
 
268
266
  Cycles is separate from Impact although both come from the graph, because the action differs: a
269
267
  cycle is fixed, a high centrality is not. **Impact × Activity** are the two terms of risk and
@@ -1624,40 +1622,3 @@ All three are now tests.
1624
1622
  - CodeScene, code health and hotspots: <https://codescene.io/docs/guides/technical/code-health.html>
1625
1623
  - Sonar, Clean as You Code: <https://www.sonarsource.com/blog/clean-as-you-code/>
1626
1624
  - Martin's package metrics: <https://en.wikipedia.org/wiki/Software_package_metrics>
1627
-
1628
- ---
1629
-
1630
- ## 11. What the second version became (HUB-46818, #98)
1631
-
1632
- The second version listed in section 0 was the Lakos family, visibility, churn and entropy. Before
1633
- writing any of it, each was measured on hublo/monorepo: its formula against what this role
1634
- already computes, its redundancy with the figures already printed, and whether it ranks the files
1635
- that were fixed afterwards. Metrics taken at 2c90e36a70d (2026-05-15), fixes counted from then to
1636
- `main`, 20 742 files, Spearman correlations, the partial one controlling for file size.
1637
-
1638
- | Planned | Decision | Why, measured |
1639
- | ------------------------------------------------------------ | ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1640
- | Coupling: degree centrality, `Ca`, `Ce`, `I` | **Already here** | `graph/scan.ts` computes density, Louvain modularity `Q`, degree centrality and `Ca`/`Ce`/`I` per file. Nothing to add |
1641
- | Visibility (MacCormack fan-in and fan-out, propagation cost) | **Not added** | Propagation cost is exactly `RACD` (identical figures). Per file, the outgoing closure ranks like `Ce` (ρ .919) and the incoming one like `Ca` (ρ .781): the closures add little to a ranking the report already prints |
1642
- | Lakos `CCD`, `ACD`, `RACD`, `NCCD` | **Not added** | `RACD` falls with module size (ρ −.725 with N) and `NCCD` follows edges per file (ρ .853); `NCCD` is above 1 on 56 of the 110 modules of 20 files or more. Against fixes per KLOC, on 51 modules, no signal. Per file, beyond size, partial ρ .04 to .09 |
1643
- | Churn | **Shipped, as the `code-churn` role** | It reads the history, not the tree, so it is a role of its own with its own adoption ([`code-churn-adoption.md`](code-churn-adoption.md)). Beyond size it is the strongest of the candidates (partial ρ about .13 to .18 against later fixes), and it is nearly independent of the import graph (ρ .09 with the incoming closure), so it says something the graph does not |
1644
- | Change entropy (Hassan) | **Dropped** | Its file model ranks files like the commit count it is built from, and its decayed variant adds nothing: what it says, churn says |
1645
-
1646
- The definition shipped is the rework one (Sourcegraph, DevStats): of the lines added in a period,
1647
- the share rewritten or deleted within 21 days. The commit count used in the measurements above is
1648
- a related but different churn (Nagappan and Ball's family); it decided that history was worth
1649
- reading, and the rework definition decided what the figure says to a reader.
1650
-
1651
- Four traps the measurements found, each handled by the role and written in its cheat sheet:
1652
-
1653
- | Trap | Measured | What the role does |
1654
- | --------------------------- | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
1655
- | Merge commits counted twice | without `--first-parent`, +74% commits on recruitment, +137% on host-admin | main's first-parent history only, a merge read as everything it brought |
1656
- | Sweeps | 3.5% of changesets touch more than 100 files and carry 33% of the file changes | a commit over 100 files OF THE MODULE is not counted (0.5 point on host-admin) |
1657
- | Renames across modules | 1 487 in 12 months | the history is read per module: a line moved in reads as new, said in the caveat |
1658
- | A pace that changed | about 250 changesets a month, then over 1 000 from 2026-06 | a fixed period of lines (90 days), each followed for the same 21 days, rather than a count of commits |
1659
-
1660
- Measured and kept for later, not shipped: co-change between files (61% of the strong pairs have
1661
- no import link at all, a candidate signal of hidden coupling) and test priority (central files
1662
- without a test of their own). The second needs real coverage: the proxy "a test imports the file"
1663
- ranked like line coverage on one module (ρ .888) and not on host-admin (ρ .091).