@lumeweb/sia-testing 0.0.1 → 0.0.3
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 +33 -41
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Sia testing
|
|
2
2
|
|
|
3
|
-
Test Sia application behavior without a server.
|
|
3
|
+
Test Sia application behavior without a server. A managed run owns the synthetic fixture objects and sharing keys, and your application code receives restricted ports instead of fixture or publication controls.
|
|
4
4
|
|
|
5
5
|
## Write a Vitest test
|
|
6
6
|
|
|
@@ -46,34 +46,30 @@ test("the recipient reads a managed fixture", async ({ signal }) => {
|
|
|
46
46
|
});
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
The test driver owns the fixtures. `run.objects.upload` uploads and pins before returning. An application's `ApplicationPort.upload` stages bytes until the application calls `pin
|
|
49
|
+
The test driver owns the fixtures. `run.objects.upload` uploads and pins before returning. An application's `ApplicationPort.upload` stages bytes until the application calls `pin`, and publication is a separate driver action. The optional upload `name` defaults to the snapshotted `TestFile.name` label; it does not set an application filename. Metadata stays required and is passed through as opaque bytes, so the empty metadata above is intentional rather than a usable file record for every application.
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
These synthetic ports do not replace the full storage SDK or model native packed finalization. A separate direct `mock.packedSdk` surface consumes bounded streams through SDK 0.2-shaped packed calls; [the packed simulation contract](https://github.com/LumeWeb/web/blob/develop/libs/sia-testing/docs/mock-contracts.md#direct-sdk-shaped-packed-simulation) covers platform signatures, partial results and its non-cryptographic `seal` behavior. For individual SDK 0.2 uploads, `mock.uploadSdk` accepts `MockPinnedObject` handles; [the direct upload contract](https://github.com/LumeWeb/web/blob/develop/libs/sia-testing/docs/mock-contracts.md#direct-sdk-02-upload-simulation) covers those.
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
handle with `shareGrants` on `mock.application` or an endpoint connection.
|
|
56
|
-
`ApplicationPort.shares` lists granted targets, inspects lifecycle and membership,
|
|
57
|
-
and supports Add, Remove, and End. End withdraws sharing without deleting owned
|
|
58
|
-
payloads. [Share grant contracts](docs/mock-contracts.md#edit-an-explicitly-granted-share)
|
|
59
|
-
describe deadlines, cancellation, and cleanup.
|
|
53
|
+
`fileFixture(path)` from `/node` streams a local file and records its digest, so an upload rejects changed bytes. Files are limited to 16 MiB. Mock runs default to 8 object reservations, 8 share reservations, and 16 MiB of logical uploads, and deletion does not refund those allowances.
|
|
54
|
+
|
|
55
|
+
Applications can edit mock shares only through explicit per-share grants. `run.shares.grant` binds an actor, label, and permitted operations; install the handle with `shareGrants` on `mock.application` or an endpoint connection. `ApplicationPort.shares` lists granted targets, inspects lifecycle and membership, and supports Add, Remove, and End. End withdraws sharing without deleting owned payloads. [Share grant contracts](https://github.com/LumeWeb/web/blob/develop/libs/sia-testing/docs/mock-contracts.md#edit-an-explicitly-granted-share) describe the deadlines, cancellation, and cleanup.
|
|
60
56
|
|
|
61
57
|
## Choose an entry
|
|
62
58
|
|
|
63
|
-
| Entry
|
|
64
|
-
|
|
|
65
|
-
| `/mock`
|
|
66
|
-
| `/node`
|
|
67
|
-
| `/vitest`
|
|
68
|
-
| `/client`
|
|
69
|
-
| `/http`
|
|
70
|
-
| `/msw`
|
|
59
|
+
| Entry | Use it for |
|
|
60
|
+
| --------- | ------------------------------------------------------------------------ |
|
|
61
|
+
| `/mock` | Portable byte fixtures, direct application ports, and driver controls |
|
|
62
|
+
| `/node` | Owned callback runs, local files, and explicitly consented live profiles |
|
|
63
|
+
| `/vitest` | Native Vitest fixtures with a portable mock run per using test |
|
|
64
|
+
| `/client` | Fetch-backed application ports and mock sign-in |
|
|
65
|
+
| `/http` | An optional owned loopback listener over a mock |
|
|
66
|
+
| `/msw` | An optional interceptor at an explicit base URL over a mock |
|
|
71
67
|
|
|
72
|
-
No Vitest plugin is required
|
|
68
|
+
No Vitest plugin is required, and MSW and Vitest are optional peers. Portable mock and client imports contain no Node, test-runner, or storage SDK runtime. HTTP and MSW speak a synthetic fixture protocol, not native Indexd. The package does not deploy services or fund accounts.
|
|
73
69
|
|
|
74
70
|
## Select a simulated DOM environment
|
|
75
71
|
|
|
76
|
-
The
|
|
72
|
+
The tests on this page also run with `--environment jsdom` or `--environment happy-dom` instead of `--environment node`. Install `jsdom` or `happy-dom` yourself as a development dependency when you choose that environment, and install the optional `msw` peer for MSW-backed Fetch tests. No package plugin or global shims are needed.
|
|
77
73
|
|
|
78
74
|
These environments simulate a DOM inside Node; they are not Vitest browser providers. Compare opaque metadata by byte contents, as in the publication recipe, because typed arrays can come from different realms.
|
|
79
75
|
|
|
@@ -117,27 +113,19 @@ for (const label of ["left", "right"]) {
|
|
|
117
113
|
}
|
|
118
114
|
```
|
|
119
115
|
|
|
120
|
-
The factory combines the runner cancellation signal with the optional external `signal`. An already-aborted signal prevents setup
|
|
116
|
+
The factory combines the runner cancellation signal with the optional external `signal`. An already-aborted signal prevents setup, and sharing an external signal cancels every test that uses it. `onTestFinished` closes the mock after a failure or timeout, including a failed dependent teardown, and `finally` also closes it after a dynamic skip. Repeated cleanup shares one promise. Run cleanup closes retained ports before deleting fixture state, including after assertion failures.
|
|
117
|
+
|
|
118
|
+
Caller-created controllers can cancel individual reads without closing the reader or run. The packed Vitest checks cover the current-global `AbortController` in Node, jsdom, and happy-dom, plus `window.AbortController` in both DOM environments, through direct readers and MSW-backed Fetch readers. In the tested versions, those DOM environments expose the same constructors through `globalThis` and `window`; these checks do not establish compatibility between Node signals and a separately created jsdom window's signal implementation.
|
|
121
119
|
|
|
122
|
-
|
|
120
|
+
Cancellation cannot force an unrelated user promise to settle, so await your work and make callbacks cooperate with cancellation. Application and owner-share ports cancel and join their pending calls on close. For both direct and fetch-backed readers, `close()` aborts requests without waiting for those calls to settle. Close a fetch application client in `finally` to join its local upload collector, because backend teardown cannot synchronously stop collection in a remote client.
|
|
123
121
|
|
|
124
|
-
|
|
122
|
+
## Test in a browser
|
|
125
123
|
|
|
126
|
-
|
|
124
|
+
Playwright tests compose the public `/node` `withSiaRun` with `/http` `startMockServer` through `test.extend`. There is no Playwright entry point in this package.
|
|
127
125
|
|
|
128
|
-
|
|
129
|
-
Use Playwright's `test.extend` to compose public `/node` `withSiaRun` and `/http`
|
|
130
|
-
`startMockServer`. Create contexts with your context options, base URL, proxy,
|
|
131
|
-
service-worker settings and empty storage state. Obtain credentials from
|
|
132
|
-
`endpoint.connection({ access, as })` and install them before navigation.
|
|
133
|
-
Use nested `try/finally` blocks to close contexts before the endpoint, and the
|
|
134
|
-
endpoint before returning from `withSiaRun`, including partial setup failures.
|
|
135
|
-
The portable Vitest fixture owns no browser contexts or navigation.
|
|
126
|
+
Create contexts with your own context options, base URL, proxy, service-worker settings, and empty storage state. Obtain credentials from `endpoint.connection({ access, as })` and install them before navigation. Close contexts before the endpoint, and the endpoint before `withSiaRun` returns, using nested `try/finally` blocks so a partial setup failure still cleans up. The portable Vitest fixture owns no browser contexts or navigation.
|
|
136
127
|
|
|
137
|
-
Node tests
|
|
138
|
-
keep using `/node` `withSiaRun` inside a native Vitest fixture or callback. This
|
|
139
|
-
storage mode supports direct Node calls only; it rejects HTTP and browser use.
|
|
140
|
-
`createSiaTest` accepts portable `MockOptions` and has no payload-storage option.
|
|
128
|
+
Node tests that need `backend.payloadStorage: { kind: "temporary-files", limits }` keep using `/node` `withSiaRun` inside a native Vitest fixture or callback. That storage mode supports direct Node calls only and rejects HTTP and browser use. `createSiaTest` accepts portable `MockOptions` and has no payload-storage option.
|
|
141
129
|
|
|
142
130
|
## Publish application writes
|
|
143
131
|
|
|
@@ -190,11 +178,15 @@ test("publishes a pinned application object explicitly", async ({ signal }) => {
|
|
|
190
178
|
});
|
|
191
179
|
```
|
|
192
180
|
|
|
193
|
-
`pin(object, { metadata })` snapshots up to 1024 opaque bytes at invocation. Upload metadata remains required. Omitted or explicit `undefined` metadata preserves the last committed value; an empty `Uint8Array` clears it. Successful repins replace metadata at the same effect as pin membership. Failure or cancellation before commit leaves the prior value unchanged
|
|
181
|
+
`pin(object, { metadata })` snapshots up to 1024 opaque bytes at invocation. Upload metadata remains required. Omitted or explicit `undefined` metadata preserves the last committed value; an empty `Uint8Array` clears it. Successful repins replace metadata at the same effect as pin membership. Failure or cancellation before commit leaves the prior value unchanged, and losing a reply after commit keeps the replacement. Reads return detached copies. Concurrent pins follow actual commit order, and `inspect` reports membership only, not which metadata update won. Events need explicit publication. This option is mock-only and adds no native storage capability.
|
|
182
|
+
|
|
183
|
+
Handles and actors grant authority by their original reference, not by copied fields or equal labels. Recipient reads check current attachments and keys. Revocation blocks fresh reads but cannot erase downloaded plaintext. The package provides no automatic retries and no idempotency guarantee.
|
|
184
|
+
|
|
185
|
+
A lost acknowledgement can follow a committed effect. Reconcile with `inspect` rather than a blind retry. For a share Add, Remove, or End, use explicit `shares.inspect` under a still-valid grant; inspection reports current state, not which request committed. Publication stays explicit after reconciliation.
|
|
194
186
|
|
|
195
|
-
|
|
187
|
+
A lost upload acknowledgement can leave no application handle. Staged bytes and committed charges remain run-owned until cleanup, and no inspection, ID, receipt or fresh client can recover the handle. Upload never pins or publishes implicitly, so another explicit upload is another attempt.
|
|
196
188
|
|
|
197
|
-
[Mock application contracts](docs/mock-contracts.md) covers pagination, lost replies, diagnostics, and transport upload limits. [Live runs](docs/live-runs.md) and [live authentication](docs/live-auth.md) describe owner-only external profiles and acknowledged-resource recovery. Nonempty live transfers and real-server compatibility have not been verified.
|
|
189
|
+
[Mock application contracts](https://github.com/LumeWeb/web/blob/develop/libs/sia-testing/docs/mock-contracts.md) covers pagination, lost replies, diagnostics, and transport upload limits. [Live runs](https://github.com/LumeWeb/web/blob/develop/libs/sia-testing/docs/live-runs.md) and [live authentication](https://github.com/LumeWeb/web/blob/develop/libs/sia-testing/docs/live-auth.md) describe owner-only external profiles and acknowledged-resource recovery. Nonempty live transfers and real-server compatibility have not been verified.
|
|
198
190
|
|
|
199
191
|
## Checks
|
|
200
192
|
|
|
@@ -206,6 +198,6 @@ pnpm --filter @lumeweb/sia-testing test:package
|
|
|
206
198
|
pnpm --filter @lumeweb/sia-testing test:consumers
|
|
207
199
|
```
|
|
208
200
|
|
|
209
|
-
Consumer checks extract and execute the complete README tests against the packed public exports in `node`, `jsdom`, and `happy-dom`. Each environment runs six ordinary tests
|
|
201
|
+
Consumer checks extract and execute the complete README tests against the packed public exports in `node`, `jsdom`, and `happy-dom`. Each environment runs six ordinary tests, covering the recipes, assertion-failure cleanup, and one Fetch and MSW transport smoke, then two expected timeout failures that check cancellation and cleanup. The checked combination is Node 26.13.0, Vitest 4.1.9, jsdom 29.1.1, happy-dom 20.10.6, and MSW 2.14.6. These checks do not certify other versions, browser providers, or native storage compatibility.
|
|
210
202
|
|
|
211
|
-
The scoped Chromium tests also exercise same-origin iframe-created byte views and abort signals. They check fixture bytes, managed metadata, application upload metadata acceptance, pin metadata capture, and held-read cancellation before reader cleanup through direct mocks and loopback Fetch. These tests import the public source facades through Vite
|
|
203
|
+
The scoped Chromium tests also exercise same-origin iframe-created byte views and abort signals. They check fixture bytes, managed metadata, application upload metadata acceptance, pin metadata capture, and held-read cancellation before reader cleanup, through direct mocks and loopback Fetch. These tests import the public source facades through Vite rather than the packed exports, and the empty scoped page does not initialize the storage SDK. This coverage does not establish other browser families, workers, cross-origin frames, or native storage behavior.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumeweb/sia-testing",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Fixtures and a mock Sia backend for testing an app without a network",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@siafoundation/sia-storage": "0.2.0",
|
|
44
44
|
"msw": "^2.14.6",
|
|
45
|
-
"vitest": "^
|
|
45
|
+
"vitest": "^5.1.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependenciesMeta": {
|
|
48
48
|
"@siafoundation/sia-storage": {
|
|
@@ -60,19 +60,20 @@
|
|
|
60
60
|
"@playwright/test": "^1.61.1",
|
|
61
61
|
"@siafoundation/sia-storage": "0.2.0",
|
|
62
62
|
"@types/node": "^26.1.0",
|
|
63
|
-
"@vitest/browser-playwright": "^
|
|
63
|
+
"@vitest/browser-playwright": "^5.1.2",
|
|
64
64
|
"happy-dom": "^20.10.6",
|
|
65
65
|
"jsdom": "29.1.1",
|
|
66
66
|
"msw": "^2.14.6",
|
|
67
67
|
"tsdown": "0.22.3",
|
|
68
68
|
"typescript": "^6.0.3",
|
|
69
69
|
"vite": "8.0.16",
|
|
70
|
-
"vitest": "^
|
|
70
|
+
"vitest": "^5.1.2",
|
|
71
71
|
"@lumeweb/tsdown-config": "0.0.0"
|
|
72
72
|
},
|
|
73
73
|
"repository": {
|
|
74
74
|
"type": "git",
|
|
75
|
-
"url": "https://github.com/LumeWeb/web"
|
|
75
|
+
"url": "https://github.com/LumeWeb/web",
|
|
76
|
+
"directory": "libs/sia-testing"
|
|
76
77
|
},
|
|
77
78
|
"publishConfig": {
|
|
78
79
|
"access": "public"
|