@owlmeans/test-ui 0.1.18-rc.8 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -7
- package/agent-meta/manifest.json +3 -3
- package/agent-meta/skills/testing-ui/SKILL.md +209 -23
- package/build/browser/types.d.ts +22 -0
- package/build/browser/types.d.ts.map +1 -0
- package/build/browser/types.js +2 -0
- package/build/browser/types.js.map +1 -0
- package/build/browser.d.ts +8 -16
- package/build/browser.d.ts.map +1 -1
- package/build/browser.js +38 -41
- package/build/browser.js.map +1 -1
- package/build/consent/types.d.ts +36 -0
- package/build/consent/types.d.ts.map +1 -0
- package/build/consent/types.js +2 -0
- package/build/consent/types.js.map +1 -0
- package/build/consent.d.ts +4 -0
- package/build/consent.d.ts.map +1 -0
- package/build/consent.js +41 -0
- package/build/consent.js.map +1 -0
- package/build/consts.local.d.ts +9 -0
- package/build/consts.local.d.ts.map +1 -0
- package/build/consts.local.js +9 -0
- package/build/consts.local.js.map +1 -0
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -0
- package/build/index.js.map +1 -1
- package/build/marketing-consent.d.ts +5 -0
- package/build/marketing-consent.d.ts.map +1 -0
- package/build/marketing-consent.js +4 -0
- package/build/marketing-consent.js.map +1 -0
- package/build/mount.d.ts +2 -27
- package/build/mount.d.ts.map +1 -1
- package/build/mount.js +11 -4
- package/build/mount.js.map +1 -1
- package/build/page/types.d.ts +141 -0
- package/build/page/types.d.ts.map +1 -0
- package/build/page/types.js +2 -0
- package/build/page/types.js.map +1 -0
- package/build/page.d.ts +4 -0
- package/build/page.d.ts.map +1 -0
- package/build/page.js +168 -0
- package/build/page.js.map +1 -0
- package/build/supervisor/types.d.ts +56 -0
- package/build/supervisor/types.d.ts.map +1 -0
- package/build/supervisor/types.js +2 -0
- package/build/supervisor/types.js.map +1 -0
- package/build/supervisor.d.ts +9 -86
- package/build/supervisor.d.ts.map +1 -1
- package/build/supervisor.js +65 -123
- package/build/supervisor.js.map +1 -1
- package/build/types.d.ts +46 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +11 -11
- package/src/browser/types.ts +22 -0
- package/src/browser.ts +43 -40
- package/src/consent/types.ts +38 -0
- package/src/consent.ts +48 -0
- package/src/consts.local.ts +12 -0
- package/src/index.ts +8 -0
- package/src/marketing-consent.ts +8 -0
- package/src/mount.ts +12 -32
- package/src/page/types.ts +144 -0
- package/src/page.ts +194 -0
- package/src/supervisor/types.ts +55 -0
- package/src/supervisor.ts +83 -187
- package/src/types.ts +47 -0
package/src/supervisor.ts
CHANGED
|
@@ -1,204 +1,100 @@
|
|
|
1
|
-
import { mkdir } from 'node:fs/promises'
|
|
2
|
-
import { join, resolve } from 'node:path'
|
|
3
1
|
import type { Page } from 'playwright'
|
|
4
|
-
import type
|
|
5
|
-
import {
|
|
6
|
-
AuthroizationType, AuthRole as Role, AuthenticationType, buildSupervisorPayload
|
|
7
|
-
} from '@owlmeans/auth'
|
|
2
|
+
import { type Auth, type AuthCredentials, AuthroizationType, AuthRole as Role, AuthenticationType, buildSupervisorPayload } from '@owlmeans/auth'
|
|
8
3
|
import { makeKeyPairModel } from '@owlmeans/basic-keys'
|
|
9
4
|
import { createIdOfLength } from '@owlmeans/basic-ids'
|
|
10
5
|
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope'
|
|
11
6
|
import { makeBearer } from '@owlmeans/test-auth'
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* `@owlmeans/test-auth`'s `makeBearer`. This is the "set a token directly"
|
|
33
|
-
* fast-path for e2e/integration tests: no UI, no live auth round-trip. The
|
|
34
|
-
* backend accepts it because it is signed by the project's own trusted key.
|
|
35
|
-
*
|
|
36
|
-
* For a faithful end-to-end login (real supervisor plugin + registration), drive
|
|
37
|
-
* {@link loginViaSupervisorForm} instead.
|
|
38
|
-
*/
|
|
39
|
-
export const pregenerateAuthToken = async (opts: PregenerateAuthTokenOptions): Promise<string> => {
|
|
40
|
-
const auth: Auth = {
|
|
41
|
-
token: createIdOfLength(32),
|
|
42
|
-
userId: opts.userId,
|
|
43
|
-
profileId: opts.profileId ?? opts.userId,
|
|
44
|
-
entityId: opts.entityId,
|
|
45
|
-
scopes: opts.scopes ?? ['*'],
|
|
46
|
-
role: opts.role ?? Role.User,
|
|
47
|
-
type: AuthroizationType.Ed25519BasicToken,
|
|
48
|
-
source: opts.source ?? '',
|
|
49
|
-
isUser: true,
|
|
50
|
-
createdAt: new Date()
|
|
7
|
+
import { makePageHelper } from './page.js'
|
|
8
|
+
import type { AcceptConsentOptions, SupervisorFormLoginOptions } from './page/types.js'
|
|
9
|
+
import type { PregenerateAuthTokenOptions, SupervisorApiAuthOptions, SupervisorAuthHelper } from './supervisor/types.js'
|
|
10
|
+
|
|
11
|
+
export const createSupervisorAuthHelper = (): SupervisorAuthHelper => {
|
|
12
|
+
const pregenerateAuthToken = async (opts: PregenerateAuthTokenOptions): Promise<string> => {
|
|
13
|
+
const auth: Auth = {
|
|
14
|
+
token: createIdOfLength(32),
|
|
15
|
+
userId: opts.userId,
|
|
16
|
+
profileId: opts.profileId ?? opts.userId,
|
|
17
|
+
entitySlug: opts.entityId,
|
|
18
|
+
scopes: opts.scopes ?? ['*'],
|
|
19
|
+
role: opts.role ?? Role.User,
|
|
20
|
+
type: AuthroizationType.Ed25519BasicToken,
|
|
21
|
+
source: opts.source ?? '',
|
|
22
|
+
isUser: true,
|
|
23
|
+
createdAt: new Date()
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return makeBearer(auth, makeKeyPairModel(opts.pk))
|
|
51
27
|
}
|
|
52
28
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
)
|
|
65
|
-
const path = opts?.dispatcherPath ?? '/dispatcher'
|
|
66
|
-
const url = new URL(path, baseUrl)
|
|
67
|
-
url.searchParams.set('token', token)
|
|
68
|
-
await page.goto(url.toString())
|
|
69
|
-
// Wait until the dispatcher has navigated away (token consumed).
|
|
70
|
-
await page.waitForURL(u => !u.pathname.startsWith(path), { timeout: 30_000 })
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface SupervisorApiAuthOptions {
|
|
74
|
-
/** Auth-manager API base URL (the backend serving /authentication/* and /authenticate). */
|
|
75
|
-
apiBaseUrl: string
|
|
76
|
-
/** Target user id / email to authenticate (and register on first use). */
|
|
77
|
-
userId: string
|
|
78
|
-
/** Supervisor private key, e.g. `ed25519:<base64>` from `.env.dev.secrets`. */
|
|
79
|
-
pk: string
|
|
80
|
-
/** Paths, overridable for non-default routing. */
|
|
81
|
-
paths?: { init?: string, authenticate?: string, dispatch?: string }
|
|
82
|
-
fetchImpl?: typeof fetch
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const postJson = async (
|
|
86
|
-
fetchImpl: typeof fetch, url: string, body: unknown
|
|
87
|
-
): Promise<any> => {
|
|
88
|
-
const res = await fetchImpl(url, {
|
|
89
|
-
method: 'POST',
|
|
90
|
-
headers: { 'Content-Type': 'application/json' },
|
|
91
|
-
body: JSON.stringify(body)
|
|
92
|
-
})
|
|
93
|
-
if (!res.ok) {
|
|
94
|
-
throw new Error(`supervisor api ${url} -> ${res.status} ${await res.text().catch(() => '')}`)
|
|
29
|
+
const postJson = async (
|
|
30
|
+
fetchImpl: typeof fetch, url: string, body: unknown
|
|
31
|
+
): Promise<any> => {
|
|
32
|
+
const res = await fetchImpl(url, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'Content-Type': 'application/json' },
|
|
35
|
+
body: JSON.stringify(body)
|
|
36
|
+
})
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
throw new Error(`supervisor api ${url} -> ${res.status} ${await res.text().catch(() => '')}`)
|
|
39
|
+
}
|
|
40
|
+
return res.json()
|
|
95
41
|
}
|
|
96
|
-
return res.json()
|
|
97
|
-
}
|
|
98
42
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
43
|
+
const authenticateViaSupervisorApi = async (
|
|
44
|
+
opts: SupervisorApiAuthOptions
|
|
45
|
+
): Promise<string> => {
|
|
46
|
+
const fetchImpl = opts.fetchImpl ?? fetch
|
|
47
|
+
const base = opts.apiBaseUrl.replace(/\/$/, '')
|
|
48
|
+
const initPath = opts.paths?.init ?? '/authentication/init'
|
|
49
|
+
const authPath = opts.paths?.authenticate ?? '/authentication/authenticate'
|
|
50
|
+
const dispatchPath = opts.paths?.dispatch ?? '/authenticate'
|
|
51
|
+
|
|
52
|
+
// 1. Ask the auth manager for a fresh, signed challenge envelope.
|
|
53
|
+
const { challenge } = await postJson(fetchImpl, base + initPath, {
|
|
54
|
+
type: AuthenticationType.Supervisor
|
|
55
|
+
}) as { challenge: string }
|
|
56
|
+
|
|
57
|
+
// 2. Sign the unwrapped challenge + userId + salt with the supervisor key.
|
|
58
|
+
const challengeMsg = makeEnvelopeModel<string>(challenge, EnvelopeKind.Wrap).message()
|
|
59
|
+
const salt = createIdOfLength(16)
|
|
60
|
+
const signature = await makeKeyPairModel(opts.pk)
|
|
61
|
+
.sign(buildSupervisorPayload(challengeMsg, opts.userId, salt))
|
|
62
|
+
|
|
63
|
+
const credentials: AuthCredentials = {
|
|
64
|
+
type: AuthenticationType.Supervisor,
|
|
65
|
+
challenge,
|
|
66
|
+
credential: JSON.stringify({ salt, signature }),
|
|
67
|
+
userId: opts.userId,
|
|
68
|
+
role: Role.User,
|
|
69
|
+
scopes: ['*']
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 3. Exchange for the intermediate auth-manager token.
|
|
73
|
+
const intermediate = await postJson(fetchImpl, base + authPath, credentials) as { token: string }
|
|
74
|
+
|
|
75
|
+
// 4. Exchange the intermediate token for the final project bearer.
|
|
76
|
+
const final = await postJson(fetchImpl, base + dispatchPath, { token: intermediate.token }) as { token: string }
|
|
77
|
+
|
|
78
|
+
return final.token
|
|
135
79
|
}
|
|
136
80
|
|
|
137
|
-
|
|
138
|
-
const intermediate = await postJson(fetchImpl, base + authPath, credentials) as { token: string }
|
|
139
|
-
|
|
140
|
-
// 4. Exchange the intermediate token for the final project bearer.
|
|
141
|
-
const final = await postJson(fetchImpl, base + dispatchPath, { token: intermediate.token }) as { token: string }
|
|
142
|
-
|
|
143
|
-
return final.token
|
|
81
|
+
return { pregenerateAuthToken, authenticateViaSupervisorApi }
|
|
144
82
|
}
|
|
145
83
|
|
|
146
|
-
|
|
147
|
-
* Save a full-page screenshot to `<dir>/<name>.png`, creating `dir` if needed.
|
|
148
|
-
* Returns the absolute file path. Use a host-backed folder (e.g. the project's
|
|
149
|
-
* `tmp/tests/screenshots`) so the file is visible whether the test runs on the
|
|
150
|
-
* host or inside a dev container.
|
|
151
|
-
*/
|
|
152
|
-
export const saveScreenshot = async (page: Page, dir: string, name: string): Promise<string> => {
|
|
153
|
-
const target = resolve(dir)
|
|
154
|
-
await mkdir(target, { recursive: true })
|
|
155
|
-
const file = join(target, `${name}.png`)
|
|
156
|
-
await page.screenshot({ path: file, fullPage: true })
|
|
157
|
-
return file
|
|
158
|
-
}
|
|
84
|
+
export const supervisorAuthHelper = createSupervisorAuthHelper()
|
|
159
85
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
userId: string
|
|
164
|
-
/** Supervisor private key (e.g. `ed25519:<base64>` from `.env.dev.secrets`). */
|
|
165
|
-
pk: string
|
|
166
|
-
/** Login path; defaults to the standard supervisor route. */
|
|
167
|
-
path?: string
|
|
168
|
-
/** Predicate/URL fragment that signals a successful landing (default: leaving the login path). */
|
|
169
|
-
expectPath?: string
|
|
170
|
-
timeout?: number
|
|
171
|
-
/** When set, capture the filled login form (`supervisor-login-form.png`) before submit. */
|
|
172
|
-
screenshotDir?: string
|
|
173
|
-
}
|
|
86
|
+
/** @deprecated compat:factory-refactor — use `supervisorAuthHelper.authenticateViaSupervisorApi(…)` */
|
|
87
|
+
export const authenticateViaSupervisorApi = async (opts: SupervisorApiAuthOptions): Promise<string> =>
|
|
88
|
+
await supervisorAuthHelper.authenticateViaSupervisorApi(opts)
|
|
174
89
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
* Drive the PK-based supervisor login FORM end-to-end (the faithful path that
|
|
179
|
-
* exercises the real supervisor plugin + registration): navigate to the
|
|
180
|
-
* supervisor login route, fill the user id + private key, submit, and wait for
|
|
181
|
-
* the app to leave the login screen.
|
|
182
|
-
*/
|
|
183
|
-
export const loginViaSupervisorForm = async (
|
|
184
|
-
page: Page, opts: SupervisorFormLoginOptions
|
|
185
|
-
): Promise<void> => {
|
|
186
|
-
const path = opts.path ?? DEFAULT_SUPERVISOR_PATH
|
|
187
|
-
const timeout = opts.timeout ?? 60_000
|
|
188
|
-
await page.goto(new URL(path, opts.baseUrl).toString())
|
|
189
|
-
|
|
190
|
-
await page.getByTestId('supervisor-user-id').fill(opts.userId)
|
|
191
|
-
await page.getByTestId('supervisor-pk').fill(opts.pk)
|
|
192
|
-
|
|
193
|
-
if (opts.screenshotDir != null) {
|
|
194
|
-
await saveScreenshot(page, opts.screenshotDir, 'supervisor-login-form')
|
|
195
|
-
}
|
|
90
|
+
/** @deprecated compat:factory-refactor — use `makePageHelper(page).saveScreenshot(…)` */
|
|
91
|
+
export const saveScreenshot = async (page: Page, dir: string, name: string): Promise<string> =>
|
|
92
|
+
await makePageHelper(page).saveScreenshot(dir, name)
|
|
196
93
|
|
|
197
|
-
|
|
94
|
+
/** @deprecated compat:factory-refactor — use `makePageHelper(page).acceptConsent(…)` */
|
|
95
|
+
export const acceptConsent = async (page: Page, opts?: AcceptConsentOptions): Promise<boolean> =>
|
|
96
|
+
await makePageHelper(page).acceptConsent(opts)
|
|
198
97
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
await page.waitForURL(url => !url.pathname.startsWith(path), { timeout })
|
|
203
|
-
}
|
|
204
|
-
}
|
|
98
|
+
/** @deprecated compat:factory-refactor — use `makePageHelper(page).loginViaSupervisorForm(…)` */
|
|
99
|
+
export const loginViaSupervisorForm = async (page: Page, opts: SupervisorFormLoginOptions): Promise<void> =>
|
|
100
|
+
await makePageHelper(page).loginViaSupervisorForm(opts)
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Page } from 'playwright'
|
|
2
|
+
import type { ConsentGeoMock } from './consent/types.js'
|
|
3
|
+
|
|
4
|
+
export interface MountOptions {
|
|
5
|
+
/**
|
|
6
|
+
* URL the harness is reachable at. The consuming package is in charge
|
|
7
|
+
* of producing it — typically a Vite dev server pointed at
|
|
8
|
+
* `node_modules/@owlmeans/test-ui/harness/` plus a per-package
|
|
9
|
+
* `mount.tsx` that registers the components under test, OR an
|
|
10
|
+
* inlined `data:text/html,...` URL for the simplest smoke tests.
|
|
11
|
+
*/
|
|
12
|
+
url: string
|
|
13
|
+
/**
|
|
14
|
+
* Component name registered in the harness. Appended as `?component=`.
|
|
15
|
+
* Omit when the harness mounts a single fixed root.
|
|
16
|
+
*/
|
|
17
|
+
component?: string
|
|
18
|
+
/**
|
|
19
|
+
* JSON-serialisable props passed to the component. Encoded into the
|
|
20
|
+
* URL as `?props=<json>` for the harness's `mount.tsx` to read.
|
|
21
|
+
*/
|
|
22
|
+
props?: Record<string, unknown>
|
|
23
|
+
/**
|
|
24
|
+
* What counts as "arrived". Defaults to `domcontentloaded`.
|
|
25
|
+
*
|
|
26
|
+
* NOT `load`, which is playwright's own default and is wrong for any page that is a real
|
|
27
|
+
* application: `load` waits for EVERY subresource, and an analytics beacon, a long-poll or a
|
|
28
|
+
* third-party pixel that never settles holds it open until the navigation times out — with the
|
|
29
|
+
* page fully rendered and working the whole time. The failure reads as "the site is down".
|
|
30
|
+
*
|
|
31
|
+
* A spec waits for the selector it actually needs; that is the assertion, not the load event.
|
|
32
|
+
*/
|
|
33
|
+
waitUntil?: 'commit' | 'domcontentloaded' | 'load' | 'networkidle'
|
|
34
|
+
/** Navigation timeout in ms. */
|
|
35
|
+
timeout?: number
|
|
36
|
+
/**
|
|
37
|
+
* Answer the page's Cloudflare trace with this — installed BEFORE the first navigation, so the
|
|
38
|
+
* consent geo gate sees it on the very first load. See `consentGeoTestHelper.mockConsentGeo`.
|
|
39
|
+
*/
|
|
40
|
+
consentGeo?: ConsentGeoMock
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface Mounted {
|
|
44
|
+
page: Page
|
|
45
|
+
/** Closes the page's browser context — the shared browser stays alive. */
|
|
46
|
+
close: () => Promise<void>
|
|
47
|
+
}
|