diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..552305f --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,26 @@ +## Testing + +- Use `cargo test` to run all tests in this workspace +- To run the full suite of tests CI will run, see `scripts/ci-local.py`. +- Before commiting run `cargo fmt` and `cargo clippy`, as well as `cd decoder && cargo fmt && cargo clippy`. YOU MUST FIX CLIPPY ERRORS. + +## Finishing Up +When instructed to "finish up", follow this process: + +1. Run `cargo +nightly fmt --all` to format all code +2. Run `cargo clippy --workspace --all-features -- -D warnings` and fix all errors +3. Fix any small issues found. For big issues, confirm with the user first +4. Amend changes into the most recent commit: `git add -A && git commit --amend --no-edit` +5. Push: `git push --force-with-lease` +6. Monitor CI on GitHub to ensure it passes. If it fails: + - Analyze why the issue was missed + - Update the pre-CI checks to catch similar issues + - Fix the problem and repeat from step 1 + +Note: For a full local CI check matching what runs on GitHub, use `scripts/ci-local.py` + +Helpful commands for monitoring CI: +- Check PR status: `gh pr checks ` +- Watch until completion: `gh pr checks --watch` (refreshes every 10s, exits when done) +- View with details: `gh pr view --json statusCheckRollup --jq '.statusCheckRollup[] | "\(.name): \(.status) - \(.conclusion)"'` + diff --git a/decoder/src/main.rs b/decoder/src/main.rs index 5b3b7f1..9462892 100644 --- a/decoder/src/main.rs +++ b/decoder/src/main.rs @@ -565,7 +565,7 @@ fn poll_event_from_user_event( Some(PollEventKey { tid: thread_id as u32, clock_start: (start_time_ticks as u64).saturating_sub(duration), - duration: duration as u64, + duration, }) } else { None diff --git a/scripts/ci-local.py b/scripts/ci-local.py new file mode 100755 index 0000000..23525ae --- /dev/null +++ b/scripts/ci-local.py @@ -0,0 +1,55 @@ +#!/usr/bin/python3 + +import os +import subprocess +import yaml +import shlex +import shutil + +def runcmd(cmd, cwd='.', extra_env=None, shell=False): + if extra_env: + env = os.environ.copy() + env.update(extra_env) + else: + env = None + print(f'cd {cwd} && {cmd}') + subprocess.check_call(cmd, cwd=cwd, env=env, shell=shell) + +def run_integration_tests(y): + print('Running integration tests') + runcmd(shlex.split('cargo +stable build --all-features --verbose --example simple --example pollcatch-without-agent'), + extra_env=y['jobs']['build-for-testing']['env']) + shutil.copy('./target/debug/examples/simple', './tests/simple') + shutil.copy('./target/debug/examples/pollcatch-without-agent', './tests/pollcatch-without-agent') + shutil.copy('./decoder/target/debug/pollcatch-decoder', './tests/pollcatch-decoder') + for action in y['jobs']['test']['steps']: + if action.get('shell') == 'bash': + runcmd(action['run'], shell=True, cwd=action.get('working-directory', '.')) + +def main(): + y = yaml.safe_load(open('.github/workflows/build.yml')) + build = y['jobs']['build'] + for ek,ev in build['env'].items(): + os.environ[ek] = str(ev) + + # Decoder + runcmd(['cargo', f'+nightly', 'fmt', '--all'], cwd='./decoder') + runcmd(['cargo', f'+nightly', 'clippy', '--workspace', '--all-features', '--', '-D', 'warnings'], cwd='./decoder') + runcmd(['cargo', '+nightly', 'test'], cwd='./decoder') + runcmd(['cargo', '+nightly', 'build'], cwd='./decoder') + + # Main + runcmd(['cargo', f'+nightly', 'fmt', '--all']) + runcmd(['cargo', f'+nightly', 'clippy', '--workspace', '--all-features', '--', '-D', 'warnings']) + for toolchain in build['strategy']['matrix']['toolchain']: + for flags in build['strategy']['matrix']['flags']: + runcmd(['cargo', f'+{toolchain}', 'build', '--verbose'] + shlex.split(flags)) + runcmd(['cargo', f'+{toolchain}', 'test', '--verbose'] + shlex.split(flags)) + runcmd(['cargo', '+nightly', 'doc', '--verbose', '--no-deps'], extra_env={'RUSTDOCFLAGS': '-D warnings --cfg docsrs'}) + + run_integration_tests(y) + + print('All tests successful!') + +if __name__ == '__main__': + main() diff --git a/tests/integration.sh b/tests/integration.sh index 884d8e1..100b3e4 100755 --- a/tests/integration.sh +++ b/tests/integration.sh @@ -28,7 +28,7 @@ found_good=0 for profile in $dir/*.jfr; do duration=$(./pollcatch-decoder duration "$profile") # Ignore "partial" profiles of less than 8s - if [[ $duration > 8 ]]; then + if ! (( $(echo "${duration}<8" | bc) )); then found_good=1 else echo "Profile $profile is too short" diff --git a/tests/separate_runtime_integration.sh b/tests/separate_runtime_integration.sh index d21ba83..8fcc011 100755 --- a/tests/separate_runtime_integration.sh +++ b/tests/separate_runtime_integration.sh @@ -19,7 +19,7 @@ found_good=0 for profile in $dir/*.jfr; do duration=$(./pollcatch-decoder duration "$profile") # Ignore "partial" profiles of less than 2s - if [[ $duration > 2 ]]; then + if ! (( $(echo "${duration}<2" | bc) )); then found_good=1 else echo "Profile $profile is too short"