Skip to content

Comments

feat: add fetchCanisterLogs method to PocketIc#235

Open
yasumorishima wants to merge 1 commit intodfinity:mainfrom
yasumorishima:feat/fetch-canister-logs
Open

feat: add fetchCanisterLogs method to PocketIc#235
yasumorishima wants to merge 1 commit intodfinity:mainfrom
yasumorishima:feat/fetch-canister-logs

Conversation

@yasumorishima
Copy link

Summary

Adds a fetchCanisterLogs() method to the PocketIc class, implementing the fetch_canister_logs management canister query call.

This allows users to programmatically retrieve canister log records, which is especially useful for debugging traps in timers and heartbeats that are otherwise invisible.

Closes #68

Changes

  • management-canister.ts: Add Candid IDL types, TypeScript interfaces, and encode/decode functions for fetch_canister_logs
  • pocket-ic-types.ts: Add FetchCanisterLogsOptions and CanisterLogRecord public types
  • pocket-ic.ts: Add fetchCanisterLogs() method that makes a query call to the management canister with effectivePrincipal set to the target canister
  • main.mo: Add print_log method to test canister for testing
  • fetchCanisterLogs.spec.ts: Add 2 test cases (fetch logs after Debug.print + empty logs for fresh canister)

Implementation notes

  • Follows the same pattern as the Rust library implementation
  • Uses effectivePrincipal: { canisterId } as required by the IC spec for management canister queries
  • The caller must be a controller of the target canister (anonymous principal is rejected)
  • Maps timestamp_nanos to timestampNanos in the public type to follow the project's camelCase convention

Test plan

  • pnpm run build passes
  • pnpm run test:pic — all 13 tests pass (11 existing + 2 new)
  • pnpm run format:check passes
  • e2e tests pass (Node.js + Bun, ubuntu + macos)

@yasumorishima yasumorishima requested a review from a team as a code owner February 13, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error messages from trap in timers not showing

1 participant