@jterrazz/test 15.1.0 → 15.2.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/dist/oxlint.cjs CHANGED
@@ -173,9 +173,6 @@ function walk(root, visit) {
173
173
  } else if (isNode(value)) walk(value, visit);
174
174
  }
175
175
  }
176
- function isNode(value) {
177
- return typeof value === "object" && value !== null && typeof value.type === "string";
178
- }
179
176
  /** The source start offset of a node or comment (oxlint `start`, else `range[0]`). */
180
177
  function nodeStart(node) {
181
178
  if (node === void 0) return -1;
@@ -222,6 +219,27 @@ function importSourceVisitor(onSource) {
222
219
  ImportExpression: fromSourceField
223
220
  };
224
221
  }
222
+ /** Is this value an AST node — an object carrying a `type` string? */
223
+ function isNode(value) {
224
+ return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
225
+ }
226
+ /**
227
+ * A node's child by key, or `undefined` when the key holds something else.
228
+ *
229
+ * Every rule reaches for `node.parent`, `node.id`, `node.value`; the node shape
230
+ * types them as `unknown`, so each reach was an assertion of its own. One
231
+ * guarded read is the same answer, checked once.
232
+ */
233
+ function child(node, key) {
234
+ const value = node?.[key];
235
+ return isNode(value) ? value : void 0;
236
+ }
237
+ /** The name of an identifier node, or `undefined` for anything else. */
238
+ function identifierName(node) {
239
+ if (node?.type !== "Identifier") return;
240
+ const { name } = node;
241
+ return typeof name === "string" ? name : void 0;
242
+ }
225
243
  //#endregion
226
244
  //#region src/lint/manifest.ts
227
245
  /**
@@ -350,7 +368,7 @@ const RULE_DOCS = {
350
368
  },
351
369
  "c1-domain-structure": {
352
370
  channel: "statique",
353
- convention: "La forme de l’arbre `specs/` se déclare via l’option `depth` : `facet-domain` (défaut — `*.test.ts` à la profondeur facet/domain, `*.specification.ts` au root de la facette), `facet` (test au root de la facette OU un dossier domaine plus bas, jamais plus profond), `mirror` (test à toute profondeur ≥ 1, nommé d’après son dossier), `off`. Dans tous les modes, `off` compris : un dossier à underscore initial est du SOL, jamais un domaine — aucune spec ne vit dedans. Une exception, et une seule : le sol peut être du CODE, et un `<module>.test.ts` posé À CÔTÉ du `<module>.ts` qu’il teste y est légal (c’est la loi I2) ; un test sans module voisin, ou un `*.specification.ts`, reste une violation.",
371
+ convention: "La forme de l’arbre `specs/` se déclare via l’option `depth` : `facet-domain` (défaut — `*.test.ts` à la profondeur facet/domain, `*.specification.ts` au root de la facette), `facet` (test au root de la facette OU un dossier domaine plus bas, jamais plus profond), `mirror` (test à toute profondeur ≥ 1, nommé d’après son dossier), `off`. Dans tous les modes, `off` compris : un dossier à underscore initial est du SOL, jamais un domaine — aucune spec ne vit dedans. Une exception, et une seule : le sol peut être du CODE, et un `<module>.test.ts` posé À CÔTÉ du `<module>.ts` qu’il teste y est légal (c’est la loi I2) ; un test sans module voisin, ou un `*.specification.ts`, reste une violation. Un `.test.tsx` est hors de portée : une unité rendue se spécifie à côté de son composant, jamais dans un arbre facette/domaine — c’est I2 qui tient son voisinage.",
354
372
  family: "C",
355
373
  id: "C1",
356
374
  rationale: "Une profondeur fixe rend la place de chaque fichier prévisible et détectable statiquement."
@@ -467,6 +485,36 @@ const RULE_DOCS = {
467
485
  id: "D15",
468
486
  rationale: "Un statut isolé ne fige que le code de réponse et jette tout le reste du payload ; le golden complet capture la forme entière et sa grammaire de tokens (complète d12w, qui exige un amas de sondes de corps et manque le cas de la sonde de statut solitaire)."
469
487
  },
488
+ "e5-no-simulated-dom": {
489
+ channel: "statique",
490
+ convention: "Un fichier de test ne déclare pas de DOM simulé : la pragma `@vitest-environment happy-dom|jsdom` est une erreur. Portée : les rôles qui EXÉCUTENT un test (`module`, `component`, `specification`) — une config de projet est le domaine de E5b.",
491
+ facet: "component",
492
+ family: "E",
493
+ fix: "Déplacer le test à côté de son composant en `.test.tsx` et le faire collecter par le projet `component()`.",
494
+ id: "E5",
495
+ rationale: "Un DOM simulé se comporte PRESQUE comme un navigateur, et ce qui est livré est jugé par un vrai : la facette component rend dans le Chromium que la facette website pilote déjà.",
496
+ reach: "tests"
497
+ },
498
+ "e5b-no-simulated-dom-config": {
499
+ channel: "statique",
500
+ convention: "Une config vitest ne déclare pas de DOM simulé : `environment: 'happy-dom'|'jsdom'` est une erreur ; `'node'` et `'edge-runtime'` nomment un vrai runtime et restent hors de portée.",
501
+ facet: "component",
502
+ family: "E",
503
+ fix: "Supprimer `environment` et collecter le rendu avec `component()` ; les tests de module restent sous node.",
504
+ id: "E5b",
505
+ rationale: "La pragma (E5) n’engage qu’un fichier ; la config engage tout ce que le projet collecte — c’est ainsi qu’un dépôt hérite d’un DOM simulé que personne n’a choisi test par test.",
506
+ reach: "config"
507
+ },
508
+ "e6-component-project-helper": {
509
+ channel: "statique",
510
+ convention: "Un projet navigateur vient de `component()` : dans une config vitest, une clé `browser` sous `test` qui n'est pas dans un appel à `component(...)` est une erreur. Une clé `browser` ailleurs (un `define`, un enregistrement d'env) n'est pas un bloc de projet et reste hors de portée.",
511
+ facet: "component",
512
+ family: "E",
513
+ fix: "Remplacer le bloc par `component({ vite })` et ne garder que ce qui appartient au projet.",
514
+ id: "E6",
515
+ rationale: "Le provider épinglé à la version exacte du runner, le service worker servi depuis l’installation du framework, la transformation JSX du Vite courant, le pré-bundling d’un cache froid et les dossiers d’artefacts sont autant de runs qui passent ici et échouent sur la machine suivante.",
516
+ reach: "config"
517
+ },
470
518
  "f1-no-subpath-import": {
471
519
  channel: "statique",
472
520
  convention: "Tout s’importe depuis `@jterrazz/test` ; un import de `@jterrazz/test/<subpath>` est une erreur, sauf les subpaths que la map `exports` du paquet publie — `@jterrazz/test/oxlint` (plugin de lint) et `@jterrazz/test/vitest` (surface de configuration du runner) — exemptés partout. La liste est LUE du manifeste, jamais recopiée dans la règle.",
@@ -483,7 +531,7 @@ const RULE_DOCS = {
483
531
  },
484
532
  "f3-specs-public-entry": {
485
533
  channel: "statique",
486
- convention: "Depuis `specs/`, seul l’import en profondeur des INTERNES du framework est interdit : un chemin relatif résolvant dans `src/{specification,integrations,vitest,lint}/` du dépôt du framework, ou tout `@jterrazz/test/<subpath>` autre que `@jterrazz/test/oxlint`. Les imports de la source de SA PROPRE app par un consommateur sont toujours permis (c’est le motif documenté) ; seul `specs/integrations/` peut importer en profondeur `src/integrations/**`.",
534
+ convention: "Depuis `specs/`, seul l’import en profondeur des INTERNES du framework est interdit : un chemin relatif résolvant dans `src/{specification,integrations,vitest,lint}/` du dépôt du framework, ou tout `@jterrazz/test/<subpath>` que la map `exports` du paquet ne publie pas — les subpaths publiés sont exemptés, LUS du manifeste comme en F1, qui en tient la liste. Les imports de la source de SA PROPRE app par un consommateur sont toujours permis (c’est le motif documenté) ; seul `specs/integrations/` peut importer en profondeur `src/integrations/**`.",
487
535
  family: "F",
488
536
  id: "F3",
489
537
  rationale: "Tester par la surface publique garde les specs découplées des chemins internes du framework, sans gêner le consommateur qui importe sa propre app."
@@ -502,6 +550,26 @@ const RULE_DOCS = {
502
550
  id: "F5",
503
551
  rationale: "Cantonner les fixtures aux tests empêche la donnée de test de fuir dans le code de prod."
504
552
  },
553
+ "f6-no-foreign-test-runtime": {
554
+ channel: "statique",
555
+ convention: "Un fichier de test n’importe pas de second runtime de test : `@testing-library/*`, `happy-dom`, `jsdom`, `vitest/browser`, `vitest-browser-*` et `@vitest/browser*` sont des erreurs. Portée : les rôles qui EXÉCUTENT un test (`module`, `component`, `specification`) — la config d’un projet fixture et un module de providers sous `specs/` nomment légitimement l’adaptateur.",
556
+ facet: "component",
557
+ family: "F",
558
+ fix: "Passer par la facette qui remplace le seam : `component.render()`, le vocabulaire d’éléments et le visiteur.",
559
+ id: "F6",
560
+ rationale: "Un test qui importe l’adaptateur parle le dialecte de l’adaptateur : un dépôt finit avec autant de vocabulaires que de seams. Les groupes livrés sont ceux que la facette component REMPLACE ; le reste de la famille suit la vague de règles.",
561
+ reach: "tests"
562
+ },
563
+ "g4-no-dom-in-module-test": {
564
+ channel: "statique",
565
+ convention: "Un test de module ne touche aucun global du DOM : `document`, `window`, `navigator`, `HTMLElement` référencés en position de VALEUR dans un fichier de rôle `module` HORS de `specs/` sont une erreur. Un nom en position de type (`x as HTMLElement`) et un garde `typeof window` n’atteignent aucun document et restent hors de portée ; tant que le rôle `spec` n’existe pas, `module` couvre aussi les `.test.ts` de `specs/`, que la règle laisse donc passer.",
566
+ facet: "component",
567
+ family: "G",
568
+ fix: "Renommer le test en `.test.tsx` à côté du composant qu’il rend, et le faire collecter par `component()`.",
569
+ id: "G4",
570
+ rationale: "Un test de module tourne sous node, où `document` n’existe pas : un test qui en réclame un ne teste pas un module, il rend quelque chose — et il a désormais un endroit où aller.",
571
+ reach: "module"
572
+ },
505
573
  "i1-layer-boundaries": {
506
574
  channel: "statique",
507
575
  convention: "Le projet DÉCLARE ses couches sous `src/` via l’option `layers` (paquets autorisés, imports internes, un dossier = une dépendance, seams) ; tout import hors des arêtes déclarées est une erreur. Sans carte de couches, la règle est inerte.",
@@ -511,9 +579,11 @@ const RULE_DOCS = {
511
579
  },
512
580
  "i2-sibling-test-naming": {
513
581
  channel: "statique",
514
- convention: "Le test de `<fichier>.ts` est `<fichier>.test.ts` à côté de lui ; un `.test.ts` mal nommé, ou un dossier `__tests__/`, est une erreur.",
582
+ convention: "Le test de `<fichier>.ts` est `<fichier>.test.ts` à côté de lui ; un `.test.ts` mal nommé, ou un dossier `__tests__/`, est une erreur. Une unité RENDUE obéit à la même loi où qu’elle vive : un `.test.tsx` est voisin du `.tsx` qu’il rend, ou du `.ts` du hook ou de la fonction DOM dont il porte l’hôte.",
515
583
  family: "I",
584
+ fix: "Poser le test à côté de l’unité qu’il couvre, sous le même basename.",
516
585
  id: "I2",
586
+ reach: "tests",
517
587
  rationale: "Des tests voisins (parité avec le `foo_test.go` de Go) gardent test et code ensemble et découvrables."
518
588
  },
519
589
  "i4-no-vi-mock-in-src": {
@@ -844,14 +914,19 @@ function sortKey(entry) {
844
914
  ];
845
915
  }
846
916
  [
847
- ...Object.entries(RULE_DOCS).map(([name, doc]) => ({
848
- channel: doc.channel,
849
- convention: doc.convention,
850
- family: doc.family,
851
- id: doc.id,
852
- name,
853
- rationale: doc.rationale
854
- })),
917
+ ...Object.entries(RULE_DOCS).map(([name, doc]) => {
918
+ const entry = {
919
+ channel: doc.channel,
920
+ convention: doc.convention,
921
+ family: doc.family,
922
+ id: doc.id,
923
+ name,
924
+ rationale: doc.rationale
925
+ };
926
+ if ("fix" in doc) entry.fix = doc.fix;
927
+ if ("reach" in doc) entry.reach = doc.reach;
928
+ return entry;
929
+ }),
855
930
  ...CHECKER_PASSES,
856
931
  ...RUNTIME_RULES,
857
932
  ...PROCESS_RULES
@@ -863,6 +938,55 @@ function sortKey(entry) {
863
938
  return av.localeCompare(bv);
864
939
  });
865
940
  //#endregion
941
+ //#region src/lint/role.ts
942
+ /** The four ground names — what the specs of a row stand ON, never a spec. */
943
+ const GROUND = /* @__PURE__ */ new Set([
944
+ "_expected",
945
+ "_fixtures",
946
+ "_requests",
947
+ "_seeds"
948
+ ]);
949
+ /** A vitest config, whatever extension the project writes it in. */
950
+ const CONFIG = /^vitest\.config\.[cm]?[jt]s$/u;
951
+ /**
952
+ * The kind of file this path names.
953
+ *
954
+ * The suffix decides, and the order matters: a `*.specification.ts` is a
955
+ * specification wherever it sits, ground swallows anything under it that is not
956
+ * a test of its own module, and `.tsx` versus `.ts` is what tells a RENDERED
957
+ * unit from a plain one — the same distinction the two project helpers collect
958
+ * on, so a file is judged by the rules of the project that actually runs it.
959
+ */
960
+ function roleOf(filename) {
961
+ const parts = segments(filename);
962
+ const base = parts.at(-1) ?? "";
963
+ const inSpecs = isUnderSpecs(filename);
964
+ if (base.endsWith(".specification.ts") || base.endsWith(".specification.tsx")) return {
965
+ inSpecs,
966
+ role: "specification"
967
+ };
968
+ if (CONFIG.test(base)) return {
969
+ inSpecs,
970
+ role: "config"
971
+ };
972
+ if (base.endsWith(".test.tsx")) return {
973
+ inSpecs,
974
+ role: "component"
975
+ };
976
+ if (base.endsWith(".test.ts")) return {
977
+ inSpecs,
978
+ role: "module"
979
+ };
980
+ if (parts.slice(0, -1).some((segment) => GROUND.has(segment))) return {
981
+ inSpecs,
982
+ role: "ground"
983
+ };
984
+ return {
985
+ inSpecs,
986
+ role: "other"
987
+ };
988
+ }
989
+ //#endregion
866
990
  //#region src/lint/rules/a1-specification-file.ts
867
991
  const SPECIFICATION_SUFFIX$2 = ".specification.ts";
868
992
  /**
@@ -873,10 +997,15 @@ const SPECIFICATION_SUFFIX$2 = ".specification.ts";
873
997
  * Framework-internal unit tests of the constructors themselves (this repo's
874
998
  * `src/**\/*.test.ts`) disable the rule via a config override — for consumers
875
999
  * the rule is universal.
1000
+ *
1001
+ * The A family does not reach a `component`-role file. A rendered unit has no
1002
+ * runner to create: no server to start, no database to isolate, no binary to
1003
+ * find — which is why the component facet has no constructor and no
1004
+ * specification file for A1 to point at.
876
1005
  */
877
1006
  const a1SpecificationFile = {
878
1007
  create(context) {
879
- if (context.filename.endsWith(SPECIFICATION_SUFFIX$2)) return {};
1008
+ if (context.filename.endsWith(SPECIFICATION_SUFFIX$2) || roleOf(context.physicalFilename).role === "component") return {};
880
1009
  return { CallExpression(node) {
881
1010
  const member = specificationMember(node);
882
1011
  if (member !== void 0) context.report({
@@ -2843,6 +2972,122 @@ const d15wStatusOnlyProbe = {
2843
2972
  }
2844
2973
  };
2845
2974
  //#endregion
2975
+ //#region src/lint/rules/e5-no-simulated-dom.ts
2976
+ /** The pragma vitest reads to swap a test file's environment. */
2977
+ const PRAGMA = /@vitest-environment\s+(?<environment>[\w-]+)/u;
2978
+ /** The two simulated DOMs. */
2979
+ const SIMULATED$1 = /* @__PURE__ */ new Set(["happy-dom", "jsdom"]);
2980
+ /** The roles that RUN a test file — the only ones a pragma steers. */
2981
+ const REACHED$1 = /* @__PURE__ */ new Set([
2982
+ "component",
2983
+ "module",
2984
+ "specification"
2985
+ ]);
2986
+ /**
2987
+ * CONVENTIONS E5 — no simulated DOM, stated per file.
2988
+ *
2989
+ * `@vitest-environment happy-dom` buys a document that behaves almost like a
2990
+ * browser's: almost is the whole problem, because what ships is judged by a
2991
+ * real one. The component facet renders in the Chromium the website facet
2992
+ * already drives, so the pragma has nothing left to buy.
2993
+ */
2994
+ const e5NoSimulatedDom = {
2995
+ create(context) {
2996
+ if (!REACHED$1.has(roleOf(context.physicalFilename).role)) return {};
2997
+ return { Program(node) {
2998
+ for (const comment of context.sourceCode.getAllComments()) {
2999
+ const environment = PRAGMA.exec(comment.value)?.groups?.environment;
3000
+ if (environment !== void 0 && SIMULATED$1.has(environment)) context.report({
3001
+ data: { environment },
3002
+ messageId: "pragma",
3003
+ node
3004
+ });
3005
+ }
3006
+ } };
3007
+ },
3008
+ meta: {
3009
+ docs: RULE_DOCS["e5-no-simulated-dom"],
3010
+ messages: { pragma: "`@vitest-environment {{environment}}` simulates a browser this framework can open for real — a rendered thing is a `.test.tsx` beside its component, collected by the `component()` project (E5 — docs/13-linting.md#e5-no-simulated-dom)." },
3011
+ type: "problem"
3012
+ }
3013
+ };
3014
+ //#endregion
3015
+ //#region src/lint/rules/e5b-no-simulated-dom-config.ts
3016
+ /** The two simulated DOMs. */
3017
+ const SIMULATED = /* @__PURE__ */ new Set(["happy-dom", "jsdom"]);
3018
+ /**
3019
+ * CONVENTIONS E5b — the same ban, where a project states it for a whole tree.
3020
+ *
3021
+ * The pragma (E5) is one file's; `environment: 'happy-dom'` in a config is
3022
+ * every file the project collects, which is how a repository ends up with a
3023
+ * simulated DOM nobody ever chose per test. `'node'` and `'edge-runtime'` are
3024
+ * out of reach: they name a real runtime, not a drawing of one.
3025
+ */
3026
+ const e5bNoSimulatedDomConfig = {
3027
+ create(context) {
3028
+ if (roleOf(context.physicalFilename).role !== "config") return {};
3029
+ return { Program(node) {
3030
+ walk(node, (candidate) => {
3031
+ if (candidate.type !== "Property" || propertyKeyName(candidate) !== "environment") return;
3032
+ const environment = stringValue(child(candidate, "value"));
3033
+ if (environment !== void 0 && SIMULATED.has(environment)) context.report({
3034
+ data: { environment },
3035
+ messageId: "configured",
3036
+ node: candidate
3037
+ });
3038
+ });
3039
+ } };
3040
+ },
3041
+ meta: {
3042
+ docs: RULE_DOCS["e5b-no-simulated-dom-config"],
3043
+ messages: { configured: "`environment: '{{environment}}'` gives every file of this project a drawing of a browser — a rendered thing is a `.test.tsx` beside its component, collected by `component()` (E5b — docs/13-linting.md#e5b-no-simulated-dom-config)." },
3044
+ type: "problem"
3045
+ }
3046
+ };
3047
+ //#endregion
3048
+ //#region src/lint/rules/e6-component-project-helper.ts
3049
+ /** Is this property the RUNNER's browser block, rather than a key that shares its name? */
3050
+ function isRunnerBrowserBlock(node) {
3051
+ for (let current = child(node, "parent"); current !== void 0; current = child(current, "parent")) if (current.type === "Property" && propertyKeyName(current) === "test") return true;
3052
+ return false;
3053
+ }
3054
+ /** Is this node inside a call to `component(...)`? */
3055
+ function insideComponentCall(node) {
3056
+ for (let current = child(node, "parent"); current !== void 0; current = child(current, "parent")) if (current.type === "CallExpression" && identifierName(child(current, "callee")) === "component") return true;
3057
+ return false;
3058
+ }
3059
+ /**
3060
+ * CONVENTIONS E6 — a browser project comes from `component()`.
3061
+ *
3062
+ * A hand-rolled `browser: { … }` block is a project that has to rediscover
3063
+ * everything the seam already knows: the provider pinned to the runner's exact
3064
+ * version, the service worker served from the framework's own install, the JSX
3065
+ * transform the current Vite actually uses, the dependencies a cold cache must
3066
+ * pre-bundle, and the artefact directories Browser Mode otherwise leaks at the
3067
+ * repository root. Every one of those is a run that fails on the second
3068
+ * machine, so the helper owns them and a config states only what is its own.
3069
+ */
3070
+ const e6ComponentProjectHelper = {
3071
+ create(context) {
3072
+ if (roleOf(context.physicalFilename).role !== "config") return {};
3073
+ return { Program(node) {
3074
+ walk(node, (candidate) => {
3075
+ if (candidate.type !== "Property" || propertyKeyName(candidate) !== "browser") return;
3076
+ if (!isRunnerBrowserBlock(candidate)) return;
3077
+ if (!insideComponentCall(candidate)) context.report({
3078
+ messageId: "handRolled",
3079
+ node: candidate
3080
+ });
3081
+ });
3082
+ } };
3083
+ },
3084
+ meta: {
3085
+ docs: RULE_DOCS["e6-component-project-helper"],
3086
+ messages: { handRolled: "Use `component({ vite })` — the provider, the worker and the pipeline are its, and a hand-rolled `browser:` block is the run that passes here and fails on the next machine (E6 — docs/13-linting.md#e6-component-project-helper)." },
3087
+ type: "problem"
3088
+ }
3089
+ };
3090
+ //#endregion
2846
3091
  //#region src/lint/package-exports.ts
2847
3092
  /**
2848
3093
  * The subpaths this package actually publishes, read from its OWN
@@ -2941,7 +3186,7 @@ const f1NoSubpathImport = {
2941
3186
  const TEST_FILE$4 = /\.(?:test|fixtures|specification)\.[cm]?[jt]sx?$/u;
2942
3187
  const CONFIG_FILE = /(?:^|[/\\])[\w.-]*\.config\.[cm]?[jt]s$/u;
2943
3188
  const TEST_IMPORT$1 = /\.(?:test|fixtures)(?:\.[cm]?[jt]sx?)?$/u;
2944
- const TOOL_SUBPATH$1 = "@jterrazz/test/oxlint";
3189
+ const TOOL_SUBPATH = "@jterrazz/test/oxlint";
2945
3190
  /**
2946
3191
  * CONVENTIONS F2 — production code never imports a test artefact. In a
2947
3192
  * non-test file (not `*.test.ts` / `*.fixtures.ts` / `*.specification.ts`,
@@ -2960,7 +3205,7 @@ const f2NoTestImportsInProd = {
2960
3205
  const file = context.filename;
2961
3206
  if (TEST_FILE$4.test(file) || CONFIG_FILE.test(file) || isUnderSpecs(file)) return {};
2962
3207
  return { ...importSourceVisitor(({ node, source }) => {
2963
- if (source === TOOL_SUBPATH$1) return;
3208
+ if (source === TOOL_SUBPATH) return;
2964
3209
  if (source === "vitest" || source.startsWith("vitest/")) context.report({
2965
3210
  data: { source },
2966
3211
  messageId: "testImport",
@@ -2987,7 +3232,6 @@ const f2NoTestImportsInProd = {
2987
3232
  //#endregion
2988
3233
  //#region src/lint/rules/f3-specs-public-entry.ts
2989
3234
  const PACKAGE = "@jterrazz/test";
2990
- const TOOL_SUBPATH = "@jterrazz/test/oxlint";
2991
3235
  /**
2992
3236
  * The framework's own top-level `src/` layers. Deep-importing any of these from
2993
3237
  * a spec couples the spec to internals the public entry exists to hide. These
@@ -3005,12 +3249,19 @@ const FRAMEWORK_LAYERS = /* @__PURE__ */ new Set([
3005
3249
  /**
3006
3250
  * CONVENTIONS F3 — from `specs/`, deep-importing the FRAMEWORK's internals is
3007
3251
  * forbidden: a relative path resolving inside the framework repo's
3008
- * `src/{specification,integrations,vitest,lint}/`, or any `@jterrazz/test/<subpath>`
3009
- * other than the sanctioned tool-facing `@jterrazz/test/oxlint`. A consumer's
3010
- * imports of its OWN app source are always allowed — that is the pattern.
3252
+ * `src/{specification,integrations,vitest,lint}/`, or a `@jterrazz/test/<subpath>`
3253
+ * the package does not publish. A consumer's imports of its OWN app source are
3254
+ * always allowed — that is the pattern.
3011
3255
  *
3012
- * Distinct from F1 (which bans `@jterrazz/test/<subpath>` from any file): F3 is
3013
- * the specs-specific guard that also reaches relative framework-internal paths.
3256
+ * The exempt subpaths are not listed here: they are read from the package's own
3257
+ * `exports` map, the same source F1 uses. A published subpath IS the public
3258
+ * surface — reaching `@jterrazz/test/vitest` from a specs-tree `vitest.config.ts`
3259
+ * is the prescribed gesture, not a leak — so what a spec must not reach is what
3260
+ * the manifest never published. The root entry (`.`) is not a subpath and never
3261
+ * concerned this branch: `@jterrazz/test` is the public entry F3 points at.
3262
+ *
3263
+ * Distinct from F1 (which judges the same specifiers from any file): F3 is the
3264
+ * specs-specific guard that also reaches relative framework-internal paths.
3014
3265
  * Documented exception: specs under `specs/integrations/` may deep-import the
3015
3266
  * integration module they cover (`src/integrations/**`).
3016
3267
  */
@@ -3018,12 +3269,17 @@ const f3SpecsPublicEntry = {
3018
3269
  create(context) {
3019
3270
  const anchor = specsAnchor(context.filename);
3020
3271
  if (anchor === void 0) return {};
3272
+ const published = new Set(declaredSubpaths());
3273
+ const exempt = published.size === 0 ? "none" : [...published].join(", ");
3021
3274
  const underIntegrations = anchor.relative[0] === "integrations";
3022
3275
  return { ...importSourceVisitor(({ node, source }) => {
3023
3276
  if (source.startsWith(`${PACKAGE}/`)) {
3024
- if (source === TOOL_SUBPATH) return;
3277
+ if (published.has(source)) return;
3025
3278
  context.report({
3026
- data: { source },
3279
+ data: {
3280
+ published: exempt,
3281
+ source
3282
+ },
3027
3283
  messageId: "deepImport",
3028
3284
  node
3029
3285
  });
@@ -3035,7 +3291,10 @@ const f3SpecsPublicEntry = {
3035
3291
  if (!FRAMEWORK_LAYERS.has(layer)) return;
3036
3292
  if (underIntegrations && layer === "integrations") return;
3037
3293
  context.report({
3038
- data: { source },
3294
+ data: {
3295
+ published: exempt,
3296
+ source
3297
+ },
3039
3298
  messageId: "deepImport",
3040
3299
  node
3041
3300
  });
@@ -3043,7 +3302,7 @@ const f3SpecsPublicEntry = {
3043
3302
  },
3044
3303
  meta: {
3045
3304
  docs: RULE_DOCS["f3-specs-public-entry"],
3046
- messages: { deepImport: "specs/ must not deep-import framework internals — reach the framework via its public entry (@jterrazz/test, or src/index.js in this repo), not \"{{source}}\" (F3 — see docs/13-linting.md; only @jterrazz/test/oxlint, and src/integrations/** from specs/integrations/, are exempt)." },
3305
+ messages: { deepImport: "specs/ must not deep-import framework internals — reach the framework via its public entry (@jterrazz/test, or src/index.js in this repo), not \"{{source}}\" (F3 — see docs/13-linting.md). Exempt: the published subpaths {{published}}, and src/integrations/** from specs/integrations/." },
3047
3306
  type: "problem"
3048
3307
  }
3049
3308
  };
@@ -3100,6 +3359,164 @@ const f5FixturesOnlyFromTests = {
3100
3359
  }
3101
3360
  };
3102
3361
  //#endregion
3362
+ //#region src/lint/rules/f6-no-foreign-test-runtime.ts
3363
+ const GROUPS = [
3364
+ {
3365
+ fix: "`component.render()` and the element vocabulary render in a real browser — the queries are the same nouns, and they run against what ships",
3366
+ matches: (source) => source === "@testing-library" || source.startsWith("@testing-library/")
3367
+ },
3368
+ {
3369
+ fix: "a drawing of a browser proves what a browser does not — a rendered thing is a `.test.tsx` beside its component, collected by `component()`",
3370
+ matches: (source) => source === "happy-dom" || source === "jsdom"
3371
+ },
3372
+ {
3373
+ fix: "Browser Mode is the seam, not the surface — `component.render()` owns the locators, the visitor and the ARIA tree",
3374
+ matches: (source) => source === "vitest/browser" || source.startsWith("vitest-browser-") || source.startsWith("@vitest/browser")
3375
+ }
3376
+ ];
3377
+ /**
3378
+ * The roles that RUN a test — never a fixture app's config or a provider module
3379
+ * that happens to sit under `specs/`. A fixture project's own `vitest.config.ts`
3380
+ * has to name the provider, and a `providers.tsx` has to import the adapter it
3381
+ * wraps: neither is a spec speaking a second dialect.
3382
+ */
3383
+ const REACHED = /* @__PURE__ */ new Set([
3384
+ "component",
3385
+ "module",
3386
+ "specification"
3387
+ ]);
3388
+ /**
3389
+ * CONVENTIONS F6 — a test file imports no second test runtime.
3390
+ *
3391
+ * Every seam the framework owns is one a spec must not reach around: a test
3392
+ * that imports the adapter speaks the adapter's dialect, and a repository ends
3393
+ * up with as many vocabularies as it has seams. The groups the rule carries are
3394
+ * the ones the component facet REPLACES.
3395
+ */
3396
+ const f6NoForeignTestRuntime = {
3397
+ create(context) {
3398
+ if (!REACHED.has(roleOf(context.physicalFilename).role)) return {};
3399
+ return { ...importSourceVisitor(({ node, source }) => {
3400
+ const group = GROUPS.find((candidate) => candidate.matches(source));
3401
+ if (group !== void 0) context.report({
3402
+ data: {
3403
+ fix: group.fix,
3404
+ source
3405
+ },
3406
+ messageId: "foreignRuntime",
3407
+ node
3408
+ });
3409
+ }) };
3410
+ },
3411
+ meta: {
3412
+ docs: RULE_DOCS["f6-no-foreign-test-runtime"],
3413
+ messages: { foreignRuntime: "`{{source}}` is a second test runtime in a test file: {{fix}} (F6 — docs/13-linting.md#f6-no-foreign-test-runtime)." },
3414
+ type: "problem"
3415
+ }
3416
+ };
3417
+ //#endregion
3418
+ //#region src/lint/rules/g4-no-dom-in-module-test.ts
3419
+ /** The globals that only exist where a document does. */
3420
+ const DOM_GLOBALS = /* @__PURE__ */ new Set([
3421
+ "document",
3422
+ "HTMLElement",
3423
+ "navigator",
3424
+ "window"
3425
+ ]);
3426
+ /** The node kinds that BIND a name, and the key each one binds it under. */
3427
+ const BINDINGS = {
3428
+ CatchClause: "param",
3429
+ ClassDeclaration: "id",
3430
+ FunctionDeclaration: "id",
3431
+ ImportDefaultSpecifier: "local",
3432
+ ImportNamespaceSpecifier: "local",
3433
+ ImportSpecifier: "local",
3434
+ VariableDeclarator: "id"
3435
+ };
3436
+ /**
3437
+ * Every name this file declares for itself.
3438
+ *
3439
+ * A file-wide set rather than a scope chain: the rule only needs to know that
3440
+ * `document` is the test's own binding somewhere, and a name shadowed in one
3441
+ * scope is not a global in another. It can only under-report, which is the
3442
+ * right direction for a guard.
3443
+ */
3444
+ function declaredNames(root) {
3445
+ const names = /* @__PURE__ */ new Set();
3446
+ const add = (node) => {
3447
+ const name = identifierName(node);
3448
+ if (name !== void 0) names.add(name);
3449
+ };
3450
+ walk(root, (node) => {
3451
+ const key = BINDINGS[node.type];
3452
+ if (key !== void 0) add(child(node, key));
3453
+ const { params } = node;
3454
+ if (Array.isArray(params)) {
3455
+ for (const parameter of params) if (isNode(parameter)) add(parameter);
3456
+ }
3457
+ });
3458
+ return names;
3459
+ }
3460
+ /** The node kinds a name sits in when it is a TYPE, not a value the test reaches. */
3461
+ const TYPE_POSITIONS = /* @__PURE__ */ new Set([
3462
+ "TSInterfaceHeritage",
3463
+ "TSQualifiedName",
3464
+ "TSTypeQuery",
3465
+ "TSTypeReference"
3466
+ ]);
3467
+ /** Is this identifier read as a value, rather than named as a property, a key or a type? */
3468
+ function isValueReference(node) {
3469
+ const parent = child(node, "parent");
3470
+ if (parent === void 0) return true;
3471
+ if (TYPE_POSITIONS.has(parent.type)) return false;
3472
+ if (parent.type === "UnaryExpression" && parent.operator === "typeof") return false;
3473
+ if (parent.type === "MemberExpression") return child(parent, "property") !== node || parent.computed === true;
3474
+ if (parent.type === "Property") return child(parent, "value") === node || parent.computed === true;
3475
+ return true;
3476
+ }
3477
+ /**
3478
+ * CONVENTIONS G4 — a module test touches no DOM.
3479
+ *
3480
+ * A module test runs under node, where `document` does not exist: a test that
3481
+ * reaches for one is not testing a module, it is rendering something, and the
3482
+ * place for that is a `.test.tsx` beside the component.
3483
+ *
3484
+ * Reach is the `module` role OUTSIDE `specs/`: a `.test.tsx` is the rendered
3485
+ * kind and lives in a page, where those globals are what it is there to use;
3486
+ * and under `specs/` an api or cli spec is a `.test.ts` too until the `spec`
3487
+ * role exists, so the guard stops at the tree it can judge.
3488
+ *
3489
+ * A name in a TYPE position (`x as HTMLElement`) and a `typeof window` guard
3490
+ * name no document: neither reaches one, and a module that must run in both
3491
+ * runtimes is tested by exactly that guard.
3492
+ */
3493
+ const g4NoDomInModuleTest = {
3494
+ create(context) {
3495
+ const identity = roleOf(context.physicalFilename);
3496
+ if (identity.role !== "module" || identity.inSpecs) return {};
3497
+ let declared = /* @__PURE__ */ new Set();
3498
+ return {
3499
+ Identifier(node) {
3500
+ const name = identifierName(node);
3501
+ if (name === void 0 || !DOM_GLOBALS.has(name) || declared.has(name) || !isValueReference(node)) return;
3502
+ context.report({
3503
+ data: { name },
3504
+ messageId: "domGlobal",
3505
+ node
3506
+ });
3507
+ },
3508
+ Program(node) {
3509
+ declared = declaredNames(node);
3510
+ }
3511
+ };
3512
+ },
3513
+ meta: {
3514
+ docs: RULE_DOCS["g4-no-dom-in-module-test"],
3515
+ messages: { domGlobal: "`{{name}}` does not exist where a module test runs — a rendered thing is a `.test.tsx` beside its component, collected by the `component()` project (G4 — docs/13-linting.md#g4-no-dom-in-module-test)." },
3516
+ type: "problem"
3517
+ }
3518
+ };
3519
+ //#endregion
3103
3520
  //#region src/lint/rules/i1-layer-boundaries.ts
3104
3521
  const TEST_OR_FIXTURES = /\.(?:test|fixtures)\.[cm]?[jt]sx?$/u;
3105
3522
  function matchesPackage(source, packages) {
@@ -3232,21 +3649,25 @@ const i1LayerBoundaries = {
3232
3649
  //#region src/lint/rules/i2-sibling-test-naming.ts
3233
3650
  const TEST_FILE$1 = /\.test\.[cm]?[jt]sx?$/u;
3234
3651
  /**
3235
- * CONVENTIONS I2 — module tests are NEIGHBOURS: the test of `<file>.ts` is
3236
- * `<file>.test.ts` next to it (Go's `foo_test.go` parity). Flags, on visited
3237
- * files:
3652
+ * CONVENTIONS I2 — a unit's test is its NEIGHBOUR: the test of `<file>.ts` is
3653
+ * `<file>.test.ts` next to it (Go's `foo_test.go` parity). A rendered unit
3654
+ * answers to the same law wherever it lives: a `.test.tsx` sits beside the
3655
+ * `.tsx` it renders, or the `.ts` of the hook or DOM function it hosts. Flags,
3656
+ * on visited files:
3238
3657
  *
3239
3658
  * - a `src/**` test whose neighbour module `<file>.ts` does not exist;
3659
+ * - a `component`-role test (`*.test.tsx`) with no neighbour of any tree;
3240
3660
  * - any file living in a `__tests__/` directory under `src/`;
3241
3661
  * - any file under a root-level `tests/` directory (the only test roots are
3242
- * sibling module tests under `src/` and product specifications in `specs/`).
3662
+ * sibling tests under `src/` and product specifications in `specs/`).
3243
3663
  */
3244
3664
  const i2SiblingTestNaming = {
3245
3665
  create(context) {
3246
3666
  const file = context.physicalFilename;
3247
3667
  const parts = segments(file);
3248
3668
  return { Program(node) {
3249
- if (parts.includes("src")) {
3669
+ const rendered = roleOf(file).role === "component";
3670
+ if (parts.includes("src") || rendered) {
3250
3671
  if (parts.includes("__tests__")) context.report({
3251
3672
  messageId: "testsDir",
3252
3673
  node
@@ -3258,8 +3679,8 @@ const i2SiblingTestNaming = {
3258
3679
  ".js"
3259
3680
  ].map((extension) => file.replace(TEST_FILE$1, extension));
3260
3681
  if (!neighbours.some(isFile)) context.report({
3261
- data: { expected: neighbours[0]?.split(/[/\\]/u).at(-1) ?? "" },
3262
- messageId: "orphanTest",
3682
+ data: { expected: neighbours[rendered ? 1 : 0]?.split(/[/\\]/u).at(-1) ?? "" },
3683
+ messageId: rendered ? "orphanComponent" : "orphanTest",
3263
3684
  node
3264
3685
  });
3265
3686
  }
@@ -3276,6 +3697,7 @@ const i2SiblingTestNaming = {
3276
3697
  meta: {
3277
3698
  docs: RULE_DOCS["i2-sibling-test-naming"],
3278
3699
  messages: {
3700
+ orphanComponent: "A component test must sit NEXT to what it renders — no neighbour \"{{expected}}\" found (I2 — see docs/13-linting.md). A hook or a DOM function is the `.ts` of the same basename, with its Host in the test file.",
3279
3701
  orphanTest: "A src/ module test must sit NEXT to the module it tests — no neighbour \"{{expected}}\" found (I2 — see docs/13-linting.md). A test needing more than its module is a specification: move it to specs/.",
3280
3702
  rootTests: "A root-level tests/ directory is banned — module tests are siblings under src/, product specifications live in specs/ (I2 — see docs/13-linting.md).",
3281
3703
  testsDir: "__tests__/ directories are banned under src/ — the test of <file>.ts is its neighbour <file>.test.ts (I2 — see docs/13-linting.md)."
@@ -3518,11 +3940,16 @@ const plugin = {
3518
3940
  "d12w-response-body-probe": d12wResponseBodyProbe,
3519
3941
  "d13w-unfrozen-negative-fixture": d13wUnfrozenNegativeFixture,
3520
3942
  "d15w-status-only-probe": d15wStatusOnlyProbe,
3943
+ "e5-no-simulated-dom": e5NoSimulatedDom,
3944
+ "e5b-no-simulated-dom-config": e5bNoSimulatedDomConfig,
3945
+ "e6-component-project-helper": e6ComponentProjectHelper,
3521
3946
  "f1-no-subpath-import": f1NoSubpathImport,
3522
3947
  "f2-no-test-imports-in-prod": f2NoTestImportsInProd,
3523
3948
  "f3-specs-public-entry": f3SpecsPublicEntry,
3524
3949
  "f4-no-test-to-test-import": f4NoTestToTestImport,
3525
3950
  "f5-fixtures-only-from-tests": f5FixturesOnlyFromTests,
3951
+ "f6-no-foreign-test-runtime": f6NoForeignTestRuntime,
3952
+ "g4-no-dom-in-module-test": g4NoDomInModuleTest,
3526
3953
  "i1-layer-boundaries": i1LayerBoundaries,
3527
3954
  "i2-sibling-test-naming": i2SiblingTestNaming,
3528
3955
  "i4-no-vi-mock-in-src": i4NoViMockInSrc,