Skip to content

Commit 30958fb

Browse files
authored
test: add gateway conformance tests (#67)
* feat: initial gateway-conformance setup * feat: basic subdomain and path requests work * docs: add debug instructions * feat: multiple changes and fixes to lint/dep-check * chore: trying to get passing tests to run is a PITA * fix: split up conformance tests so its not one big long run * fix: longer spec test timeout and more accurate fail/pass count * chore: ensure test:node script exists * feat: making progress on conformance test running * feat: gateway-conformance tests are running and passing locally NOTE: we are failing actual conformance tests, but the tests here ensure no regressions * tmp: fix for #68 * feat: use gateway-conformance cmd instead of docker * feat: create github action for running gateway conformance * fix: gateway conformance action working dir * fix: remove test:node script so tests aren't run with others because additional setup is required * fix: json formatting * fix: tighten up expectations with minSuccesses * fix: gateway conformance action syntax is correct * fix: gwc can npm install deps * chore: gwc gh action caches node modules * fix: remove mkdir * chore: update actions/upload-artifact * test: explicit counts for default gwc specs * chore: apply suggestions from code review * test: support IPFS_NS_MAP fixtures * chore: various fixes * test: disable ipfs_ns_map in CI
1 parent 754e219 commit 30958fb

21 files changed

+1257
-0
lines changed
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Gateway Conformance
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
jobs:
11+
gateway-conformance:
12+
runs-on: ubuntu-latest
13+
steps:
14+
# 1, Setup Node, install npm dependencies, and build all packages/*
15+
# see https://github.com/ipdxco/unified-github-workflows/blob/3a1a7870ce5967163d8f5c8210b8ad50b2e659aa/.github/workflows/js-test-and-release.yml#L28-L34
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: lts/*
20+
- uses: ipfs/aegir/actions/cache-node-modules@master
21+
22+
# 2. Set up 'go' so we can install the gateway-conformance binary
23+
- name: Setup Go
24+
uses: actions/setup-go@v4
25+
with:
26+
go-version: 1.21.x
27+
28+
# 3. Download the gateway-conformance fixtures using ipfs/gateway-conformance action
29+
# This will prevent us from needing to install `docker` on the github runner
30+
- name: Download gateway-conformance fixtures
31+
uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.5.1
32+
# working-directory: ./packages/gateway-conformance
33+
with:
34+
output: ./packages/gateway-conformance/dist/src/fixtures/data/gateway-conformance-fixtures
35+
36+
37+
# 4. Run the tests
38+
- name: Run gateway-conformance tests
39+
run: |
40+
npm run test
41+
working-directory: ./packages/gateway-conformance
42+
43+
# 5. Convert json output to reports similar to how it's done at https://github.com/ipfs/gateway-conformance/blob/main/.github/actions/test/action.yml
44+
# the 'gwc-report-all.json' file is created by the 'has expected total failures and successes' test
45+
# TODO: remove this when we're passing enough tests to use the 'ipfs/gateway-conformance/.github/actions/test' action
46+
- name: Create the XML
47+
if: failure() || success()
48+
uses: pl-strflt/gotest-json-to-junit-xml@v1
49+
with:
50+
input: ./packages/gateway-conformance/gwc-report-all.json
51+
output: ./packages/gateway-conformance/gwc-report-all.xml
52+
- name: Create the HTML
53+
if: failure() || success()
54+
uses: pl-strflt/junit-xml-to-html@v1
55+
with:
56+
mode: no-frames
57+
input: ./packages/gateway-conformance/gwc-report-all.xml
58+
output: ./packages/gateway-conformance/gwc-report-all.html
59+
- name: Create the Markdown
60+
if: failure() || success()
61+
uses: pl-strflt/junit-xml-to-html@v1
62+
with:
63+
mode: summary
64+
input: ./packages/gateway-conformance/gwc-report-all.xml
65+
output: ./packages/gateway-conformance/gwc-report-all.md
66+
67+
# 6. Upload the reports
68+
- name: Upload MD summary
69+
if: failure() || success()
70+
run: cat ./packages/gateway-conformance/gwc-report-all.md >> $GITHUB_STEP_SUMMARY
71+
- name: Upload HTML report
72+
if: failure() || success()
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: gateway-conformance.html
76+
path: ./packages/gateway-conformance/gwc-report-all.html
77+
- name: Upload JSON report
78+
if: failure() || success()
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: gateway-conformance.json
82+
path: ./packages/gateway-conformance/gwc-report-all.json
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// @ts-check
2+
import getPort from 'aegir/get-port'
3+
4+
/** @type {import('aegir').PartialOptions} */
5+
export default {
6+
test: {
7+
files: ['./dist/src/*.spec.js'],
8+
before: async (options) => {
9+
if (options.runner !== 'node') {
10+
throw new Error('Only node runner is supported')
11+
}
12+
13+
const { GWC_IMAGE } = await import('./dist/src/constants.js')
14+
const { loadKuboFixtures, kuboRepoDir } = await import('./dist/src/fixtures/kubo-mgmt.js')
15+
const IPFS_NS_MAP = await loadKuboFixtures()
16+
17+
const { createKuboNode } = await import('./dist/src/fixtures/create-kubo.js')
18+
const controller = await createKuboNode(await getPort(3440))
19+
await controller.start()
20+
const kuboGateway = `http://${controller.api.gatewayHost}:${controller.api.gatewayPort}`
21+
22+
const { startBasicServer } = await import('./dist/src/fixtures/basic-server.js')
23+
const SERVER_PORT = await getPort(3441)
24+
const stopBasicServer = await startBasicServer({
25+
serverPort: SERVER_PORT,
26+
kuboGateway
27+
})
28+
29+
const { startReverseProxy } = await import('./dist/src/fixtures/reverse-proxy.js')
30+
const PROXY_PORT = await getPort(3442)
31+
const KUBO_PORT = controller.api.gatewayPort
32+
const stopReverseProxy = await startReverseProxy({
33+
backendPort: SERVER_PORT,
34+
targetHost: 'localhost',
35+
proxyPort: PROXY_PORT
36+
})
37+
38+
const CONFORMANCE_HOST = 'localhost'
39+
40+
return {
41+
controller,
42+
stopReverseProxy,
43+
stopBasicServer,
44+
env: {
45+
IPFS_NS_MAP,
46+
GWC_IMAGE,
47+
CONFORMANCE_HOST,
48+
KUBO_PORT: `${KUBO_PORT}`,
49+
PROXY_PORT: `${PROXY_PORT}`,
50+
SERVER_PORT: `${SERVER_PORT}`,
51+
KUBO_GATEWAY: kuboGateway,
52+
KUBO_REPO: process.env.KUBO_REPO || kuboRepoDir
53+
}
54+
}
55+
},
56+
after: async (options, beforeResult) => {
57+
// @ts-expect-error - broken aegir types
58+
await beforeResult.stopReverseProxy()
59+
// @ts-expect-error - broken aegir types
60+
await beforeResult.stopBasicServer()
61+
// @ts-expect-error - broken aegir types
62+
await beforeResult.controller.stop()
63+
}
64+
}
65+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gwc-report*.json

packages/gateway-conformance/CHANGELOG.md

Whitespace-only changes.

packages/gateway-conformance/LICENSE

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This project is dual licensed under MIT and Apache-2.0.
2+
3+
MIT: https://www.opensource.org/licenses/mit
4+
Apache-2.0: https://www.apache.org/licenses/license-2.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
2+
3+
http://www.apache.org/licenses/LICENSE-2.0
4+
5+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<p align="center">
2+
<a href="https://github.com/ipfs/helia" title="Helia">
3+
<img src="https://raw.githubusercontent.com/ipfs/helia/main/assets/helia.png" alt="Helia logo" width="300" />
4+
</a>
5+
</p>
6+
7+
# @helia/verified-fetch-gateway-conformance
8+
9+
[![ipfs.tech](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](https://ipfs.tech)
10+
[![Discuss](https://img.shields.io/discourse/https/discuss.ipfs.tech/posts.svg?style=flat-square)](https://discuss.ipfs.tech)
11+
[![codecov](https://img.shields.io/codecov/c/github/ipfs/helia-verified-fetch.svg?style=flat-square)](https://codecov.io/gh/ipfs/helia-verified-fetch)
12+
[![CI](https://img.shields.io/github/actions/workflow/status/ipfs/helia-verified-fetch/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/ipfs/helia-verified-fetch/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
13+
14+
> [Gateway Conformance](https://github.com/ipfs/gateway-conformance) tests for @helia/verified-fetch
15+
16+
# About
17+
18+
Runs Gateway Conformance tests against @helia/verified-fetch using Kubo as a backing trustless-gateway.
19+
20+
## Example - Testing a new Kubo release
21+
22+
```console
23+
$ npm i @helia/verified-fetch-gateway-conformance
24+
$ KUBO_BINARY=/path/to/kubo verified-fetch-gateway-conformance
25+
```
26+
27+
# Install
28+
29+
```console
30+
$ npm i @helia/verified-fetch-gateway-conformance
31+
```
32+
33+
## Browser `<script>` tag
34+
35+
Loading this module through a script tag will make it's exports available as `HeliaInterop` in the global namespace.
36+
37+
```html
38+
<script src="https://unpkg.com/@helia/verified-fetch-gateway-conformance/dist/index.min.js"></script>
39+
```
40+
41+
# License
42+
43+
Licensed under either of
44+
45+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
46+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
47+
48+
# Contribute
49+
50+
Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia-verified-fetch/issues).
51+
52+
Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.
53+
54+
Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
55+
56+
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
57+
58+
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"name": "@helia/verified-fetch-gateway-conformance",
3+
"version": "1.20.0",
4+
"description": "Gateway conformance tests for @helia/verified-fetch",
5+
"license": "Apache-2.0 OR MIT",
6+
"homepage": "https://github.com/ipfs/helia-verified-fetch/tree/main/packages/gateway-conformance#readme",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/ipfs/helia-verified-fetch.git"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/ipfs/helia-verified-fetch/issues"
13+
},
14+
"publishConfig": {
15+
"access": "public",
16+
"provenance": true
17+
},
18+
"keywords": [
19+
"IPFS"
20+
],
21+
"bin": {
22+
"demo-server": "./dist/src/demo-server.js",
23+
"verified-fetch-gateway-conformance": "./dist/src/bin.js"
24+
},
25+
"type": "module",
26+
"types": "./dist/src/index.d.ts",
27+
"files": [
28+
"src",
29+
"dist",
30+
"!dist/test",
31+
"!**/*.tsbuildinfo"
32+
],
33+
"exports": {
34+
".": {
35+
"types": "./dist/src/index.d.ts",
36+
"import": "./dist/src/index.js"
37+
}
38+
},
39+
"eslintConfig": {
40+
"extends": "ipfs",
41+
"parserOptions": {
42+
"project": true,
43+
"sourceType": "module"
44+
}
45+
},
46+
"scripts": {
47+
"clean": "aegir clean dist gwc-report-*.json",
48+
"lint": "aegir lint",
49+
"dep-check": "aegir dep-check",
50+
"doc-check": "aegir doc-check",
51+
"build": "aegir build",
52+
"test": "aegir test -t node"
53+
},
54+
"dependencies": {
55+
"@helia/verified-fetch": "1.3.13",
56+
"@libp2p/logger": "^4.0.11",
57+
"@sgtpooki/file-type": "^1.0.1",
58+
"aegir": "^42.2.5",
59+
"execa": "^8.0.1",
60+
"glob": "^10.3.12",
61+
"ipfsd-ctl": "^13.0.0",
62+
"kubo": "^0.27.0",
63+
"kubo-rpc-client": "^3.0.4",
64+
"undici": "^6.15.0"
65+
},
66+
"browser": {
67+
"./dist/src/fixtures/create-kubo.js": "./dist/src/fixtures/create-kubo.browser.js",
68+
"kubo": false
69+
}
70+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env node
2+
/* eslint-disable no-console */
3+
4+
import { spawn } from 'node:child_process'
5+
import { dirname, resolve } from 'node:path'
6+
import { fileURLToPath } from 'node:url'
7+
8+
// aegir should be run from `node_modules/@helia/verified-fetch-gateway-conformance`
9+
const cwd = resolve(dirname(fileURLToPath(import.meta.url)), '../../')
10+
11+
const test = spawn('npx', ['aegir', 'test'], {
12+
cwd
13+
})
14+
15+
test.stdout.on('data', (data) => {
16+
process.stdout.write(data)
17+
})
18+
19+
test.stderr.on('data', (data) => {
20+
process.stderr.write(data)
21+
})
22+
23+
test.on('close', (code) => {
24+
process.exit(code ?? 0)
25+
})

0 commit comments

Comments
 (0)