Skip to content

Commit f77f9ee

Browse files
committed
test(replay): resolve package-relative ownership imports
1 parent fec8036 commit f77f9ee

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎src/daemon/__tests__/replay-coordinator-ownership.test.ts‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ type ImportSite = {
5050
declarationTypeOnly: boolean;
5151
};
5252

53+
const PRODUCTION_ROOTS = ['src', 'packages/replay-port/src'] as const;
54+
5355
function listProductionSourceFiles(): string[] {
54-
const roots = ['src', 'packages/replay-port/src'];
5556
const out: string[] = [];
5657
const walk = (dir: string): void => {
5758
for (const entry of fs.readdirSync(path.join(REPO_ROOT, dir), { withFileTypes: true })) {
@@ -65,14 +66,14 @@ function listProductionSourceFiles(): string[] {
6566
out.push(relPath);
6667
}
6768
};
68-
for (const root of roots) walk(root);
69+
for (const root of PRODUCTION_ROOTS) walk(root);
6970
return out;
7071
}
7172

7273
function resolveRelativeTarget(fromFile: string, spec: string): string | null {
7374
if (!spec.startsWith('.')) return null;
7475
const resolved = path.posix.normalize(path.posix.join(path.posix.dirname(fromFile), spec));
75-
return resolved.startsWith('src/') ? resolved : null;
76+
return PRODUCTION_ROOTS.some((root) => resolved.startsWith(`${root}/`)) ? resolved : null;
7677
}
7778

7879
function collectImportSites(
@@ -401,6 +402,17 @@ test('coordinator ownership scanning catches aliases, namespaces, and dynamic im
401402
);
402403
});
403404

405+
test('a package-relative dynamic import resolves within the scanned replay port', () => {
406+
const probe = 'packages/replay-port/src/daemon-port/probe.ts';
407+
const source = "void import('./session-replay-divergence.ts');";
408+
const overrides = new Map([[probe, source]]);
409+
assert.deepEqual(unresolvedDynamicImportSites([probe], overrides), []);
410+
assert.equal(
411+
collectImportSites(probe, source)[0]?.target,
412+
'packages/replay-port/src/daemon-port/session-replay-divergence.ts',
413+
);
414+
});
415+
404416
test('daemon replay production files never import the P4a ReplaySessionTransaction projection', () => {
405417
const offenders = PRODUCTION_FILES.filter(
406418
(file) =>

0 commit comments

Comments
 (0)