11import { readFileSync } from "node:fs" ;
22import { Script , createContext } from "node:vm" ;
33import { describe , expect , it , vi } from "vitest" ;
4+ import { buildOpenApiSpec } from "../../src/openapi/spec" ;
45
56const contentScript = readFileSync ( "apps/loopover-extension/content.js" , "utf8" ) ;
67const manifest = JSON . parse ( readFileSync ( "apps/loopover-extension/manifest.json" , "utf8" ) ) as {
@@ -22,21 +23,29 @@ describe("extension content script", () => {
2223 repo : "loopover" ,
2324 pullNumber : 146 ,
2425 } ) ;
25- // Issue pages are out of scope — no kind:"issue" classification, and no match.
26- expect ( internals . matchGitHubPageTarget ( "/JSONbored/loopover/issues/145" ) ) . toBeNull ( ) ;
27- expect ( internals . matchGitHubPageTarget ( "/JSONbored/loopover/pulls" ) ) . toBeNull ( ) ;
28- expect ( internals . matchPullRequestTarget ( "/JSONbored/loopover/pull/146" ) ) . toEqual ( {
29- owner : "JSONbored" ,
30- repo : "loopover" ,
31- pullNumber : 146 ,
32- } ) ;
33- expect ( internals . matchPullRequestTarget ( "/JSONbored/loopover/pull/146/files" ) ) . toEqual ( {
26+ // Sub-path pull pages still match (coverage previously pinned through the removed
27+ // matchPullRequestTarget duplicate — #8023).
28+ expect ( internals . matchGitHubPageTarget ( "/JSONbored/loopover/pull/146/files" ) ) . toEqual ( {
29+ kind : "pull_request" ,
3430 owner : "JSONbored" ,
3531 repo : "loopover" ,
3632 pullNumber : 146 ,
3733 } ) ;
38- expect ( internals . matchPullRequestTarget ( "/JSONbored/loopover/issues/146" ) ) . toBeNull ( ) ;
39- expect ( internals . matchPullRequestTarget ( "/JSONbored/loopover" ) ) . toBeNull ( ) ;
34+ // Issue pages are out of scope — no kind:"issue" classification, and no match.
35+ expect ( internals . matchGitHubPageTarget ( "/JSONbored/loopover/issues/145" ) ) . toBeNull ( ) ;
36+ expect ( internals . matchGitHubPageTarget ( "/JSONbored/loopover/pulls" ) ) . toBeNull ( ) ;
37+ expect ( internals . matchGitHubPageTarget ( "/JSONbored/loopover" ) ) . toBeNull ( ) ;
38+ } ) ;
39+
40+ // Extension ↔ backend drift guard (#8023): content.js's overlay request is only useful while
41+ // background.js routes the message type and the backend still serves pull-context. Anchoring
42+ // both here also exercises instrumented src/** so scoped CI shards emit a non-empty lcov when
43+ // --coverage.changed inherits the apps/**+test/** diff.
44+ it ( "sends a message type background.js routes, backed by a live pull-context endpoint" , ( ) => {
45+ expect ( contentScript ) . toContain ( 'type: "loopover:pull-context"' ) ;
46+ const backgroundScript = readFileSync ( "apps/loopover-extension/background.js" , "utf8" ) ;
47+ expect ( backgroundScript ) . toContain ( '"loopover:pull-context"' ) ;
48+ expect ( buildOpenApiSpec ( ) . paths [ "/v1/extension/pull-context" ] ) . toBeDefined ( ) ;
4049 } ) ;
4150
4251 it ( "renders private pull-context sections and escapes API text" , ( ) => {
@@ -134,7 +143,6 @@ function loadContentInternals(overrides: Record<string, unknown> = {}) {
134143 matchGitHubPageTarget : (
135144 pathname : string ,
136145 ) => { kind : "pull_request" ; owner : string ; repo : string ; pullNumber : number } | null ;
137- matchPullRequestTarget : ( pathname : string ) => { owner : string ; repo : string ; pullNumber : number } | null ;
138146 createOverlayLoader : ( container : { querySelector : ( selector : string ) => unknown } , target : unknown ) => ( ) => Promise < void > ;
139147 renderPullContext : ( payload : unknown ) => string ;
140148 } ;
0 commit comments