Skip to content

Commit 5f9736f

Browse files
authored
Merge branch 'master' into jack/crp-2550
2 parents 348e2cd + 1406b99 commit 5f9736f

File tree

401 files changed

+13785
-5520
lines changed

Some content is hidden

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

401 files changed

+13785
-5520
lines changed

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.5.1
1+
8.6.0

.claude/CLAUDE.md

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,54 @@
1-
Rust
2-
====
3-
4-
After changing Rust code (`*.rs`) first format the code using:
5-
6-
```
7-
cargo fmt -- <MODIFIED_RUST_FILES>
8-
````
9-
10-
Then check the code for linting errors using:
11-
12-
```
13-
cargo clippy --all-features --workspace --all-targets -- \
14-
-D warnings \
15-
-D clippy::all \
16-
-D clippy::mem_forget \
17-
-C debug-assertions=off \
18-
-A clippy::uninlined_format_args
19-
```
20-
21-
Fix any linting errors before continuing with building and testing.
22-
23-
24-
Building
25-
--------
26-
27-
Rust code is built using both `cargo build` and Bazel.
28-
29-
After changing a package under `rs/$PACKAGE` run `bazel build //rs/$PACKAGE`.
30-
31-
32-
Changing crate dependencies
33-
---------------------------
34-
35-
If crate dependencies need to be changed or added:
36-
37-
1. First modify the `Cargo.toml` local to the package.
38-
2. If a crate is used by multiple packages add it to the workspace `Cargo.toml` in the root of the repo and reference it in the `Cargo.toml` local to the package using `{ workspace = true }`.
39-
3. Add the crate to `bazel/rust.MODULE.bazel`.
40-
4. Run a `cargo check` such that the `Cargo.lock` files get updated.
41-
5. Run `bin/bazel-pin.sh --force` to sync `Cargo.lock` with `Cargo.Bazel.json.lock`.
42-
43-
44-
Testing
45-
=======
46-
47-
After code can be built it needs to be tested.
48-
49-
After changing a package under `rs/$PACKAGE` run `bazel test //rs/$PACKAGE`.
1+
# General
2+
3+
All commands should be run from the repository root (`/ic`).
4+
5+
# Rust
6+
7+
After changing Rust code (`*.rs`) follow these steps in order:
8+
9+
1. **Format** by running the following from the root of the repository:
10+
```
11+
cd "$(git rev-parse --show-toplevel)"
12+
rustfmt <MODIFIED_RUST_FILES>
13+
```
14+
where `<MODIFIED_RUST_FILES>` is a space separated list of paths of all modified Rust files relative to the root of the repository.
15+
2. **Lint** by running the following from the root of the repository:
16+
```
17+
cd "$(git rev-parse --show-toplevel)"
18+
cargo clippy --all-features <CRATES> -- \
19+
-D warnings \
20+
-D clippy::all \
21+
-D clippy::mem_forget \
22+
-A clippy::uninlined_format_args
23+
```
24+
where `<CRATES>` is a space separated list of
25+
`-p <CRATE>` options for all modified crates.
26+
e.g., `-p ic-crypto -p ic-types` if both were modified.
27+
Run a single clippy invocation covering all modified crates.
28+
29+
To determine the crate name, check the `name` field in the nearest
30+
ancestor `Cargo.toml` relative to the modified file.
31+
32+
Fix any linting errors.
33+
3. **Build** the directly affected bazel targets by running the following from the root of the repository:
34+
```
35+
cd "$(git rev-parse --show-toplevel)"
36+
TARGETS="$(bazel query 'kind(rule, rdeps(//..., set(<MODIFIED_FILES>), 1))' --keep_going 2>/dev/null)"
37+
if [ -n "$TARGETS" ]; then
38+
bazel build $TARGETS
39+
fi
40+
```
41+
where `<MODIFIED_FILES>` is a space separated list of paths of all modified files relative to the root of the repository.
42+
43+
Fix all build errors.
44+
4. **Test** the directly affected bazel tests by running the following from the root of the repository:
45+
```
46+
cd "$(git rev-parse --show-toplevel)"
47+
TESTS="$(bazel query 'kind(".*_test|test_suite", kind(rule, rdeps(//..., set(<MODIFIED_FILES>), 2)))' --keep_going 2>/dev/null)"
48+
if [ -n "$TESTS" ]; then
49+
bazel test --test_output=errors $TESTS
50+
fi
51+
```
52+
(Use a depth of 2 in `rdeps` because tests usually depend on source files indirectly through a `rust_library` for example).
53+
54+
Fix all test failures.

.claude/skills/fix-flaky-tests/SKILL.md

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,78 @@ description: Use this when asked to fix flaky bazel tests.
55

66
This guide explains how to find flaky tests to fix and how to debug them. Flaky tests are bazel tests that run on GitHub workflows that pass after having failed in a previous attempt.
77

8-
1. Make sure you're on an up-to-date `master` branch to make sure you're using and reading the latest code:
8+
# Prerequisites
9+
10+
1. Make sure you're on an up-to-date `master` branch to ensure you're using and reading the latest code:
911
```
1012
git checkout master && git pull
1113
```
1214

13-
2. Determine which flaky bazel test to fix by picking the most flaky test in the last week which has not yet been fixed. To do this:
15+
2. Run `gh auth status` to check if `gh` is authenticated with `github.com` using `Git operations protocol: ssh`.
16+
17+
If not run:
18+
```
19+
gh auth login --hostname github.com --git-protocol ssh --skip-ssh-key --web
20+
```
21+
This prints a one-time device code and a URL. Instruct the user to open the URL in their browser and enter the code.
22+
23+
**Do not** use the bare `gh auth login` command, as the interactive prompts are unreliable when run from an AI agent.
1424

15-
1. Run the following command to get the top 10 tests ordered by the number of times they flaked in the last week:
25+
# Fix a flaky test
26+
27+
1. If not instructed to fix a test with a specified `label` determine which test to fix by picking the most flaky test in the last week which has not yet been fixed. To do this:
28+
29+
1. Run the following command to get the top 100 tests ordered descendingly by how much percent of their total runs they flaked in the last week, showing only tests which flaked 1% or more of their runs:
1630
```
17-
bazel run //ci/githubstats:query -- top 10 flaky --week
31+
bazel run //ci/githubstats:query -- top 100 flaky% --ge 1 --week
32+
```
33+
34+
2. Pick the `label` of the top most test which doesn't have an open PR or git commit in the last week mentioning its `<test_name>` which is the part of the `label` after the `:`.
35+
36+
`<test_name>` might be suffixed with `_head_nns` or `_colocate` which are variants of the same test. Strip those suffixes when checking for open PRs or commits to avoid missing matches.
37+
38+
To check if there is an open PR mentioning the test, run the following command
39+
(replace underscores with spaces because GitHub search doesn't match underscored compound words):
40+
```
41+
gh pr list --search "$(echo '<test_name>' | tr '_' ' ')" --state open
1842
```
19-
2. Pick the `label` of the top most test which doesn't have an open PR or git commit in the last week mentioning its `<test_name>` which is the part of the `label` after the `:`. Also strip `_head_nns` or `_colocate` from the `<test_name>` to get a more fuzzy match.
2043
2144
To check if there is a git commit mentioning the test, run the following command:
2245
```
23-
git log --since 'last week' | grep <test_name>
46+
git log --oneline --since 'last week' | grep "$(echo '<test_name>' | tr '_' '.')"
2447
```
48+
2549
Continue with the next test if you find an open PR or commit mentioning `<test_name>`
2650
even if it seems the commit is not about fixing flakiness.
2751
It's better to pick a test which has no other work being done on it to avoid conflicts.
2852
29-
3. Get the last flaky runs of the test named `label` in the last week by running the following command, replacing `<label>` with the label of the test:
53+
2. Get the last flaky runs of the test named `label` in the last week by running the following command, replacing `<label>` with the label of the test:
3054
```
3155
bazel run //ci/githubstats:query -- last --flaky --week --download-ic-logs --download-console-logs <label>
3256
```
3357
Note the command will print `Downloading logs to: <LOG_DIR>`.
3458
35-
The directory `<LOG_DIR>` will contain an "invocation" directory, named like `<bazel_invocation_timestamp>_<bazel_invocation_id>`,
36-
per bazel invocation that had a flaky run of the test.
59+
Read `<LOG_DIR>/README.md` to understand how the logs are organized.
3760
38-
That invocation directory will have a directory per attempt of the test, named like `1`, `2`, `3`, etc.
61+
3. Analyze the source code of `label` and the logs in `<LOG_DIR>` to determine the root cause of the flakiness.
3962
40-
Each attempt directory will either contain a `FAILED.log` or `PASSED.log` file with the log of the test if the attempt failed or passed, respectively.
63+
4. Once you have determined the root cause,
64+
fix the test taking `.claude/CLAUDE.md` into account.
4165
42-
In case the test was a system-test, i.e. when the `label` starts with `//rs/tests/`, the attempt directory will also contain:
43-
* an `ic_logs` directory containing the logs of IC nodes that were deployed as part of the test.
44-
Each IC node will have its own log file named `<node_id>.log` and there will be a symlink pointing to it with the IPv6 of the node: `<node_IPv6>.log`.
45-
* a `console_logs` directory containing a `<vm_name>.log` file for each VM deployed as part of the test containing the console output of that VM. Often `<vm_name>` equals `<node_id>`.
46-
47-
4. Analyze the source code of `label` and the logs in `<LOG_DIR>` to determine the root cause of the flakiness.
48-
49-
5. Once you have determined the root cause, fix the test.
66+
5. Verify the test still passes by running:
67+
```
68+
bazel test --test_output=errors --runs_per_test=3 --jobs=3 <label>
69+
```
70+
This executes 3 runs of the test in parallel to increase the chances of reproducing the flakiness. If it fails, analyze the failure and fix it until it passes reliably.
5071
51-
6. Run `bazel test <label>` to verify the test still passes.
72+
6. Make a draft Pull Request with the fix, following these steps:
5273
53-
7. Create a new git branch named like `ai/deflake-<test_name>`, replacing `<test_name>` with the name of the test
54-
and commit your fix to that branch.
74+
1. From the root of the repository, create a new git branch named `ai/deflake-<test_name>-<date>`,
75+
replacing `<test_name>` with the name of the test
76+
and `<date>` with the current date in `YYYY-MM-DD` format,
77+
and commit your fix to that branch.
5578
56-
8. Submit a draft PR with the fix.
57-
Name it: `fix: deflake <label>`.
58-
Include the root cause analysis in the PR description and link to this `SKILL.md` file.
79+
2. Submit a draft PR using `gh` with the fix.
80+
Name it: `fix: deflake <label>`.
81+
Include the root cause analysis in the PR description
82+
and mention the PR was created following the steps in `.claude/skills/fix-flaky-tests/SKILL.md`.

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"image": "ghcr.io/dfinity/ic-build@sha256:62ef680d95901d1c191442d2a5f382315ed4b916e97a81335c8d13baba2fe30d",
2+
"image": "ghcr.io/dfinity/ic-dev@sha256:fe06783d9cf8e9fc901a5996d9fc8b726f15769f2fd6bd86969d1fbbf77ae025",
33
"remoteUser": "ubuntu",
44
"privileged": true,
55
"runArgs": [

.github/CODEOWNERS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ go.sum @dfinity/idx
137137
/rs/interfaces/ @dfinity/ic-interface-owners
138138
/rs/interfaces/adapter_client/ @dfinity/consensus
139139
/rs/interfaces/certified_stream_store/ @dfinity/team-dsm
140-
/rs/interfaces/mocks/src/payload_builder @dfinity/consensus
140+
/rs/interfaces/mocks/src/consensus_pool.rs @dfinity/consensus
141+
/rs/interfaces/mocks/src/crypto.rs @dfinity/consensus
142+
/rs/interfaces/mocks/src/payload_builder.rs @dfinity/consensus
141143
/rs/interfaces/registry/ @dfinity/governance-team
142144
/rs/interfaces/src/canister_http.rs @dfinity/consensus
143145
/rs/interfaces/src/consensus.rs @dfinity/consensus

.github/actions/bazel/action.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ runs:
6565
run: |
6666
set -euo pipefail
6767
68-
# Set up .netrc so that bazel can authenticate with GitHub to have higher rate limits for fetching dependencies.
69-
touch ~/.netrc
70-
chmod 600 ~/.netrc
71-
echo "machine github.com login x-access-token password ${{ github.token }}" > ~/.netrc
72-
echo "machine api.github.com login x-access-token password ${{ github.token }}" >> ~/.netrc
73-
echo "Current GitHub API rate limits:"
74-
curl -s --netrc https://api.github.com/rate_limit | jq '.resources.core'
75-
7668
# Here we overwrite the PATH with our custom bazel wrapper to ensure
7769
# the specified commands are run with the CI-specific options included
7870
# in the wrapper.

.github/actions/netrc/action.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 'GitHub Authentication with netrc'
2+
description: Set up authentication in netrc using github token. Picked up by tools like Bazel.
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
# write netrc to $HOME
8+
- shell: bash
9+
run: |
10+
# Set up .netrc so that tools can authenticate with GitHub to have higher rate limits for fetching dependencies.
11+
touch ~/.netrc
12+
chmod 600 ~/.netrc
13+
echo "machine github.com login x-access-token password ${{ github.token }}" > ~/.netrc
14+
echo "machine api.github.com login x-access-token password ${{ github.token }}" >> ~/.netrc
15+
echo "Current GitHub API rate limits:"
16+
17+
# Show how close we are to the limits (ignore errors from curl or invalid JSON)
18+
curl -sf --netrc https://api.github.com/rate_limit 2>/dev/null | \
19+
jq -r '.resources.core | "Rate limit remaining: \(.remaining)/\(.limit) (resets at \(.reset | strftime("%Y-%m-%d %H:%M:%S %Z")))"' 2>/dev/null \
20+
|| echo "Could not retrieve rate limit information"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: API BN Recovery Test
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 6 * * 1' # weekly on Monday at 06:00 UTC
7+
pull_request:
8+
paths:
9+
- '.github/workflows/api-bn-recovery-test.yml'
10+
- 'ic-os/api-bn-recovery/**'
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
14+
cancel-in-progress: true
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
test:
21+
name: API BN Recovery Smoke Test
22+
runs-on:
23+
labels: dind-large
24+
container:
25+
image: ghcr.io/dfinity/ic-build@sha256:18d23aef1f5e9e7e1eef94c32563f8ed15531ae79065bb00bb5206a643fc49fe
26+
options: >-
27+
-e NODE_NAME --privileged --cgroupns host
28+
--mount type=tmpfs,target="/home/buildifier/.local/share/containers"
29+
timeout-minutes: 15
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
- uses: ./.github/actions/netrc
34+
35+
- name: Install dfx
36+
run: |
37+
DFXVM_INIT_YES=1 sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
38+
echo "$HOME/.local/share/dfx/bin" >> "$GITHUB_PATH"
39+
40+
- name: Run smoke test
41+
uses: ./.github/actions/bazel
42+
with:
43+
run: ./ic-os/api-bn-recovery/test.sh

0 commit comments

Comments
 (0)