3232import fs from 'node:fs' ;
3333import path from 'node:path' ;
3434import { parseImports , resolveWorkspaceSpecifier } from './model.ts' ;
35- import { listTrackedPackageManifests , listTrackedProductionSources } from './tracked-sources.ts' ;
35+ import {
36+ DAEMON_SOURCE_ROOT ,
37+ listTrackedPackageManifests ,
38+ listTrackedProductionSources ,
39+ } from './tracked-sources.ts' ;
3640
3741export type PackageBoundaryViolation = {
3842 rule : string ;
@@ -174,9 +178,19 @@ function namedByExports(target: WorkspacePackage, specifier: string): boolean {
174178 return resolveWorkspaceSpecifier ( specifier , target . exportTargets ) !== undefined ;
175179}
176180
177- // Root `test/`, package-local `packages/*/test/`, *.test.*, and __tests__ trees are all
178- // test consumers — the same file vocabulary TEST_ONLY_FIXTURE_SUBPATHS' predicate uses.
179- const TEST_FILE_RE = / ( ^ | \/ ) _ _ t e s t s _ _ \/ | \. t e s t \. [ c m ] ? [ j t ] s x ? $ | (?: ^ | \/ ) t e s t \/ / ;
181+ const TEST_CONSUMER_RE = / ( ^ | \/ ) _ _ t e s t s _ _ \/ | \. t e s t \. [ c m ] ? [ j t ] s x ? $ | (?: ^ | \/ ) t e s t \/ / ;
182+
183+ /**
184+ * The one file vocabulary for "this file consumes test data": the root `test/` tree, a
185+ * package-local `test/` harness tree, `*.test.*` files, and `__tests__/` trees (root or
186+ * nested). Both test-data gates call this — the `./testing/` façade check and the
187+ * TEST_ONLY_FIXTURE_SUBPATHS predicate — so what counts as a test consumer is one rule,
188+ * not two spellings that drift. Pinned by an accept/deny table in
189+ * `package-boundaries-facade.test.ts`.
190+ */
191+ export function isTestConsumerFile ( file : string ) : boolean {
192+ return TEST_CONSUMER_RE . test ( file ) ;
193+ }
180194
181195/**
182196 * Façade policy (ADR-0033 amendment): a package publishes test data only under its
@@ -193,7 +207,7 @@ function checkTestDataOnlySites(
193207) : PackageBoundaryViolation | undefined {
194208 if ( ! site . specifier . startsWith ( `${ target . name } /testing/` ) ) return undefined ;
195209 if ( ! namedByExports ( target , site . specifier ) ) return undefined ;
196- if ( TEST_FILE_RE . test ( site . file ) ) return undefined ;
210+ if ( isTestConsumerFile ( site . file ) ) return undefined ;
197211 return {
198212 rule : 'R11 package-boundaries' ,
199213 file : site . file ,
@@ -244,12 +258,6 @@ export const TEST_ONLY_FIXTURE_SUBPATHS: ReadonlySet<string> = new Set([
244258 '@agent-device/replay-port/replay-script-source-fixtures' ,
245259] ) ;
246260
247- // Root `test/`, package-local `packages/<pkg>/test/`, *.test.ts, and __tests__ trees are test
248- // consumers; anything else is production. Mirrors R13's non-production predicate.
249- function isTestConsumerFile ( file : string ) : boolean {
250- return / (?: ^ | \/ ) t e s t \/ / . test ( file ) || file . endsWith ( '.test.ts' ) || file . includes ( '/__tests__/' ) ;
251- }
252-
253261/** Consumer side of `TEST_ONLY_FIXTURE_SUBPATHS`. */
254262function importsTestOnlyFixtureFromProduction ( file : string , specifier : string ) : boolean {
255263 return TEST_ONLY_FIXTURE_SUBPATHS . has ( specifier ) && ! isTestConsumerFile ( file ) ;
@@ -265,8 +273,7 @@ export const CLIENT_ONLY_SUBPATHS: ReadonlySet<string> = new Set([
265273 '@agent-device/replay-port/source-discovery' ,
266274] ) ;
267275
268- const DAEMON_SOURCE_FILE = / ^ (?: s r c \/ d a e m o n | p a c k a g e s \/ d a e m o n \/ s r c ) \/ / ;
269- // The daemon process also runs its root entry and composition root, outside the daemon tree.
276+ // The daemon process also runs its root entry and composition root, outside the daemon package.
270277const DAEMON_PROCESS_ROOT_FILES : ReadonlySet < string > = new Set ( [
271278 'src/daemon.ts' ,
272279 'src/daemon-composition.ts' ,
@@ -275,7 +282,7 @@ const DAEMON_PROCESS_ROOT_FILES: ReadonlySet<string> = new Set([
275282function importsClientOnlyFromDaemon ( file : string , specifier : string ) : boolean {
276283 return (
277284 CLIENT_ONLY_SUBPATHS . has ( specifier ) &&
278- ( DAEMON_SOURCE_FILE . test ( file ) || DAEMON_PROCESS_ROOT_FILES . has ( file ) ) &&
285+ ( file . startsWith ( DAEMON_SOURCE_ROOT ) || DAEMON_PROCESS_ROOT_FILES . has ( file ) ) &&
279286 ! isTestConsumerFile ( file )
280287 ) ;
281288}
0 commit comments