feat: add fetchCanisterLogs method to PocketIc - #235
Open
yasumorishima wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds first-class support in the PocketIc client for retrieving canister log records via the management canister fetch_canister_logs query, enabling programmatic access to logs useful for debugging timers/heartbeats.
Changes:
- Added Candid IDL encode/decode and TypeScript types for the management canister
fetch_canister_logsAPI. - Introduced public
FetchCanisterLogsOptionsandCanisterLogRecordtypes and a newPocketIc.fetchCanisterLogs()method usingeffectivePrincipal: { canisterId }. - Added a test-canister
print_logmethod and new Jest tests validating log retrieval and the empty-logs case.
Reviewed changes
Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/pic/src/management-canister.ts | Adds IDL record types and encode/decode helpers for fetch_canister_logs. |
| packages/pic/src/pocket-ic-types.ts | Exposes new public option/record types for the feature. |
| packages/pic/src/pocket-ic.ts | Implements PocketIc.fetchCanisterLogs() and maps response fields to public types. |
| packages/pic/tests/src/fetchCanisterLogs.spec.ts | Adds coverage for fetching logs and handling empty logs. |
| packages/pic/tests/test-canister/main.mo | Adds print_log method to emit log output from the test canister. |
| packages/pic/tests/test-canister/test_canister.did | Updates DID to include the new print_log method. |
| packages/pic/tests/test-canister/declarations/test_canister.did.js | Regenerates JS DID bindings including print_log. |
| packages/pic/tests/test-canister/declarations/test_canister.did.d.ts | Regenerates TS DID typings including print_log. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+874
to
+877
| public async fetchCanisterLogs({ | ||
| canisterId, | ||
| sender = Principal.anonymous(), | ||
| }: FetchCanisterLogsOptions): Promise<CanisterLogRecordPublic[]> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
fetchCanisterLogs()method to thePocketIcclass, implementing thefetch_canister_logsmanagement 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 forfetch_canister_logspocket-ic-types.ts: AddFetchCanisterLogsOptionsandCanisterLogRecordpublic typespocket-ic.ts: AddfetchCanisterLogs()method that makes a query call to the management canister witheffectivePrincipalset to the target canistermain.mo: Addprint_logmethod to test canister for testingfetchCanisterLogs.spec.ts: Add 2 test cases (fetch logs afterDebug.print+ empty logs for fresh canister)Implementation notes
effectivePrincipal: { canisterId }as required by the IC spec for management canister queriestimestamp_nanostotimestampNanosin the public type to follow the project's camelCase conventionTest plan
pnpm run buildpassespnpm run test:pic— all 13 tests pass (11 existing + 2 new)pnpm run format:checkpasses