Skip to content

test(build): a repo-root reader, so the new URL(…, import.meta.url) trap can be linted #302

Closed

Description

@sydevs-bot

Summary

#289 found that new URL(<literal>, import.meta.url) is a landmine in a spec: Vite compiles that
form, and a client transform resolves it to the dev server's http://localhost/@fs/… rather than
a file URL. fileURLToPath then throws at import, so the whole spec file dies before one
assertion runs. It cost src/test-support/source-tree.ts exactly that, and
src/styles/sheet.adopt.test.ts had recorded the wrong root cause for it for as long as the
comment existed.

Four live sites remain, each one // @vitest-environment jsdom away from the same crash:

  • src/styles/sheet.test.ts:13 — vite.config.ts
  • src/styles/sheet.test.ts:53 — scripts/assert-css-scoped.mjs
  • src/styles/host-reset.test.ts:58 — docs/embedding.md
  • src/config/translations.test.ts:170 — scripts/sync-translations.mjs

All four are node-only today, so none is a defect. The cost is that the trap is held by prose in
one module's docblock, and #286's sibling hazard is held by a lint rule instead —
no-restricted-imports in eslint.config.js bans readdirSync under src/ outside
test-support/, and docs/testing.md praises it for being "caught at the import instead of by a
grep nobody runs". The reader rule got the grep.

Approach

A lint rule alone cannot close this: the four reads have nowhere else to go, because
readSource (src/test-support/source-tree.ts:66) joins against SRC_DIR and is src/-relative
by contract. Widening it would void the one thing its docblock protects.

So the two halves go together:

  1. A repo-root reader beside it — readRepoSource('docs/embedding.md'), resolved off the same
    SRC_DIR-derived root, memoised through the existing memo. test(build): the private spec readers readRepoSource supersedes #289 deliberately left the four
    reads local rather than reverse its own ticket's decision, so this is the decision to make
    first
    : does the repo want a second rooted reader, or does it prefer the reads local and the
    trap held by prose?
  2. Then the rule — no-restricted-syntax for NewExpression[callee.name='URL'] taking
    import.meta.url as its second argument, under src/**/*.{ts,tsx}, with a message naming
    this issue. Only reachable once (1) gives every legitimate read somewhere to go.

Seven sites write the same one-liner today, so the reader has callers beyond the four:
sheet.test.ts ×2, host-reset.test.ts:58, config/translations.test.ts:170,
scripts/ci-workflows.test.ts:11, scripts/postcss-scope-widget.test.ts:285,
scripts/deploy-headers.test.ts:23, scripts/wrangler-config.test.ts:15. ⚠ The scripts/ four
are outside the src/ lint scope and outside test-support/'s import rule — decide whether they
are in scope rather than assuming it.

Acceptance criteria

  • A decision is recorded on whether the repo wants a repo-root reader at all. A "no" closes
    this ticket, with the reason in docs/testing.md beside the grep.
  • On a "yes": every read of a path outside src/ from a src/ spec goes through it, and no
    src/ spec writes new URL(…, import.meta.url).
  • eslint.config.js fails on that form under src/, with a message naming the issue.
  • The rule was watched failing: add the form to a spec, see pnpm lint go red, remove it.
  • docs/testing.md's src/test-support/ section replaces the grep with the rule, and drops
    the "four live sites" warning test(build): the private spec readers readRepoSource supersedes #289 left there.

Verification checklist

  • grep -rn "new URL(.*import.meta.url" src/ --include='*.test.ts' --include='*.test.tsx'
    returns nothing but prose
  • pnpm lint && pnpm typecheck && pnpm test:run green
  • The per-edit walker set is still 12 and the widest selection still 24
    (scripts/select-unit-specs.test.ts) — a new shared module must not become a walker route

Notes

Raised by the altitude lens on the #289 PR, as a finding outside that ticket's scope: #289's own
body ruled the out-of-src/ reads stay local, and reversing that is a decision rather than a
cleanup. Six-plus files and outside prAllowlistGlobs, so a ticket rather than a commit there.

Activity

  1. added theissue type on Oct 15, 2026
  2. added
    proposal
    on Oct 15, 2026
  3. moved this from Revising to Proposed in SYDevelopers Technical Roadmapon Oct 15, 2026
  4. Ardnived commented on Oct 15, 2026

    @Ardnived
    Contributor

    @sydevs-bot implement

  5. removed
    proposal
    on Oct 15, 2026
  6. moved this from Proposed to Approved in SYDevelopers Technical Roadmapon Oct 15, 2026
  7. added
    bot:working
    on Oct 15, 2026
  8. sydevs-bot commented on Oct 15, 2026

    @sydevs-bot
    ContributorAuthor

    🤖 no session running

    recent dispatches
    • 06:56Z implement · attempt 1 · session · done
    • 06:56Z implement · attempt 1 · session
    • 05:14Z implement · attempt 2 · session · done
    • 05:14Z implement · attempt 2 · session
    • 23:25Z implement · attempt 1 · session · timed out

    Written by the sydevs dispatcher. Sessions never edit this comment.

  9. added
    bot:working
    and removed
    bot:working
    on Oct 16, 2026
  10. sydevs-bot commented on Oct 16, 2026

    @sydevs-bot
    ContributorAuthor

    The session for this item did not finish after 3 attempts. I have stopped retrying. A @sydevs-bot verb or mention from you starts me again.

    🤖 sydevs dispatcher

  11. added
    bot:working
    and removed on Oct 16, 2026
  12. removed
    bot:working
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    Low

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions