@ultimat3/testing 30.9.0 → 31.1.0
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/CLAUDE.md +46 -55
- package/README.md +179 -39
- package/package.json +23 -17
- package/src/ai-conformance-answer.ts +67 -0
- package/src/ai-gateway-conformance.ts +105 -0
- package/src/ai-provider-conformance.ts +69 -0
- package/src/ai-provider-transport-conformance.ts +170 -0
- package/src/audit-sink-conformance.ts +204 -0
- package/src/auth-adapter-conformance-credentials.ts +124 -0
- package/src/auth-adapter-conformance-mfa.ts +70 -0
- package/src/auth-adapter-conformance-passkeys.ts +133 -0
- package/src/auth-adapter-conformance-sessions.ts +115 -0
- package/src/auth-adapter-conformance-support.ts +71 -0
- package/src/auth-adapter-conformance-users.ts +128 -0
- package/src/auth-adapter-conformance.ts +34 -0
- package/src/auth-limiter-factory-conformance.ts +224 -0
- package/src/auth-server-store-conformance-records.ts +69 -0
- package/src/auth-server-store-conformance.ts +208 -0
- package/src/cache-tier-conformance-checks.ts +142 -0
- package/src/cache-tier-conformance.ts +24 -0
- package/src/cassette-format.ts +8 -13
- package/src/cassette-record.ts +1 -1
- package/src/cdp-browser.ts +10 -11
- package/src/cdp-e2e-page.ts +2 -2
- package/src/cdp-e2e-session.ts +2 -2
- package/src/cdp-network-probe.ts +1 -1
- package/src/cdp-offline-script.ts +2 -2
- package/src/clock-conformance.ts +126 -0
- package/src/conformance.ts +239 -0
- package/src/e2e-browser-handle.ts +1 -2
- package/src/e2e-error-codes.ts +17 -16
- package/src/e2e-run.ts +4 -3
- package/src/embedder-conformance.ts +101 -0
- package/src/entity-conformance-aggregates.ts +210 -0
- package/src/entity-conformance-batches.ts +216 -0
- package/src/entity-conformance-bulk.ts +379 -0
- package/src/entity-conformance-checks.ts +27 -0
- package/src/entity-conformance-entities.ts +52 -0
- package/src/entity-conformance-locks.ts +286 -0
- package/src/entity-conformance-matrix.ts +397 -0
- package/src/entity-conformance-reads.ts +241 -0
- package/src/entity-conformance-support.ts +56 -0
- package/src/entity-conformance-tenancy.ts +296 -0
- package/src/entity-conformance-values.ts +305 -0
- package/src/entity-conformance-versions.ts +60 -0
- package/src/entity-conformance-writes.ts +348 -0
- package/src/entity-driver-conformance.ts +103 -0
- package/src/error-groups-store-conformance.ts +198 -0
- package/src/error-reporter-conformance.ts +119 -0
- package/src/errors.ts +20 -2
- package/src/event-bus-conformance.ts +161 -0
- package/src/exercise-drift-hint.ts +4 -1
- package/src/exercise-judge.ts +5 -3
- package/src/exercise-override-line.ts +98 -0
- package/src/exercise-report.ts +138 -115
- package/src/exercise-room-mail.ts +40 -0
- package/src/exercise.ts +33 -29
- package/src/factories.ts +192 -179
- package/src/factory-api.ts +131 -0
- package/src/factory-associations.ts +67 -0
- package/src/factory-errors.ts +38 -0
- package/src/factory-lint.ts +92 -0
- package/src/factory-persist.ts +74 -16
- package/src/factory-pipeline.ts +191 -0
- package/src/factory-registry.ts +2 -1
- package/src/factory-types.ts +131 -0
- package/src/failure-store-conformance.ts +137 -0
- package/src/fixture-jobs.ts +27 -11
- package/src/fixture-mail.ts +7 -7
- package/src/fixture-seed.ts +111 -0
- package/src/fixture-statements.ts +68 -52
- package/src/framework-fixtures.ts +1 -1
- package/src/idempotency-store-conformance.ts +186 -0
- package/src/idempotency-store-replay-conformance.ts +140 -0
- package/src/idempotency-store-tx-conformance.ts +132 -0
- package/src/idempotency-store-world-conformance.ts +82 -0
- package/src/identity-provider-conformance.ts +144 -0
- package/src/image-transform-conformance.ts +89 -0
- package/src/index.ts +68 -157
- package/src/isr-store-conformance.ts +113 -0
- package/src/job-sim-effects.ts +19 -31
- package/src/job-sim-world.ts +6 -15
- package/src/lease-store-conformance.ts +195 -0
- package/src/mail-driver-conformance.ts +108 -0
- package/src/matcher-doubles.ts +104 -0
- package/src/matcher-stub.ts +78 -0
- package/src/matcher-surface.ts +21 -0
- package/src/matchers.ts +19 -1
- package/src/mcp-confirmation-store-conformance.ts +262 -0
- package/src/meter-store-conformance.ts +135 -0
- package/src/notify-digest-conformance.ts +133 -0
- package/src/notify-inbox-conformance.ts +130 -0
- package/src/notify-ledger-conformance.ts +134 -0
- package/src/notify-preference-conformance.ts +49 -0
- package/src/notify-stores-conformance.ts +73 -0
- package/src/outbox-store-conformance-claims.ts +112 -0
- package/src/outbox-store-conformance-subject.ts +65 -0
- package/src/outbox-store-conformance.ts +71 -0
- package/src/per-test-reset.ts +55 -20
- package/src/preload.ts +4 -2
- package/src/purge-conformance.ts +79 -0
- package/src/push-device-conformance.ts +124 -0
- package/src/push-subscription-conformance.ts +123 -0
- package/src/quiet-logs.ts +4 -4
- package/src/rate-limit-store-conformance.ts +178 -0
- package/src/registry-leak-error.ts +8 -1
- package/src/scale-sweep-run.ts +6 -9
- package/src/scrape-driver-conformance-frame-checks.ts +97 -0
- package/src/scrape-driver-conformance-page-checks.ts +114 -0
- package/src/scrape-driver-conformance-site.ts +84 -0
- package/src/scrape-driver-conformance.ts +34 -0
- package/src/sealed-network.ts +20 -2
- package/src/search-index-conformance-list.ts +76 -0
- package/src/search-index-conformance-support.ts +69 -0
- package/src/search-index-conformance-versions.ts +66 -0
- package/src/search-index-conformance.ts +126 -0
- package/src/secret-source-conformance.ts +91 -0
- package/src/seed-factories.ts +57 -0
- package/src/seed-writer.ts +8 -19
- package/src/semantic-cache-factory-conformance.ts +86 -0
- package/src/sms-transport-conformance.ts +102 -0
- package/src/step-store-conformance.ts +171 -0
- package/src/storage-conformance-read-checks.ts +132 -0
- package/src/storage-conformance-shape.ts +121 -0
- package/src/storage-conformance-stream-checks.ts +226 -0
- package/src/storage-conformance.ts +34 -0
- package/src/stub-action.ts +24 -0
- package/src/stub-errors.ts +86 -0
- package/src/stub-job.ts +30 -0
- package/src/stub-query.ts +25 -0
- package/src/stub-script.ts +76 -0
- package/src/stub-stack.ts +29 -0
- package/src/stub.ts +73 -0
- package/src/swap-adapter.ts +135 -0
- package/src/test-scope.ts +96 -0
- package/src/test-types.ts +1 -1
- package/src/totp-replay-guard-conformance.ts +76 -0
- package/src/transport-conformance.ts +179 -0
- package/src/upload-scanner-conformance.ts +112 -0
- package/src/vector-store-conformance-checks.ts +174 -0
- package/src/vector-store-conformance.ts +21 -0
- package/src/cdp-connection.ts +0 -291
- package/src/cdp-errors.ts +0 -179
- package/src/cdp-launch-attempt.ts +0 -224
- package/src/cdp-launch-candidates.ts +0 -62
- package/src/cdp-launch-profile.ts +0 -106
- package/src/cdp-launch-reap.ts +0 -68
- package/src/cdp-launch-wire.ts +0 -171
- package/src/cdp-launch.ts +0 -175
- package/src/cdp-pipe.ts +0 -77
- package/src/cdp-wire-watch.ts +0 -113
package/src/scale-sweep-run.ts
CHANGED
|
@@ -71,15 +71,12 @@ async function callAt(
|
|
|
71
71
|
return { failed: `its exercise.ts input threw: ${renderThrowable(error)}` };
|
|
72
72
|
}
|
|
73
73
|
if (prepared === undefined) return { failed: 'no actor its policy permits' };
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
options.room.end();
|
|
81
|
-
return { failed: renderThrowable(error) };
|
|
82
|
-
}
|
|
74
|
+
// Observed by the call's own async context: a timer's statement in its window is not its shape.
|
|
75
|
+
const seen = await options.room.observe(undefined, () =>
|
|
76
|
+
subject.call(prepared.input, prepared.actor, tenant, jobs),
|
|
77
|
+
);
|
|
78
|
+
if ('error' in seen) return { failed: renderThrowable(seen.error) };
|
|
79
|
+
return 'failure' in seen.value ? { failed: renderThrowable(seen.value.failure) } : seen.observed;
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
/** Seed both sizes, call each subject at each, judge. Unseedable: every subject `unproven`. */
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// The frame and keyboard half of the `ScrapeDriver` contract. A frame target is built by spreading
|
|
2
|
+
// the parent's, so a verb nobody overrode acts on the PARENT document — an iframe'd SSO login
|
|
3
|
+
// typing a password into the page around it. Lifted from
|
|
4
|
+
// `scraping/src/driver-parity-{frames,keys}.test.ts`.
|
|
5
|
+
|
|
6
|
+
import { expect } from 'bun:test';
|
|
7
|
+
import type { ScrapeDriverCheck } from './scrape-driver-conformance-page-checks';
|
|
8
|
+
import { codeOf, SCRAPE_CONFORMANCE_URLS } from './scrape-driver-conformance-site';
|
|
9
|
+
|
|
10
|
+
export const SCRAPE_FRAME_CHECKS: readonly ScrapeDriverCheck[] = [
|
|
11
|
+
{
|
|
12
|
+
name: 'a frame reads its OWN document, through values and query alike',
|
|
13
|
+
async run({ page }) {
|
|
14
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.login);
|
|
15
|
+
expect((await page.frame('idp').values('#q'))[0]?.value).toBe('frame-value');
|
|
16
|
+
expect((await page.frame('idp').query('#q'))[0]?.value).toBe('frame-value');
|
|
17
|
+
expect((await page.query('#q'))[0]?.value).toBe('page-value');
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'fill inside a frame REPLACES the frame field and leaves the parent untouched',
|
|
22
|
+
async run({ page }) {
|
|
23
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.login);
|
|
24
|
+
await page.frame('idp').fill('#q', 'typed');
|
|
25
|
+
expect((await page.frame('idp').values('#q'))[0]?.value).toBe('typed');
|
|
26
|
+
expect((await page.frame('idp').query('#q'))[0]?.value).toBe('typed');
|
|
27
|
+
expect((await page.values('#q'))[0]?.value).toBe('page-value');
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'type inside a frame appends to the frame value, never the parent`s',
|
|
32
|
+
async run({ page }) {
|
|
33
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.login);
|
|
34
|
+
await page.frame('idp').type('#q', '-more');
|
|
35
|
+
expect((await page.frame('idp').values('#q'))[0]?.value).toBe('frame-value-more');
|
|
36
|
+
expect((await page.values('#q'))[0]?.value).toBe('page-value');
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'select inside a frame sets the frame control, never the parent`s',
|
|
41
|
+
async run({ page }) {
|
|
42
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.login);
|
|
43
|
+
await page.frame('idp').select('#s', ['f1']);
|
|
44
|
+
expect((await page.frame('idp').values('#s'))[0]?.value).toBe('f1');
|
|
45
|
+
expect((await page.values('#s'))[0]?.value).toBe('');
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'a click inside a frame leaves the PARENT where it was',
|
|
50
|
+
async run({ page }) {
|
|
51
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.login);
|
|
52
|
+
await page.frame('idp').click('#go');
|
|
53
|
+
expect(page.url()).toBe(SCRAPE_CONFORMANCE_URLS.login);
|
|
54
|
+
expect((await page.values('#q'))[0]?.value).toBe('page-value');
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'focus resolves on a present control and is X_SCRAPE_SELECTOR_MISSING on a missing one',
|
|
59
|
+
async run({ page }) {
|
|
60
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.search);
|
|
61
|
+
expect(await page.focus('#q')).toBeUndefined();
|
|
62
|
+
expect(await codeOf(() => page.focus('#nothing', { timeout: 50 }))).toBe(
|
|
63
|
+
'X_SCRAPE_SELECTOR_MISSING',
|
|
64
|
+
);
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "a well-formed chord resolves; a bad one is X_SCRAPE_KEY_INVALID — 'Ctrl' is no modifier",
|
|
69
|
+
async run({ page }) {
|
|
70
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.search);
|
|
71
|
+
expect(await codeOf(() => page.press('Meta+K'))).toBeUndefined();
|
|
72
|
+
expect(await codeOf(() => page.press('Enter'))).toBeUndefined();
|
|
73
|
+
expect(await codeOf(() => page.press('Ctrl+K'))).toBe('X_SCRAPE_KEY_INVALID');
|
|
74
|
+
expect(await codeOf(() => page.press('Shift+'))).toBe('X_SCRAPE_KEY_INVALID');
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'accessibility() answers the computed role and name, or is refused X_NOT_IMPLEMENTED',
|
|
79
|
+
async run({ page }) {
|
|
80
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.search);
|
|
81
|
+
// Screened before any driver is asked, whichever kind this is.
|
|
82
|
+
expect(await codeOf(() => page.accessibility('#go', { max: Number.NaN }))).toBe(
|
|
83
|
+
'X_INVARIANT',
|
|
84
|
+
);
|
|
85
|
+
expect(await codeOf(() => page.accessibility('#go', { max: 0 }))).toBe('X_INVARIANT');
|
|
86
|
+
const refused = await codeOf(() => page.accessibility('#go'));
|
|
87
|
+
if (refused !== undefined) {
|
|
88
|
+
// An offline driver refuses rather than reading `role=` off the markup and inventing one.
|
|
89
|
+
expect(refused).toBe('X_NOT_IMPLEMENTED');
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
expect(await page.accessibility('#go')).toMatchObject([
|
|
93
|
+
{ role: 'button', name: 'Run search' },
|
|
94
|
+
]);
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
];
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// The page half of the `ScrapeDriver` contract: the read vocabulary, clicks, the allow list on both
|
|
2
|
+
// legs, and the members an offline driver must REFUSE by name rather than fake. Lifted from
|
|
3
|
+
// `scraping/src/driver-parity.test.ts`, where each held only for the three drivers that file named.
|
|
4
|
+
|
|
5
|
+
import { expect } from 'bun:test';
|
|
6
|
+
import type { ScrapeSession } from '@ultimat3/scraping';
|
|
7
|
+
import { codeOf, SCRAPE_CONFORMANCE_URLS } from './scrape-driver-conformance-site';
|
|
8
|
+
|
|
9
|
+
export interface ScrapeDriverCheck {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
run(session: ScrapeSession): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const SCRAPE_PAGE_CHECKS: readonly ScrapeDriverCheck[] = [
|
|
15
|
+
{
|
|
16
|
+
name: 'text, values and count read the document',
|
|
17
|
+
async run({ page }) {
|
|
18
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.orders);
|
|
19
|
+
expect(await page.text('#title')).toBe('Orders');
|
|
20
|
+
expect(await page.count('.row')).toBe(2);
|
|
21
|
+
const rows = await page.values('.row');
|
|
22
|
+
expect(rows.map((row) => [row.text, row.attrs['data-id']])).toEqual([
|
|
23
|
+
['One', '1'],
|
|
24
|
+
['Two', '2'],
|
|
25
|
+
]);
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'query answers every match with visible and enabled; no match is [], never a refusal',
|
|
30
|
+
async run({ page }) {
|
|
31
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.orders);
|
|
32
|
+
expect((await page.query('.row')).map((row) => row.attrs['data-id'])).toEqual(['1', '2']);
|
|
33
|
+
expect((await page.query('#pay'))[0]?.enabled).toBe(false);
|
|
34
|
+
expect((await page.query('#hidden'))[0]?.visible).toBe(false);
|
|
35
|
+
expect((await page.query('#title'))[0]?.visible).toBe(true);
|
|
36
|
+
expect(await page.query('#nothing')).toEqual([]);
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'a click that navigates lands on the next page, and url() follows it',
|
|
41
|
+
async run({ page }) {
|
|
42
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.orders);
|
|
43
|
+
expect(page.url()).toBe(SCRAPE_CONFORMANCE_URLS.orders);
|
|
44
|
+
// Read again after an operation that navigates nothing: a url() refreshed only by a wait.
|
|
45
|
+
expect(await page.text('#title')).toBe('Orders');
|
|
46
|
+
expect(page.url()).toBe(SCRAPE_CONFORMANCE_URLS.orders);
|
|
47
|
+
await page.click('#next');
|
|
48
|
+
expect([page.url(), await page.text('#title')]).toEqual([
|
|
49
|
+
SCRAPE_CONFORMANCE_URLS.second,
|
|
50
|
+
'Page two',
|
|
51
|
+
]);
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'a multi-match selector clicks the FIRST match',
|
|
56
|
+
async run({ page }) {
|
|
57
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.orders);
|
|
58
|
+
// The second `.go` points at a page the site does not have.
|
|
59
|
+
await page.click('.go');
|
|
60
|
+
expect(await page.text('#title')).toBe('Page two');
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'a disabled control is X_SCRAPE_NOT_ACTIONABLE; a missing one X_SCRAPE_SELECTOR_MISSING',
|
|
65
|
+
async run({ page }) {
|
|
66
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.orders);
|
|
67
|
+
expect(await codeOf(() => page.click('#pay', { timeout: 50 }))).toBe(
|
|
68
|
+
'X_SCRAPE_NOT_ACTIONABLE',
|
|
69
|
+
);
|
|
70
|
+
expect(await codeOf(() => page.waitFor('#nothing', { timeout: 50 }))).toBe(
|
|
71
|
+
'X_SCRAPE_SELECTOR_MISSING',
|
|
72
|
+
);
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'a host the allow list does not name is X_SCRAPE_HOST_BLOCKED on BOTH legs',
|
|
77
|
+
async run({ page, http }) {
|
|
78
|
+
expect(await codeOf(() => page.goto('https://evil.test/'))).toBe('X_SCRAPE_HOST_BLOCKED');
|
|
79
|
+
expect(await codeOf(() => http.request('https://evil.test/api'))).toBe(
|
|
80
|
+
'X_SCRAPE_HOST_BLOCKED',
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'the HTTP leg answers the site`s endpoint in the same session as the page',
|
|
86
|
+
async run({ page, http }) {
|
|
87
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.orders);
|
|
88
|
+
const response = await http.request(SCRAPE_CONFORMANCE_URLS.api);
|
|
89
|
+
expect(response.status).toBe(200);
|
|
90
|
+
expect(await response.json()).toEqual({ orders: [{ id: 1 }] });
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'pageErrors() answers, empty on a page that threw nothing',
|
|
95
|
+
async run({ page }) {
|
|
96
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.orders);
|
|
97
|
+
expect([page.pageErrors(), page.pageErrorsDropped()]).toEqual([[], 0]);
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: 'offline(true) cuts the browser off or is refused X_NOT_IMPLEMENTED — never a no-op',
|
|
102
|
+
async run({ page }) {
|
|
103
|
+
await page.goto(SCRAPE_CONFORMANCE_URLS.orders);
|
|
104
|
+
const refused = await codeOf(() => page.offline(true));
|
|
105
|
+
if (refused !== undefined) {
|
|
106
|
+
expect(refused).toBe('X_NOT_IMPLEMENTED');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// Set: then the browser must actually fail a navigation, or a test proved nothing offline.
|
|
110
|
+
expect(await codeOf(() => page.goto(SCRAPE_CONFORMANCE_URLS.second))).not.toBeUndefined();
|
|
111
|
+
await page.offline(false);
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
];
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// The one small site every `ScrapeDriver` check reads: pages, an iframe'd login whose frame
|
|
2
|
+
// carries the SAME ids as its parent (the only shape in which a frame verb aimed at the parent is
|
|
3
|
+
// visible), and one JSON endpoint behind them. A subject's driver must serve exactly these — an
|
|
4
|
+
// offline driver from recordings of them, a real browser from a server answering them.
|
|
5
|
+
|
|
6
|
+
import type { Logger } from '@ultimat3/core';
|
|
7
|
+
import { frozenClock, structuredLogger } from '@ultimat3/core';
|
|
8
|
+
import type { HttpRecording, PageRecording, ScrapeDriver, ScrapeSession } from '@ultimat3/scraping';
|
|
9
|
+
|
|
10
|
+
export const SCRAPE_CONFORMANCE_HOST = 'shop.test';
|
|
11
|
+
const ORIGIN = `https://${SCRAPE_CONFORMANCE_HOST}`;
|
|
12
|
+
|
|
13
|
+
export const SCRAPE_CONFORMANCE_URLS = {
|
|
14
|
+
orders: `${ORIGIN}/orders`,
|
|
15
|
+
second: `${ORIGIN}/orders/2`,
|
|
16
|
+
login: `${ORIGIN}/login`,
|
|
17
|
+
search: `${ORIGIN}/search`,
|
|
18
|
+
api: `${ORIGIN}/api/orders?page=1`,
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
const ORDERS = `<html><body>
|
|
22
|
+
<h1 id="title">Orders</h1>
|
|
23
|
+
<ul><li class="row" data-id="1">One</li><li class="row" data-id="2">Two</li></ul>
|
|
24
|
+
<a id="next" href="/orders/2">Next</a>
|
|
25
|
+
<a class="go" href="/orders/2">Go first</a>
|
|
26
|
+
<a class="go" href="/orders/nowhere">Go second</a>
|
|
27
|
+
<button id="pay" disabled>Pay</button>
|
|
28
|
+
<p id="hidden" style="display:none">gone</p>
|
|
29
|
+
<img src="https://tracker.test/pixel.gif">
|
|
30
|
+
</body></html>`;
|
|
31
|
+
|
|
32
|
+
const LOGIN = `<html><body>
|
|
33
|
+
<input id="q" name="q" value="page-value">
|
|
34
|
+
<select id="s"><option value="p1">P1</option></select>
|
|
35
|
+
<a id="go" href="/orders/2">Leave</a>
|
|
36
|
+
<iframe name="idp" src="/idp"></iframe>
|
|
37
|
+
</body></html>`;
|
|
38
|
+
|
|
39
|
+
/** `#go` here does NOT navigate: a frame click resolved against the parent moves the whole page. */
|
|
40
|
+
const IDP =
|
|
41
|
+
'<input id="q" name="q" value="frame-value"><select id="s"><option value="f1">F1</option></select><button id="go">Stay</button>';
|
|
42
|
+
|
|
43
|
+
const SEARCH = `<html><body>
|
|
44
|
+
<input id="q" name="q" placeholder="Search">
|
|
45
|
+
<button id="go" aria-label="Run search">Go</button>
|
|
46
|
+
</body></html>`;
|
|
47
|
+
|
|
48
|
+
export const SCRAPE_CONFORMANCE_PAGES: readonly PageRecording[] = [
|
|
49
|
+
{ url: SCRAPE_CONFORMANCE_URLS.orders, html: ORDERS },
|
|
50
|
+
{
|
|
51
|
+
url: SCRAPE_CONFORMANCE_URLS.second,
|
|
52
|
+
html: '<html><body><h1 id="title">Page two</h1></body></html>',
|
|
53
|
+
},
|
|
54
|
+
{ url: SCRAPE_CONFORMANCE_URLS.login, html: LOGIN, frames: { idp: IDP } },
|
|
55
|
+
{ url: SCRAPE_CONFORMANCE_URLS.search, html: SEARCH },
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
export const SCRAPE_CONFORMANCE_HTTP: readonly HttpRecording[] = [
|
|
59
|
+
{ url: SCRAPE_CONFORMANCE_URLS.api, method: 'GET', status: 200, body: '{"orders":[{"id":1}]}' },
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const silent: Logger = structuredLogger({ writer: () => undefined });
|
|
63
|
+
|
|
64
|
+
/** A session on `driver` the way a scrape opens one: this site allowed, images blocked. */
|
|
65
|
+
export const openOn = (driver: ScrapeDriver): Promise<ScrapeSession> =>
|
|
66
|
+
driver.open({
|
|
67
|
+
name: 'conformance',
|
|
68
|
+
logger: silent,
|
|
69
|
+
rules: { allowHosts: [SCRAPE_CONFORMANCE_HOST], block: ['image'] },
|
|
70
|
+
clock: frozenClock(),
|
|
71
|
+
timeoutMs: 5_000,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/** The code a call failed with, or `undefined` when it answered. */
|
|
75
|
+
export async function codeOf(run: () => Promise<unknown>): Promise<string | undefined> {
|
|
76
|
+
try {
|
|
77
|
+
await run();
|
|
78
|
+
return undefined;
|
|
79
|
+
} catch (thrown) {
|
|
80
|
+
const code: unknown =
|
|
81
|
+
typeof thrown === 'object' && thrown !== null ? Reflect.get(thrown, 'code') : undefined;
|
|
82
|
+
return typeof code === 'string' ? code : `uncoded: ${String(thrown)}`;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// The `scrapeDriver` port's contract as shared examples: `behavesLike(scrapeDriverConformance, ()
|
|
2
|
+
// => driver)` — a driver serving `SCRAPE_CONFORMANCE_PAGES` and `SCRAPE_CONFORMANCE_HTTP`. Each
|
|
3
|
+
// check opens its own session the way a scrape does, and closes it whatever happens. Where drivers
|
|
4
|
+
// genuinely cannot agree, a check accepts the answer OR the coded refusal.
|
|
5
|
+
|
|
6
|
+
import { test } from 'bun:test';
|
|
7
|
+
import type { ScrapeDriver } from '@ultimat3/scraping';
|
|
8
|
+
import { SCRAPE_FRAME_CHECKS } from './scrape-driver-conformance-frame-checks';
|
|
9
|
+
import type { ScrapeDriverCheck } from './scrape-driver-conformance-page-checks';
|
|
10
|
+
import { SCRAPE_PAGE_CHECKS } from './scrape-driver-conformance-page-checks';
|
|
11
|
+
import { openOn } from './scrape-driver-conformance-site';
|
|
12
|
+
import type { SharedExamples } from './shared-examples';
|
|
13
|
+
import { sharedExamples } from './shared-examples';
|
|
14
|
+
|
|
15
|
+
export const SCRAPE_DRIVER_CHECKS: readonly ScrapeDriverCheck[] = [
|
|
16
|
+
...SCRAPE_PAGE_CHECKS,
|
|
17
|
+
...SCRAPE_FRAME_CHECKS,
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export const scrapeDriverConformance: SharedExamples<ScrapeDriver> = sharedExamples(
|
|
21
|
+
'a scrape driver',
|
|
22
|
+
(subject) => {
|
|
23
|
+
for (const check of SCRAPE_DRIVER_CHECKS) {
|
|
24
|
+
test(check.name, async () => {
|
|
25
|
+
const session = await openOn(subject());
|
|
26
|
+
try {
|
|
27
|
+
await check.run(session);
|
|
28
|
+
} finally {
|
|
29
|
+
await session.close();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
);
|
package/src/sealed-network.ts
CHANGED
|
@@ -42,6 +42,24 @@ const state: SealState = {
|
|
|
42
42
|
network: 'online',
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
+
const dialListeners = new Set<(call: LoggedRequest) => void>();
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Each dial as it is logged, synchronously and in the dialler's own async context — so a listener
|
|
49
|
+
* can tell whose call it was (`exercise-report.ts`'s room). Internal: never on the barrel.
|
|
50
|
+
*/
|
|
51
|
+
export function onDial(listener: (call: LoggedRequest) => void): () => void {
|
|
52
|
+
dialListeners.add(listener);
|
|
53
|
+
return () => {
|
|
54
|
+
dialListeners.delete(listener);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const logDial = (call: LoggedRequest): void => {
|
|
59
|
+
state.log.push(call);
|
|
60
|
+
for (const listener of dialListeners) listener(call);
|
|
61
|
+
};
|
|
62
|
+
|
|
45
63
|
/**
|
|
46
64
|
* What a mocked host resolves to: one `public` address (`classifyAddress`), so an SSRF screen
|
|
47
65
|
* passes it, and never a host network — a screen refuses those. Never dialled: a dial pinned to it
|
|
@@ -76,7 +94,7 @@ const isThisMachine = (hostname: string): boolean => {
|
|
|
76
94
|
/** The socket dials' gate: the same allow-list, offline state and record as `fetch`. No mocks — a
|
|
77
95
|
* socket test injects its transport (`connect`, `client`), it does not intercept the dial. */
|
|
78
96
|
const socketRefusal = (url: string, method: string): Error | undefined => {
|
|
79
|
-
|
|
97
|
+
logDial({ method, url, headers: {}, body: null });
|
|
80
98
|
let target: URL;
|
|
81
99
|
try {
|
|
82
100
|
target = new URL(url);
|
|
@@ -135,7 +153,7 @@ export function sealNetwork(): void {
|
|
|
135
153
|
// In the log before the first await, so concurrent calls keep their order; every verdict below
|
|
136
154
|
// is reached before the body is awaited too, so a call is judged by the state it was made in.
|
|
137
155
|
const call = { method, url, headers: headersOf(probe), body: null as string | null };
|
|
138
|
-
|
|
156
|
+
logDial(call);
|
|
139
157
|
const openEnded = isOpenEnded(input, init);
|
|
140
158
|
/** A finite body is in the entry when `fetch` settles; an open-ended one, once it ends. */
|
|
141
159
|
const logBody = async (source: Request | undefined): Promise<void> => {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// The search index's `list` contract — what `reindex`'s sweep reads to find documents whose row is
|
|
2
|
+
// gone: every live document of one tenant, paged without a repeat or a gap, never a removed id and
|
|
3
|
+
// never another tenant's; every tenant's when the query names none.
|
|
4
|
+
|
|
5
|
+
import { expect } from 'bun:test';
|
|
6
|
+
import type { SearchListEntry, SearchListQuery, SearchScope } from '@ultimat3/entity/adapter';
|
|
7
|
+
import type { SearchIndexCheck, SearchIndexSubject } from './search-index-conformance-support';
|
|
8
|
+
import {
|
|
9
|
+
searchDoc as doc,
|
|
10
|
+
putSearchDocs,
|
|
11
|
+
SEARCH_TENANT_A,
|
|
12
|
+
SEARCH_TENANT_B,
|
|
13
|
+
searchDocId,
|
|
14
|
+
} from './search-index-conformance-support';
|
|
15
|
+
|
|
16
|
+
/** Every page of `query`, followed to its end; a page past the entries there are is a failure. */
|
|
17
|
+
export const listAll = async (
|
|
18
|
+
subject: SearchIndexSubject,
|
|
19
|
+
query: Omit<SearchListQuery, 'after' | 'entity'>,
|
|
20
|
+
): Promise<readonly SearchListEntry[]> => {
|
|
21
|
+
const entries: SearchListEntry[] = [];
|
|
22
|
+
let after: string | null = null;
|
|
23
|
+
for (let pages = 0; pages < 20; pages += 1) {
|
|
24
|
+
const page = await subject.index.list({ ...query, entity: subject.entity, after });
|
|
25
|
+
expect(page.entries.length).toBeLessThanOrEqual(query.limit);
|
|
26
|
+
entries.push(...page.entries);
|
|
27
|
+
if (page.next === null) return entries;
|
|
28
|
+
after = page.next;
|
|
29
|
+
}
|
|
30
|
+
return expect.unreachable(`list never ended: ${entries.length} entries in 20 pages`);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const ids = (entries: readonly SearchListEntry[]) => entries.map((entry) => entry.id).sort();
|
|
34
|
+
|
|
35
|
+
export const SEARCH_INDEX_LIST_CHECKS: readonly SearchIndexCheck[] = [
|
|
36
|
+
{
|
|
37
|
+
name: "list pages one tenant's live documents: each once, none removed, none of another tenant",
|
|
38
|
+
async run(subject) {
|
|
39
|
+
await putSearchDocs(subject, [
|
|
40
|
+
doc(subject.entity, 1, 'zebra'),
|
|
41
|
+
doc(subject.entity, 2, 'quokka'),
|
|
42
|
+
doc(subject.entity, 3, 'lantern'),
|
|
43
|
+
doc(subject.entity, 4, 'harbour', { tenant: SEARCH_TENANT_B }),
|
|
44
|
+
]);
|
|
45
|
+
const own: SearchScope = { entity: subject.entity, tenant: SEARCH_TENANT_A };
|
|
46
|
+
await subject.drop(own, [searchDocId(2)]);
|
|
47
|
+
await subject.index.remove(own, [searchDocId(2)], 2);
|
|
48
|
+
const listed = await listAll(subject, { tenant: SEARCH_TENANT_A, limit: 1 });
|
|
49
|
+
expect(ids(listed)).toEqual([searchDocId(1), searchDocId(3)]);
|
|
50
|
+
expect(listed.length).toBe(2);
|
|
51
|
+
for (const entry of listed) {
|
|
52
|
+
expect(entry.tenant).toBe(SEARCH_TENANT_A);
|
|
53
|
+
expect(Number.isFinite(entry.version)).toBe(true);
|
|
54
|
+
}
|
|
55
|
+
const other = await listAll(subject, { tenant: SEARCH_TENANT_B, limit: 10 });
|
|
56
|
+
expect(other.map((entry) => [entry.tenant, entry.id])).toEqual([
|
|
57
|
+
[SEARCH_TENANT_B, searchDocId(4)],
|
|
58
|
+
]);
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: "list naming no tenant pages every tenant's documents, each with its own tenant",
|
|
63
|
+
async run(subject) {
|
|
64
|
+
await putSearchDocs(subject, [
|
|
65
|
+
doc(subject.entity, 1, 'zebra'),
|
|
66
|
+
doc(subject.entity, 2, 'zebra', { tenant: SEARCH_TENANT_B }),
|
|
67
|
+
]);
|
|
68
|
+
const every = subject.everyTenant ?? ((read) => read());
|
|
69
|
+
const listed = await every(() => listAll(subject, { limit: 1 }));
|
|
70
|
+
expect(listed.map((entry) => [entry.tenant, entry.id]).sort()).toEqual([
|
|
71
|
+
[SEARCH_TENANT_A, searchDocId(1)],
|
|
72
|
+
[SEARCH_TENANT_B, searchDocId(2)],
|
|
73
|
+
]);
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
];
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// What every search-index check shares: the subject, the suite's ids and tenants, one document
|
|
2
|
+
// builder (version 1 unless a check says otherwise), stored-then-indexed, and the sorted hit ids.
|
|
3
|
+
|
|
4
|
+
import { finiteOption } from '@ultimat3/core';
|
|
5
|
+
import type { SearchDocument, SearchIndex, SearchScope } from '@ultimat3/entity/adapter';
|
|
6
|
+
|
|
7
|
+
export interface SearchIndexSubject {
|
|
8
|
+
readonly index: SearchIndex;
|
|
9
|
+
/** A searchable entity with `title` and `body` searchable columns and a tenant column. */
|
|
10
|
+
readonly entity: string;
|
|
11
|
+
/** Writes (upserts) each document's source row; a no-op for an index holding its own copy. */
|
|
12
|
+
store(documents: readonly SearchDocument[]): Promise<void>;
|
|
13
|
+
/** Deletes the source rows of `ids` under `scope`; a no-op for an index holding its own copy. */
|
|
14
|
+
drop(scope: SearchScope, ids: readonly string[]): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Runs a read that names no tenant — `list` across every tenant, as `reindex` sweeps. Absent, it
|
|
17
|
+
* runs as is; the built-in Postgres index needs the `crossTenant` capability around it.
|
|
18
|
+
*/
|
|
19
|
+
everyTenant?<T>(read: () => Promise<T>): Promise<T>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SearchIndexCheck {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
run(subject: SearchIndexSubject): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const SEARCH_TENANT_A = '00000000-0000-7000-8000-00000000a0a0';
|
|
28
|
+
export const SEARCH_TENANT_B = '00000000-0000-7000-8000-00000000b0b0';
|
|
29
|
+
|
|
30
|
+
/** A uuid-shaped id, so a uuid-keyed table holds the suite's rows. */
|
|
31
|
+
export const searchDocId = (n: number): string =>
|
|
32
|
+
`00000000-0000-7000-8000-${String(n).padStart(12, '0')}`;
|
|
33
|
+
|
|
34
|
+
export interface SearchDocOptions {
|
|
35
|
+
readonly body?: string;
|
|
36
|
+
readonly tenant?: string;
|
|
37
|
+
/** The row's version (its `onUpdateNow()` instant, epoch ms). Default 1. */
|
|
38
|
+
readonly version?: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** One suite document: tenant A, version 1, unless the check says otherwise. */
|
|
42
|
+
export const searchDoc = (
|
|
43
|
+
entity: string,
|
|
44
|
+
n: number,
|
|
45
|
+
title: string,
|
|
46
|
+
options: SearchDocOptions = {},
|
|
47
|
+
): SearchDocument => ({
|
|
48
|
+
entity,
|
|
49
|
+
tenant: options.tenant ?? SEARCH_TENANT_A,
|
|
50
|
+
id: searchDocId(n),
|
|
51
|
+
version: finiteOption('searchDoc', 'version', options.version ?? 1),
|
|
52
|
+
fields: options.body === undefined ? { title } : { title, body: options.body },
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/** Stored then indexed — the order a write hook and `reindex` both keep. */
|
|
56
|
+
export const putSearchDocs = async (
|
|
57
|
+
subject: SearchIndexSubject,
|
|
58
|
+
documents: readonly SearchDocument[],
|
|
59
|
+
) => {
|
|
60
|
+
await subject.store(documents);
|
|
61
|
+
await subject.index.index(documents);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const searchIds = async (
|
|
65
|
+
subject: SearchIndexSubject,
|
|
66
|
+
term: string,
|
|
67
|
+
tenant = SEARCH_TENANT_A,
|
|
68
|
+
) =>
|
|
69
|
+
(await subject.index.query({ entity: subject.entity, tenant, term })).map((hit) => hit.id).sort();
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// The search index's ordering contract: keep only NEWER. A `reindex` batch that read a row at v1
|
|
2
|
+
// may call `index` after the write path indexed v2 or removed the row; the index must answer v2, or
|
|
3
|
+
// nothing. Each stale call is `index` ALONE, as when a batch's read raced a write, so the built-in
|
|
4
|
+
// Postgres index passes by construction.
|
|
5
|
+
|
|
6
|
+
// An EQUAL version is a replay: the writer, not the index, keeps versions strictly increasing per
|
|
7
|
+
// row (`@ultimat3/entity`'s `advanceVersion`). A `committed` document — the write path's — replaces
|
|
8
|
+
// a tombstone whatever its version: a key deleted and written again is live.
|
|
9
|
+
|
|
10
|
+
import { expect } from 'bun:test';
|
|
11
|
+
import type { SearchScope } from '@ultimat3/entity/adapter';
|
|
12
|
+
import type { SearchIndexCheck } from './search-index-conformance-support';
|
|
13
|
+
import {
|
|
14
|
+
searchDoc as doc,
|
|
15
|
+
putSearchDocs,
|
|
16
|
+
SEARCH_TENANT_A,
|
|
17
|
+
searchDocId,
|
|
18
|
+
searchIds,
|
|
19
|
+
} from './search-index-conformance-support';
|
|
20
|
+
|
|
21
|
+
export const SEARCH_INDEX_VERSION_CHECKS: readonly SearchIndexCheck[] = [
|
|
22
|
+
{
|
|
23
|
+
name: 'a committed document replaces a newer tombstone: a key deleted and written again is found',
|
|
24
|
+
async run(subject) {
|
|
25
|
+
await putSearchDocs(subject, [doc(subject.entity, 1, 'zebra', { version: 10 })]);
|
|
26
|
+
const own: SearchScope = { entity: subject.entity, tenant: SEARCH_TENANT_A };
|
|
27
|
+
await subject.drop(own, [searchDocId(1)]);
|
|
28
|
+
await subject.index.remove(own, [searchDocId(1)], 30);
|
|
29
|
+
const again = doc(subject.entity, 1, 'quokka', { version: 20 });
|
|
30
|
+
await subject.store([again]);
|
|
31
|
+
await subject.index.index([again], { committed: true });
|
|
32
|
+
expect(await searchIds(subject, 'quokka')).toEqual([searchDocId(1)]);
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'an older version indexed after a newer one leaves the newer one',
|
|
37
|
+
async run(subject) {
|
|
38
|
+
await putSearchDocs(subject, [doc(subject.entity, 1, 'lantern', { version: 20 })]);
|
|
39
|
+
await subject.index.index([doc(subject.entity, 1, 'zebra', { version: 10 })]);
|
|
40
|
+
expect(await searchIds(subject, 'zebra')).toEqual([]);
|
|
41
|
+
expect(await searchIds(subject, 'lantern')).toEqual([searchDocId(1)]);
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'a version indexed after the id was removed at a later version stays removed',
|
|
46
|
+
async run(subject) {
|
|
47
|
+
await putSearchDocs(subject, [doc(subject.entity, 1, 'zebra', { version: 10 })]);
|
|
48
|
+
const own: SearchScope = { entity: subject.entity, tenant: SEARCH_TENANT_A };
|
|
49
|
+
await subject.drop(own, [searchDocId(1)]);
|
|
50
|
+
await subject.index.remove(own, [searchDocId(1)], 30);
|
|
51
|
+
await subject.index.index([doc(subject.entity, 1, 'zebra', { version: 20 })]);
|
|
52
|
+
expect(await searchIds(subject, 'zebra')).toEqual([]);
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'an id written again after its removal, at a newer version, is found',
|
|
57
|
+
async run(subject) {
|
|
58
|
+
await putSearchDocs(subject, [doc(subject.entity, 1, 'zebra', { version: 10 })]);
|
|
59
|
+
const own: SearchScope = { entity: subject.entity, tenant: SEARCH_TENANT_A };
|
|
60
|
+
await subject.drop(own, [searchDocId(1)]);
|
|
61
|
+
await subject.index.remove(own, [searchDocId(1)], 30);
|
|
62
|
+
await putSearchDocs(subject, [doc(subject.entity, 1, 'quokka', { version: 40 })]);
|
|
63
|
+
expect(await searchIds(subject, 'quokka')).toEqual([searchDocId(1)]);
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
];
|