@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.
Files changed (175) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/.env.example +3 -0
  3. package/.github/actions/setup/action.yml +16 -0
  4. package/.github/workflows/ci.yml +71 -0
  5. package/.trunk/configs/.markdownlint.yaml +2 -0
  6. package/.trunk/configs/.yamllint.yaml +7 -0
  7. package/.trunk/configs/svgo.config.mjs +14 -0
  8. package/.trunk/trunk.yaml +34 -0
  9. package/docs/superpowers/bidi-roadmap.md +60 -0
  10. package/docs/superpowers/plans/2026-09-29-auto-wait.md +1827 -0
  11. package/docs/superpowers/plans/2026-09-29-expect.md +1350 -0
  12. package/docs/superpowers/plans/2026-10-01-ci.md +350 -0
  13. package/docs/superpowers/plans/2026-10-01-test-api-alignment.md +1821 -0
  14. package/docs/superpowers/recorder-roadmap.md +52 -0
  15. package/docs/superpowers/specs/2026-09-29-auto-wait-design.md +185 -0
  16. package/docs/superpowers/specs/2026-09-29-bidi-foundation-design.md +130 -0
  17. package/docs/superpowers/specs/2026-09-29-contexts-and-storage-design.md +88 -0
  18. package/docs/superpowers/specs/2026-09-29-downloads-and-file-dialogs-design.md +94 -0
  19. package/docs/superpowers/specs/2026-09-29-emulation-design.md +88 -0
  20. package/docs/superpowers/specs/2026-09-29-expect-design.md +130 -0
  21. package/docs/superpowers/specs/2026-09-29-locate-nodes-design.md +90 -0
  22. package/docs/superpowers/specs/2026-09-29-logs-and-errors-design.md +87 -0
  23. package/docs/superpowers/specs/2026-09-29-navigation-waits-design.md +83 -0
  24. package/docs/superpowers/specs/2026-09-29-network-data-design.md +78 -0
  25. package/docs/superpowers/specs/2026-09-29-network-interception-design.md +91 -0
  26. package/docs/superpowers/specs/2026-09-29-network-tracking-design.md +86 -0
  27. package/docs/superpowers/specs/2026-09-29-page-api-design.md +90 -0
  28. package/docs/superpowers/specs/2026-09-29-preload-scripts-design.md +82 -0
  29. package/docs/superpowers/specs/2026-09-29-script-call-function-design.md +107 -0
  30. package/docs/superpowers/specs/2026-09-29-set-files-design.md +62 -0
  31. package/docs/superpowers/specs/2026-09-29-user-prompts-design.md +75 -0
  32. package/docs/superpowers/specs/2026-10-01-ci-design.md +106 -0
  33. package/docs/superpowers/specs/2026-10-01-test-api-alignment-design.md +241 -0
  34. package/package.json +27 -0
  35. package/public/logo-dark.svg +236 -0
  36. package/public/logo-light.svg +262 -0
  37. package/samurai.config.ts +7 -0
  38. package/src/api.ts +4 -0
  39. package/src/assert/assertion-error.test.ts +55 -0
  40. package/src/assert/assertion-error.ts +62 -0
  41. package/src/assert/expect-locator.test.ts +217 -0
  42. package/src/assert/expect.test.ts +73 -0
  43. package/src/assert/expect.ts +299 -0
  44. package/src/browser/browser-context.browser-test.ts +201 -0
  45. package/src/browser/browser-context.test.ts +407 -0
  46. package/src/browser/browser-context.ts +208 -0
  47. package/src/browser/browser-finder.ts +110 -0
  48. package/src/browser/browser.test.ts +88 -0
  49. package/src/browser/browser.ts +515 -0
  50. package/src/browser/context-tree.test.ts +86 -0
  51. package/src/browser/context-tree.ts +70 -0
  52. package/src/browser/dialog.browser-test.ts +144 -0
  53. package/src/browser/dialog.test.ts +322 -0
  54. package/src/browser/dialog.ts +83 -0
  55. package/src/browser/download.test.ts +161 -0
  56. package/src/browser/download.ts +172 -0
  57. package/src/browser/downloads-dir.test.ts +75 -0
  58. package/src/browser/downloads-dir.ts +39 -0
  59. package/src/browser/emulation.browser-test.ts +186 -0
  60. package/src/browser/emulation.test.ts +200 -0
  61. package/src/browser/emulation.ts +204 -0
  62. package/src/browser/file-chooser.test.ts +142 -0
  63. package/src/browser/file-chooser.ts +99 -0
  64. package/src/browser/file-paths.ts +18 -0
  65. package/src/browser/goto.browser-test.ts +44 -0
  66. package/src/browser/navigation-error.ts +26 -0
  67. package/src/browser/navigation.browser-test.ts +172 -0
  68. package/src/browser/page-api.browser-test.ts +228 -0
  69. package/src/browser/page-logs.browser-test.ts +119 -0
  70. package/src/browser/page-logs.test.ts +212 -0
  71. package/src/browser/page-logs.ts +208 -0
  72. package/src/browser/page-wait.ts +19 -0
  73. package/src/browser/page.test.ts +1567 -0
  74. package/src/browser/page.ts +1176 -0
  75. package/src/browser/pdf.ts +62 -0
  76. package/src/browser/screenshot.ts +65 -0
  77. package/src/browser/transfers.browser-test.ts +180 -0
  78. package/src/config/config.ts +33 -0
  79. package/src/config/default.ts +5 -0
  80. package/src/config/fixtures.test.ts +137 -0
  81. package/src/config/mask.test.ts +143 -0
  82. package/src/config/mask.ts +87 -0
  83. package/src/config/run-settings.test.ts +163 -0
  84. package/src/config/run-settings.ts +114 -0
  85. package/src/config/secrets.ts +70 -0
  86. package/src/config/variables.ts +31 -0
  87. package/src/index.ts +10 -0
  88. package/src/locator/action-timeout-error.test.ts +83 -0
  89. package/src/locator/action-timeout-error.ts +72 -0
  90. package/src/locator/element-state.test.ts +181 -0
  91. package/src/locator/element-state.ts +159 -0
  92. package/src/locator/locate-nodes.browser-test.ts +169 -0
  93. package/src/locator/locator-actions.test.ts +355 -0
  94. package/src/locator/locator-chain.test.ts +292 -0
  95. package/src/locator/locator.browser-test.ts +137 -0
  96. package/src/locator/locator.test.ts +179 -0
  97. package/src/locator/locator.ts +656 -0
  98. package/src/locator/selector-errors.ts +18 -0
  99. package/src/locator/selector.test.ts +124 -0
  100. package/src/locator/selector.ts +107 -0
  101. package/src/locator/set-files.browser-test.ts +141 -0
  102. package/src/locator/set-files.test.ts +191 -0
  103. package/src/locator/text-locator.test.ts +118 -0
  104. package/src/locator/text-locator.ts +38 -0
  105. package/src/logger/index.test.ts +28 -0
  106. package/src/logger/index.ts +40 -0
  107. package/src/network/data-collector.test.ts +111 -0
  108. package/src/network/data-collector.ts +92 -0
  109. package/src/network/network-data.browser-test.ts +192 -0
  110. package/src/network/network-tracker.browser-test.ts +151 -0
  111. package/src/network/network-tracker.test.ts +307 -0
  112. package/src/network/network-tracker.ts +286 -0
  113. package/src/network/network-wait.ts +28 -0
  114. package/src/network/response.test.ts +93 -0
  115. package/src/network/response.ts +58 -0
  116. package/src/network/router.browser-test.ts +260 -0
  117. package/src/network/router.test.ts +528 -0
  118. package/src/network/router.ts +420 -0
  119. package/src/network/url-match.test.ts +69 -0
  120. package/src/network/url-match.ts +41 -0
  121. package/src/runner/page-logs-report.test.ts +144 -0
  122. package/src/runner/page-logs-report.ts +82 -0
  123. package/src/runner/prepare-run.test.ts +33 -0
  124. package/src/runner/prepare-run.ts +36 -0
  125. package/src/runner/registry.test.ts +59 -0
  126. package/src/runner/registry.ts +46 -0
  127. package/src/runner/reporter.test.ts +73 -0
  128. package/src/runner/reporter.ts +109 -0
  129. package/src/runner/test-error.test.ts +39 -0
  130. package/src/runner/test-error.ts +20 -0
  131. package/src/runner/test-runner.ts +184 -0
  132. package/src/script/call-function.browser-test.ts +112 -0
  133. package/src/script/call-function.test.ts +174 -0
  134. package/src/script/call-function.ts +113 -0
  135. package/src/script/element-handle.ts +11 -0
  136. package/src/script/helpers.test.ts +116 -0
  137. package/src/script/helpers.ts +68 -0
  138. package/src/script/preload.browser-test.ts +144 -0
  139. package/src/script/preload.test.ts +180 -0
  140. package/src/script/preload.ts +102 -0
  141. package/src/script/serialize.test.ts +182 -0
  142. package/src/script/serialize.ts +203 -0
  143. package/src/testing/browser-fixture.ts +18 -0
  144. package/src/testing/fake-websocket.ts +72 -0
  145. package/src/testing/stub-connector.ts +154 -0
  146. package/src/tests/index.spec.ts +30 -0
  147. package/src/transport/bidi-connection.test.ts +155 -0
  148. package/src/transport/bidi-connection.ts +256 -0
  149. package/src/transport/bidi-error.ts +23 -0
  150. package/src/transport/foundation.browser-test.ts +73 -0
  151. package/src/transport/subscriptions.test.ts +140 -0
  152. package/src/transport/subscriptions.ts +110 -0
  153. package/src/types/bidi-commands.test-d.ts +55 -0
  154. package/src/types/bidi-modules/browser.d.ts +103 -0
  155. package/src/types/bidi-modules/browsing-context.d.ts +430 -0
  156. package/src/types/bidi-modules/emulation.d.ts +280 -0
  157. package/src/types/bidi-modules/input.d.ts +201 -0
  158. package/src/types/bidi-modules/log.d.ts +49 -0
  159. package/src/types/bidi-modules/network.d.ts +358 -0
  160. package/src/types/bidi-modules/permissions.d.ts +19 -0
  161. package/src/types/bidi-modules/script.d.ts +543 -0
  162. package/src/types/bidi-modules/session.d.ts +135 -0
  163. package/src/types/bidi-modules/storage.d.ts +92 -0
  164. package/src/types/bidi-modules/web-extensions.d.ts +9 -0
  165. package/src/types/bidi-protocols/command.d.ts +7 -0
  166. package/src/types/bidi-protocols/error.d.ts +38 -0
  167. package/src/types/bidi-protocols/event.d.ts +17 -0
  168. package/src/types/bidi.d.ts +65 -0
  169. package/src/types/browser.d.ts +1 -0
  170. package/src/types/config.d.ts +157 -0
  171. package/src/types/env.d.ts +5 -0
  172. package/src/types/test.d.ts +95 -0
  173. package/src/wait/wait-until.test.ts +117 -0
  174. package/src/wait/wait-until.ts +86 -0
  175. package/tsconfig.json +44 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(npx tsc *)"
5
+ ]
6
+ }
7
+ }
package/.env.example ADDED
@@ -0,0 +1,3 @@
1
+ # Copy to .env.<environment>, e.g. .env.staging. Never commit real values.
2
+ # Tests read these as secrets.TEST_CARD; real environment variables win over this file.
3
+ SAMURAI_SECRET_TEST_CARD=
@@ -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,2 @@
1
+ # Prettier friendly markdownlint config (all formatting rules disabled)
2
+ extends: markdownlint/style/prettier
@@ -0,0 +1,7 @@
1
+ rules:
2
+ quoted-strings:
3
+ required: only-when-needed
4
+ extra-allowed: ["{|}"]
5
+ key-duplicates: {}
6
+ octal-values:
7
+ forbid-implicit-octal: true
@@ -0,0 +1,14 @@
1
+ export default {
2
+ plugins: [
3
+ {
4
+ name: "preset-default",
5
+ params: {
6
+ overrides: {
7
+ removeViewBox: false, // https://github.com/svg/svgo/issues/1128
8
+ sortAttrs: true,
9
+ removeOffCanvasPaths: true,
10
+ },
11
+ },
12
+ },
13
+ ],
14
+ };
@@ -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.