Skip to content

Commit ea50cde

Browse files
authored
feat: add CLI integration tests
2 parents 73d847f + c2b49d8 commit ea50cde

File tree

87 files changed

+720
-71
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+720
-71
lines changed

.github/workflows/cli-test.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: CLI Integration Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'src.ts/**'
8+
- 'package.json'
9+
- 'pnpm-lock.yaml'
10+
- '.github/workflows/cli-test.yml'
11+
pull_request:
12+
branches: [main]
13+
paths:
14+
- 'src.ts/**'
15+
- 'package.json'
16+
- 'pnpm-lock.yaml'
17+
- '.github/workflows/cli-test.yml'
18+
workflow_dispatch:
19+
20+
jobs:
21+
user-scenario-test:
22+
name: User Test (Node ${{ matrix.node-version }} / ${{ matrix.pkg-manager }})
23+
runs-on: ubuntu-latest
24+
25+
strategy:
26+
matrix:
27+
node-version: [20.x, 22.x]
28+
pkg-manager: [npm, yarn, pnpm]
29+
fail-fast: false
30+
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@v4
34+
35+
- name: Setup pnpm (for building)
36+
uses: pnpm/action-setup@v2
37+
with:
38+
version: 9.15.4
39+
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: ${{ matrix.node-version }}
44+
cache: 'pnpm'
45+
46+
- name: Build and pack project
47+
run: |
48+
pnpm install --frozen-lockfile
49+
pnpm build
50+
pnpm pack
51+
52+
- name: Setup test environment
53+
run: |
54+
mkdir -p /tmp/user-test
55+
cd /tmp/user-test
56+
cp $GITHUB_WORKSPACE/*.tgz ./package.tgz
57+
58+
- name: Setup package manager
59+
run: |
60+
if [ "${{ matrix.pkg-manager }}" = "yarn" ]; then
61+
corepack enable
62+
corepack prepare yarn@stable --activate
63+
elif [ "${{ matrix.pkg-manager }}" = "pnpm" ]; then
64+
npm install -g pnpm@9.15.4
65+
fi
66+
67+
- name: Test package installation and CLI
68+
working-directory: /tmp/user-test
69+
run: |
70+
# Initialize test project
71+
npm init -y
72+
73+
# Install our package with peer dependencies
74+
case "${{ matrix.pkg-manager }}" in
75+
npm)
76+
npm install ./package.tgz @types/crypto-js@4.2.2 crypto-js@4.2.0 ethers@6.13.1
77+
;;
78+
yarn)
79+
yarn add ./package.tgz @types/crypto-js@4.2.2 crypto-js@4.2.0 ethers@6.13.1
80+
;;
81+
pnpm)
82+
pnpm add ./package.tgz @types/crypto-js@4.2.2 crypto-js@4.2.0 ethers@6.13.1
83+
;;
84+
esac
85+
86+
# Test CLI commands using local binary
87+
if [ -f "./node_modules/.bin/0g-compute-cli" ]; then
88+
# npm/yarn classic with node_modules/.bin
89+
./node_modules/.bin/0g-compute-cli --version
90+
./node_modules/.bin/0g-compute-cli --help
91+
./node_modules/.bin/0g-compute-cli inference --help
92+
./node_modules/.bin/0g-compute-cli show-network || echo "Network command tested"
93+
elif [ "${{ matrix.pkg-manager }}" = "yarn" ]; then
94+
# yarn 4+ with PnP mode
95+
yarn run 0g-compute-cli --version
96+
yarn run 0g-compute-cli --help
97+
yarn run 0g-compute-cli inference --help
98+
yarn run 0g-compute-cli show-network || echo "Network command tested"
99+
else
100+
echo "CLI binary not found"
101+
exit 1
102+
fi
103+
env:
104+
ZG_RPC_ENDPOINT: https://evmrpc-testnet.0g.ai
105+
106+
test-summary:
107+
name: Test Summary
108+
runs-on: ubuntu-latest
109+
needs: [user-scenario-test]
110+
if: always()
111+
112+
steps:
113+
- name: Check test results
114+
run: |
115+
if [ "${{ needs.user-scenario-test.result }}" == "success" ]; then
116+
echo "✅ All CLI user scenario tests passed!"
117+
echo "- User installation scenarios: ✅"
118+
else
119+
echo "❌ User scenario tests failed:"
120+
echo "- User scenarios: ${{ needs.user-scenario-test.result }}"
121+
exit 1
122+
fi

.npmrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Node version enforcement
2+
# Set to false to allow installation with warnings on incompatible Node versions
3+
# Set to true to strictly enforce Node >= 20.0.0
4+
engine-strict=false
5+
6+
# Peer dependencies handling
7+
# Automatically installs peer dependencies (ethers, crypto-js, etc.)
8+
auto-install-peers=true
9+
10+
# Recommended package manager for development
11+
# While we recommend pnpm for development, the package works with any package manager
12+
# pnpm version: 9.15.4

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
This document provides an overview of the 0G Serving Broker, including setup and usage instructions.
66

7+
## Requirements
8+
9+
- Node.js >= 20.0.0
10+
711
## Setup and Usage
812

913
To integrate the 0G Serving Broker into your project, follow these steps
@@ -13,9 +17,18 @@ To integrate the 0G Serving Broker into your project, follow these steps
1317
To get started, you need to install the `@0glabs/0g-serving-broker` package:
1418

1519
```bash
20+
# Using npm
21+
npm install @0glabs/0g-serving-broker @types/crypto-js@4.2.2 crypto-js@4.2.0
22+
23+
# Using yarn
24+
yarn add @0glabs/0g-serving-broker @types/crypto-js@4.2.2 crypto-js@4.2.0
25+
26+
# Using pnpm (recommended for development)
1627
pnpm add @0glabs/0g-serving-broker @types/crypto-js@4.2.2 crypto-js@4.2.0
1728
```
1829

30+
**Note for Contributors**: This project uses pnpm@9.15.4 for development. If you're contributing to this project, please use pnpm. For regular users installing as a dependency, any package manager works.
31+
1932
### Step 2: Initialize a Broker Instance
2033

2134
The broker instance is initialized with a `signer`. This signer is an instance that implements the `JsonRpcSigner` or `Wallet` interface from the ethers package and is used to sign transactions for a specific Ethereum account. You can create this instance using your private key via the ethers library or use a wallet framework tool like [wagmi](https://wagmi.sh/react/guides/ethers) to initialize the signer.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export {};
2+
//# sourceMappingURL=cli.integration.test.d.ts.map

cli.commonjs/cli/__tests__/cli.integration.test.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)