Skip to content

test(core): import scanner and reference-exclusion rule - #6

Merged
omercnet merged 3 commits into
mainfrom
replay/03-scan
Nov 21, 2026
Merged

omercnet merged 3 commits into
mainfrom
replay/03-scan

Conversation

@omercnet

Copy link
Copy Markdown
Contributor

What changed

The import scanner used by the architecture tests (packages/core/test/boundaries/scan.ts, a parser-based scan for forbidden imports and process.env use), its tests, and the rule that no TypeScript project includes the reference/ directory (passes with that directory absent). It also brings the 17 fixture files that scan.test.ts reads.

Stacked on #4 (which is stacked on #3). Auto-merge stays off until the base has merged and this branch has been rebased onto main and retargeted.

Why

Later slices add rules that every package must obey; the scanner is the shared tool for them.

How it was verified

npm ci --ignore-scripts, lint, typecheck, build, npm test (28 tests), npm run test:tools, gitleaks (git and dir), actionlint, zizmor: all exit 0. The diff against its base is exactly the 21 files of this slice.

The fixtures were planned for the next slice, but scan.test.ts fails without them, so they moved here.

Not here yet

The adapter import rules and the lint-fixture test (next slice).

Checklist

  • Tests added or updated, or not applicable
  • No secrets or credentials committed
  • Docs updated, or not applicable

@baz-reviewer

baz-reviewer Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Review this PR on Baz

Baz Summary

Implement the architecture-test import scanner and validate repository boundaries around process.env, forbidden modules, and reference/ exclusion. Add parser-based scanning utilities, fixture coverage, and configuration checks across ESLint, TypeScript, Vitest, and workspace globs.

Topics

TopicDetails
Reference exclusion Verify that reference/ remains outside ESLint, TypeScript, Vitest, and workspace processing, while preserving benchmark project isolation and testing the TypeScript matcher behavior.
Modified files (1)
  • packages/core/test/boundaries/reference-excluded.test.ts
Latest Contributors(1)
UserCommitDate
omercnetfix(core): match tscon...November 21, 2026
Import scanner Implement scanSource and directory scanning to detect forbidden imports and process environment access, with fixtures covering allowed and disallowed patterns and verification against core source.
Modified files (20)
  • packages/core/test/boundaries/fixtures/allowed-zod.ts.txt
  • packages/core/test/boundaries/fixtures/clean.ts.txt
  • packages/core/test/boundaries/fixtures/env-default-import.ts.txt
  • packages/core/test/boundaries/fixtures/env-destructure.ts.txt
  • packages/core/test/boundaries/fixtures/env-named-import.ts.txt
  • packages/core/test/boundaries/fixtures/env-namespace-alias.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-aws-sdk-client-s3.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-descope-node-sdk.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-env.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-hocuspocus-server.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-kysely.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-pg-boss.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-pg.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-pino.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-rate-limiter-flexible.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-y-protocols.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-yjs.ts.txt
  • packages/core/test/boundaries/paths.ts
  • packages/core/test/boundaries/scan.test.ts
  • packages/core/test/boundaries/scan.ts
Latest Contributors(1)
UserCommitDate
omercnettest(core): import sca...November 21, 2026


Merger  Activate to get a short verdict whether this PR is good to go or not

Skills  Activate Skill Maintainer to keep your skills up to date

Planner  This PR would have been improved with Baz Planner - Try it now

@omercnet
omercnet marked this pull request as ready for review November 21, 2026 10:04
@shuni-bot

shuni-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🐕 Shuni Review

Adds the core boundary scanner, its fixtures and tests, and architecture tests that keep reference/ out of ESLint, tsconfig, Vitest, and workspaces.

Actionable comments posted: 0

🧹 Nitpick comments: 1

Merge risk: 🟢 Low: the change is test-only; the new gap affects only $-prefixed or $-suffixed process aliases.

See inline comments for details.

Unresolved prior findings: 1

⚠️ Review follow-up issue: Unresolved prior review threads: PRRT_kwDOV2YuVM66VFGP.

🤖 Model: claude-opus-5.5 · Effort: medium


Review scope: Full review

Reviewed files (21)
  • packages/core/test/boundaries/paths.ts
  • packages/core/test/boundaries/scan.ts
  • packages/core/test/boundaries/scan.test.ts
  • packages/core/test/boundaries/reference-excluded.test.ts
  • packages/core/test/boundaries/fixtures/allowed-zod.ts.txt
  • packages/core/test/boundaries/fixtures/clean.ts.txt
  • packages/core/test/boundaries/fixtures/env-default-import.ts.txt
  • packages/core/test/boundaries/fixtures/env-destructure.ts.txt
  • packages/core/test/boundaries/fixtures/env-named-import.ts.txt
  • packages/core/test/boundaries/fixtures/env-namespace-alias.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-aws-sdk-client-s3.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-descope-node-sdk.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-env.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-hocuspocus-server.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-kysely.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-pg-boss.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-pg.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-pino.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-rate-limiter-flexible.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-y-protocols.ts.txt
  • packages/core/test/boundaries/fixtures/forbidden-yjs.ts.txt

🐕 Review complete — View session on Shuni Portal 🐾

🤖 Model: claude-opus-5.5 · Effort: medium

baz-app[bot]
baz-app Bot previously approved these changes Nov 21, 2026

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: 1 inline finding. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

@baz-app
baz-app Bot dismissed their stale review November 21, 2026 10:10

Baz withdrew its approval because this pull request is no longer ready to merge.

Base automatically changed from replay/02-sleeps to main November 21, 2026 10:12

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: no new findings. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

@omercnet
omercnet merged commit a23abe2 into main Nov 21, 2026
10 checks passed
@omercnet
omercnet deleted the replay/03-scan branch November 21, 2026 10:20

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: 1 inline finding. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

const rel = path.relative(dir, path.join(repoRoot, probe)).split(path.sep).join("/");
const matches = (glob: string) => path.matchesGlob(rel, glob) || path.matchesGlob(rel, `${glob.replace(/\/$/, "")}/**`);
const excluded = (config.exclude ?? []).some(matches);
return !excluded && ((config.files ?? []).some((f) => path.resolve(dir, f) === path.join(repoRoot, probe)) || (config.include ?? []).some(matches));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Test Reliability | 🔵 Trivial | ⚡ Quick fix

Don't let exclude cancel an explicit files entry

In TypeScript, exclude filters only what include matches; files listed in files are always compiled. Here excluded also suppresses a files match. As a result, { files: ["reference/relay/src/index.ts"], exclude: ["reference"] } returns false even though tsc would compile that file.

Suggested change
return !excluded && ((config.files ?? []).some((f) => path.resolve(dir, f) === path.join(repoRoot, probe)) || (config.include ?? []).some(matches));
return (config.files ?? []).some((f) => path.resolve(dir, f) === path.join(repoRoot, probe)) || (!excluded && (config.include ?? []).some(matches));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still open at the current head. Line 23 still applies excluded before the files check, so exclude can cancel an explicitly listed file.

@shuni-bot shuni-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐕 Shuni review: 1 inline finding. Every changed file in this pull request was reviewed.

The full review summary is in Shuni's sticky review comment on this pull request.

if (processNamedEnvImport.test(text)) found.push("imports env from the process module");
for (const match of text.matchAll(processAliasImport)) {
const alias = match[1] ?? "";
if (new RegExp(`\\b${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\.\\s*env\\b`).test(text)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick fix

Use an identifier-aware boundary instead of \b around the alias

The escape is now complete, but \b sees a boundary only between a word character and a non-word character, and $ is not a word character. For import * as $p from "node:process"; $p.env.X, the pattern \b\$p… needs a boundary between the space and $ and finds none, so the env read is not reported. An alias that ends in $ fails the same way: the capture group backtracks and returns a shorter name. A lookbehind for identifier characters handles both cases.

Suggested change
if (new RegExp(`\\b${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\.\\s*env\\b`).test(text)) {
if (new RegExp(`(?<![\\w$])${alias.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*\\.\\s*env\\b`).test(text)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants