|
| 1 | +// Per-entry eager-closure budgets -- the ADR-0019 loading-shape probe (#1739, #1960). |
| 2 | +// |
| 3 | +// ADR-0019's "Implementation-laziness" section requires platform-package façades to stay |
| 4 | +// implementation-lazy and is explicit that a startup-time threshold alone is not a substitute for |
| 5 | +// preserving the loading shape (`docs/adr/0019-request-bound-platform-runtime.md`): "the tracking |
| 6 | +// issue owns the exact probe and planted-red procedure." #1950 built the AST-level walker |
| 7 | +// (`eager-import-closure.fixtures.ts`) and proved the planted-red procedure on one file |
| 8 | +// (`session-teardown.ts`'s android-helper denylist, kept below as its own ad hoc test). This |
| 9 | +// table generalizes that proof: every workspace-package façade gets a numeric ceiling on how many |
| 10 | +// repo modules importing it may evaluate, plus -- for façades whose contract is |
| 11 | +// implementation-neutral vocabulary -- a standing assertion that the closure never reaches a |
| 12 | +// concrete platform implementation before discovery/binding selects one. |
| 13 | +// |
| 14 | +// Entry files are repo-root-relative. |
| 15 | + |
| 16 | +export type EagerClosureBudget = { |
| 17 | + /** Stable label for test names and failure messages -- the entry's repo-relative path. */ |
| 18 | + id: string; |
| 19 | + /** Repo-root-relative path to the module a consumer imports. */ |
| 20 | + entryFile: string; |
| 21 | + /** |
| 22 | + * Upper bound on `eagerClosureOf(entryFile).length`. Seeded from the file's CURRENT measured |
| 23 | + * closure size (recorded in the trailing comment on each entry below) plus a few files of |
| 24 | + * headroom for ordinary drift. A regression of the class this gate exists to catch -- a static |
| 25 | + * value import of a heavy module that used to be lazy -- costs tens to low-hundreds of extra |
| 26 | + * evaluated modules (#1960 simulation: single-file regressions of this class cost 5-12% of |
| 27 | + * suite import work each), far past any of this table's headroom. |
| 28 | + */ |
| 29 | + budget: number; |
| 30 | + /** |
| 31 | + * 'facade' entries are discovered mechanically -- every `.ts` file under a `src/facades/` |
| 32 | + * directory -- and the exhaustiveness test in `eager-closure-budgets.test.ts` requires each one |
| 33 | + * to appear here exactly once. 'hub' entries are hand-designated, high-fan-in files that |
| 34 | + * value-import a façade for only a slice of it (ADR-0019's other named case). There is no |
| 35 | + * mechanical way to enumerate "every hub" the way a façade directory enumerates every façade, |
| 36 | + * so membership is a reviewed judgment call -- the same judgment call the two existing ad hoc |
| 37 | + * pins this table's mechanism is built to generalize already made by hand. |
| 38 | + */ |
| 39 | + kind: 'facade' | 'hub'; |
| 40 | + /** |
| 41 | + * When true, the closure must never evaluate a concrete platform implementation (matched by |
| 42 | + * `PLATFORM_IMPLEMENTATION_PATTERNS`) -- the ADR-0019 rule that a façade whose contract is |
| 43 | + * implementation-neutral vocabulary may not evaluate implementation before discovery/binding |
| 44 | + * selects one. Hub entries default this false: a hub is a *consumer* of façades, not vocabulary |
| 45 | + * itself, and may legitimately reach one platform family already (e.g. session teardown's Apple |
| 46 | + * perf cleanup steps) through its own lazy seam. Verified, not merely assumed -- see the |
| 47 | + * measurement note on the `src/daemon/session-teardown.ts` entry below. |
| 48 | + */ |
| 49 | + denyPlatformImplementations: boolean; |
| 50 | +}; |
| 51 | + |
| 52 | +/** |
| 53 | + * A concrete platform implementation: the legacy daemon-owned `src/platforms/<family>/` tree, or |
| 54 | + * a `@agent-device/platform-<family>` workspace package. ADR-0019 names both as "concrete device |
| 55 | + * mechanics" that platform-neutral code may depend on only through contracts, never directly. |
| 56 | + */ |
| 57 | +export const PLATFORM_IMPLEMENTATION_PATTERNS: RegExp[] = [ |
| 58 | + /[/\\]platforms[/\\](apple|android|harmonyos|vega|linux|web)[/\\]/, |
| 59 | + /[/\\]packages[/\\]platform-(apple|android|harmonyos|vega|linux|web)[/\\]/, |
| 60 | +]; |
| 61 | + |
| 62 | +function facade(entryFile: string, budget: number): EagerClosureBudget { |
| 63 | + return { id: entryFile, entryFile, budget, kind: 'facade', denyPlatformImplementations: true }; |
| 64 | +} |
| 65 | + |
| 66 | +function hub(entryFile: string, budget: number): EagerClosureBudget { |
| 67 | + return { id: entryFile, entryFile, budget, kind: 'hub', denyPlatformImplementations: false }; |
| 68 | +} |
| 69 | + |
| 70 | +export const EAGER_CLOSURE_BUDGETS: EagerClosureBudget[] = [ |
| 71 | + // packages/contracts/src/facades/*.ts -- measured 2026-08-22 on origin/main (base e5bfde3d1); |
| 72 | + // budget = actual + a few files of headroom. All 14 are implementation-neutral vocabulary per |
| 73 | + // ADR-0019 ("Contracts may depend on kernel vocabulary but never on concrete platform |
| 74 | + // packages or daemon implementation types"), so all deny platform implementations. |
| 75 | + facade('packages/contracts/src/facades/client.ts', 4), // actual 2 |
| 76 | + facade('packages/contracts/src/facades/command.ts', 12), // actual 9 |
| 77 | + facade('packages/contracts/src/facades/device.ts', 11), // actual 8 |
| 78 | + facade('packages/contracts/src/facades/interaction.ts', 30), // actual 25 |
| 79 | + facade('packages/contracts/src/facades/capture.ts', 12), // actual 9 |
| 80 | + facade('packages/contracts/src/facades/platform.ts', 48), // actual 42 |
| 81 | + facade('packages/contracts/src/facades/session.ts', 8), // actual 5 |
| 82 | + facade('packages/contracts/src/facades/recording.ts', 6), // actual 3 |
| 83 | + facade('packages/contracts/src/facades/observability.ts', 10), // actual 7 |
| 84 | + facade('packages/contracts/src/facades/remote.ts', 4), // actual 2 |
| 85 | + facade('packages/contracts/src/facades/replay.ts', 6), // actual 3 |
| 86 | + facade('packages/contracts/src/facades/snapshot.ts', 11), // actual 8 |
| 87 | + facade('packages/contracts/src/facades/divergence.ts', 6), // actual 3 |
| 88 | + facade('packages/contracts/src/facades/progress.ts', 3), // actual 1 |
| 89 | + |
| 90 | + // Designated hub modules (ADR-0019's other named case): high-fan-in entry points that already |
| 91 | + // hold their own ad hoc eager-closure pin (`cli-startup-import-closure.test.ts`, |
| 92 | + // `session-teardown-import-closure.test.ts`). Those files keep their existing, MORE specific |
| 93 | + // assertions -- each names an individual known-expensive module, a stronger property for that |
| 94 | + // one module than a numeric ceiling gives. This table adds a second, general-purpose layer: a |
| 95 | + // size ceiling that catches ANY unexpected growth at the entry, not only the one pattern each ad |
| 96 | + // hoc test already watches for. |
| 97 | + hub('src/cli.ts', 420), // actual 386 |
| 98 | + // session-teardown.ts already eagerly evaluates 24 Apple perf/runner modules under |
| 99 | + // src/platforms/apple/ (that migration hasn't happened yet -- only the Android perf/ |
| 100 | + // snapshot-helper pair is lazy today, per the ad hoc test above), so denyPlatformImplementations |
| 101 | + // stays false here: turning it on would fail on today's real, reviewed state, not a regression. |
| 102 | + hub('src/daemon/session-teardown.ts', 140), // actual 121 |
| 103 | +]; |
0 commit comments