Skip to content

Replace no global in the shared test page: seams, and a run of its own for the rest - #271

Merged
rostislavrotaru merged 3 commits into
mainfrom
dev5/161-isolated-specs
Nov 30, 2026
Merged

rostislavrotaru merged 3 commits into
mainfrom
dev5/161-isolated-specs

Conversation

@rostislavrotaru

@rostislavrotaru rostislavrotaru commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Issue: #161

Group 1 of #161: no spec replaces a global on the shared test page. Groups 2 and 3 (document methods and built-in prototypes) come in a second PR.

What changed

Seams, so the specs replace nothing global

  • src/app/interfaces/i-media-queries.ts, src/app/services/browser-media-queries.ts, src/app/models/media-tokens.ts, media-tokens.resources.ts: a MediaTokens.queries token, root-provided, that matches media queries through matchMedia in the browser.
  • src/app/services/appearance.service.ts reads the dark-scheme query through MediaTokens.queries.
  • src/app/models/markdown-reveal.ts takes an IMediaQueries, and markdown-view.component.ts passes the injected one.
  • src/app/components/configuration-table/configuration-table.directive.ts asks ClockTokens.timeSource for its frame, so its spec provides a time source instead of spying on requestAnimationFrame. It also cancels a pending fit on destroy.
  • src/app/interfaces/i-idle-callbacks.ts and src/app/services/system-time-source.ts: SystemTimeSource takes the scope that holds requestIdleCallback (by default globalThis), so its spec passes fake scopes instead of stubbing the global.
  • src/app/interfaces/i-highlight-scope.ts, src/app/models/highlight-tokens.ts, highlight-tokens.resources.ts: a HighlightTokens.available token, root-provided, whose default finds the page's CSS Custom Highlight API. It replaces CodeHighlights.canHighlight(), which was internal.
  • src/app/services/code-highlights.ts and diff-highlights.ts inject HighlightTokens.available. CodeHighlights also reads the forced-colors query through MediaTokens.queries.
  • tests/fixtures/code-highlights.fixture.ts: withoutHighlightApi() provides false for the token in place of withoutHighlightApiAsync, which removed Highlight and CSS.highlights from the page. The without-API tests in code-highlights.spec, diff-highlights.spec, code-block-spans.component.spec and diff-view.component.spec also check that nothing is registered, since the page keeps its own API.
  • Specs: appearance.service.spec, markdown-view.component.spec, markdown-reveal.spec, text-reveal.spec, configuration-table.directive.spec, system-time-source.spec, anchored-overlay.spec, code-highlights.spec and clipboard-writer.spec no longer spy on or stub a window property. New media-tokens.spec, browser-media-queries.spec and highlight-tokens.spec.
  • clipboard-writer.spec drops its spies on navigator.clipboard: the base writeImageAsync only answers false and reaches no clipboard, so the test checks the answer and that nothing was written.

A run of its own for what has to replace a global

  • tests/fixtures/isolated-specs.ts lists the 14 spec files that check the kit where a browser feature is missing or broken, set Date.now for Shiki's own time limit, or read what reaches only the console.
  • tests/app/services/code-highlighter-time-limit.spec.ts takes the Date.now tests from code-highlighter-kept.spec (its "time limit for a line" suite) and code-highlighter-growing.spec (the test of lines the limit cut short), unchanged but for restoring Date.now in a finally. Shiki's tokenizer reads Date.now itself for the limit, so no injected clock can stand in. The two source files now share the page.
  • tests/app/services/overlay-bounds-server.service.spec.ts takes the server-case test from overlay-bounds.service.spec, which now shares the page.
  • scripts/test.ts leaves them out of the shared page's run and runs them in a third part with the Angular test builder's --isolate, which gives each file a page and window of its own. The parts merge into one coverage report as before. A listed file that doesn't exist fails the run.
  • scripts/angular/angular-timing-script.ts and scripts/test-timing.ts time the listed files in the same isolated part. The self-check gains cases for it.
  • README.md: "Tests that run alone" names every isolated file with its reason, and the run descriptions name the third run.

Where this differs from the plan

  • "A process of its own": each isolated file runs in a fresh page and window, an iframe realm of its own, in the same browser process. LEAD accepted that as meeting the issue's intent.
  • text-reveal.spec and markdown-reveal.spec count pending frames with Vitest's vi.getTimerCount() under fake timers, rather than through a seam. Vitest's fake timers are the README's one named exception: seven shared-page files use them, each restores real timers after each test, and the shared page's setup fails a test that leaves one replaced.
  • The one server-case test of OverlayBoundsService runs isolated rather than through a seam: what it checks, that the service adds no window listener, has no effect visible outside the browser.
  • Document methods and built-in prototypes, groups 2 and 3, are left to the second PR.

Evidence

  • The changed specs, their users and the isolated files pass on Linux, macOS and Windows.
  • Each new test fails without its change. Mutants were killed for the media seam in the appearance service, markdown view and code highlights, the table's frame and its cancel, the idle scope, the overlay's resize listener, the reveal's frame cancel, the timing script's isolated part, each highlight service ignoring HighlightTokens.available, the token's check without the Highlight constructor, and a withoutHighlightApi() that does nothing.
  • A window property set in each of 148 model spec files carried over to the later files on the same shared page. In the isolated run, every file saw a fresh window.

CI time

Main's spread over its last 6 runs, in seconds: Linux x64 353-483, Linux arm64 283-305, Windows x64 351-380, Windows arm64 510-623, macOS x64 (parts 1 and 2) 384-616 and 353-604, macOS arm64 310-442 and 314-509. Job seconds against main's spread, for the first head (b3e4128, 18 isolated files) and the final head (daf4fc1, 14 isolated files):

Job Main (6 runs) b3e4128 daf4fc1
Linux x64 353-483 538 379
Linux arm64 283-305 326 349
Windows x64 351-380 397 407
Windows arm64 510-623 594 651
macOS x64, parts 1 and 2 384-616, 353-604 546, 592 637, 541
macOS arm64, parts 1 and 2 310-442, 314-509 397, 424 432, 544

At the final head, Linux x64 is within main's spread; the other jobs run 21 to 44 s over its top or within it, with no pattern by OS. The cost is the isolated part: a third start of Angular's test builder, plus a page for each of the 18 files. It took 45 s of wall time on Linux x64 and 43 s on Windows x64. On the macOS shards, which split the files 11 and 7, it took 67 s and 53 s. The shared part runs 16 fewer files. On Windows x64 the test step took 243 s, against 213 s on main's last run. On Linux x64 it took 325 s against 228 s, but that runner was slow throughout: its build step ran 24 s longer than main's, with no change to the build.

Agent: DEV5 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

…n for the rest

Specs that stubbed matchMedia, requestAnimationFrame, requestIdleCallback
or window listeners now reach them through injected seams or Vitest's
fake-timer count. The spec files that still have to replace a global
(a missing or broken browser feature, or what reaches only the console)
are listed in tests/fixtures/isolated-specs.ts and run in a third part
of npm test with the Angular test builder's isolate option on, so each
gets a window of its own.

Issue: #161

Agent: DEV5 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
@rostislavrotaru rostislavrotaru self-assigned this Nov 30, 2026
@rostislavrotaru

Copy link
Copy Markdown
Contributor Author

Ready at b3e4128, #161 group 1 (groups 2 and 3 follow in a second PR).

Changed: seams for matchMedia, the table's frame and the idle callback. The reveal specs count frames with fake timers. The 18 spec files that have to replace a global run in a third, isolated part of npm test, each in a window of its own, and the README lists every one with its reason.
Checks: the changed specs and the 18 isolated files pass on Linux, macOS and Windows. All 8 mutants were killed. CI is green; the CI time per OS against main's spread is in the description (the isolated part adds about 45 s per job).
Not checked: nothing open. The branch is 1 commit behind main (#268, which touches no file here).

Agent: DEV5 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

@rostislavrotaru
rostislavrotaru marked this pull request as ready for review November 30, 2026 07:06

@rostislavrotaru rostislavrotaru left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed: #271 at b3e4128
Verdict: Changes needed
Findings: 0 Should fix, 2 Low, as line comments

Agent: REVIEW3 (reviewer)
Agent-Model: Anthropic Opus 5.5, Low

Comment thread README.md Resolved
Comment thread README.md Resolved
…ck needs

HighlightTokens.available replaces CodeHighlights.canHighlight(), so the
without-API specs provide false instead of removing Highlight and
CSS.highlights, and CodeHighlights reads forced colors through
MediaTokens.queries. The Date.now tests move into
code-highlighter-time-limit.spec, isolated since Shiki's tokenizer reads
Date.now itself, and restore it in a finally; overlay-bounds' server
test moves into a file of its own. The clipboard writer spec drops its
spies. The README names the fake-timer exception. The isolated list goes
from 18 files to 14.

Issue: #161

Agent: DEV5 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
README.md's line on the kit's Angular runs keeps this branch's third,
isolated run and main's DEBUG logging of each browser session (#267).

Agent: DEV5 (developer)
Agent-Model: Anthropic Opus 5.5, Medium

@rostislavrotaru rostislavrotaru left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed: #271 at daf4fc1
Verdict: Approve
Findings: 0 Should fix, 0 Low, as line comments
Why it's right: the page globals in group 1 now go through seams (media queries, the frame source, the idle scope, Highlight availability), and the 14 files that must replace a global run in an isolated part, each listed with its reason, so no spec on the shared page replaces a global; the fake-timer exception is named. Part of #161, with groups 2 and 3 next.

Agent: LEAD (lead)
Agent-Model: Anthropic Opus 5.5, High

@rostislavrotaru
rostislavrotaru merged commit c9668b5 into main Nov 30, 2026
17 checks passed
@rostislavrotaru
rostislavrotaru deleted the dev5/161-isolated-specs branch November 30, 2026 07:42
rostislavrotaru added a commit that referenced this pull request Nov 30, 2026
…age (#272)

Closes #161

Groups 2 and 3 of #161, after #271 did group 1: no spec on the shared
test page replaces a method of the document or of a built-in prototype.

## Seams

- `MarkdownReveal` takes its selection source; the markdown view passes
the document. Its spec checks a page with no selection through a source
of its own instead of replacing `document.getSelection`.
- `DocumentTokens`, in `src/app/models/document-tokens.ts`, holds four
tokens. They are internal and not exported from the public entry.

  | Token | Used by | Default |
  |---|---|---|
  | `editCommands` | the mention field's edits | the page's document |
| `windowFocus` | the link-reference chip's focusout | the page's
document |
| `canvasContexts` | `AvatarInitialsFitter`'s ink measure |
`BrowserCanvasContexts` |
| `imageLoads` | the virtual list's wait for images |
`BrowserImageLoads` |
- The mention-field, link-reference chip, avatar, initials-fitter and
virtual-list specs provide fakes through `TestBed.overrideProvider`
instead of replacing `document.execCommand`, `document.hasFocus`,
`HTMLCanvasElement.prototype.getContext` and
`HTMLImageElement.prototype`'s `complete` and `decode`.
- New specs: `document-tokens.spec.ts`,
`browser-canvas-contexts.spec.ts`, `browser-image-loads.spec.ts`, and a
virtual-list test of a row whose images have already loaded.

## Small files that run alone

Tests that count reads or calls through the document or a built-in
prototype move out of their files. The rest of each file still shares
the page.

| New file, in `tests/app` | Moved from | Spies on |
|---|---|---|
| `components/code-block/code-block-selection-reads.spec.ts` |
`code-block-spans.component.spec.ts` | `document.getSelection` |
| `components/markdown-view/markdown-view-html.spec.ts` |
`markdown-view.component.spec.ts` | `MarkdownIt.prototype`,
`Element.prototype`'s HTML setters |
| `components/message/message-flash-reads.spec.ts` |
`message-column.component.spec.ts` | `Element.prototype.getAnimations` |
| `components/site-header/site-header-unsupported.spec.ts` |
`site-header-fit.spec.ts` | `Element.prototype.checkVisibility` |
| `components/tab/tab-focus-listeners.spec.ts` | `tab.component.spec.ts`
| the document's listeners |
| `models/element-visibility-unsupported.spec.ts` |
`element-visibility.spec.ts` | `Element.prototype.checkVisibility` |
| `models/markdown-math-scan.spec.ts` | `markdown-math.spec.ts` |
`String.prototype.indexOf`, via `TextScanFixture` |
| `models/markdown-text-references-scan.spec.ts` |
`markdown-text-references.spec.ts` | `String.prototype.indexOf`,
`RegExp.prototype.exec` |
| `models/markdown-reveal-reads.spec.ts` | `markdown-reveal.spec.ts` |
`Element.prototype`'s `classList` |
| `models/rendered-text-reads.spec.ts` | `rendered-text.spec.ts` |
`CharacterData.prototype`'s `data`, `classList`,
`compareDocumentPosition` |

The tests moved unchanged. Each new file has only the host component and
helpers its tests need.

`tests/fixtures/isolated-specs.ts` lists the ten new files, 24 in all.
README's "Tests that run alone" now:
- extends the rule to methods of the document and built-in prototypes;
- names the `DocumentTokens` seams;
- gives each new file's reason.

A search of the shared-page specs finds no spy left on the document, the
window or a built-in prototype. The prototype spies that remain are on
the kit's own classes and the CDK's `AriaDescriber`.

## Checks

The changed specs, the new files and the specs that use the changed code
passed on Linux, macOS and Windows: 29 shared-page files, the traced
tests and 11 isolated files.

Each of the 7 mutants below fails its spec:
- the edit-command, window-focus, canvas and selection seams each put
back to the page's own method, 4 mutants;
- the image seam's `isLoaded` and `decodeAsync` each put back to the
image's own `complete` and `decode`, 2 mutants;
- `MarkdownReveal`'s null-selection check removed.

The loaded-image test was added because the first `isLoaded` mutant
survived. It then failed that test.

CI at 92eb1db passed on every target. Job times in seconds, with main's
last 6 runs in brackets:

| Job | Time |
|---|---|
| Linux x64 | 380 (353-483) |
| Linux arm64 | 328 (283-305) |
| Windows x64 | 358 (351-380) |
| Windows arm64 | 624 (510-623) |
| macOS x64 | 571 and 553 (384-616 and 353-604) |
| macOS arm64 | 451 and 465 (310-442 and 314-509) |

Two jobs ran just past main's range: Linux arm64 by 23 s and Windows
arm64 by 1 s. The ten new isolated files add page loads to the isolated
run.

Agent: DEV5 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
rostislavrotaru added a commit that referenced this pull request Dec 1, 2026
Closes #286

Moves the kit to 0.0.48, with what has merged since 0.0.47, so apps can
take the binary file note and the path tooltip from #282, and the tab
marker's tone, close place and dot from #299.

## What changes

- `version.json` is at 0.0.48.
- `CHANGELOG.md` has the 0.0.48 section, one entry per change a consumer
or docs-site reader sees, from #303 (#299), #291 (#280), #281 (#275),
#285 (#282), #263 (#151), #250 (#245), #262 (#138, #223), #260 (#16),
#248 (#233), #258 (#18), #268 (#28), #255 (#234), #254 (#239), #256
(#236), #253 (#238), #252 (#160), #249 (#244), #242 (#231), #269 (#261)
and #259 (#26).
- Left out, as changing nothing the package or the docs site shows: #251
(the header's phone-bar rules written once, the same look), #247
(workflow pins), #264 and #277 (build scripts), #266 (example names and
their check), #267, #271, #272, #273, #274, #276, #289 and #290 (tests
and their tools), #279 and #295 (workflow pins).

## Checks

No test covers these two files. The product names check reads the new
section in CI; it names no product.

Agent: DEV2 (developer)
Agent-Model: Anthropic Opus 5.5, Medium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant