@itmetsam/samurai-framework 0.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/settings.local.json +7 -0
- package/.env.example +3 -0
- package/.github/actions/setup/action.yml +16 -0
- package/.github/workflows/ci.yml +71 -0
- package/.trunk/configs/.markdownlint.yaml +2 -0
- package/.trunk/configs/.yamllint.yaml +7 -0
- package/.trunk/configs/svgo.config.mjs +14 -0
- package/.trunk/trunk.yaml +34 -0
- package/docs/superpowers/bidi-roadmap.md +60 -0
- package/docs/superpowers/plans/2026-09-29-auto-wait.md +1827 -0
- package/docs/superpowers/plans/2026-09-29-expect.md +1350 -0
- package/docs/superpowers/plans/2026-10-01-ci.md +350 -0
- package/docs/superpowers/plans/2026-10-01-test-api-alignment.md +1821 -0
- package/docs/superpowers/recorder-roadmap.md +52 -0
- package/docs/superpowers/specs/2026-09-29-auto-wait-design.md +185 -0
- package/docs/superpowers/specs/2026-09-29-bidi-foundation-design.md +130 -0
- package/docs/superpowers/specs/2026-09-29-contexts-and-storage-design.md +88 -0
- package/docs/superpowers/specs/2026-09-29-downloads-and-file-dialogs-design.md +94 -0
- package/docs/superpowers/specs/2026-09-29-emulation-design.md +88 -0
- package/docs/superpowers/specs/2026-09-29-expect-design.md +130 -0
- package/docs/superpowers/specs/2026-09-29-locate-nodes-design.md +90 -0
- package/docs/superpowers/specs/2026-09-29-logs-and-errors-design.md +87 -0
- package/docs/superpowers/specs/2026-09-29-navigation-waits-design.md +83 -0
- package/docs/superpowers/specs/2026-09-29-network-data-design.md +78 -0
- package/docs/superpowers/specs/2026-09-29-network-interception-design.md +91 -0
- package/docs/superpowers/specs/2026-09-29-network-tracking-design.md +86 -0
- package/docs/superpowers/specs/2026-09-29-page-api-design.md +90 -0
- package/docs/superpowers/specs/2026-09-29-preload-scripts-design.md +82 -0
- package/docs/superpowers/specs/2026-09-29-script-call-function-design.md +107 -0
- package/docs/superpowers/specs/2026-09-29-set-files-design.md +62 -0
- package/docs/superpowers/specs/2026-09-29-user-prompts-design.md +75 -0
- package/docs/superpowers/specs/2026-10-01-ci-design.md +106 -0
- package/docs/superpowers/specs/2026-10-01-test-api-alignment-design.md +241 -0
- package/package.json +27 -0
- package/public/logo-dark.svg +236 -0
- package/public/logo-light.svg +262 -0
- package/samurai.config.ts +7 -0
- package/src/api.ts +4 -0
- package/src/assert/assertion-error.test.ts +55 -0
- package/src/assert/assertion-error.ts +62 -0
- package/src/assert/expect-locator.test.ts +217 -0
- package/src/assert/expect.test.ts +73 -0
- package/src/assert/expect.ts +299 -0
- package/src/browser/browser-context.browser-test.ts +201 -0
- package/src/browser/browser-context.test.ts +407 -0
- package/src/browser/browser-context.ts +208 -0
- package/src/browser/browser-finder.ts +110 -0
- package/src/browser/browser.test.ts +88 -0
- package/src/browser/browser.ts +515 -0
- package/src/browser/context-tree.test.ts +86 -0
- package/src/browser/context-tree.ts +70 -0
- package/src/browser/dialog.browser-test.ts +144 -0
- package/src/browser/dialog.test.ts +322 -0
- package/src/browser/dialog.ts +83 -0
- package/src/browser/download.test.ts +161 -0
- package/src/browser/download.ts +172 -0
- package/src/browser/downloads-dir.test.ts +75 -0
- package/src/browser/downloads-dir.ts +39 -0
- package/src/browser/emulation.browser-test.ts +186 -0
- package/src/browser/emulation.test.ts +200 -0
- package/src/browser/emulation.ts +204 -0
- package/src/browser/file-chooser.test.ts +142 -0
- package/src/browser/file-chooser.ts +99 -0
- package/src/browser/file-paths.ts +18 -0
- package/src/browser/goto.browser-test.ts +44 -0
- package/src/browser/navigation-error.ts +26 -0
- package/src/browser/navigation.browser-test.ts +172 -0
- package/src/browser/page-api.browser-test.ts +228 -0
- package/src/browser/page-logs.browser-test.ts +119 -0
- package/src/browser/page-logs.test.ts +212 -0
- package/src/browser/page-logs.ts +208 -0
- package/src/browser/page-wait.ts +19 -0
- package/src/browser/page.test.ts +1567 -0
- package/src/browser/page.ts +1176 -0
- package/src/browser/pdf.ts +62 -0
- package/src/browser/screenshot.ts +65 -0
- package/src/browser/transfers.browser-test.ts +180 -0
- package/src/config/config.ts +33 -0
- package/src/config/default.ts +5 -0
- package/src/config/fixtures.test.ts +137 -0
- package/src/config/mask.test.ts +143 -0
- package/src/config/mask.ts +87 -0
- package/src/config/run-settings.test.ts +163 -0
- package/src/config/run-settings.ts +114 -0
- package/src/config/secrets.ts +70 -0
- package/src/config/variables.ts +31 -0
- package/src/index.ts +10 -0
- package/src/locator/action-timeout-error.test.ts +83 -0
- package/src/locator/action-timeout-error.ts +72 -0
- package/src/locator/element-state.test.ts +181 -0
- package/src/locator/element-state.ts +159 -0
- package/src/locator/locate-nodes.browser-test.ts +169 -0
- package/src/locator/locator-actions.test.ts +355 -0
- package/src/locator/locator-chain.test.ts +292 -0
- package/src/locator/locator.browser-test.ts +137 -0
- package/src/locator/locator.test.ts +179 -0
- package/src/locator/locator.ts +656 -0
- package/src/locator/selector-errors.ts +18 -0
- package/src/locator/selector.test.ts +124 -0
- package/src/locator/selector.ts +107 -0
- package/src/locator/set-files.browser-test.ts +141 -0
- package/src/locator/set-files.test.ts +191 -0
- package/src/locator/text-locator.test.ts +118 -0
- package/src/locator/text-locator.ts +38 -0
- package/src/logger/index.test.ts +28 -0
- package/src/logger/index.ts +40 -0
- package/src/network/data-collector.test.ts +111 -0
- package/src/network/data-collector.ts +92 -0
- package/src/network/network-data.browser-test.ts +192 -0
- package/src/network/network-tracker.browser-test.ts +151 -0
- package/src/network/network-tracker.test.ts +307 -0
- package/src/network/network-tracker.ts +286 -0
- package/src/network/network-wait.ts +28 -0
- package/src/network/response.test.ts +93 -0
- package/src/network/response.ts +58 -0
- package/src/network/router.browser-test.ts +260 -0
- package/src/network/router.test.ts +528 -0
- package/src/network/router.ts +420 -0
- package/src/network/url-match.test.ts +69 -0
- package/src/network/url-match.ts +41 -0
- package/src/runner/page-logs-report.test.ts +144 -0
- package/src/runner/page-logs-report.ts +82 -0
- package/src/runner/prepare-run.test.ts +33 -0
- package/src/runner/prepare-run.ts +36 -0
- package/src/runner/registry.test.ts +59 -0
- package/src/runner/registry.ts +46 -0
- package/src/runner/reporter.test.ts +73 -0
- package/src/runner/reporter.ts +109 -0
- package/src/runner/test-error.test.ts +39 -0
- package/src/runner/test-error.ts +20 -0
- package/src/runner/test-runner.ts +184 -0
- package/src/script/call-function.browser-test.ts +112 -0
- package/src/script/call-function.test.ts +174 -0
- package/src/script/call-function.ts +113 -0
- package/src/script/element-handle.ts +11 -0
- package/src/script/helpers.test.ts +116 -0
- package/src/script/helpers.ts +68 -0
- package/src/script/preload.browser-test.ts +144 -0
- package/src/script/preload.test.ts +180 -0
- package/src/script/preload.ts +102 -0
- package/src/script/serialize.test.ts +182 -0
- package/src/script/serialize.ts +203 -0
- package/src/testing/browser-fixture.ts +18 -0
- package/src/testing/fake-websocket.ts +72 -0
- package/src/testing/stub-connector.ts +154 -0
- package/src/tests/index.spec.ts +30 -0
- package/src/transport/bidi-connection.test.ts +155 -0
- package/src/transport/bidi-connection.ts +256 -0
- package/src/transport/bidi-error.ts +23 -0
- package/src/transport/foundation.browser-test.ts +73 -0
- package/src/transport/subscriptions.test.ts +140 -0
- package/src/transport/subscriptions.ts +110 -0
- package/src/types/bidi-commands.test-d.ts +55 -0
- package/src/types/bidi-modules/browser.d.ts +103 -0
- package/src/types/bidi-modules/browsing-context.d.ts +430 -0
- package/src/types/bidi-modules/emulation.d.ts +280 -0
- package/src/types/bidi-modules/input.d.ts +201 -0
- package/src/types/bidi-modules/log.d.ts +49 -0
- package/src/types/bidi-modules/network.d.ts +358 -0
- package/src/types/bidi-modules/permissions.d.ts +19 -0
- package/src/types/bidi-modules/script.d.ts +543 -0
- package/src/types/bidi-modules/session.d.ts +135 -0
- package/src/types/bidi-modules/storage.d.ts +92 -0
- package/src/types/bidi-modules/web-extensions.d.ts +9 -0
- package/src/types/bidi-protocols/command.d.ts +7 -0
- package/src/types/bidi-protocols/error.d.ts +38 -0
- package/src/types/bidi-protocols/event.d.ts +17 -0
- package/src/types/bidi.d.ts +65 -0
- package/src/types/browser.d.ts +1 -0
- package/src/types/config.d.ts +157 -0
- package/src/types/env.d.ts +5 -0
- package/src/types/test.d.ts +95 -0
- package/src/wait/wait-until.test.ts +117 -0
- package/src/wait/wait-until.ts +86 -0
- package/tsconfig.json +44 -0
package/.env.example
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: Setup
|
|
2
|
+
description: Install bun, Node and the locked dependencies
|
|
3
|
+
|
|
4
|
+
runs:
|
|
5
|
+
using: composite
|
|
6
|
+
steps:
|
|
7
|
+
- uses: oven-sh/setup-bun@v2
|
|
8
|
+
with:
|
|
9
|
+
bun-version: 1.3.0
|
|
10
|
+
# The test scripts run tsx on Node's test runner, which needs Node 22+ (fs/promises glob)
|
|
11
|
+
- uses: actions/setup-node@v4
|
|
12
|
+
with:
|
|
13
|
+
node-version: 26
|
|
14
|
+
- name: Install dependencies
|
|
15
|
+
shell: bash
|
|
16
|
+
run: bun install --frozen-lockfile
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ci-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
typecheck:
|
|
17
|
+
name: Typecheck
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
timeout-minutes: 5
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- uses: ./.github/actions/setup
|
|
23
|
+
- name: Typecheck
|
|
24
|
+
run: bunx tsc --noEmit -p .
|
|
25
|
+
|
|
26
|
+
unit:
|
|
27
|
+
name: Unit tests
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
timeout-minutes: 10
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@v4
|
|
32
|
+
- uses: ./.github/actions/setup
|
|
33
|
+
- name: Unit tests
|
|
34
|
+
run: bun run test
|
|
35
|
+
|
|
36
|
+
browser:
|
|
37
|
+
name: Browser tests (Firefox)
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
timeout-minutes: 15
|
|
40
|
+
steps:
|
|
41
|
+
- uses: actions/checkout@v4
|
|
42
|
+
- uses: ./.github/actions/setup
|
|
43
|
+
- name: Firefox version
|
|
44
|
+
run: firefox --version
|
|
45
|
+
- name: Browser tests
|
|
46
|
+
timeout-minutes: 12
|
|
47
|
+
run: bun run test:browser
|
|
48
|
+
- name: Upload logs
|
|
49
|
+
if: failure()
|
|
50
|
+
uses: actions/upload-artifact@v4
|
|
51
|
+
with:
|
|
52
|
+
name: browser-test-logs
|
|
53
|
+
path: |
|
|
54
|
+
logs/
|
|
55
|
+
result/
|
|
56
|
+
retention-days: 7
|
|
57
|
+
if-no-files-found: ignore
|
|
58
|
+
|
|
59
|
+
trunk:
|
|
60
|
+
name: Code quality (Trunk)
|
|
61
|
+
runs-on: ubuntu-latest
|
|
62
|
+
timeout-minutes: 15
|
|
63
|
+
permissions:
|
|
64
|
+
contents: read
|
|
65
|
+
checks: write
|
|
66
|
+
steps:
|
|
67
|
+
- uses: actions/checkout@v4
|
|
68
|
+
with:
|
|
69
|
+
fetch-depth: 0
|
|
70
|
+
# Checks only what the PR or push changed; linters come from .trunk/trunk.yaml
|
|
71
|
+
- uses: trunk-io/trunk-action@v1
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
|
|
2
|
+
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
|
|
3
|
+
version: 0.1
|
|
4
|
+
cli:
|
|
5
|
+
version: 1.25.0
|
|
6
|
+
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
|
|
7
|
+
plugins:
|
|
8
|
+
sources:
|
|
9
|
+
- id: trunk
|
|
10
|
+
ref: v1.11.0
|
|
11
|
+
uri: https://github.com/trunk-io/plugins
|
|
12
|
+
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
|
|
13
|
+
runtimes:
|
|
14
|
+
enabled:
|
|
15
|
+
- node@22.16.0
|
|
16
|
+
- python@3.14.4
|
|
17
|
+
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
|
|
18
|
+
lint:
|
|
19
|
+
enabled:
|
|
20
|
+
- checkov@3.3.22
|
|
21
|
+
- git-diff-check
|
|
22
|
+
- grype@0.119.0
|
|
23
|
+
- markdownlint@0.49.1
|
|
24
|
+
- osv-scanner@2.6.0
|
|
25
|
+
- prettier@3.9.9
|
|
26
|
+
- svgo@4.1.0
|
|
27
|
+
- trufflehog@3.97.9
|
|
28
|
+
- yamllint@1.38.0
|
|
29
|
+
actions:
|
|
30
|
+
enabled:
|
|
31
|
+
- trunk-announce
|
|
32
|
+
- trunk-check-pre-push
|
|
33
|
+
- trunk-fmt-pre-commit
|
|
34
|
+
- trunk-upgrade-available
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# WebDriver BiDi adoption — roadmap
|
|
2
|
+
|
|
3
|
+
Date: 2026-09-29
|
|
4
|
+
Source: https://www.w3.org/TR/webdriver-bidi/
|
|
5
|
+
Status: all 15 specs (0 to 14) are implemented.
|
|
6
|
+
|
|
7
|
+
Each item links to its spec in `docs/superpowers/specs/`. Order respects dependencies (`←`).
|
|
8
|
+
|
|
9
|
+
## Todo
|
|
10
|
+
|
|
11
|
+
### Phase 0 — prerequisite
|
|
12
|
+
- [x] **0. Foundation** — connector error replies, command typings, refcounted subscriptions, context tree, `newPage` fix — [spec](specs/2026-09-29-bidi-foundation-design.md)
|
|
13
|
+
|
|
14
|
+
### Phase 1 — locator core
|
|
15
|
+
- [x] **1. `script.callFunction` (+ `script.disown`)** ← 0 — [spec](specs/2026-09-29-script-call-function-design.md)
|
|
16
|
+
- [x] **2. `script.addPreloadScript`** ← 0, 1 — [spec](specs/2026-09-29-preload-scripts-design.md)
|
|
17
|
+
- [x] **3. `browsingContext.locateNodes`** ← 1 (2 optional) — [spec](specs/2026-09-29-locate-nodes-design.md)
|
|
18
|
+
- [x] **4. `input.setFiles`** ← 1, 3 — [spec](specs/2026-09-29-set-files-design.md)
|
|
19
|
+
|
|
20
|
+
### Phase 2 — waiting correctness
|
|
21
|
+
- [x] **5. Network tracking + real network idle** ← 0 — [spec](specs/2026-09-29-network-tracking-design.md)
|
|
22
|
+
- [x] **6. Navigation waits (`navigate` wait, load events, reload)** ← 0, 5 — [spec](specs/2026-09-29-navigation-waits-design.md)
|
|
23
|
+
- [x] **7. User prompts (`handleUserPrompt`)** ← 0 — [spec](specs/2026-09-29-user-prompts-design.md)
|
|
24
|
+
- [x] **8. Logs and page errors (`log.entryAdded`)** ← 0, 1 — [spec](specs/2026-09-29-logs-and-errors-design.md)
|
|
25
|
+
|
|
26
|
+
### Phase 3 — features
|
|
27
|
+
- [x] **9. Network interception (mock / block / modify)** ← 0, 5 — [spec](specs/2026-09-29-network-interception-design.md)
|
|
28
|
+
- [x] **10. Network data (cache control, response bodies)** ← 5 — [spec](specs/2026-09-29-network-data-design.md)
|
|
29
|
+
- [x] **11. Page API completeness (viewport, reload, history, close, pdf, screenshot)** ← 0, 1 — [spec](specs/2026-09-29-page-api-design.md)
|
|
30
|
+
- [x] **12. User contexts + storage** ← 0 — [spec](specs/2026-09-29-contexts-and-storage-design.md)
|
|
31
|
+
|
|
32
|
+
### Phase 4 — nice to have
|
|
33
|
+
- [x] **13. Emulation** ← 12 — [spec](specs/2026-09-29-emulation-design.md)
|
|
34
|
+
- [x] **14. Downloads + file dialogs** ← 0, 4 — [spec](specs/2026-09-29-downloads-and-file-dialogs-design.md)
|
|
35
|
+
|
|
36
|
+
## Dependency graph
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
0 ─┬─ 1 ─┬─ 2
|
|
40
|
+
│ ├─ 3 ── 4 ── 14
|
|
41
|
+
│ ├─ 8
|
|
42
|
+
│ └─ 11
|
|
43
|
+
├─ 5 ─┬─ 6
|
|
44
|
+
│ ├─ 9
|
|
45
|
+
│ └─ 10
|
|
46
|
+
├─ 7
|
|
47
|
+
└─ 12 ── 13
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Deliberately skipped
|
|
51
|
+
|
|
52
|
+
`webExtension.*`, `session.end`, `script.getRealms`, `script.removePreloadScript` as public API (used internally only), `network.continueWithAuth` (folded into spec 9 as a follow-up).
|
|
53
|
+
|
|
54
|
+
## Cross-cutting rules for every spec
|
|
55
|
+
|
|
56
|
+
- Test-first: each unit test before its implementation, using `src/testing/stub-connector.ts`; browser tests in `*.browser-test.ts` (`npm run test:browser`).
|
|
57
|
+
- Any feature that needs an event subscribes through the refcounted API from spec 0, never a bare `session.subscribe`.
|
|
58
|
+
- Every command a feature sends must be typed in `BiDiCommands` (spec 0 lists the missing ones).
|
|
59
|
+
- Timeouts resolve through `resolveTimeout` (actions/assertions) or the navigation timeout from spec 6 (navigation); no unbounded waits.
|
|
60
|
+
- Browser support is verified against Firefox (the only `SupportedBrowser` today). A command Firefox lacks is documented in its spec and surfaced as `UnsupportedOperationError`, not a hang.
|