Skip to content

Commit ff757b2

Browse files
committed
Add local ICP end-to-end test
1 parent 3697e52 commit ff757b2

3 files changed

Lines changed: 140 additions & 1 deletion

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node_modules/
33
scripts/*
44
!scripts/test.mjs
55
!scripts/smoke.mjs
6+
!scripts/e2e-icp-local.sh
67
!scripts/test-phase-1-icp-canister.sh
78
npm-debug.log*
89
yarn-debug.log*
@@ -37,4 +38,4 @@ Desktop.ini
3738
# Archives / misc
3839
*.zip
3940
*.tgz
40-
.codex
41+
.codex

packages/icp-canister/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ All notable changes to the ICP canister adapter will be documented in this file.
1515
- Phase 3 local `dfx` example under `examples/icp-knowledge-canister`, including a minimal `dfx.json`, sample pack generator, upload script, query script, and checked-in demo knowledge files.
1616
- Phase 4 browser frontend under `examples/icp-knowledge-canister/frontend`, using a direct Vite React client with `@dfinity/agent` and no middleware API route.
1717
- Phase 5 `knolo icp` CLI commands for local ICP init, pack build, upload, and query flows, plus a bundled ICP scaffold template shipped with `@knolo/cli`.
18+
- Phase 6 local ICP end-to-end script at `scripts/e2e-icp-local.sh`, covering Rust builds, `dfx` startup and deploy, sample pack upload, lexical query assertion, and clean replica shutdown.
1819

1920
### Changed
2021
- Added the `knolo_icp.did` interface definition for the new canister package.

scripts/e2e-icp-local.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
EXAMPLE_DIR="$ROOT/examples/icp-knowledge-canister"
6+
CORE_MANIFEST="$ROOT/packages/core-rust/Cargo.toml"
7+
CANISTER_MANIFEST="$ROOT/packages/icp-canister/Cargo.toml"
8+
PACK_PATH="$EXAMPLE_DIR/dist/knowledge.knolo"
9+
DFX_BIN="${DFX_BIN:-dfx}"
10+
DFX_DATA_HOME="${DFX_DATA_HOME:-}"
11+
DFX_STARTED=0
12+
DFX_DATA_HOME_CREATED=0
13+
DFX_TERM="${DFX_TERM:-xterm-256color}"
14+
15+
log() {
16+
echo "[e2e] $*"
17+
}
18+
19+
cleanup() {
20+
if [ "$DFX_STARTED" -eq 1 ]; then
21+
log "Stop dfx"
22+
(
23+
cd "$EXAMPLE_DIR"
24+
TERM="$DFX_TERM" XDG_DATA_HOME="$DFX_DATA_HOME" "$DFX_RUN_BIN" stop >/dev/null 2>&1 || true
25+
)
26+
fi
27+
28+
if [ "$DFX_DATA_HOME_CREATED" -eq 1 ] && [ -n "$DFX_DATA_HOME" ]; then
29+
rm -rf "$DFX_DATA_HOME"
30+
fi
31+
}
32+
33+
trap cleanup EXIT
34+
35+
if ! command -v "$DFX_BIN" >/dev/null 2>&1; then
36+
echo "[e2e] Missing dfx binary: $DFX_BIN" >&2
37+
exit 1
38+
fi
39+
40+
if ! command -v cargo >/dev/null 2>&1; then
41+
echo "[e2e] Missing cargo" >&2
42+
exit 1
43+
fi
44+
45+
if ! command -v node >/dev/null 2>&1; then
46+
echo "[e2e] Missing node" >&2
47+
exit 1
48+
fi
49+
50+
if ! command -v npm >/dev/null 2>&1; then
51+
echo "[e2e] Missing npm" >&2
52+
exit 1
53+
fi
54+
55+
if [ ! -d "$EXAMPLE_DIR" ]; then
56+
echo "[e2e] Example directory not found: $EXAMPLE_DIR" >&2
57+
exit 1
58+
fi
59+
60+
if [ -z "$DFX_DATA_HOME" ]; then
61+
DFX_DATA_HOME="$(mktemp -d "${TMPDIR:-/tmp}/knolo-dfx-data-XXXXXX")"
62+
DFX_DATA_HOME_CREATED=1
63+
fi
64+
65+
DFX_VERSION="$("$DFX_BIN" --version | awk '{print $2}')"
66+
DFX_VERSIONED_BIN="$HOME/.local/share/dfx/versions/$DFX_VERSION/dfx"
67+
DFX_RUN_BIN="$DFX_BIN"
68+
69+
if [ -x "$DFX_VERSIONED_BIN" ]; then
70+
DFX_RUN_BIN="$DFX_VERSIONED_BIN"
71+
fi
72+
73+
mkdir -p "$DFX_DATA_HOME"
74+
75+
run_dfx() {
76+
TERM="$DFX_TERM" XDG_DATA_HOME="$DFX_DATA_HOME" "$DFX_RUN_BIN" "$@"
77+
}
78+
79+
log "Build Rust core"
80+
cargo build --manifest-path "$CORE_MANIFEST"
81+
82+
log "Test Rust core"
83+
cargo test --manifest-path "$CORE_MANIFEST"
84+
85+
log "Build ICP canister"
86+
cargo build --target wasm32-unknown-unknown --release --manifest-path "$CANISTER_MANIFEST"
87+
88+
log "Test ICP canister"
89+
cargo test --manifest-path "$CANISTER_MANIFEST"
90+
91+
log "Start dfx"
92+
(
93+
cd "$EXAMPLE_DIR"
94+
run_dfx start --background --clean
95+
)
96+
DFX_STARTED=1
97+
98+
log "Deploy canister"
99+
(
100+
cd "$EXAMPLE_DIR"
101+
run_dfx deploy
102+
)
103+
104+
log "Build sample pack"
105+
(
106+
cd "$EXAMPLE_DIR"
107+
node scripts/build-sample-pack.mjs
108+
)
109+
110+
if [ ! -f "$PACK_PATH" ]; then
111+
echo "[e2e] Expected pack output at $PACK_PATH" >&2
112+
exit 1
113+
fi
114+
115+
log "Upload pack"
116+
(
117+
cd "$EXAMPLE_DIR"
118+
DFX_BIN="$DFX_RUN_BIN" TERM="$DFX_TERM" XDG_DATA_HOME="$DFX_DATA_HOME" bash scripts/upload-pack.sh
119+
)
120+
121+
log "Query canister"
122+
OUT="$(
123+
cd "$EXAMPLE_DIR"
124+
DFX_BIN="$DFX_RUN_BIN" TERM="$DFX_TERM" XDG_DATA_HOME="$DFX_DATA_HOME" bash scripts/query.sh "alpha beta"
125+
)"
126+
printf '%s\n' "$OUT"
127+
128+
if [ -z "$OUT" ]; then
129+
echo "[e2e] Search result was empty" >&2
130+
exit 1
131+
fi
132+
133+
echo "$OUT" | grep -q '"text"'
134+
echo "$OUT" | grep -qi "alpha"
135+
echo "$OUT" | grep -qi "beta"
136+
137+
log "OK"

0 commit comments

Comments
 (0)