Skip to content

test(build): the private spec readers readRepoSource supersedes #289

Closed

Description

@sydevs-bot

Summary

#286 gave the nine specs that inventory src/ one walk. #302 (merged as #303, f09ac88) gave
every other spec one rooted reader — readRepoSource in src/test-support/repo-source.ts — and
a lint rule that bans the new URL(…, import.meta.url) root. Four specs still resolve a private
root with dirname(fileURLToPath(import.meta.url)), the form the rule leaves alone.

This is cleanup, not a defect: all four work. The cost is that the pattern a tenth spec author
copies is still the hand-rolled one, and nothing says so — #303's rule cannot see this form,
because repo-source.ts itself and six scripts/*.mjs need it.

Decisions

Approach

readRepoSource clears both walls the original three options were weighed against, and #303
measured each one:

  • jsdom is safe. REPO_ROOT is dirname(fileURLToPath(import.meta.url)), which Vite's web
    transform leaves alone. src/test-support/repo-source.jsdom.test.ts is the live proof.
  • It is not a walker route. scripts/select-unit-specs.mjs:61 marks a walker by the import of
    src/test-support/source-tree.ts alone, so these specs do not join the set that runs on every
    lane edit. That is why repo-source.ts is a module of its own, which its docblock states.

readSource is still the wrong reader for all four, even for a path under src/: it lives behind
the walk.

The four readers

Spec Carries Becomes
src/views/MapFrame.test.tsx:222 SRC plus a read helper, over 5 reads (:227, :251, :254, :258, :264) readRepoSource('src/views/FullInterface.tsx') and the rest, src/-prefixed
src/Widget.theme-root.test.tsx:98 the same reader, inline in the describe readRepoSource('src/Widget.tsx')
src/components/organisms/EventsList/DynamicEventsList.test.ts:15 FILE plus its own comment strip readRepoSource('src/components/organisms/EventsList/DynamicEventsList.tsx'), strip unchanged
src/Widget.translate.test.ts:19 FILE, read once at :26 and passed to ts.createSourceFile as its fileName readRepoSource('src/Widget.tsx'), with a path literal kept for the fileName argument

Two more things these four do not change:

  • DynamicEventsList.test.ts's comment strip stays local. readSourceWithoutComments is the
    deduped version and it is behind the walk, so taking it would cost the walker.
  • Widget.translate.test.ts keeps its own ts.createSourceFile. parseSource
    (src/test-support/source-ast.ts:3) imports source-tree, so it is a walker route too.

src/lib/brand.test.ts — the third shape

:64 and :68 read 'src/config/translations.en.json' and the seven COPY_FILES paths as
cwd-relative strings. They work only because vitest runs from the repo root. Those paths are
already repo-relative, so readRepoSource(copySnapshot()) and readRepoSource(file) are the
whole change, and the cwd dependency goes with it.

⚠ Keep COPY_FILES and copySnapshot() as quoted path literals. docs/testing.md names this
file as the spec that reaches src/App.tsx through the quoted repo-relative specifier form, which
scripts/select-unit-specs.mjs resolves. Inlining them would drop it from that selection.

The #156 contract is unchanged: readRepoSource returns raw text, comments included.

The lint rule that stops regrowth

After the migrations, exactly one spec writes fileURLToPath(import.meta.url):
src/Widget.standalone.test.ts:43, which needs an absolute root because importGraph resolves
module specifiers on disk (:77). So the form can be banned in specs with one
eslint-disable-next-line there naming the reason.

⚠ Add it as a second config object scoped to specs alone, and re-state #303's new URL
selector inside it.
ESLint flat config replaces a rule's options rather than merging them, so a
later block matching **/*.{test,spec}.{ts,tsx} would silently drop the new URL ban for every
spec. Widening #303's own block instead is not an option: src/test-support/repo-source.ts and
six scripts/*.mjs are in its scope and legitimately write the form.

{
  files: ['**/*.{test,spec}.{ts,tsx}'],
  rules: {
    'no-restricted-syntax': [
      'error',
      /* #303's NewExpression selector, restated verbatim */,
      {
        selector:
          'CallExpression[callee.name="fileURLToPath"][arguments.0.type="MetaProperty"][arguments.0.property.name="url"]',
        message: 'Read a repo file with readRepoSource (src/test-support/repo-source.ts) (#289).',
      },
    ],
  },
}

docs/testing.md

#303's new paragraph reads "A spec reading a file the walk cannot reach goes through
readRepoSource". All four specs here read files the walk can reach and come here anyway,
because the walk is what marks a walker. repo-source.ts's docblock already says it the right
way — "a spec reading a file or two comes here, whichever directory it sits in". Bring the doc in
line, and name the new rule beside #303's.

Acceptance criteria

  • The four specs in the table read through readRepoSource, and none declares a root or a
    reader of its own.
  • src/lib/brand.test.ts reads through readRepoSource, and COPY_FILES and
    copySnapshot() still hold quoted repo-relative path literals.
  • eslint.config.js fails a spec that writes fileURLToPath(import.meta.url), and still
    fails one that writes new URL(…, import.meta.url).
  • src/Widget.standalone.test.ts:43 keeps its root, under an eslint-disable-next-line whose
    comment says the graph walk needs an absolute path.
  • Every migrated spec still fails when its own defect is reintroduced at the causing site.
  • docs/testing.md says a single-file read comes to readRepoSource whatever directory the
    spec sits in, and names both lint rules.

Verification checklist

  • git grep -n "fileURLToPath(import.meta.url)" -- '*.test.ts' '*.test.tsx' returns only
    src/Widget.standalone.test.ts:43
  • Both bans watched going red: add fileURLToPath(import.meta.url) to a spec, then
    new URL('./x', import.meta.url) to a different one, run pnpm lint after each, remove both
  • pnpm lint && pnpm typecheck && pnpm test:run green
  • For each of the five specs changed, reintroduce its own defect at the site that causes it
    and watch it go red
  • pnpm test:run scripts/select-unit-specs.test.ts green — the walker set is still 12 and the
    widest selection still ≤ 26. An edit to repo-source.ts itself selected 20 on f09ac88;
    five more importers put it near 25, so measure rather than assume

Notes

Why four of #303's five "stay as they are" specs move here. #303's Detail lists
Widget.standalone, MapFrame, Widget.theme-root, Widget.translate and DynamicEventsList
as safe under both transforms and leaves them. That call was about the crash its lint rule
closes. This ticket is about the duplicate reader, which is why four of them move and
Widget.standalone does not.

Out of scope, and why:

  • src/Widget.standalone.test.ts:43 — importGraph resolves specifiers with existsSync /
    statSync (:77), so it works in absolute paths by construction. test(build): one source walker for the nine specs that inventory src/ #286 measured the memo it
    misses at ~10ms over 231 files.
  • src/lib/shadow-patches.test.ts:147 — its root is createRequire(...).resolve() into
    node_modules, which no repo-relative reader can serve.

Two corrections to the body this replaces. src/Widget.translate.test.ts carries the same
private reader and was missed by the original survey; it predates this ticket (#240).
src/lib/brand.test.ts was ruled out for reading no src/-relative path, which was right for
readSource and is wrong for a repo-relative reader. src/styles/sheet.test.ts,
src/config/theme/palette.defaults.test.ts and src/styles/host-reset.test.ts are done — #303
took all three.

Raised by the cleanup lenses on the #286 PR as a finding outside that ticket's walk. Five files is
past the direct-fix bound, and these specs are outside prAllowlistGlobs, so it is a ticket rather
than a commit on that PR.

Activity

  1. added theissue type on Oct 13, 2026
  2. added
    proposal
    on Oct 13, 2026
  3. moved this from Revising to Proposed in SYDevelopers Technical Roadmapon Oct 13, 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
    • 17:26Z implement · attempt 1 · session · done
    • 17:26Z implement · attempt 1 · session
    • 17:13Z revise · attempt 1 · session · done
    • 17:13Z revise · attempt 1 · session
    • 07:46Z implement · attempt 2 · session · done

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

  9. added
    bot:working
    and removed
    bot:working
    on Oct 16, 2026
  10. 11 remaining items

  11. Ardnived commented on Oct 16, 2026

    @Ardnived
    Contributor

    @sydevs-bot Revise the ticket to take your recommended approach. #303 is merged or in the merge queue

  12. added
    bot:working
    and removed on Oct 16, 2026
  13. changed the title [-]test(build): the per-file `src/` readers the shared walker now supersedes[/-] [+]test(build): the private spec readers `readRepoSource` supersedes[/+] on Oct 16, 2026
  14. sydevs-bot commented on Oct 16, 2026

    @sydevs-bot
    ContributorAuthor

    Revised to option 1. #303 merged as f09ac88, so readRepoSource is on main and nothing blocks this.

    Narrowed and corrected against that merge:

    • Four specs left, not six. test(build): a repo-root reader, so the new URL(…, import.meta.url) trap can be linted #303 took sheet, palette.defaults and host-reset.
    • Widget.translate.test.ts:19 joins — same private reader, missed by the first survey.
    • brand.test.ts:64 joins. I ruled it out for reading no src/-relative path. That was right for readSource and wrong for a repo-relative reader: its paths are already repo-relative, read off the cwd.
    • A lint rule bans fileURLToPath(import.meta.url) in specs. Only Widget.standalone.test.ts:43 then writes it, under one disable. Without the rule the hand-rolled root is still what the next author copies.

    The jsdom wall is gone — REPO_ROOT survives the web transform. The walker wall stands, and repo-source.ts sits outside it.

    Title now names the reader, not the walker.

    @sydevs-bot implement starts the work.

    🤖 Written by the sydevs autonomous loop — see what this is


    Generated by Claude Code

  15. added and removed
    bot:working
    on Oct 16, 2026
  16. Ardnived commented on Oct 16, 2026

    @Ardnived
    Contributor

    @sydevs-bot implement

  17. moved this from Revising to Approved in SYDevelopers Technical Roadmapon Oct 16, 2026
  18. added
    bot:working
    on Oct 16, 2026
  19. removed
    bot:working
    on Oct 16, 2026
  20. added a commit that references this issue on Nov 20, 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