Repository navigation
Replace no global in the shared test page: seams, and a run of its own for the rest - #271
Conversation
…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
|
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 Agent: DEV5 (developer) |
…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
left a comment
There was a problem hiding this comment.
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
…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
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
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: aMediaTokens.queriestoken, root-provided, that matches media queries throughmatchMediain the browser.src/app/services/appearance.service.tsreads the dark-scheme query throughMediaTokens.queries.src/app/models/markdown-reveal.tstakes anIMediaQueries, andmarkdown-view.component.tspasses the injected one.src/app/components/configuration-table/configuration-table.directive.tsasksClockTokens.timeSourcefor its frame, so its spec provides a time source instead of spying onrequestAnimationFrame. It also cancels a pending fit on destroy.src/app/interfaces/i-idle-callbacks.tsandsrc/app/services/system-time-source.ts:SystemTimeSourcetakes the scope that holdsrequestIdleCallback(by defaultglobalThis), 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: aHighlightTokens.availabletoken, root-provided, whose default finds the page's CSS Custom Highlight API. It replacesCodeHighlights.canHighlight(), which was internal.src/app/services/code-highlights.tsanddiff-highlights.tsinjectHighlightTokens.available.CodeHighlightsalso reads the forced-colors query throughMediaTokens.queries.tests/fixtures/code-highlights.fixture.ts:withoutHighlightApi()providesfalsefor the token in place ofwithoutHighlightApiAsync, which removedHighlightandCSS.highlightsfrom the page. The without-API tests incode-highlights.spec,diff-highlights.spec,code-block-spans.component.specanddiff-view.component.specalso check that nothing is registered, since the page keeps its own API.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.specandclipboard-writer.specno longer spy on or stub a window property. Newmedia-tokens.spec,browser-media-queries.specandhighlight-tokens.spec.clipboard-writer.specdrops its spies onnavigator.clipboard: the basewriteImageAsynconly 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.tslists the 14 spec files that check the kit where a browser feature is missing or broken, setDate.nowfor Shiki's own time limit, or read what reaches only the console.tests/app/services/code-highlighter-time-limit.spec.tstakes theDate.nowtests fromcode-highlighter-kept.spec(its "time limit for a line" suite) andcode-highlighter-growing.spec(the test of lines the limit cut short), unchanged but for restoringDate.nowin afinally. Shiki's tokenizer readsDate.nowitself 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.tstakes the server-case test fromoverlay-bounds.service.spec, which now shares the page.scripts/test.tsleaves 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.tsandscripts/test-timing.tstime 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
text-reveal.specandmarkdown-reveal.speccount pending frames with Vitest'svi.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.OverlayBoundsServiceruns isolated rather than through a seam: what it checks, that the service adds no window listener, has no effect visible outside the browser.Evidence
HighlightTokens.available, the token's check without theHighlightconstructor, and awithoutHighlightApi()that does nothing.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):
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